From 9561b46e1baba9786457189d423d0d9611ec9f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9C=A7=E9=9B=A8=E7=83=A8?= Date: Thu, 13 Jun 2024 14:13:55 +0800 Subject: [PATCH] Clean up the code and fill in the comments --- scripts/inventory/Packsack.cs | 6 ------ scripts/item/ItemType.cs | 4 ++++ scripts/item/ItemTypeManager.cs | 4 +++- scripts/item/itemStacks/IItemStack.cs | 25 ++++++++++++++++++++----- scripts/item/weapon/ProjectileWeapon.cs | 21 --------------------- scripts/item/weapon/WeaponTemplate.cs | 11 ----------- 6 files changed, 27 insertions(+), 44 deletions(-) diff --git a/scripts/inventory/Packsack.cs b/scripts/inventory/Packsack.cs index 3e2a42b..99b61a1 100644 --- a/scripts/inventory/Packsack.cs +++ b/scripts/inventory/Packsack.cs @@ -44,12 +44,6 @@ public partial class Packsack : RigidBody2D, IItem public override void _Ready() { base._Ready(); - // Id = GetMeta("ID", "1").AsString(); - // Quantity = GetMeta("Quantity", "1").AsInt32(); - // MaxStackQuantity = GetMeta("MaxStackQuantity", Config.MaxStackQuantity).AsInt32(); - // Icon = GetMeta("Icon", "").As(); - // Name = GetMeta("Name", "").AsString(); - // Description = GetMeta("Description", "").AsString(); _itemContainer = new UniversalItemContainer(); } diff --git a/scripts/item/ItemType.cs b/scripts/item/ItemType.cs index d12b93a..01ac9b8 100644 --- a/scripts/item/ItemType.cs +++ b/scripts/item/ItemType.cs @@ -8,18 +8,22 @@ public readonly struct ItemType(string id, Func newItemFunc, Texture2D? i { /// /// Item id of this type + /// 该类型物品的id /// public string Id { get; init; } = id; /// /// A function returns a new item instance of this type + /// 用于创建该类型的物品实例的函数 /// public Func NewItemFunc { get; init; } = newItemFunc; /// /// Default icon of items of this type + /// 该类型物品的默认图标 /// public Texture2D? Icon { get; init; } = icon; /// /// Max number in item stack of this type + /// 该类型物品的最大堆叠数量 /// public int MaxStackQuantity { get; init; } = maxStackQuantity; } \ No newline at end of file diff --git a/scripts/item/ItemTypeManager.cs b/scripts/item/ItemTypeManager.cs index c2e116d..4d35cfa 100644 --- a/scripts/item/ItemTypeManager.cs +++ b/scripts/item/ItemTypeManager.cs @@ -8,7 +8,9 @@ namespace ColdMint.scripts.item; public static class ItemTypeManager { - // Register items statically here + /// + /// Register items statically here + /// public static void StaticRegister() { var staffOfTheUndeadScene = ResourceLoader.Load("res://prefab/weapons/staffOfTheUndead.tscn"); diff --git a/scripts/item/itemStacks/IItemStack.cs b/scripts/item/itemStacks/IItemStack.cs index 8e77872..34d8fce 100644 --- a/scripts/item/itemStacks/IItemStack.cs +++ b/scripts/item/itemStacks/IItemStack.cs @@ -11,31 +11,44 @@ public interface IItemStack { /// /// Max number of current stack + /// 当前物品堆的最大物品数量 /// int MaxQuantity { get; } /// /// Quantity of current stack + /// 当前物品堆的物品数量 /// int Quantity { get; } /// /// True if this stack is empty + /// 当物品堆空时为真 /// + /// + /// + /// This attribute is used to check if the item stack is empty after the operation for subsequent processing,
+ /// i.e. there should not be any item stacks with this attribute true outside of the operation process + ///
+ /// 此属性用于检查操作后该物品堆是否为空以便后续处理,也就是说在操作过程以外的时候不应当存在任何该属性为true的物品堆 + ///
bool Empty { get; } /// - /// Icon of current item + /// Icon of current item stack + /// 当前物品堆显示的图标 /// Texture2D Icon { get; } /// - /// Display name of current item + /// Display name of current item stack + /// 当前物品堆显示的名称 /// string Name { get; } /// - /// Description of current item, which may show in inventory + /// Description of current item stack, which may show in inventory + /// 当前物品堆的描述,可能显示在物品栏中 /// string? Description { get; } @@ -126,12 +139,14 @@ public interface IItemStack public int RemoveItem(int number); /// - /// Clear current stack, which means should dispose all items inside current stack here + /// Clear current stack, which means should remove all items inside current stack from the game here + /// 清除当前物品堆,意味着从游戏中移除当前堆中的所有物品。 /// public void ClearStack(); /// - /// Create a new ItemStack with the given item as the first item + /// Create a new ItemStack with the given item as the first item + /// 以给定的物品为第一个物品创建物品堆 /// public static IItemStack FromItem(IItem item) => item.SpecialStack() ?? diff --git a/scripts/item/weapon/ProjectileWeapon.cs b/scripts/item/weapon/ProjectileWeapon.cs index 323caa2..a8394e0 100644 --- a/scripts/item/weapon/ProjectileWeapon.cs +++ b/scripts/item/weapon/ProjectileWeapon.cs @@ -24,14 +24,6 @@ public partial class ProjectileWeapon : WeaponTemplate /// private Marker2D? _marker2D; - // /// - // /// List of projectiles - // /// 抛射体列表 - // /// - // private string[]? _projectiles; - // - // private Dictionary? _projectileCache; - [Export] protected PackedScene[] ProjectileScenes { get; set; } = []; private Node2D? _projectileContainer; @@ -41,19 +33,6 @@ public partial class ProjectileWeapon : WeaponTemplate base._Ready(); _marker2D = GetNode("Marker2D"); - // _projectileCache = new Dictionary(); - // _projectiles = GetMeta("Projectiles", "").AsStringArray(); - // foreach (var projectileItem in _projectiles) - // { - // var packedScene = GD.Load(projectileItem); - // if (packedScene == null) - // { - // continue; - // } - // - // _projectileCache.Add(projectileItem, packedScene); - // } - _projectileContainer = GetNode("/root/Game/ProjectileContainer") as Node2D; } diff --git a/scripts/item/weapon/WeaponTemplate.cs b/scripts/item/weapon/WeaponTemplate.cs index d934fd7..77759f1 100644 --- a/scripts/item/weapon/WeaponTemplate.cs +++ b/scripts/item/weapon/WeaponTemplate.cs @@ -104,17 +104,6 @@ public abstract partial class WeaponTemplate : RigidBody2D, IItem _damageArea2D.BodyEntered += OnBodyEnter; _damageArea2D.BodyExited += OnBodyExited; - // Id = GetMeta("ID", "1").AsString(); - // Quantity = GetMeta("Quantity", "1").AsInt32(); - // MaxStackQuantity = GetMeta("MaxStackQuantity", Config.MaxStackQuantity).AsInt32(); - // Icon = GetMeta("Icon", "").As(); - // Name = GetMeta("Name", "").AsString(); - // Description = GetMeta("Description", "").AsString(); - // _firingInterval = TimeSpan.FromMilliseconds(GetMeta("FiringInterval", "100").AsInt64()); - // _minContactInjury = GetMeta("MinContactInjury", "1").AsInt32(); - // _maxContactInjury = GetMeta("MaxContactInjury", "2").AsInt32(); - // _recoil = GetMeta("Recoil", Vector2.Zero).AsVector2(); - _firingInterval = TimeSpan.FromMilliseconds(_firingIntervalAsMillisecond); }