Remove old item interfaces,rename new
移除旧的物品接口,重命名新的
This commit is contained in:
parent
94a2e78efc
commit
23877e82cc
|
@ -271,7 +271,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
{
|
||||
//Empty reference checking is implicitly performed here.
|
||||
//此处隐式的执行了空引用检查。
|
||||
if (pickAbleItem is not IItem_New item)
|
||||
if (pickAbleItem is not IItem item)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -348,7 +348,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
return false;
|
||||
}
|
||||
|
||||
if (_currentItem is IItem_New item)
|
||||
if (_currentItem is IItem item)
|
||||
{
|
||||
item.Use(this, position);
|
||||
}
|
||||
|
@ -537,7 +537,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
/// <param name="node"></param>
|
||||
protected virtual void EnterThePickingRangeBody(Node node)
|
||||
{
|
||||
if (node is not IItem_New)
|
||||
if (node is not IItem)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -552,7 +552,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
/// <param name="node"></param>
|
||||
protected virtual void ExitThePickingRangeBody(Node node)
|
||||
{
|
||||
if (node is not IItem_New)
|
||||
if (node is not IItem)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
*/
|
|
@ -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; }
|
||||
}
|
||||
*/
|
|
@ -24,7 +24,7 @@ public interface IItemContainer
|
|||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
bool CanAddItem(IItem_New item);
|
||||
bool CanAddItem(IItem item);
|
||||
|
||||
/// <summary>
|
||||
/// <para>Implement methods for adding items</para>
|
||||
|
@ -32,7 +32,7 @@ public interface IItemContainer
|
|||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
bool AddItem(IItem_New item);
|
||||
bool AddItem(IItem item);
|
||||
|
||||
/// <summary>
|
||||
/// <para>Add an stack of items to this container</para>
|
||||
|
@ -64,7 +64,7 @@ public interface IItemContainer
|
|||
/// <para>如果存在,移除当前选中位置的槽位中的一个物品并将其返回</para>
|
||||
/// </summary>
|
||||
/// <seealso cref="PickItemFromItemSlot"/><seealso cref="PickItemsFromItemSlotBySelectIndex"/>
|
||||
IItem_New? PickItemFromItemSlotBySelectIndex();
|
||||
IItem? PickItemFromItemSlotBySelectIndex();
|
||||
|
||||
/// <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>
|
||||
|
@ -115,7 +115,7 @@ public interface IItemContainer
|
|||
/// <para>如果存在,移除指定位置的槽位中的一个物品并将其返回</para>
|
||||
/// </summary>
|
||||
/// <seealso cref="PickItemsFromItemSlot"/>
|
||||
IItem_New? PickItemFromItemSlot(int itemSlotIndex);
|
||||
IItem? PickItemFromItemSlot(int itemSlotIndex);
|
||||
|
||||
/// <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>
|
||||
|
@ -157,7 +157,7 @@ public interface IItemContainer
|
|||
/// <para>Return null if there is no slot to place the item in</para>
|
||||
/// <para>若没有槽可放置此物品,则返回null</para>
|
||||
/// </returns>
|
||||
ItemSlotNode? Match(IItem_New item);
|
||||
ItemSlotNode? Match(IItem item);
|
||||
|
||||
/// <summary>
|
||||
/// <para>Based on the given item stack, match the item slots where it can be added to</para>
|
||||
|
|
|
@ -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>如果存在,获取该槽位中物品堆顶部的物品</para>
|
||||
/// </summary>
|
||||
public IItem_New? GetItem() => _itemStack?.GetItem();
|
||||
public IItem? GetItem() => _itemStack?.GetItem();
|
||||
|
||||
/// <summary>
|
||||
/// <para>If present, remove an item in this slot and return it.</para>
|
||||
/// <para>如果存在,移除该槽位中的一个物品并将其返回</para>
|
||||
/// </summary>
|
||||
/// <seealso cref="PickItems"/>
|
||||
public IItem_New? PickItem()
|
||||
public IItem? PickItem()
|
||||
{
|
||||
if (_itemStack is null) return null;
|
||||
|
||||
|
@ -149,7 +149,7 @@ public partial class ItemSlotNode : MarginContainer
|
|||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
public bool CanAddItem(IItem_New item)
|
||||
public bool CanAddItem(IItem item)
|
||||
{
|
||||
if (_itemStack == null) return true;
|
||||
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>尝试向当前槽位中加入物品,如果该物品不能被放入该槽位,返回false</para>
|
||||
/// </summary>
|
||||
public bool AddItem(IItem_New item)
|
||||
public bool AddItem(IItem item)
|
||||
{
|
||||
bool result;
|
||||
if (_itemStack is null)
|
||||
|
|
|
@ -35,12 +35,12 @@ public class UniversalItemContainer : IItemContainer
|
|||
//_selectIndex默认为0.
|
||||
private int _selectIndex;
|
||||
|
||||
public bool CanAddItem(IItem_New item)
|
||||
public bool CanAddItem(IItem item)
|
||||
{
|
||||
return Match(item) != null;
|
||||
}
|
||||
|
||||
public bool AddItem(IItem_New item)
|
||||
public bool AddItem(IItem item)
|
||||
{
|
||||
var itemSlotNode = Match(item);
|
||||
if (itemSlotNode == null)
|
||||
|
@ -87,7 +87,7 @@ public class UniversalItemContainer : IItemContainer
|
|||
return null;
|
||||
}
|
||||
|
||||
public IItem_New? PickItemFromItemSlotBySelectIndex() => PickItemFromItemSlot(_selectIndex);
|
||||
public IItem? PickItemFromItemSlotBySelectIndex() => PickItemFromItemSlot(_selectIndex);
|
||||
|
||||
public IItemStack? PickItemsFromItemSlotBySelectIndex(int value) => PickItemsFromItemSlot(_selectIndex, value);
|
||||
|
||||
|
@ -114,7 +114,7 @@ public class UniversalItemContainer : IItemContainer
|
|||
return _itemSlotNodes[safeIndex];
|
||||
}
|
||||
|
||||
public IItem_New? PickItemFromItemSlot(int itemSlotIndex)
|
||||
public IItem? PickItemFromItemSlot(int itemSlotIndex)
|
||||
{
|
||||
if (_itemSlotNodes == null) return null;
|
||||
var safeIndex = GetSafeIndex(itemSlotIndex);
|
||||
|
@ -153,7 +153,7 @@ public class UniversalItemContainer : IItemContainer
|
|||
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
|
||||
//寻找并返回第一个遇到的可放置此物品的物品槽,若列表为空或不存在,将返回null
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
namespace ColdMint.scripts.item;
|
||||
|
||||
//Todo: Merge this with IItem (and, then change this ugly name
|
||||
public interface IItem_New
|
||||
public interface IItem
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>ID of current item</para>
|
|
@ -45,14 +45,14 @@ public interface IItemStack
|
|||
/// <para>判断能否容纳指定物品</para>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool CanAddItem(IItem_New item);
|
||||
public bool CanAddItem(IItem item);
|
||||
|
||||
/// <summary>
|
||||
/// <para>Hold a given item</para>
|
||||
/// </summary>
|
||||
/// <param name="item">Item to hold by current stack</param>
|
||||
/// <returns>Whether successful</returns>
|
||||
public bool AddItem(IItem_New item);
|
||||
public bool AddItem(IItem item);
|
||||
|
||||
/// <summary>
|
||||
/// <para>判断能从指定物品堆中接收的物品数量</para>
|
||||
|
@ -81,7 +81,7 @@ public interface IItemStack
|
|||
/// <seealso cref="PickItem"/>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IItem_New? GetItem();
|
||||
public IItem? GetItem();
|
||||
|
||||
/// <summary>
|
||||
/// <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"/>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IItem_New? PickItem();
|
||||
public IItem? PickItem();
|
||||
|
||||
/// <summary>
|
||||
/// <para>Remove the specified number of items and return them as a new item stack</para>
|
||||
|
@ -134,7 +134,7 @@ public interface IItemStack
|
|||
/// <summary>
|
||||
/// Create a new ItemStack with the given item as the first item
|
||||
/// </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 => throw new NotImplementedException(),
|
||||
|
|
|
@ -4,7 +4,7 @@ using Godot;
|
|||
|
||||
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>
|
||||
/// <para>Item id of this type</para>
|
||||
|
@ -13,7 +13,7 @@ public readonly struct ItemType(string id, Func<IItem_New> newItemFunc, Texture2
|
|||
/// <summary>
|
||||
/// <para>A function returns a new item instance of this type</para>
|
||||
/// </summary>
|
||||
public Func<IItem_New> NewItemFunc { get; init; } = newItemFunc;
|
||||
public Func<IItem> NewItemFunc { get; init; } = newItemFunc;
|
||||
/// <summary>
|
||||
/// <para>Default icon of items of this type</para>
|
||||
/// </summary>
|
||||
|
|
|
@ -12,7 +12,7 @@ public static class ItemTypeManager
|
|||
public static void StaticRegister()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ public static class ItemTypeManager
|
|||
/// <para>Creates a new instance of the item registered to the given id.</para>
|
||||
/// <para>Returns null when the id is not registered.</para>
|
||||
/// </summary>
|
||||
public static IItem_New? NewItem(string id) =>
|
||||
public static IItem? NewItem(string id) =>
|
||||
Registry.TryGetValue(id, out var itemType) ? itemType.NewItemFunc() : null;
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -10,9 +10,9 @@ namespace ColdMint.scripts.item;
|
|||
/// <para>Item stack of single item</para>
|
||||
/// </summary>
|
||||
//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 int MaxQuantity => 1;
|
||||
|
@ -21,20 +21,20 @@ public class SingleItemStack(IItem_New item) : IItemStack
|
|||
public string Name => Item.Name;
|
||||
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 bool TakeFrom(IItemStack itemStack) => false;
|
||||
|
||||
public IItem_New? GetItem()
|
||||
public IItem? GetItem()
|
||||
{
|
||||
return Quantity == 1 ? Item : null;
|
||||
}
|
||||
|
||||
public IItem_New? PickItem()
|
||||
public IItem? PickItem()
|
||||
{
|
||||
Quantity = 0;
|
||||
return Item;
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace ColdMint.scripts.item.weapon;
|
|||
/// <para>WeaponTemplate</para>
|
||||
/// <para>武器模板</para>
|
||||
/// </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();
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ public partial class ProjectileTemplate : CharacterBody2D
|
|||
|
||||
//Match any item now
|
||||
//现在使它识别任何物品
|
||||
if (target is IItem_New)
|
||||
if (target is IItem)
|
||||
{
|
||||
//Bullets are allowed to strike objects.
|
||||
//允许子弹撞击物品。
|
||||
|
|
Loading…
Reference in New Issue
Block a user