Clean up the code and fill in the comments
This commit is contained in:
parent
229098b261
commit
9561b46e1b
|
@ -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<Texture2D>();
|
||||
// Name = GetMeta("Name", "").AsString();
|
||||
// Description = GetMeta("Description", "").AsString();
|
||||
_itemContainer = new UniversalItemContainer();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,18 +8,22 @@ public readonly struct ItemType(string id, Func<IItem> newItemFunc, Texture2D? i
|
|||
{
|
||||
/// <summary>
|
||||
/// <para>Item id of this type</para>
|
||||
/// <para>该类型物品的id</para>
|
||||
/// </summary>
|
||||
public string Id { get; init; } = id;
|
||||
/// <summary>
|
||||
/// <para>A function returns a new item instance of this type</para>
|
||||
/// <para>用于创建该类型的物品实例的函数</para>
|
||||
/// </summary>
|
||||
public Func<IItem> NewItemFunc { get; init; } = newItemFunc;
|
||||
/// <summary>
|
||||
/// <para>Default icon of items of this type</para>
|
||||
/// <para>该类型物品的默认图标</para>
|
||||
/// </summary>
|
||||
public Texture2D? Icon { get; init; } = icon;
|
||||
/// <summary>
|
||||
/// <para>Max number in item stack of this type</para>
|
||||
/// <para>该类型物品的最大堆叠数量</para>
|
||||
/// </summary>
|
||||
public int MaxStackQuantity { get; init; } = maxStackQuantity;
|
||||
}
|
|
@ -8,7 +8,9 @@ namespace ColdMint.scripts.item;
|
|||
|
||||
public static class ItemTypeManager
|
||||
{
|
||||
// Register items statically here
|
||||
/// <summary>
|
||||
/// Register items statically here
|
||||
/// </summary>
|
||||
public static void StaticRegister()
|
||||
{
|
||||
var staffOfTheUndeadScene = ResourceLoader.Load<PackedScene>("res://prefab/weapons/staffOfTheUndead.tscn");
|
||||
|
|
|
@ -11,31 +11,44 @@ public interface IItemStack
|
|||
{
|
||||
/// <summary>
|
||||
/// <para>Max number of current stack</para>
|
||||
/// <para>当前物品堆的最大物品数量</para>
|
||||
/// </summary>
|
||||
int MaxQuantity { get; }
|
||||
|
||||
/// <summary>
|
||||
/// <para>Quantity of current stack</para>
|
||||
/// <para>当前物品堆的物品数量</para>
|
||||
/// </summary>
|
||||
int Quantity { get; }
|
||||
|
||||
/// <summary>
|
||||
/// <para>True if this stack is empty</para>
|
||||
/// <para>当物品堆空时为真</para>
|
||||
/// </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; }
|
||||
|
||||
/// <summary>
|
||||
/// <para>Icon of current item</para>
|
||||
/// <para>Icon of current item stack</para>
|
||||
/// <para>当前物品堆显示的图标</para>
|
||||
/// </summary>
|
||||
Texture2D Icon { get; }
|
||||
|
||||
/// <summary>
|
||||
/// <para>Display name of current item</para>
|
||||
/// <para>Display name of current item stack</para>
|
||||
/// <para>当前物品堆显示的名称</para>
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
|
||||
/// <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>
|
||||
string? Description { get; }
|
||||
|
||||
|
@ -126,12 +139,14 @@ public interface IItemStack
|
|||
public int RemoveItem(int number);
|
||||
|
||||
/// <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>
|
||||
public void ClearStack();
|
||||
|
||||
/// <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>
|
||||
public static IItemStack FromItem(IItem item) =>
|
||||
item.SpecialStack() ??
|
||||
|
|
|
@ -24,14 +24,6 @@ public partial class ProjectileWeapon : WeaponTemplate
|
|||
/// </summary>
|
||||
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; } = [];
|
||||
|
||||
private Node2D? _projectileContainer;
|
||||
|
@ -41,19 +33,6 @@ public partial class ProjectileWeapon : WeaponTemplate
|
|||
base._Ready();
|
||||
_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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user