Files
PolyphiaGame/Scripts/Singleton/GameItem.cs
T
2025-12-17 19:13:10 -08:00

56 lines
2.0 KiB
C#

using System;
using System.Collections.Generic;
using Godot;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
public class GameItem {
public GameItem(int ItemId) {
this.ItemID = ItemId;
this.Guid = Guid.NewGuid();
this.InventoryObject = new InventoryItem();
}
public int ItemID { get; } // Overall ItemID
public Guid Guid { get; } // In Game ItemID
public InventoryItem InventoryObject { get; } // Reference to the items dynamic stats
public Node GameObject { get; set; } // Reference to the GameObject
public Panel InventoryFrame { get; set; } // Reference to the UI Panel
public static List<StatItem> _ItemStats; // Global reference to the list of items stats
public StatItem ItemStats { get { // Reference to the items static stats
foreach ( StatItem cur in _ItemStats) {
if (cur.ItemID == ItemID) {
return cur;
}
}
return null;
}
}
}
public class StatItem {
public static void LoadItemStats() {
using var file = FileAccess.Open("res://Scripts/ItemStats.yaml", FileAccess.ModeFlags.Read);
string Contents = file.GetAsText();
var deserializer = new DeserializerBuilder().WithNamingConvention(PascalCaseNamingConvention.Instance).Build();
GameItem._ItemStats = deserializer.Deserialize<List<StatItem>>(Contents);
}
public int ItemID { get; }
public string ItemName { get; }
public Vector2I InventorySize { get; }
public int InventoryWeight { get; }
public bool IsQuantityItem { get; }
public int MaxQuantity { get; }
public string ToolPath { get; }
public int ToolDamage { get; }
}
public class InventoryItem {
public Vector2I GridPosition { get; set; }
public bool Rotated { get; set; }
public int Quantity { get; set; }
}