Refactor all gameItem into one object for easier stats
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
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; }
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bbkc7kal5blnf
|
||||
@@ -1,36 +0,0 @@
|
||||
using Godot;
|
||||
|
||||
public partial class ItemStats : Node {
|
||||
|
||||
// Item 0
|
||||
public StatItem[] stats = {
|
||||
new StatItem{
|
||||
ItemName = "Sniper",
|
||||
InventorySize = new Vector2I(1, 4),
|
||||
Weight = 400,
|
||||
IsQuantityItem = false,
|
||||
ToolPath = "res://Prefab/Tools/Sniper.tscn",
|
||||
ToolDamage = 50
|
||||
},
|
||||
|
||||
// Item 1
|
||||
new StatItem{
|
||||
|
||||
},
|
||||
|
||||
// Item 2
|
||||
new StatItem{
|
||||
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
public class StatItem {
|
||||
public string ItemName {get; set;} = "";
|
||||
public Vector2I InventorySize {get; set;}
|
||||
public int Weight {get; set;}
|
||||
public bool IsQuantityItem {get; set;}
|
||||
public int MaxQuantity {get; set;}
|
||||
public string ToolPath {get; set;}
|
||||
public int ToolDamage { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Godot;
|
||||
|
||||
public partial class Pickup : RigidBody3D {
|
||||
|
||||
[Export]
|
||||
public int ItemID {get; set;}
|
||||
|
||||
[Export]
|
||||
public int Quantity {get; set;}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://c5ea6nx28rvxv
|
||||
Reference in New Issue
Block a user