diff --git a/scripts/character/CharacterTemplate.cs b/scripts/character/CharacterTemplate.cs index 30c19a2..bd30162 100644 --- a/scripts/character/CharacterTemplate.cs +++ b/scripts/character/CharacterTemplate.cs @@ -332,9 +332,8 @@ public partial class CharacterTemplate : CharacterBody2D pickAbleTemplate.Sleeping = true; } - var itemStack = selectItemSlotNode.GetItemStack(); - var itemFromStack = itemStack?.GetItem(); - if (itemFromStack != null && itemFromStack == item && _currentItem == null) + var selectItem = selectItemSlotNode.GetItem(); + if (_currentItem == null) { //If the selected item slot in the item container is a newly picked item, and there is no item in the hand, then we put the selected item into the hand. //如果物品容器内选中的物品槽是刚刚捡到的物品,且手里没有物品持有,那么我们将选中的物品放到手上。 @@ -667,7 +666,7 @@ public partial class CharacterTemplate : CharacterBody2D { //Pick an item from the item container //从物品容器内取出一个物品 - var item = itemSlotNode.PickItem(); + var item = itemSlotNode.GetItem(); if (item is not Node2D node2D) { diff --git a/scripts/character/Player.cs b/scripts/character/Player.cs index edcf35a..ecb6d72 100644 --- a/scripts/character/Player.cs +++ b/scripts/character/Player.cs @@ -87,7 +87,7 @@ public partial class Player : CharacterTemplate private void SelectedItemSlotChangeEvent(SelectedItemSlotChangeEvent selectedItemSlotChangeEvent) { - var item = selectedItemSlotChangeEvent.NewItemSlotNode?.GetItemStack()?.GetItem(); + var item = selectedItemSlotChangeEvent.NewItemSlotNode?.GetItem(); GameSceneNodeHolder.HideBackpackUiContainerIfVisible(); if (item is Node2D node2D) { diff --git a/scripts/inventory/IItemContainer.cs b/scripts/inventory/IItemContainer.cs index 5e45ddd..48a0302 100644 --- a/scripts/inventory/IItemContainer.cs +++ b/scripts/inventory/IItemContainer.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using ColdMint.scripts.item; -using ColdMint.scripts.item.itemStacks; using ColdMint.scripts.map.events; using Godot; @@ -44,28 +43,7 @@ public interface IItemContainer : IEnumerable /// 此物品容器是否支持选中 /// public bool SupportSelect { get; set; } - - /// - /// Determines the number of items that can be received from the specified pile - /// 判断能从指定物品堆中接收的物品数量 - /// - /// - /// Item stack to add to the current container - /// 向该容器中放入物品的物品堆 - /// - /// - int CanAddItemStack(IItemStack itemStack); - - /// - /// Add an stack of items to this container - /// 向当前容器中存入一堆物品 - /// - /// - /// - /// If the source item stack is empty after the operation is completed - /// 操作完成后,源物品堆是否被取空 - /// - bool AddItemStack(IItemStack itemStack); + /// /// Gets the selected location @@ -81,23 +59,8 @@ public interface IItemContainer : IEnumerable /// ItemSlotNode? GetSelectItemSlotNode(); - /// - /// If present, remove an item from the slot at the currently selected location and return it. - /// 如果存在,移除当前选中位置的槽位中的一个物品并将其返回 - /// - /// - IItem? PickItemFromItemSlotBySelectIndex(); - - /// - /// Remove the specified number of items from the item slot at the currently selected location, and return them as a new item stack - /// 取出当前选中位置的物品槽中指定数量的物品,并作为新的物品堆返回 - /// - /// - /// Quantity to be taken out, inputs below zero represent all items - /// 要取出的数量,小于0的输入代表全部物品 - /// - /// - IItemStack? PickItemsFromItemSlotBySelectIndex(int value); + + /// /// Removes an item from the inventory at the currently selected location @@ -111,10 +74,6 @@ public interface IItemContainer : IEnumerable /// The remaining number, if the number of items in the current item stack is less than the specified number. Otherwise,0 /// 若物品槽内物品少于指定的数量,返回相差的数量。否则返回0 /// - /// - /// Will remove the removed items from the game, if that is not the intent, consider using the - /// 会将移除的物品从游戏中删除,如果目的并非如此,请考虑使用 - /// int RemoveItemFromItemSlotBySelectIndex(int number); /// @@ -139,25 +98,8 @@ public interface IItemContainer : IEnumerable /// /// ItemSlotNode? this[int index] => GetItemSlotNode(index); - - /// - /// If present, remove an item from the slot in the specified location and return it. - /// 如果存在,移除指定位置的槽位中的一个物品并将其返回 - /// - /// - IItem? PickItemFromItemSlot(int itemSlotIndex); - - /// - /// Remove the specified number of items from the item slot in the specified location, and return them as a new item stack - /// 取出指定位置的物品槽中指定数量的物品,并作为新的物品堆返回 - /// - /// - /// - /// Quantity to be taken out, inputs below zero represent all items - /// 要取出的数量,小于0的输入代表全部物品 - /// - /// - IItemStack? PickItemsFromItemSlot(int itemSlotIndex, int value); + + /// /// Removes an item from the item slot in the specified location @@ -172,10 +114,6 @@ public interface IItemContainer : IEnumerable /// The remaining number, if the number of items in the current item stack is less than the specified number. Otherwise,0 /// 若物品槽内物品少于指定的数量,返回相差的数量。否则返回0 /// - /// - /// Will remove the removed items from the game, if that is not the intent, consider using the - /// 会将移除的物品从游戏中删除,如果目的并非如此,请考虑使用 - /// int RemoveItemFromItemSlot(int itemSlotIndex, int number); /// @@ -189,43 +127,6 @@ public interface IItemContainer : IEnumerable /// ItemSlotNode? Match(IItem item); - /// - /// Based on the given item stack, match the item slots where it can be added to - /// 根据给定的物品堆,匹配可放置它的物品槽 - /// - /// - /// - /// Return null if there is no slot to add the item slot in - /// 若没有槽可放置此物品堆,则返回null - /// - ItemSlotNode? Match(IItemStack stack); - - /// - /// Match the first item slot that satisfies the predicate - /// 匹配首个拥有满足指定条件的物品槽 - /// - /// - ///predicate - ///谓语 - /// - /// - /// Return null if there is no slot satisfies the predicate - /// 若没有满足条件的槽位,返回null - /// - /// - ItemSlotNode? Match(Func predicate); - - /// - /// Match all item slots that satisfies the predicate - /// 匹配所有拥有满足指定条件的物品槽 - /// - /// - /// - /// IEnumerable for the item slot matched to, will be empty if there's no slot satisfies the predicate - /// 包含匹配到的槽位的IEnumerable,当没有满足条件的槽位时为空 - /// - IEnumerable MatchAll(Func predicate); - /// /// AddItemSlot diff --git a/scripts/inventory/ItemSlotNode.cs b/scripts/inventory/ItemSlotNode.cs index a6be80e..ac62e69 100644 --- a/scripts/inventory/ItemSlotNode.cs +++ b/scripts/inventory/ItemSlotNode.cs @@ -1,5 +1,6 @@ +using System; +using System.Text.RegularExpressions; using ColdMint.scripts.item; -using ColdMint.scripts.item.itemStacks; using ColdMint.scripts.utils; using Godot; @@ -11,7 +12,6 @@ namespace ColdMint.scripts.inventory; /// public partial class ItemSlotNode : MarginContainer { - private IItemStack? _itemStack; private TextureRect? _backgroundTextureRect; private TextureRect? _iconTextureRect; private Label? _quantityLabel; @@ -19,6 +19,7 @@ public partial class ItemSlotNode : MarginContainer private bool _isSelect; private Texture2D? _backgroundTexture; private Texture2D? _backgroundTextureWhenSelect; + private IItem? _item = null; public override void _Ready() { @@ -34,7 +35,7 @@ public partial class ItemSlotNode : MarginContainer public override Variant _GetDragData(Vector2 atPosition) { - if (_isSelect || _iconTextureRect == null || _itemStack == null) + if (_isSelect || _iconTextureRect == null) { //Drag is not allowed if there is no icon or no pile of items. //如果没有图标或者没有物品堆,那么不允许拖动。 @@ -67,15 +68,20 @@ public partial class ItemSlotNode : MarginContainer } var itemSlotNode = data.As(); - var itemStack = itemSlotNode.GetItemStack(); - if (itemStack == null) + var item = itemSlotNode.GetItem(); + if (item == null) { - //Return null when trying to get the source item heap. - //尝试获取源物品堆时返回null。 + //Return null when trying to get the source item. + //尝试获取源物品时返回null。 return false; } - return _itemStack == null; + return _item == null; + } + + public IItem? GetItem() + { + return _item; } public override void _DropData(Vector2 atPosition, Variant data) @@ -94,7 +100,7 @@ public partial class ItemSlotNode : MarginContainer } var itemSlotNode = data.As(); - var itemStack = itemSlotNode.ReplaceItemStack(null); + var itemStack = itemSlotNode._item; if (itemStack == null) { //Return null when trying to get the source item heap. @@ -102,7 +108,7 @@ public partial class ItemSlotNode : MarginContainer return; } - ReplaceItemStack(itemStack); + // ReplaceItemStack(itemStack); } public bool IsSelect @@ -121,212 +127,22 @@ public partial class ItemSlotNode : MarginContainer public TextureRect? BackgroundTextureRect => _backgroundTextureRect; - public bool IsEmpty() => _itemStack == null; - /// - /// Get the item stack in the item slot - /// 获取物品槽内的物品堆 - /// - /// - public IItemStack? GetItemStack() => _itemStack; - - /// - /// If present, remove an item in this slot and return it. - /// 如果存在,移除该槽位中的一个物品并将其返回 - /// - /// - public IItem? PickItem() - { - if (_itemStack is null) return null; - - var result = _itemStack.PickItem(); - if (_itemStack.Empty) - { - SetItemStack(null); - } - - UpdateAllDisplay(); - - return result; - } - - /// - /// Remove the specified number of items and return them as a new item stack - /// 取出当前物品槽中指定数量的物品,并作为新的物品堆返回 - /// - /// - /// Quantity to be taken out, inputs below zero represent all items - /// 要取出的数量,小于0的输入代表全部物品 - /// - /// - public IItemStack? PickItems(int value) - { - if (_itemStack is null) return null; - - var result = _itemStack.PickItems(value); - if (_itemStack.Empty) - { - SetItemStack(null); - } - - UpdateAllDisplay(); - - return result; - } - - /// - /// Removes the specified number of items from the item slot - /// 在物品槽内移除指定数量的物品 - /// - /// - /// Quantity to be removed, inputs below zero represent all items - /// 要删除的数量,小于0的输入代表全部物品 - /// - /// - /// The remaining number, if the number of items in the current item stack is less than the specified number. Otherwise,0 - /// 若物品槽内物品少于指定的数量,返回相差的数量。否则返回0 - /// - /// - /// Will remove the removed items from the game, if that is not the intent, consider using the - /// 会将移除的物品从游戏中删除,如果目的并非如此,请考虑使用 - /// - public int RemoveItem(int number) - { - if (_itemStack == null) - { - return number; - } - - var result = _itemStack.RemoveItem(number); - //If the specified number of items is removed, the number of items is less than or equal to 0. Then we empty the inventory. - //如果移除指定数量的物品后,物品数量小于或等于0。那么我们清空物品栏。 - if (_itemStack.Empty) - { - SetItemStack(null); - } - - UpdateAllDisplay(); - - return result; - } - - /// - /// Remove item stack from slot and return it, equivalent to ReplaceItemStack(null) - /// 从当前槽位中移出并返回物品堆,等价于ReplaceItemStack(null) - /// - /// - public IItemStack? RemoveItemStack() => ReplaceItemStack(null); - - /// - /// Empty the item slot - /// 清空当前物品槽 - /// - /// - ///This method will remove all items stored in the item slots from the game, if this is not what you want to do, consider using the method. - ///此方法会从游戏中移除储存于物品槽中的所有物品,若这不是您希望的操作,请考虑使用方法。 - /// - public void ClearSlot() - { - _itemStack?.ClearStack(); - SetItemStack(null); - UpdateAllDisplay(); - } - - /// - /// - /// Set item stack for this slot, this will completely replace current item stack. - /// If you want the item stack to be added to current stack, use the . - /// - /// 为物品槽设置物品堆,将完全替换掉当前物品堆。如果想要物品堆叠加至该物品堆,请使用 + /// Whether the item in this node is empty + /// 此节点内的物品是否为空的 /// /// - /// The item stack that was previously in this slot - /// 该槽位中原本的物品堆 + ///Return true if the number of items is 0 or the item object does not exist + ///当物品数量为0或物品对象不存在时,返回true /// - public IItemStack? ReplaceItemStack(IItemStack? newItemStack) + public bool IsEmpty() { - var result = _itemStack; - SetItemStack(newItemStack); - UpdateAllDisplay(); - - return result; - } - - /// - /// Can the specified item be placed in the item slot? - /// 指定的物品是否可设置在物品槽内? - /// - /// - /// - public bool CanAddItem(IItem item) - { - if (_itemStack == null) return true; - return _itemStack.CanAddItem(item); - } - - /// - /// Try to add an item to this slot, if it can't be added to this slot, return false - /// 尝试向当前槽位中加入物品,如果该物品不能被放入该槽位,返回false - /// - public bool AddItem(IItem item) - { - bool result; - if (_itemStack is null) + if (_item == null || _item.Quantity == 0) { - SetItemStack(IItemStack.FromItem(item)); - result = true; - } - else - { - result = _itemStack.AddItem(item); + return true; } - if (result) - { - UpdateAllDisplay(); - } - - return result; - } - - /// - /// Determines the number of items that can be received from the specified pile - /// 判断能从指定物品堆中接收的物品数量 - /// - /// - /// Item stack to add to the current slot - /// 向该物品槽中放入物品的物品堆 - /// - /// - public int CanAddItemStack(IItemStack itemStack) - { - if (_itemStack is null) return itemStack.Quantity; - return _itemStack.CanTakeFrom(itemStack); - } - - /// - /// Try to combine an item stack into this slot - /// 尝试将一个物品堆合并至该槽位中 - /// - /// - /// If the source item stack is empty after the operation is completed - /// 操作完成后,源物品堆是否被取空 - /// - public bool AddItemStack(IItemStack itemStack) - { - bool result; - if (_itemStack is null) - { - SetItemStack(itemStack); - result = false; - } - else - { - result = _itemStack.TakeFrom(itemStack); - } - - UpdateAllDisplay(); - return result; + return false; } @@ -347,7 +163,7 @@ public partial class ItemSlotNode : MarginContainer /// private void UpdateTooltipText() { - if (_itemStack == null) + if (_item == null) { TooltipText = null; return; @@ -358,16 +174,16 @@ public partial class ItemSlotNode : MarginContainer var debugText = TranslationServerUtils.Translate("item_prompt_debug"); if (debugText != null) { - TooltipText = string.Format(debugText, _itemStack.GetItem()?.Id, - TranslationServerUtils.Translate(_itemStack.Name), - _itemStack.Quantity, _itemStack.MaxQuantity, _itemStack.GetType().Name, - TranslationServerUtils.Translate(_itemStack.Description)); + TooltipText = string.Format(debugText, _item.Id, + TranslationServerUtils.Translate(_item.Name), + _item.Quantity, _item.MaxQuantity, _item.GetType().Name, + TranslationServerUtils.Translate(_item.Description)); } } else { - TooltipText = TranslationServerUtils.Translate(_itemStack.Name) + "\n" + - TranslationServerUtils.Translate(_itemStack.Description); + TooltipText = TranslationServerUtils.Translate(_item.Name) + "\n" + + TranslationServerUtils.Translate(_item.Description); } } @@ -382,7 +198,7 @@ public partial class ItemSlotNode : MarginContainer return; } - switch (_itemStack?.Quantity) + switch (_item?.Quantity) { case null or 1: _quantityLabel.Hide(); @@ -390,25 +206,12 @@ public partial class ItemSlotNode : MarginContainer default: //When the quantity is not null or 1, we display the quantity. //当数量不为null或1时,我们显示数量 - _quantityLabel.Text = _itemStack?.Quantity.ToString(); + _quantityLabel.Text = _item?.Quantity.ToString(); _quantityLabel.Show(); break; } } - /// - /// SetItemStack - /// 设置物品堆 - /// - /// - ///This method broadcasts changes to the stack to the outside world - ///此方法会对外广播物品堆的变更事件 - /// - /// - private void SetItemStack(IItemStack? itemStack) - { - _itemStack = itemStack; - } /// /// Update texture of the icon rect @@ -418,7 +221,72 @@ public partial class ItemSlotNode : MarginContainer { if (_iconTextureRect != null) { - _iconTextureRect.Texture = _itemStack?.Icon; + _iconTextureRect.Texture = _item?.Icon; } } + + public bool CanAddItem(IItem item) + { + if (_item == null) + { + //If there is no item in the current item slot, it is allowed to add. + //如果当前物品槽内没物品,那么允许添加。 + return true; + } + + if (item.Id != _item.Id) + { + //If the item ID you want to add is different from the current item ID, disable. + //如果要添加的物品ID和当前的物品ID不一样,那么禁止。 + return false; + } + + var newQuantity = item.Quantity + _item.Quantity; + if (newQuantity > _item.MaxQuantity) + { + //The maximum number is exceeded and items cannot be added. + //超过了最大数量,无法添加物品。 + return false; + } + + return true; + } + + /// + /// Remove items from the item slot + /// 从物品槽内移除物品 + /// + /// + ///number(Less than 0, remove all items) + ///物品数量(小于0,则移除全部物品) + /// + /// + ///How many items were actually removed + ///实际移除了多少个物品 + /// + public int RemoveItem(int number) + { + if (_item == null) + { + return 0; + } + + //The number of actual removals + //实际移除的数量 + var removeNumber = number < 0 ? _item.Quantity : number; + _item.Quantity -= removeNumber; + return removeNumber; + } + + public bool AddItem(IItem item) + { + if (_item == null) + { + return false; + } + + var newQuantity = item.Quantity + _item.Quantity; + _item.Quantity = Math.Min(newQuantity, _item.MaxQuantity); + return true; + } } \ No newline at end of file diff --git a/scripts/inventory/UniversalItemContainer.cs b/scripts/inventory/UniversalItemContainer.cs index d55d020..160e455 100644 --- a/scripts/inventory/UniversalItemContainer.cs +++ b/scripts/inventory/UniversalItemContainer.cs @@ -3,7 +3,6 @@ using System.Collections; using System.Collections.Generic; using System.Linq; using ColdMint.scripts.item; -using ColdMint.scripts.item.itemStacks; using ColdMint.scripts.map.events; using ColdMint.scripts.utils; using Godot; @@ -17,10 +16,9 @@ namespace ColdMint.scripts.inventory; /// public class UniversalItemContainer : IItemContainer { - private readonly PackedScene? _itemSlotPackedScene = GD.Load("res://prefab/ui/ItemSlot.tscn"); - private readonly List? _itemSlotNodes = []; + private readonly PackedScene? _itemSlotPackedScene = GD.Load("res://prefab/ui/ItemSlot.tscn"); /// /// UnknownIndex @@ -31,8 +29,17 @@ public class UniversalItemContainer : IItemContainer //_selectIndex默认为0. private int _selectIndex; + [MustDisposeResource] + public IEnumerator GetEnumerator() + { + return _itemSlotNodes?.GetEnumerator() ?? Enumerable.Empty().GetEnumerator(); + } - public bool SupportSelect { get; set; } = true; + [MustDisposeResource] + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } public Action? SelectedItemSlotChangeEvent { get; set; } @@ -52,43 +59,16 @@ public class UniversalItemContainer : IItemContainer return itemSlotNode.AddItem(item); } - public int CanAddItemStack(IItemStack itemStack) - { - var testItem = itemStack.GetItem(); - if (testItem is null) return 0; - var slots = MatchAll(slot => slot.CanAddItem(testItem)); - return - Math.Min(itemStack.Quantity, - slots.Select(slot => slot.CanAddItemStack(itemStack)).Sum()); - } - - public bool AddItemStack(IItemStack itemStack) - { - ItemSlotNode? itemSlotNode = Match(itemStack); - while (itemSlotNode is not null) - { - if (itemSlotNode.AddItemStack(itemStack)) - return true; - - itemSlotNode = Match(itemStack); - } - - return false; - } + public bool SupportSelect { get; set; } public int GetSelectIndex() { - if (!SupportSelect) - { - return 0; - } - return _selectIndex; } public ItemSlotNode? GetSelectItemSlotNode() { - if (!SupportSelect || _itemSlotNodes == null || _itemSlotNodes.Count == 0) + if (_itemSlotNodes == null || _itemSlotNodes.Count == 0) { return null; } @@ -103,35 +83,7 @@ public class UniversalItemContainer : IItemContainer return null; } - public IItem? PickItemFromItemSlotBySelectIndex() - { - if (!SupportSelect) - { - return null; - } - - return PickItemFromItemSlot(_selectIndex); - } - - public IItemStack? PickItemsFromItemSlotBySelectIndex(int value) - { - if (!SupportSelect) - { - return null; - } - - return PickItemsFromItemSlot(_selectIndex, value); - } - - public int RemoveItemFromItemSlotBySelectIndex(int number) - { - if (!SupportSelect) - { - return 0; - } - - return RemoveItemFromItemSlot(_selectIndex, number); - } + public int RemoveItemFromItemSlotBySelectIndex(int number) => RemoveItemFromItemSlot(_selectIndex, number); public int GetItemSlotCount() { @@ -154,32 +106,6 @@ public class UniversalItemContainer : IItemContainer return _itemSlotNodes[safeIndex]; } - public IItem? PickItemFromItemSlot(int itemSlotIndex) - { - if (_itemSlotNodes == null) return null; - var safeIndex = GetSafeIndex(itemSlotIndex); - if (safeIndex == UnknownIndex) - { - return null; - } - - var itemSlot = _itemSlotNodes[safeIndex]; - return itemSlot.PickItem(); - } - - public IItemStack? PickItemsFromItemSlot(int itemSlotIndex, int value) - { - if (_itemSlotNodes == null) return null; - var safeIndex = GetSafeIndex(itemSlotIndex); - if (safeIndex == UnknownIndex) - { - return null; - } - - var itemSlot = _itemSlotNodes[safeIndex]; - return itemSlot.PickItems(value); - } - public int RemoveItemFromItemSlot(int itemSlotIndex, int number) { if (_itemSlotNodes == null) return number; @@ -193,30 +119,6 @@ public class UniversalItemContainer : IItemContainer return itemSlot.RemoveItem(number); } - 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 - return _itemSlotNodes?.FirstOrDefault(itemSlotNode => itemSlotNode.CanAddItem(item)); - } - - public ItemSlotNode? Match(IItemStack stack) - { - var item = stack.GetItem(); - return item == null ? null : _itemSlotNodes?.FirstOrDefault(itemSlotNode => itemSlotNode.CanAddItem(item)); - } - - public ItemSlotNode? Match(Func predicate) - { - return _itemSlotNodes?.FirstOrDefault(predicate); - } - - public IEnumerable MatchAll(Func predicate) - { - return from node in _itemSlotNodes where predicate(node) select node; - } - - /// /// Gets a secure subscript index /// 获取安全的下标索引 @@ -244,10 +146,13 @@ public class UniversalItemContainer : IItemContainer return itemSlotIndex % count; } - /// - /// Add items tank - /// 添加物品槽 - /// + 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 + return _itemSlotNodes?.FirstOrDefault(itemSlotNode => itemSlotNode.CanAddItem(item)); + } + public ItemSlotNode? AddItemSlot(Node rootNode) { if (_itemSlotNodes == null || _itemSlotPackedScene == null) @@ -261,22 +166,14 @@ public class UniversalItemContainer : IItemContainer return null; } - if (SupportSelect) - { - itemSlotNode.IsSelect = (_itemSlotNodes.Count) == _selectIndex; - } - else - { - itemSlotNode.IsSelect = false; - } - + itemSlotNode.IsSelect = (_itemSlotNodes.Count) == _selectIndex; _itemSlotNodes.Add(itemSlotNode); return itemSlotNode; } public void SelectTheNextItemSlot() { - if (!SupportSelect || _itemSlotNodes == null) + if (_itemSlotNodes == null) { return; } @@ -299,7 +196,7 @@ public class UniversalItemContainer : IItemContainer public void SelectThePreviousItemSlot() { - if (!SupportSelect || _itemSlotNodes == null) + if (_itemSlotNodes == null) { return; } @@ -319,23 +216,7 @@ public class UniversalItemContainer : IItemContainer PrivateSelectItemSlot(oldSelectIndex, newSelectIndex); } - - public void SelectItemSlot(int newSelectIndex) - { - if (!SupportSelect || newSelectIndex == _selectIndex) - { - return; - } - - var safeIndex = GetSafeIndex(newSelectIndex); - if (safeIndex == UnknownIndex) - { - return; - } - - PrivateSelectItemSlot(_selectIndex, newSelectIndex); - } - + /// /// Select an item slot /// 选中某个物品槽 @@ -360,7 +241,7 @@ public class UniversalItemContainer : IItemContainer }); _selectIndex = newSelectIndex; } - + /// /// HideItem /// 隐藏某个物品 @@ -368,7 +249,7 @@ public class UniversalItemContainer : IItemContainer /// private void HideItem(int index) { - var oldItem = _itemSlotNodes?[index].GetItemStack()?.GetItem(); + var oldItem = _itemSlotNodes?[index].GetItem(); if (oldItem is not Node2D oldNode2D) return; oldNode2D.ProcessMode = Node.ProcessModeEnum.Disabled; oldNode2D.Hide(); @@ -385,22 +266,25 @@ public class UniversalItemContainer : IItemContainer /// private void DisplayItem(int index) { - var item = _itemSlotNodes?[index].GetItemStack()?.GetItem(); + var item = _itemSlotNodes?[index].GetItem(); if (item is not Node2D newNode2D) return; newNode2D.ProcessMode = Node.ProcessModeEnum.Inherit; newNode2D.Show(); } - - [MustDisposeResource] - public IEnumerator GetEnumerator() + public void SelectItemSlot(int newSelectIndex) { - return _itemSlotNodes?.GetEnumerator() ?? Enumerable.Empty().GetEnumerator(); - } + if (newSelectIndex == _selectIndex) + { + return; + } - [MustDisposeResource] - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); + var safeIndex = GetSafeIndex(newSelectIndex); + if (safeIndex == UnknownIndex) + { + return; + } + + PrivateSelectItemSlot(_selectIndex, newSelectIndex); } } \ No newline at end of file diff --git a/scripts/item/ICommonItem.cs b/scripts/item/ICommonItem.cs deleted file mode 100644 index a41a60e..0000000 --- a/scripts/item/ICommonItem.cs +++ /dev/null @@ -1,24 +0,0 @@ -using ColdMint.scripts.item.itemStacks; - -namespace ColdMint.scripts.item; - -/// -/// The special item interface makes the item a normal item, in other words, will be stacked in -/// 该特殊的物品接口使得物品成为普通的物品,换言之,将会堆叠在中。 -/// -/// -/// -/// Notice when you implement: To avoid unexpected behavior, unless you understand what you're doing, the method -/// of an item that implements the interface must only match its own exact same instance. -/// -/// 实现时注意:为避免意外行为,除非你明白自己在做什么,否则实现接口的物品的方法必须只和自己完全相同的实例匹配。 -/// -public interface ICommonItem : IItem -{ - /// - /// Method to clone an instance same with self. Will be used to pick out item instance from a - /// 复制与自身相同的实例的方法。将用于从 中拿取新的物品实例。 - /// - /// - ICommonItem CloneInstance(); -} \ No newline at end of file diff --git a/scripts/item/IItem.cs b/scripts/item/IItem.cs index 6ed7bbb..2b40859 100644 --- a/scripts/item/IItem.cs +++ b/scripts/item/IItem.cs @@ -1,6 +1,4 @@ -using ColdMint.scripts.item.itemStacks; - -using Godot; +using Godot; namespace ColdMint.scripts.item; @@ -11,29 +9,36 @@ public interface IItem /// 当前项目的ID /// string Id { get; } + /// /// Icon of current item /// 当前项目的图标 /// Texture2D Icon { get; } + /// /// Display name of current item /// 显示当前Item的名称 /// string Name { get; } + /// /// Description of current item, which may show in inventory /// 当前项目的描述 /// string? Description { get; } + /// - /// - /// Whether the current item can be put into item containers like packsack.
- /// This attribute is usually set to false for items of the backpack class to avoid pack nesting. - ///
- /// 当前物品是否可以放入背包类的容器中。一般将背包类物品的该属性设为false来避免背包嵌套。 + /// Quantity + /// 当前的数量 ///
- bool CanPutInPack { get; } + int Quantity { get; set; } + + /// + /// MaxItemQuantity + /// 最大物品数量 + /// + int MaxQuantity { get; } /// /// Execute when current item is used
e.g. when player clicks left mouse button with current item in hand
@@ -42,43 +47,4 @@ public interface IItem /// Owner of current item, if any /// Target position, such as the position of the cursor when used by the player void Use(Node2D? owner, Vector2 targetGlobalPosition); - - /// - /// Execute when current item be removed from game. - /// 当前物品从游戏中移除时执行。 - /// - void Destroy(); - - /// - /// Return true if this item can be stacked with the given item in one stack - /// 若该物品是否能与给定物品堆叠在同一个物品堆上,返回true - /// - /// - /// - /// ! Note in the implementation: the correspondence of this predicate must be an equivalence relation over the full set of stackable items - /// (i.e., be able to derive a division into the full set of stackable items).
- /// Or if the item is not stackable, make it always return false. - ///
- /// - /// !实现时注意:该谓词的对应关系必须是在全部可堆叠的物品集合上的等价关系(即能导出一个对可堆叠物品全集的划分)。
- /// 或如果该物品不可堆叠,令其永远返回false。
- ///
- /// - /// If it is necessary to implement special stacking relationships (e.g. containers that can be stacked to hold items), - /// customize the special type, implement the special stacking determination in it by overriding , - /// and override the method so that it returns an instance of that custom ItemStack. - /// - /// - /// 如果有必要实现特殊的堆叠关系(如可以用堆叠来收纳物品的容器),请自定义特殊的类型,在其中重写以实现特殊的堆叠判定, - /// 并重写方法使其返回该自定义ItemStack实例。 - /// - ///
- bool CanStackWith(IItem item); - - /// - /// If this item need a special stack type, return the special item stack instance that contains the item. If else, just leave this null. - /// 如果该项目需要特殊的物品堆类型,重写此方法来返回包含该物品的特殊物品堆实例。否则,保留原本的null返回值。 - /// - /// - IItemStack? SpecialStack() => null; } \ No newline at end of file diff --git a/scripts/item/ItemTypeRegister.cs b/scripts/item/ItemTypeRegister.cs index 85bb773..65ff272 100644 --- a/scripts/item/ItemTypeRegister.cs +++ b/scripts/item/ItemTypeRegister.cs @@ -120,9 +120,7 @@ public static class ItemTypeRegister string ScenePath, string IconPath, int MaxStackValue, - IList? CustomArgs) - { - } + IList? CustomArgs); private readonly record struct CustomArg(string Name, CustomArgType Type, string Value) { diff --git a/scripts/item/Packsack.cs b/scripts/item/Packsack.cs index e29b3fa..54477ef 100644 --- a/scripts/item/Packsack.cs +++ b/scripts/item/Packsack.cs @@ -19,17 +19,7 @@ public partial class Packsack : PickAbleTemplate public int NumberSlots { get; set; } public override bool CanPutInPack => false; - - public override void Destroy() - { - if (ItemContainer == null) return; - foreach (var itemSlot in ItemContainer) - { - itemSlot.ClearSlot(); - } - - QueueFree(); - } + public override void Use(Node2D? owner, Vector2 targetGlobalPosition) { diff --git a/scripts/item/itemStacks/CommonItemStack.cs b/scripts/item/itemStacks/CommonItemStack.cs deleted file mode 100644 index 0018e04..0000000 --- a/scripts/item/itemStacks/CommonItemStack.cs +++ /dev/null @@ -1,108 +0,0 @@ -using System; -using Godot; - -namespace ColdMint.scripts.item.itemStacks; - -/// -/// An ordinary item pile, in which only one instance of the item is actually saved. -/// 普通的物品堆,堆中实际保存的物品实例仅有一个。 -/// -/// -///When the method is called in this implementation, the number of internal items is increased by one and new items passed in are destroyed. -///在此实现下调用方法时,会对内部物品的数量加一,并销毁传递进来的新物品。 -/// -/// -///innerItem -///内部物品 -/// -/// -/// -public class CommonItemStack(ICommonItem innerItem) : IItemStack -{ - public int MaxQuantity { get; } = ItemTypeManager.MaxStackQuantityOf(innerItem.Id); - public int Quantity { get; private set; } = 1; - public bool Empty => Quantity == 0; - public Texture2D Icon => innerItem.Icon; - public string Name => $"{innerItem.Name}({Quantity})"; - public string? Description => innerItem.Description; - - public bool CanAddItem(IItem item1) - { - return innerItem.CanStackWith(item1) && (Quantity < MaxQuantity); - } - - public bool AddItem(IItem item) - { - if (!CanAddItem(item)) return false; - Quantity++; - item.Destroy(); - return true; - } - - public int CanTakeFrom(IItemStack itemStack) - { - var item = itemStack.GetItem(); - if (item == null) - { - return 0; - } - if (itemStack.Empty || !innerItem.CanStackWith(item)) return 0; - return Math.Min(itemStack.Quantity, MaxQuantity - Quantity); - } - - public bool TakeFrom(IItemStack itemStack) - { - var number = CanTakeFrom(itemStack); - itemStack.RemoveItem(number); - Quantity += number; - return itemStack.Empty; - } - - public IItem? GetItem() - { - return Empty ? null : innerItem; - } - - public IItem? PickItem() - { - if(Empty) return null; - Quantity--; - var result = innerItem.CloneInstance(); - if(Empty) innerItem.Destroy(); - return result; - } - - public IItemStack? PickItems(int value) - { - if (Empty) return null; - var result = new CommonItemStack(innerItem.CloneInstance()); - var n = Math.Min(Quantity, value); - if (n < 0) - { - n = Quantity; - } - result.Quantity = n; - Quantity -= n; - if (Empty) innerItem.Destroy(); - return result; - } - - public int RemoveItem(int number) - { - var n = Math.Min(number, Quantity); - if (n < 0) - { - n = Quantity; - } - Quantity -= n; - if (Empty) innerItem.Destroy(); - return number - n; - } - - public void ClearStack() - { - if (Empty) return; - Quantity = 0; - innerItem.Destroy(); - } -} \ No newline at end of file diff --git a/scripts/item/itemStacks/IItemStack.cs b/scripts/item/itemStacks/IItemStack.cs deleted file mode 100644 index 7cb6bf8..0000000 --- a/scripts/item/itemStacks/IItemStack.cs +++ /dev/null @@ -1,175 +0,0 @@ -using System; -using Godot; - -namespace ColdMint.scripts.item.itemStacks; - -/// -/// 物品槽中的物品堆 -/// Item stack in an inventory slot -/// -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 stack - /// 当前物品堆显示的图标 - /// - Texture2D Icon { get; } - - /// - /// Display name of current item stack - /// 当前物品堆显示的名称 - /// - string Name { get; } - - /// - /// Description of current item stack, which may show in inventory - /// 当前物品堆的描述,可能显示在物品栏中 - /// - string? Description { get; } - - /// - /// Determine whether a specified item can be accommodated - /// 判断能否容纳指定物品 - /// - /// - public bool CanAddItem(IItem item); - - /// - /// Add items to the itemStack - /// 添加物品到物品堆内 - /// - /// - ///Items to add - ///需要添加的物品 - /// - /// - ///Whether successful - ///是否成功 - /// - public bool AddItem(IItem item); - - /// - /// Determines the number of items that can be received from the specified pile - /// 判断能从指定物品堆中接收的物品数量 - /// - /// - /// Item stack to add to the current stack - /// 向该物品堆中放入物品的物品堆 - /// - /// - public int CanTakeFrom(IItemStack itemStack); - - /// - /// Move as many items as possible from the specified item pile to the current item pile. Items that have been moved to the current item pile should be removed from the original item pile. - /// 将指定物品堆中尽可能多的物品移动至当前物品堆中,被移入当前堆的物品应从原物品堆中移除。 - /// - /// - /// The pile of items that are moved into the current pile - /// 被移入当前堆的物品堆 - /// - /// - /// Whether the original stack is empty after the operation - /// 操作结束后原物品堆是否为空 - /// - public bool TakeFrom(IItemStack itemStack); - - /// - /// Gets an item instance of the current item pile without retrieving the item - /// 获取当前物品堆的物品实例而不取出该物品 - /// - /// - /// - public IItem? GetItem(); - - /// - /// Pop the item instance at the top of current item stack and return it - /// 取出当前物品堆顶部的物品实例并返回该物品 - /// - /// - /// - public IItem? PickItem(); - - /// - /// Remove the specified number of items and return them as a new item stack - /// 取出当前堆中指定数量的物品,并作为新的物品堆返回 - /// - /// - /// - /// Quantity to be taken out, inputs below zero represent all items - /// 要取出的数量,小于0的输入代表全部物品 - /// - /// - /// The item stack that is taken out, can be null if out nothing, should not be the current item stack itself - /// 取出的物品堆,没有取出物品时可为null,不应是当前物品堆自身 - /// - public IItemStack? PickItems(int value); - - /// - /// - /// Removes the specified number of items from current item stack,removed items should be removed from the game
- /// If you don't want remove them from game, consider and - ///
- /// - /// 在当前物品堆移除指定数量的物品,被移除的物品应当从游戏中移除。
- /// 如果您并不打算将它们从游戏中移除,请考虑使用 - ///
- ///
- /// - /// Quantity to be removed, inputs below zero represent all items - /// 要删除的数量,小于0的输入代表全部物品 - /// - /// - /// The remaining number, if the number of items in the current item stack is less than the specified number. Otherwise,0 - /// 若物品槽内物品少于指定的数量,返回相差的数量。否则返回0 - /// - public int RemoveItem(int number); - - /// - /// 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 - /// 以给定的物品为第一个物品创建物品堆 - /// - /// - ///Assuming the item implements the method, then use the return value of the SpecialStack method, otherwise extrapolate from the maximum number of stacks of items. - ///假设物品实现了方法,那么使用SpecialStack方法的返回值,否则根据物品的最大堆叠数量来推断。 - /// - public static IItemStack FromItem(IItem item) => - item.SpecialStack() ?? - ItemTypeManager.MaxStackQuantityOf(item.Id) switch - { - 1 => new SingleItemStack(item), - > 1 => item is ICommonItem commonItem ? new CommonItemStack(commonItem) : new UniqueItemStack(item), - var other => throw new ArgumentException( - $"item {item} of type '{item.Id}' has unexpected max stack quantity {other}") - }; -} \ No newline at end of file diff --git a/scripts/item/itemStacks/PacksackStack.cs b/scripts/item/itemStacks/PacksackStack.cs deleted file mode 100644 index 3e96266..0000000 --- a/scripts/item/itemStacks/PacksackStack.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System; - -using Godot; - -namespace ColdMint.scripts.item.itemStacks; - -/// -/// ItemStack for item. Can add items into pack by stack them to this stack. -/// 用于物品的堆栈。可以将物品堆叠到此堆栈中,从而将物品添加到背包中。 -/// -/// -public class PacksackStack(Packsack packsack) : IItemStack -{ - public int MaxQuantity => 1; - public int Quantity => 1; - public bool Empty { get; private set; } - public Texture2D Icon => packsack.Icon; - public string Name => packsack.Name; - public string? Description => packsack.Description; - - public bool CanAddItem(IItem item) - { - if (!item.CanPutInPack) return false; - return packsack.ItemContainer?.CanAddItem(item) ?? false; - } - - public bool AddItem(IItem item) - { - if (!item.CanPutInPack) return false; - return packsack.ItemContainer?.AddItem(item) ?? false; - } - - public int CanTakeFrom(IItemStack itemStack) - { - if (itemStack.GetItem() is Packsack) return 0; - return packsack.ItemContainer?.CanAddItemStack(itemStack) ?? 0; - } - - public bool TakeFrom(IItemStack itemStack) - { - if (itemStack.GetItem() is Packsack) return false; - return packsack.ItemContainer?.AddItemStack(itemStack) ?? false; - } - - public IItem? GetItem() - { - return Empty ? null : packsack; - } - - public IItem? PickItem() - { - if (Empty) return null; - Empty = true; - return packsack; - } - - public IItemStack? PickItems(int value) - { - if (Empty || value == 0) return null; - Empty = true; - return new PacksackStack(packsack); - } - - public int RemoveItem(int number) - { - if (Empty || number == 0) return number; - Empty = true; - packsack.Destroy(); - return Math.Max(0, number - 1); - } - - public void ClearStack() - { - if (Empty) return; - packsack.Destroy(); - Empty = true; - } -} \ No newline at end of file diff --git a/scripts/item/itemStacks/SingleItemStack.cs b/scripts/item/itemStacks/SingleItemStack.cs deleted file mode 100644 index f573a37..0000000 --- a/scripts/item/itemStacks/SingleItemStack.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System; - -using Godot; - -namespace ColdMint.scripts.item.itemStacks; - -/// -/// One of the basic item stacks, there are always one item in stack(Stack not supported) -/// 单身狗物品堆,基础物品堆之一,堆中永远只会有一个物品(不支持堆叠) -/// -/// -/// -public class SingleItemStack(IItem item) : IItemStack -{ - public IItem Item { get; init; } = item; - - public int MaxQuantity => 1; - public int Quantity => 1; - public bool Empty { get; private set; } - public Texture2D Icon => Item.Icon; - public string Name => Item.Name; - public string? Description => Item.Description; - - public bool CanAddItem(IItem item) => false; - - public bool AddItem(IItem item) => false; - - public int CanTakeFrom(IItemStack itemStack) => 0; - - public bool TakeFrom(IItemStack itemStack) => false; - - public IItem? GetItem() - { - return Empty ? null : Item; - } - - public IItem? PickItem() - { - if (Empty) return null; - Empty = true; - return Item; - } - - public IItemStack? PickItems(int value) - { - if (value == 0 || Empty) return null; - - Empty = true; - return new SingleItemStack(Item); - } - - public int RemoveItem(int number) - { - if (number == 0 || Empty) return 0; - Empty = true; - Item.Destroy(); - return Math.Max(number - 1, 0); - } - - public void ClearStack() - { - RemoveItem(1); - } -} \ No newline at end of file diff --git a/scripts/item/itemStacks/UniqueItemStack.cs b/scripts/item/itemStacks/UniqueItemStack.cs deleted file mode 100644 index 4837fe8..0000000 --- a/scripts/item/itemStacks/UniqueItemStack.cs +++ /dev/null @@ -1,123 +0,0 @@ -using System; -using System.Collections.Generic; -using Godot; - -namespace ColdMint.scripts.item.itemStacks; - -/// -/// One of the basic item stacks, where each item in the stack maintains its original state (allowing for items that are not identical to each other) -/// 独特物品堆,基础物品堆之一,堆中的每一个物品会保持各自原本的状态(允许互不相同的物品存在) -/// -/// -public class UniqueItemStack : IItemStack -{ - private readonly Stack _items; - - public UniqueItemStack(IItem item) - { - _items = []; - _items.Push(item); - MaxQuantity = ItemTypeManager.MaxStackQuantityOf(item.Id); - } - - - private UniqueItemStack(UniqueItemStack from) - { - _items = from._items; - MaxQuantity = from.MaxQuantity; - Quantity = from.Quantity; - from.Quantity = 0; - } - - public int MaxQuantity { get; } - public int Quantity { get; private set; } = 1; - public bool Empty => Quantity == 0; - public Texture2D Icon => GetItem()?.Icon ?? new PlaceholderTexture2D(); - public string Name => $"{GetItem()?.Name}({Quantity})"; - public string? Description => GetItem()?.Description; - - public bool CanAddItem(IItem item) - { - //当两个物品相容,且当前堆未满时,我们返回true - return (GetItem()?.CanStackWith(item) ?? false) && (Quantity < MaxQuantity); - } - - public bool AddItem(IItem item) - { - if (!CanAddItem(item)) return false; - _items.Push(item); - Quantity++; - return true; - } - - public int CanTakeFrom(IItemStack itemStack) - { - if (!(itemStack.GetItem() is { } item)) return 0; - //如果两个物品相容,那么可以获取的数量取决于当前物品堆空位的大小和对方物品数量中较小的一方 - if (CanAddItem(item)) - return Mathf.Min(itemStack.Quantity, MaxQuantity - Quantity); - else return 0; - } - - public bool TakeFrom(IItemStack itemStack) - { - var value = CanTakeFrom(itemStack); - for (int i = 0; i < value; i++) - { - //一个如果代码没有出错就用不到的安全检查 - if (!AddItem(itemStack.PickItem()!)) break; - } - - return itemStack.Empty; - } - - public IItem? GetItem() - { - return Empty ? null : _items.Peek(); - } - - public IItem? PickItem() - { - if (Empty) return null; - Quantity--; - return _items.Pop(); - } - - public IItemStack? PickItems(int value) - { - if (Empty) return null; - - if (value < 0) value = Quantity; - - var result = new UniqueItemStack(PickItem()!); - //Calculate the amount left to take out - //计算剩余的要取出的数量 - var restToMove = Math.Min(value - 1, Quantity); - for (var i = 0; i < restToMove; i++) - { - result.AddItem(PickItem()!); - } - - return result; - } - - public int RemoveItem(int number) - { - if (number < 0) number = Quantity; - while (number > 0 && Quantity > 0) - { - PickItem()!.Destroy(); - number--; - } - - return number; - } - - public void ClearStack() - { - while (Quantity > 0) - { - PickItem()!.Destroy(); - } - } -} \ No newline at end of file diff --git a/scripts/loader/uiLoader/MainMenuLoader.cs b/scripts/loader/uiLoader/MainMenuLoader.cs index 14d263b..7360ae9 100644 --- a/scripts/loader/uiLoader/MainMenuLoader.cs +++ b/scripts/loader/uiLoader/MainMenuLoader.cs @@ -22,146 +22,146 @@ namespace ColdMint.scripts.loader.uiLoader; ///
public partial class MainMenuLoader : UiLoaderTemplate { - private Button? _startGameButton; - private Label? _copyrightLabel; - private StringBuilder? _copyrightBuilder; - private PackedScene? _gameScene; - private PackedScene? _contributor; - private PackedScene? _levelGraphEditor; - private Label? _sloganLabel; - private Label? _versionLabel; - private Button? _levelGraphEditorButton; - private LinkButton? _contributorButton; + private Button? _startGameButton; + private Label? _copyrightLabel; + private StringBuilder? _copyrightBuilder; + private PackedScene? _gameScene; + private PackedScene? _contributor; + private PackedScene? _levelGraphEditor; + private Label? _sloganLabel; + private Label? _versionLabel; + private Button? _levelGraphEditorButton; + private LinkButton? _contributorButton; - public override void InitializeData() - { - if (Config.IsDebug()) - { - //Set the minimum log level to Info in debug mode.(Print all logs) - //在调试模式下将最小日志等级设置为Info。(打印全部日志) - LogCat.MinLogLevel = LogCat.InfoLogLevel; - } - else - { - //Disable all logs in the release version. - //在发行版禁用所有日志。 - LogCat.MinLogLevel = LogCat.DisableAllLogLevel; - } + public override void InitializeData() + { + if (Config.IsDebug()) + { + //Set the minimum log level to Info in debug mode.(Print all logs) + //在调试模式下将最小日志等级设置为Info。(打印全部日志) + LogCat.MinLogLevel = LogCat.InfoLogLevel; + } + else + { + //Disable all logs in the release version. + //在发行版禁用所有日志。 + LogCat.MinLogLevel = LogCat.DisableAllLogLevel; + } - ContributorDataManager.RegisterAllContributorData(); - DeathInfoGenerator.RegisterDeathInfoHandler(new SelfDeathInfoHandler()); - MapGenerator.RegisterRoomInjectionProcessor(new ChanceRoomInjectionProcessor()); - MapGenerator.RegisterRoomInjectionProcessor(new TimeIntervalRoomInjectorProcessor()); - //Register the corresponding encoding provider to solve the problem of garbled Chinese path of the compressed package - //注册对应的编码提供程序,解决压缩包中文路径乱码问题 - Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); - //创建游戏数据文件夹 - var dataPath = Config.GetGameDataDirectory(); - if (!Directory.Exists(dataPath)) - { - Directory.CreateDirectory(dataPath); - } + ContributorDataManager.RegisterAllContributorData(); + DeathInfoGenerator.RegisterDeathInfoHandler(new SelfDeathInfoHandler()); + MapGenerator.RegisterRoomInjectionProcessor(new ChanceRoomInjectionProcessor()); + MapGenerator.RegisterRoomInjectionProcessor(new TimeIntervalRoomInjectorProcessor()); + //Register the corresponding encoding provider to solve the problem of garbled Chinese path of the compressed package + //注册对应的编码提供程序,解决压缩包中文路径乱码问题 + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + //创建游戏数据文件夹 + var dataPath = Config.GetGameDataDirectory(); + if (!Directory.Exists(dataPath)) + { + Directory.CreateDirectory(dataPath); + } - //Registered camp - //注册阵营 - var defaultCamp = new Camp(Config.CampId.Default) - { - FriendInjury = true - }; - CampManager.SetDefaultCamp(defaultCamp); - var mazoku = new Camp(Config.CampId.Mazoku); - CampManager.AddCamp(mazoku); - var aborigines = new Camp(Config.CampId.Aborigines); - CampManager.AddCamp(aborigines); - _gameScene = GD.Load("res://scenes/game.tscn"); - _contributor = GD.Load("res://scenes/contributor.tscn"); - _levelGraphEditor = GD.Load("res://scenes/levelGraphEditor.tscn"); - - //Register ItemTypes from file - //从文件注册物品类型 - ItemTypeRegister.RegisterFromFile(); - //Hardcoded ItemTypes Register - //硬编码注册物品类型 - ItemTypeRegister.StaticRegister(); - - //静态注册掉落表 - LootRegister.StaticRegister(); - } + //Registered camp + //注册阵营 + var defaultCamp = new Camp(Config.CampId.Default) + { + FriendInjury = true + }; + CampManager.SetDefaultCamp(defaultCamp); + var mazoku = new Camp(Config.CampId.Mazoku); + CampManager.AddCamp(mazoku); + var aborigines = new Camp(Config.CampId.Aborigines); + CampManager.AddCamp(aborigines); + _gameScene = GD.Load("res://scenes/game.tscn"); + _contributor = GD.Load("res://scenes/contributor.tscn"); + _levelGraphEditor = GD.Load("res://scenes/levelGraphEditor.tscn"); + + //Register ItemTypes from file + //从文件注册物品类型 + ItemTypeRegister.RegisterFromFile(); + //Hardcoded ItemTypes Register + //硬编码注册物品类型 + ItemTypeRegister.StaticRegister(); + + //静态注册掉落表 + LootRegister.StaticRegister(); + } - public override void InitializeUi() - { - _contributorButton = GetNode("VBoxContainer2/ContributorButton"); - _startGameButton = GetNode
/// - public void Flip(bool facingLeft) { } + public void Flip(bool facingLeft) + { + } public virtual void Destroy() {