diff --git a/data/itemRegs/packsacks.yaml b/data/itemRegs/packsacks.yaml
index 707ade6..3c77d2f 100644
--- a/data/itemRegs/packsacks.yaml
+++ b/data/itemRegs/packsacks.yaml
@@ -1,5 +1,9 @@
#Register an item container here.
#在这里注册物品容器。
+#Note: The id must be the same as the item id in the scene. Otherwise, an ArgumentException will be thrown.
+#备注:id必须和场景内的物品id保持一致。否则会抛出ArgumentException。
+#After you declare the id of the item, add the corresponding localized text to the csv file in the locals' folder. For example, if the id is a corresponding name is item_a and the corresponding description is item_a_desc.
+#当您声明物品的id后,请在locals文件夹中的csv文件中添加相应的本地化文本。例如:id为a,则对应的名称为item_a,对应的描述为item_a_desc。
#portable_backpacks
#便携式背包
diff --git a/data/itemRegs/weapons.yaml b/data/itemRegs/weapons.yaml
index 41e5514..061fc51 100644
--- a/data/itemRegs/weapons.yaml
+++ b/data/itemRegs/weapons.yaml
@@ -1,5 +1,9 @@
#Register your weapon here.
#在这里注册你的武器。
+#Note: The id must be the same as the item id in the scene. Otherwise, an ArgumentException will be thrown.
+#备注:id必须和场景内的物品id保持一致。否则会抛出ArgumentException。
+#After you declare the id of the item, add the corresponding localized text to the csv file in the locals' folder. For example, if the id is a corresponding name is item_a and the corresponding description is item_a_desc.
+#当您声明物品的id后,请在locals文件夹中的csv文件中添加相应的本地化文本。例如:id为a,则对应的名称为item_a,对应的描述为item_a_desc。
#staff_necromancy
#死灵法杖
diff --git a/locals/Item.csv b/locals/Item.csv
index 7085a40..78af003 100644
--- a/locals/Item.csv
+++ b/locals/Item.csv
@@ -1,5 +1,5 @@
id,zh,en,ja
-item_staff_of_the_undead,死灵法杖,StaffOfTheUndead,ネクロポリスの杖です
-item_staff_of_the_undead_desc,发射诅咒,可将敌人转化为邪恶的怪物。,Cast a curse that transforms enemies into evil monsters.,呪いを発射して、敵を邪悪な怪物に変えることができます。
-item_packsack,背包,Packsack,背嚢
-item_packsack_desc,可以装载更多物品的背包。,A backpack that can hold more items.,より多くのアイテムを保持できるバックパックです。
\ No newline at end of file
+item_staff_necromancy,死灵法杖,staffNecromancy,ネクロポリスの杖です
+item_staff_necromancy_desc,发射诅咒,可将敌人转化为邪恶的怪物。,Cast a curse that transforms enemies into evil monsters.,呪いを発射して、敵を邪悪な怪物に変えることができます。
+item_portable_backpacks,便携式背包,PortableBackpacks,ポータブルバックパック
+item_portable_backpacks_desc,为玩家提供9个物品槽。,Provides 9 item slots for the player.,プレイヤーに9つのアイテムスロットを提供します。
\ No newline at end of file
diff --git a/prefab/packsacks/PortableBackpacks.tscn b/prefab/packsacks/PortableBackpacks.tscn
index 90b577b..3079339 100644
--- a/prefab/packsacks/PortableBackpacks.tscn
+++ b/prefab/packsacks/PortableBackpacks.tscn
@@ -14,7 +14,6 @@ collision_layer = 8
collision_mask = 38
script = ExtResource("1_slakl")
NumberSlots = 30
-Id = "packsack"
[node name="DamageArea2D" type="Area2D" parent="."]
collision_layer = 8
diff --git a/prefab/roomTemplates/dungeon/initialRoom.tscn b/prefab/roomTemplates/dungeon/initialRoom.tscn
index ba92a1f..c2ee845 100644
--- a/prefab/roomTemplates/dungeon/initialRoom.tscn
+++ b/prefab/roomTemplates/dungeon/initialRoom.tscn
@@ -1,9 +1,8 @@
-[gd_scene load_steps=8 format=4 uid="uid://du5ldsp613fei"]
+[gd_scene load_steps=7 format=4 uid="uid://du5ldsp613fei"]
[ext_resource type="TileSet" uid="uid://c4wpp12rr44hi" path="res://tileSets/dungeon.tres" id="1_rn2om"]
[ext_resource type="Script" path="res://scripts/map/PlayerSpawn.cs" id="2_6p8mv"]
[ext_resource type="Script" path="res://scripts/map/ItemSpawn.cs" id="3_v1tlc"]
-[ext_resource type="Texture2D" uid="uid://b2blj0yf4ohx3" path="res://icon.svg" id="4_psvpu"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_kiih8"]
size = Vector2(450, 191)
@@ -42,11 +41,7 @@ script = ExtResource("2_6p8mv")
[node name="ItemMarker2D" type="Marker2D" parent="."]
position = Vector2(142, 84)
script = ExtResource("3_v1tlc")
-ItemId = "staff_of_the_undead"
-
-[node name="Icon" type="Sprite2D" parent="ItemMarker2D"]
-scale = Vector2(0.3, 0.3)
-texture = ExtResource("4_psvpu")
+ItemId = "staff_necromancy"
[node name="NavigationRegion2D" type="NavigationRegion2D" parent="."]
navigation_polygon = SubResource("NavigationPolygon_064c7")
diff --git a/prefab/weapons/StaffNecromancy.tscn b/prefab/weapons/StaffNecromancy.tscn
index 4ea975a..0243e8e 100644
--- a/prefab/weapons/StaffNecromancy.tscn
+++ b/prefab/weapons/StaffNecromancy.tscn
@@ -1,8 +1,9 @@
-[gd_scene load_steps=7 format=3 uid="uid://dnnn2xyayiehk"]
+[gd_scene load_steps=8 format=3 uid="uid://dnnn2xyayiehk"]
[ext_resource type="Texture2D" uid="uid://wt50kx6bup51" path="res://sprites/weapon/StaffNecromancy.png" id="1_ms3us"]
[ext_resource type="Script" path="res://scripts/weapon/ProjectileWeapon.cs" id="1_w8hhv"]
[ext_resource type="PackedScene" uid="uid://c01av43yk1q71" path="res://prefab/projectile/curseOfTheUndead.tscn" id="2_34250"]
+[ext_resource type="Texture2D" uid="uid://dg5vwprt66w4j" path="res://sprites/weapon/StaffNecromancy_Icon.png" id="3_31iau"]
[ext_resource type="AudioStream" uid="uid://cak6chjjsu7wo" path="res://sounds/fire.wav" id="4_ffr2k"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_obcq2"]
@@ -17,7 +18,7 @@ collision_mask = 34
script = ExtResource("1_w8hhv")
ProjectileScenes = [ExtResource("2_34250")]
FiringIntervalAsMillisecond = 300
-Id = "staff_of_the_undead"
+UniqueIcon = ExtResource("3_31iau")
[node name="DamageArea2D" type="Area2D" parent="."]
collision_layer = 8
diff --git a/scripts/inventory/IItem.cs b/scripts/inventory/IItem.cs
index 65ece50..f64a988 100644
--- a/scripts/inventory/IItem.cs
+++ b/scripts/inventory/IItem.cs
@@ -6,9 +6,9 @@ public interface IItem
{
///
/// ID of current item
- /// 当前项目的ID
+ /// 当前物品的ID
///
- string Id { get; }
+ string Id { get; set; }
///
/// Icon of current item
diff --git a/scripts/inventory/ItemType.cs b/scripts/inventory/ItemType.cs
index e8e83c7..f1aaaa5 100644
--- a/scripts/inventory/ItemType.cs
+++ b/scripts/inventory/ItemType.cs
@@ -5,9 +5,10 @@ namespace ColdMint.scripts.inventory;
public readonly struct ItemType(
string id,
- Func createItemFunc,
Texture2D? icon,
- int maxStackQuantity)
+ int maxStackQuantity,
+ Func createItemFunc
+)
{
///
/// Item id of this type
@@ -19,7 +20,7 @@ public readonly struct ItemType(
/// A function returns a new item instance of this type
/// 用于创建该类型的物品实例的函数
///
- public Func CreateItemFunc { get; init; } = createItemFunc;
+ public Func CreateItemFunc { get; init; } = createItemFunc;
///
/// Default icon of items of this type
diff --git a/scripts/inventory/ItemTypeManager.cs b/scripts/inventory/ItemTypeManager.cs
index 75861b7..29b759b 100644
--- a/scripts/inventory/ItemTypeManager.cs
+++ b/scripts/inventory/ItemTypeManager.cs
@@ -1,5 +1,4 @@
using System.Collections.Generic;
-using ColdMint.scripts.utils;
using Godot;
namespace ColdMint.scripts.inventory;
@@ -49,7 +48,7 @@ public static class ItemTypeManager
///
- /// Create multiple new item instances for the given item Id
+ /// Create multiple new item instances for the given item ID
/// 创建多个给定物品Id的新物品实例
///
///
@@ -84,24 +83,7 @@ public static class ItemTypeManager
return items.ToArray();
}
-
- ///
- /// Get the translated default name of the item type for the given id
- /// 获取指定物品id翻译后的物品名
- ///
- ///
- /// Translated default name of the item id if it exists. Else, return the id itself
- ///
- public static string DefaultNameOf(string id) => TranslationServerUtils.Translate($"item_{id}") ?? id;
-
- ///
- /// Get the translated default description of the item type for the given id
- /// 获取指定物品id翻译后的描述
- ///
- ///
- /// Translated default description of the item id if it exists. Else, return null
- ///
- public static string? DefaultDescriptionOf(string id) => TranslationServerUtils.Translate($"item_{id}_desc");
+
///
/// Get the default icon of the item type for the given id
diff --git a/scripts/inventory/ItemTypeRegister.cs b/scripts/inventory/ItemTypeRegister.cs
index cf329ce..8ff408f 100644
--- a/scripts/inventory/ItemTypeRegister.cs
+++ b/scripts/inventory/ItemTypeRegister.cs
@@ -1,5 +1,4 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
using ColdMint.scripts.debug;
using ColdMint.scripts.serialization;
using ColdMint.scripts.utils;
@@ -30,7 +29,7 @@ public static class ItemTypeRegister
LogCat.Log("start_item_register_from_file");
//初始化文件目录
//initialize file dir
- var itemRegsDirPath = "res://data/itemRegs";
+ const string itemRegsDirPath = "res://data/itemRegs";
var itemRegsDir = DirAccess.Open(itemRegsDirPath);
var error = DirAccess.GetOpenError();
if (error is not Error.Ok)
@@ -103,15 +102,10 @@ public static class ItemTypeRegister
//加载场景和图标
var scene = ResourceLoader.Load(typeInfo.ScenePath);
var icon = ResourceLoader.Load(typeInfo.IconPath);
-
-
- //Create init delegate
- //创建初始化委托
- Action? setArgs = null;
//构造项目类型,寄存器
//construct item type, register
var itemType = new ItemType(typeInfo.Id,
- defaultParentNode =>
+ icon, typeInfo.MaxStackValue, defaultParentNode =>
{
var newItem = NodeUtils.InstantiatePackedScene(scene);
if (newItem is not Node node) return newItem;
@@ -121,11 +115,10 @@ public static class ItemTypeRegister
return null;
}
- setArgs?.Invoke(node);
+ newItem.Id = typeInfo.Id;
NodeUtils.CallDeferredAddChild(NodeUtils.FindContainerNode(node, defaultParentNode), node);
return newItem;
- },
- icon, typeInfo.MaxStackValue);
+ });
var succeed = ItemTypeManager.Register(itemType);
LogCat.LogWithFormat("register_item", label: LogCat.LogLabel.Default, LogCat.UploadFormat, itemType.Id,
succeed);
@@ -138,5 +131,4 @@ public static class ItemTypeRegister
string ScenePath,
string IconPath,
int MaxStackValue);
-
}
\ No newline at end of file
diff --git a/scripts/pickable/PickAbleTemplate.cs b/scripts/pickable/PickAbleTemplate.cs
index 21f147f..ea3852b 100644
--- a/scripts/pickable/PickAbleTemplate.cs
+++ b/scripts/pickable/PickAbleTemplate.cs
@@ -4,6 +4,7 @@ using ColdMint.scripts.character;
using ColdMint.scripts.damage;
using ColdMint.scripts.debug;
using ColdMint.scripts.inventory;
+using ColdMint.scripts.utils;
using Godot;
namespace ColdMint.scripts.pickable;
@@ -14,12 +15,21 @@ namespace ColdMint.scripts.pickable;
///
public partial class PickAbleTemplate : RigidBody2D, IItem
{
- [Export] public virtual string Id { get; set; } = "ID";
+ //Do not export this field because the ID is specified within yaml.
+ //不要导出此字段,因为ID是在yaml内指定的。
+ public virtual string Id { get; set; } = "ID";
[Export] protected Texture2D? UniqueIcon { get; set; }
public Texture2D Icon => UniqueIcon ?? ItemTypeManager.DefaultIconOf(Id);
- [Export] protected string? UniqueName { get; set; }
- public new string Name => UniqueName ?? ItemTypeManager.DefaultNameOf(Id);
- [Export] protected string? UniqueDescription { get; set; }
+
+ public new string Name
+ {
+ get
+ {
+ var key = $"item_{Id}";
+ return TranslationServerUtils.Translate(key) ?? key;
+ }
+ }
+
public virtual bool CanPutInPack => true;
///
@@ -37,7 +47,15 @@ public partial class PickAbleTemplate : RigidBody2D, IItem
[Export] private int _minContactInjury = 1;
[Export] private int _maxContactInjury = 2;
- public string? Description => UniqueDescription ?? ItemTypeManager.DefaultDescriptionOf(Id);
+ public string Description
+ {
+ get
+ {
+ var key = $"item_{Id}_desc";
+ return TranslationServerUtils.Translate(key) ?? key;
+ }
+ }
+
public int Quantity { get; set; } = 1;
///