Clean up the code and fill in the comments

This commit is contained in:
霧雨烨 2024-06-13 14:13:55 +08:00
parent 229098b261
commit 9561b46e1b
6 changed files with 27 additions and 44 deletions

View File

@ -44,12 +44,6 @@ public partial class Packsack : RigidBody2D, IItem
public override void _Ready() public override void _Ready()
{ {
base._Ready(); base._Ready();
// Id = GetMeta("ID", "1").AsString();
// Quantity = GetMeta("Quantity", "1").AsInt32();
// MaxStackQuantity = GetMeta("MaxStackQuantity", Config.MaxStackQuantity).AsInt32();
// Icon = GetMeta("Icon", "").As<Texture2D>();
// Name = GetMeta("Name", "").AsString();
// Description = GetMeta("Description", "").AsString();
_itemContainer = new UniversalItemContainer(); _itemContainer = new UniversalItemContainer();
} }

View File

@ -8,18 +8,22 @@ public readonly struct ItemType(string id, Func<IItem> newItemFunc, Texture2D? i
{ {
/// <summary> /// <summary>
/// <para>Item id of this type</para> /// <para>Item id of this type</para>
/// <para>该类型物品的id</para>
/// </summary> /// </summary>
public string Id { get; init; } = id; public string Id { get; init; } = id;
/// <summary> /// <summary>
/// <para>A function returns a new item instance of this type</para> /// <para>A function returns a new item instance of this type</para>
/// <para>用于创建该类型的物品实例的函数</para>
/// </summary> /// </summary>
public Func<IItem> NewItemFunc { get; init; } = newItemFunc; public Func<IItem> NewItemFunc { get; init; } = newItemFunc;
/// <summary> /// <summary>
/// <para>Default icon of items of this type</para> /// <para>Default icon of items of this type</para>
/// <para>该类型物品的默认图标</para>
/// </summary> /// </summary>
public Texture2D? Icon { get; init; } = icon; public Texture2D? Icon { get; init; } = icon;
/// <summary> /// <summary>
/// <para>Max number in item stack of this type</para> /// <para>Max number in item stack of this type</para>
/// <para>该类型物品的最大堆叠数量</para>
/// </summary> /// </summary>
public int MaxStackQuantity { get; init; } = maxStackQuantity; public int MaxStackQuantity { get; init; } = maxStackQuantity;
} }

View File

@ -8,7 +8,9 @@ namespace ColdMint.scripts.item;
public static class ItemTypeManager public static class ItemTypeManager
{ {
// Register items statically here /// <summary>
/// Register items statically here
/// </summary>
public static void StaticRegister() public static void StaticRegister()
{ {
var staffOfTheUndeadScene = ResourceLoader.Load<PackedScene>("res://prefab/weapons/staffOfTheUndead.tscn"); var staffOfTheUndeadScene = ResourceLoader.Load<PackedScene>("res://prefab/weapons/staffOfTheUndead.tscn");

View File

@ -11,31 +11,44 @@ public interface IItemStack
{ {
/// <summary> /// <summary>
/// <para>Max number of current stack</para> /// <para>Max number of current stack</para>
/// <para>当前物品堆的最大物品数量</para>
/// </summary> /// </summary>
int MaxQuantity { get; } int MaxQuantity { get; }
/// <summary> /// <summary>
/// <para>Quantity of current stack</para> /// <para>Quantity of current stack</para>
/// <para>当前物品堆的物品数量</para>
/// </summary> /// </summary>
int Quantity { get; } int Quantity { get; }
/// <summary> /// <summary>
/// <para>True if this stack is empty</para> /// <para>True if this stack is empty</para>
/// <para>当物品堆空时为真</para>
/// </summary> /// </summary>
/// <remarks>
/// <para>
/// This attribute is used to check if the item stack is empty after the operation for subsequent processing,<br/>
/// i.e. there should not be any item stacks with this attribute true outside of the operation process
/// </para>
/// <para>此属性用于检查操作后该物品堆是否为空以便后续处理也就是说在操作过程以外的时候不应当存在任何该属性为true的物品堆</para>
/// </remarks>
bool Empty { get; } bool Empty { get; }
/// <summary> /// <summary>
/// <para>Icon of current item</para> /// <para>Icon of current item stack</para>
/// <para>当前物品堆显示的图标</para>
/// </summary> /// </summary>
Texture2D Icon { get; } Texture2D Icon { get; }
/// <summary> /// <summary>
/// <para>Display name of current item</para> /// <para>Display name of current item stack</para>
/// <para>当前物品堆显示的名称</para>
/// </summary> /// </summary>
string Name { get; } string Name { get; }
/// <summary> /// <summary>
/// <para>Description of current item, which may show in inventory</para> /// <para>Description of current item stack, which may show in inventory</para>
/// <para>当前物品堆的描述,可能显示在物品栏中</para>
/// </summary> /// </summary>
string? Description { get; } string? Description { get; }
@ -126,12 +139,14 @@ public interface IItemStack
public int RemoveItem(int number); public int RemoveItem(int number);
/// <summary> /// <summary>
/// <para>Clear current stack, which means should dispose all items inside current stack here</para> /// <para>Clear current stack, which means should remove all items inside current stack from the game here</para>
/// <para>清除当前物品堆,意味着从游戏中移除当前堆中的所有物品</para>。
/// </summary> /// </summary>
public void ClearStack(); public void ClearStack();
/// <summary> /// <summary>
/// Create a new ItemStack with the given item as the first item /// <para>Create a new ItemStack with the given item as the first item</para>
/// <para>以给定的物品为第一个物品创建物品堆</para>
/// </summary> /// </summary>
public static IItemStack FromItem(IItem item) => public static IItemStack FromItem(IItem item) =>
item.SpecialStack() ?? item.SpecialStack() ??

View File

@ -24,14 +24,6 @@ public partial class ProjectileWeapon : WeaponTemplate
/// </summary> /// </summary>
private Marker2D? _marker2D; private Marker2D? _marker2D;
// /// <summary>
// /// <para>List of projectiles</para>
// /// <para>抛射体列表</para>
// /// </summary>
// private string[]? _projectiles;
//
// private Dictionary<string, PackedScene>? _projectileCache;
[Export] protected PackedScene[] ProjectileScenes { get; set; } = []; [Export] protected PackedScene[] ProjectileScenes { get; set; } = [];
private Node2D? _projectileContainer; private Node2D? _projectileContainer;
@ -41,19 +33,6 @@ public partial class ProjectileWeapon : WeaponTemplate
base._Ready(); base._Ready();
_marker2D = GetNode<Marker2D>("Marker2D"); _marker2D = GetNode<Marker2D>("Marker2D");
// _projectileCache = new Dictionary<string, PackedScene>();
// _projectiles = GetMeta("Projectiles", "").AsStringArray();
// foreach (var projectileItem in _projectiles)
// {
// var packedScene = GD.Load<PackedScene>(projectileItem);
// if (packedScene == null)
// {
// continue;
// }
//
// _projectileCache.Add(projectileItem, packedScene);
// }
_projectileContainer = GetNode("/root/Game/ProjectileContainer") as Node2D; _projectileContainer = GetNode("/root/Game/ProjectileContainer") as Node2D;
} }

View File

@ -104,17 +104,6 @@ public abstract partial class WeaponTemplate : RigidBody2D, IItem
_damageArea2D.BodyEntered += OnBodyEnter; _damageArea2D.BodyEntered += OnBodyEnter;
_damageArea2D.BodyExited += OnBodyExited; _damageArea2D.BodyExited += OnBodyExited;
// Id = GetMeta("ID", "1").AsString();
// Quantity = GetMeta("Quantity", "1").AsInt32();
// MaxStackQuantity = GetMeta("MaxStackQuantity", Config.MaxStackQuantity).AsInt32();
// Icon = GetMeta("Icon", "").As<Texture2D>();
// 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); _firingInterval = TimeSpan.FromMilliseconds(_firingIntervalAsMillisecond);
} }