Remove old item interfaces,rename new

移除旧的物品接口,重命名新的
This commit is contained in:
霧雨烨 2024-06-13 03:07:55 +08:00
parent 94a2e78efc
commit 23877e82cc
13 changed files with 36 additions and 117 deletions

View File

@ -271,7 +271,7 @@ public partial class CharacterTemplate : CharacterBody2D
{ {
//Empty reference checking is implicitly performed here. //Empty reference checking is implicitly performed here.
//此处隐式的执行了空引用检查。 //此处隐式的执行了空引用检查。
if (pickAbleItem is not IItem_New item) if (pickAbleItem is not IItem item)
{ {
return false; return false;
} }
@ -348,7 +348,7 @@ public partial class CharacterTemplate : CharacterBody2D
return false; return false;
} }
if (_currentItem is IItem_New item) if (_currentItem is IItem item)
{ {
item.Use(this, position); item.Use(this, position);
} }
@ -537,7 +537,7 @@ public partial class CharacterTemplate : CharacterBody2D
/// <param name="node"></param> /// <param name="node"></param>
protected virtual void EnterThePickingRangeBody(Node node) protected virtual void EnterThePickingRangeBody(Node node)
{ {
if (node is not IItem_New) if (node is not IItem)
{ {
return; return;
} }
@ -552,7 +552,7 @@ public partial class CharacterTemplate : CharacterBody2D
/// <param name="node"></param> /// <param name="node"></param>
protected virtual void ExitThePickingRangeBody(Node node) protected virtual void ExitThePickingRangeBody(Node node)
{ {
if (node is not IItem_New) if (node is not IItem)
{ {
return; return;
} }

View File

@ -1,22 +0,0 @@
using System;
using Godot;
namespace ColdMint.scripts.inventory;
/*
/// <summary>
/// <para>Common goods</para>
/// <para>普通的物品</para>
/// </summary>
public class CommonItem : IItem
{
public string? Id { get; set; }
public int Quantity { get; set; }
public int MaxStackQuantity { get; set; }
public Texture2D? Icon { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public Action<IItem>? OnUse { get; set; }
public Func<IItem, Node>? OnInstantiation { get; set; }
}
*/

View File

@ -1,58 +0,0 @@
using System;
using Godot;
namespace ColdMint.scripts.inventory;
/*
public interface IItem
{
/// <summary>
/// <para>Item and ID</para>
/// <para>物品还有ID</para>
/// </summary>
string? Id { get; set; }
/// <summary>
/// <para>Represents the quantity of this item</para>
/// <para>表示此物品的数量</para>
/// </summary>
int Quantity { get; set; }
/// <summary>
/// <para>How many can this item stack up to</para>
/// <para>这个物品最多叠加到多少个</para>
/// </summary>
int MaxStackQuantity { get; set; }
/// <summary>
/// <para>Items can be set with Icon</para>
/// <para>物品可以设置图标</para>
/// </summary>
Texture2D? Icon { get; set; }
/// <summary>
/// <para>Item has a name</para>
/// <para>物品有名称</para>
/// </summary>
string? Name { get; set; }
/// <summary>
/// <para>Description</para>
/// <para>描述</para>
/// </summary>
string? Description { get; set; }
/// <summary>
/// <para>When using items</para>
/// <para>当使用物品时</para>
/// </summary>
Action<IItem>? OnUse { get; set; }
/// <summary>
/// <para>When removing items from the backpack, instantiate them</para>
/// <para>当从背包内取出,实例化物品时</para>
/// </summary>
Func<IItem, Node>? OnInstantiation { get; set; }
}
*/

View File

@ -24,7 +24,7 @@ public interface IItemContainer
/// </summary> /// </summary>
/// <param name="item"></param> /// <param name="item"></param>
/// <returns></returns> /// <returns></returns>
bool CanAddItem(IItem_New item); bool CanAddItem(IItem item);
/// <summary> /// <summary>
/// <para>Implement methods for adding items</para> /// <para>Implement methods for adding items</para>
@ -32,7 +32,7 @@ public interface IItemContainer
/// </summary> /// </summary>
/// <param name="item"></param> /// <param name="item"></param>
/// <returns></returns> /// <returns></returns>
bool AddItem(IItem_New item); bool AddItem(IItem item);
/// <summary> /// <summary>
/// <para>Add an stack of items to this container</para> /// <para>Add an stack of items to this container</para>
@ -64,7 +64,7 @@ public interface IItemContainer
/// <para>如果存在,移除当前选中位置的槽位中的一个物品并将其返回</para> /// <para>如果存在,移除当前选中位置的槽位中的一个物品并将其返回</para>
/// </summary> /// </summary>
/// <seealso cref="PickItemFromItemSlot"/><seealso cref="PickItemsFromItemSlotBySelectIndex"/> /// <seealso cref="PickItemFromItemSlot"/><seealso cref="PickItemsFromItemSlotBySelectIndex"/>
IItem_New? PickItemFromItemSlotBySelectIndex(); IItem? PickItemFromItemSlotBySelectIndex();
/// <summary> /// <summary>
/// <para>Remove the specified number of items from the item slot at the currently selected location, and return them as a new item stack</para> /// <para>Remove the specified number of items from the item slot at the currently selected location, and return them as a new item stack</para>
@ -115,7 +115,7 @@ public interface IItemContainer
/// <para>如果存在,移除指定位置的槽位中的一个物品并将其返回</para> /// <para>如果存在,移除指定位置的槽位中的一个物品并将其返回</para>
/// </summary> /// </summary>
/// <seealso cref="PickItemsFromItemSlot"/> /// <seealso cref="PickItemsFromItemSlot"/>
IItem_New? PickItemFromItemSlot(int itemSlotIndex); IItem? PickItemFromItemSlot(int itemSlotIndex);
/// <summary> /// <summary>
/// <para>Remove the specified number of items from the item slot in the specified location, and return them as a new item stack</para> /// <para>Remove the specified number of items from the item slot in the specified location, and return them as a new item stack</para>
@ -157,7 +157,7 @@ public interface IItemContainer
/// <para>Return null if there is no slot to place the item in</para> /// <para>Return null if there is no slot to place the item in</para>
/// <para>若没有槽可放置此物品则返回null</para> /// <para>若没有槽可放置此物品则返回null</para>
/// </returns> /// </returns>
ItemSlotNode? Match(IItem_New item); ItemSlotNode? Match(IItem item);
/// <summary> /// <summary>
/// <para>Based on the given item stack, match the item slots where it can be added to</para> /// <para>Based on the given item stack, match the item slots where it can be added to</para>

View File

@ -50,14 +50,14 @@ public partial class ItemSlotNode : MarginContainer
/// <para>If present, get the item at the top of the item stack in this slot</para> /// <para>If present, get the item at the top of the item stack in this slot</para>
/// <para>如果存在,获取该槽位中物品堆顶部的物品</para> /// <para>如果存在,获取该槽位中物品堆顶部的物品</para>
/// </summary> /// </summary>
public IItem_New? GetItem() => _itemStack?.GetItem(); public IItem? GetItem() => _itemStack?.GetItem();
/// <summary> /// <summary>
/// <para>If present, remove an item in this slot and return it.</para> /// <para>If present, remove an item in this slot and return it.</para>
/// <para>如果存在,移除该槽位中的一个物品并将其返回</para> /// <para>如果存在,移除该槽位中的一个物品并将其返回</para>
/// </summary> /// </summary>
/// <seealso cref="PickItems"/> /// <seealso cref="PickItems"/>
public IItem_New? PickItem() public IItem? PickItem()
{ {
if (_itemStack is null) return null; if (_itemStack is null) return null;
@ -149,7 +149,7 @@ public partial class ItemSlotNode : MarginContainer
/// </summary> /// </summary>
/// <param name="item"></param> /// <param name="item"></param>
/// <returns></returns> /// <returns></returns>
public bool CanAddItem(IItem_New item) public bool CanAddItem(IItem item)
{ {
if (_itemStack == null) return true; if (_itemStack == null) return true;
return _itemStack.CanAddItem(item); return _itemStack.CanAddItem(item);
@ -180,7 +180,7 @@ public partial class ItemSlotNode : MarginContainer
/// <para>Try to add an item to this slot, if it can't be added to this slot, return false</para> /// <para>Try to add an item to this slot, if it can't be added to this slot, return false</para>
/// <para>尝试向当前槽位中加入物品如果该物品不能被放入该槽位返回false</para> /// <para>尝试向当前槽位中加入物品如果该物品不能被放入该槽位返回false</para>
/// </summary> /// </summary>
public bool AddItem(IItem_New item) public bool AddItem(IItem item)
{ {
bool result; bool result;
if (_itemStack is null) if (_itemStack is null)

View File

@ -35,12 +35,12 @@ public class UniversalItemContainer : IItemContainer
//_selectIndex默认为0. //_selectIndex默认为0.
private int _selectIndex; private int _selectIndex;
public bool CanAddItem(IItem_New item) public bool CanAddItem(IItem item)
{ {
return Match(item) != null; return Match(item) != null;
} }
public bool AddItem(IItem_New item) public bool AddItem(IItem item)
{ {
var itemSlotNode = Match(item); var itemSlotNode = Match(item);
if (itemSlotNode == null) if (itemSlotNode == null)
@ -87,7 +87,7 @@ public class UniversalItemContainer : IItemContainer
return null; return null;
} }
public IItem_New? PickItemFromItemSlotBySelectIndex() => PickItemFromItemSlot(_selectIndex); public IItem? PickItemFromItemSlotBySelectIndex() => PickItemFromItemSlot(_selectIndex);
public IItemStack? PickItemsFromItemSlotBySelectIndex(int value) => PickItemsFromItemSlot(_selectIndex, value); public IItemStack? PickItemsFromItemSlotBySelectIndex(int value) => PickItemsFromItemSlot(_selectIndex, value);
@ -114,7 +114,7 @@ public class UniversalItemContainer : IItemContainer
return _itemSlotNodes[safeIndex]; return _itemSlotNodes[safeIndex];
} }
public IItem_New? PickItemFromItemSlot(int itemSlotIndex) public IItem? PickItemFromItemSlot(int itemSlotIndex)
{ {
if (_itemSlotNodes == null) return null; if (_itemSlotNodes == null) return null;
var safeIndex = GetSafeIndex(itemSlotIndex); var safeIndex = GetSafeIndex(itemSlotIndex);
@ -153,7 +153,7 @@ public class UniversalItemContainer : IItemContainer
return itemSlot.RemoveItem(number); return itemSlot.RemoveItem(number);
} }
public ItemSlotNode? Match(IItem_New item) public ItemSlotNode? Match(IItem item)
{ {
//Find and return the first slot that can hold this item, if the list is null or not found, return null //Find and return the first slot that can hold this item, if the list is null or not found, return null
//寻找并返回第一个遇到的可放置此物品的物品槽若列表为空或不存在将返回null //寻找并返回第一个遇到的可放置此物品的物品槽若列表为空或不存在将返回null

View File

@ -2,8 +2,7 @@
namespace ColdMint.scripts.item; namespace ColdMint.scripts.item;
//Todo: Merge this with IItem (and, then change this ugly name public interface IItem
public interface IItem_New
{ {
/// <summary> /// <summary>
/// <para>ID of current item</para> /// <para>ID of current item</para>

View File

@ -45,14 +45,14 @@ public interface IItemStack
/// <para>判断能否容纳指定物品</para> /// <para>判断能否容纳指定物品</para>
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public bool CanAddItem(IItem_New item); public bool CanAddItem(IItem item);
/// <summary> /// <summary>
/// <para>Hold a given item</para> /// <para>Hold a given item</para>
/// </summary> /// </summary>
/// <param name="item">Item to hold by current stack</param> /// <param name="item">Item to hold by current stack</param>
/// <returns>Whether successful</returns> /// <returns>Whether successful</returns>
public bool AddItem(IItem_New item); public bool AddItem(IItem item);
/// <summary> /// <summary>
/// <para>判断能从指定物品堆中接收的物品数量</para> /// <para>判断能从指定物品堆中接收的物品数量</para>
@ -81,7 +81,7 @@ public interface IItemStack
/// <seealso cref="PickItem"/> /// <seealso cref="PickItem"/>
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public IItem_New? GetItem(); public IItem? GetItem();
/// <summary> /// <summary>
/// <para>Pop the item instance at the top of current item stack and return it</para> /// <para>Pop the item instance at the top of current item stack and return it</para>
@ -89,7 +89,7 @@ public interface IItemStack
/// <seealso cref="GetItem"/><seealso cref="PickItems"/> /// <seealso cref="GetItem"/><seealso cref="PickItems"/>
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public IItem_New? PickItem(); public IItem? PickItem();
/// <summary> /// <summary>
/// <para>Remove the specified number of items and return them as a new item stack</para> /// <para>Remove the specified number of items and return them as a new item stack</para>
@ -134,7 +134,7 @@ public interface IItemStack
/// <summary> /// <summary>
/// Create a new ItemStack with the given item as the first item /// Create a new ItemStack with the given item as the first item
/// </summary> /// </summary>
public static IItemStack FromItem(IItem_New item) => ItemTypeManager.MaxStackQuantityOf(item.Id) switch public static IItemStack FromItem(IItem item) => ItemTypeManager.MaxStackQuantityOf(item.Id) switch
{ {
1 => new SingleItemStack(item), 1 => new SingleItemStack(item),
> 1 => throw new NotImplementedException(), > 1 => throw new NotImplementedException(),

View File

@ -4,7 +4,7 @@ using Godot;
namespace ColdMint.scripts.item; namespace ColdMint.scripts.item;
public readonly struct ItemType(string id, Func<IItem_New> newItemFunc, Texture2D? icon, int maxStackQuantity) public readonly struct ItemType(string id, Func<IItem> newItemFunc, Texture2D? icon, int maxStackQuantity)
{ {
/// <summary> /// <summary>
/// <para>Item id of this type</para> /// <para>Item id of this type</para>
@ -13,7 +13,7 @@ public readonly struct ItemType(string id, Func<IItem_New> newItemFunc, Texture2
/// <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>
/// </summary> /// </summary>
public Func<IItem_New> 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>
/// </summary> /// </summary>

View File

@ -12,7 +12,7 @@ public static class ItemTypeManager
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");
var staffOfTheUndead = new ItemType("staff_of_the_undead", () => staffOfTheUndeadScene.Instantiate<IItem_New>(), null, 1); var staffOfTheUndead = new ItemType("staff_of_the_undead", () => staffOfTheUndeadScene.Instantiate<IItem>(), null, 1);
Register(staffOfTheUndead); Register(staffOfTheUndead);
} }
@ -31,7 +31,7 @@ public static class ItemTypeManager
/// <para>Creates a new instance of the item registered to the given id.</para> /// <para>Creates a new instance of the item registered to the given id.</para>
/// <para>Returns null when the id is not registered.</para> /// <para>Returns null when the id is not registered.</para>
/// </summary> /// </summary>
public static IItem_New? NewItem(string id) => public static IItem? NewItem(string id) =>
Registry.TryGetValue(id, out var itemType) ? itemType.NewItemFunc() : null; Registry.TryGetValue(id, out var itemType) ? itemType.NewItemFunc() : null;
/// <summary> /// <summary>

View File

@ -10,9 +10,9 @@ namespace ColdMint.scripts.item;
/// <para>Item stack of single item</para> /// <para>Item stack of single item</para>
/// </summary> /// </summary>
//maybe we'd move this into inventory namespace //maybe we'd move this into inventory namespace
public class SingleItemStack(IItem_New item) : IItemStack public class SingleItemStack(IItem item) : IItemStack
{ {
public IItem_New Item { get; init; } = item; public IItem Item { get; init; } = item;
public string Id => Item.Id; public string Id => Item.Id;
public int MaxQuantity => 1; public int MaxQuantity => 1;
@ -21,20 +21,20 @@ public class SingleItemStack(IItem_New item) : IItemStack
public string Name => Item.Name; public string Name => Item.Name;
public string? Description => Item.Description; public string? Description => Item.Description;
public bool CanAddItem(IItem_New item) => false; public bool CanAddItem(IItem item) => false;
public bool AddItem(IItem_New item) => false; public bool AddItem(IItem item) => false;
public int CanTakeFrom(IItemStack itemStack) => 0; public int CanTakeFrom(IItemStack itemStack) => 0;
public bool TakeFrom(IItemStack itemStack) => false; public bool TakeFrom(IItemStack itemStack) => false;
public IItem_New? GetItem() public IItem? GetItem()
{ {
return Quantity == 1 ? Item : null; return Quantity == 1 ? Item : null;
} }
public IItem_New? PickItem() public IItem? PickItem()
{ {
Quantity = 0; Quantity = 0;
return Item; return Item;

View File

@ -13,7 +13,7 @@ namespace ColdMint.scripts.item.weapon;
/// <para>WeaponTemplate</para> /// <para>WeaponTemplate</para>
/// <para>武器模板</para> /// <para>武器模板</para>
/// </summary> /// </summary>
public abstract partial class WeaponTemplate : RigidBody2D, IItem_New public abstract partial class WeaponTemplate : RigidBody2D, IItem
{ {
private float _gravity = ProjectSettings.GetSetting("physics/2d/default_gravity").AsSingle(); private float _gravity = ProjectSettings.GetSetting("physics/2d/default_gravity").AsSingle();

View File

@ -116,7 +116,7 @@ public partial class ProjectileTemplate : CharacterBody2D
//Match any item now //Match any item now
//现在使它识别任何物品 //现在使它识别任何物品
if (target is IItem_New) if (target is IItem)
{ {
//Bullets are allowed to strike objects. //Bullets are allowed to strike objects.
//允许子弹撞击物品。 //允许子弹撞击物品。