From e307a5829959f71d9457f1a9d76a3d953f6ca968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9C=A7=E9=9B=A8=E7=83=A8?= Date: Thu, 13 Jun 2024 11:04:51 +0800 Subject: [PATCH] Make packsack new interface, too. --- ColdMint.Traveler.csproj | 3 ++ locals/Item.en.translation | Bin 570 -> 570 bytes locals/Item.ja.translation | Bin 693 -> 693 bytes locals/Item.zh.translation | Bin 609 -> 609 bytes prefab/packsacks/packsack.tscn | 1 + scripts/character/Player.cs | 1 + scripts/inventory/Packsack.cs | 46 ++++++++++++++++++-------- scripts/item/ItemTypeManager.cs | 9 ++++- scripts/item/weapon/WeaponTemplate.cs | 2 +- 9 files changed, 46 insertions(+), 16 deletions(-) diff --git a/ColdMint.Traveler.csproj b/ColdMint.Traveler.csproj index c893429..ec53ff3 100644 --- a/ColdMint.Traveler.csproj +++ b/ColdMint.Traveler.csproj @@ -8,4 +8,7 @@ enable 12 + + + \ No newline at end of file diff --git a/locals/Item.en.translation b/locals/Item.en.translation index 1c8ae5245b84c7d6c4aac1b1b6a586822361efa6..f16d6d9617920b6cb1672fab2900d03969731584 100644 GIT binary patch delta 149 zcmdnRvWsPdG$X57T5)FnWCcdE`u{+{00eA6%mc)%K&$}7VnECY#nB?~1A$Bi0U#EH zih<zNUahOTLN+1bgdiKKw1WfRe=~}mpl-MGcZiP%9siO DS85fr delta 149 zcmdnRvWsPdG$U)CQJO`@WCcdEdIlh117ZOn{tpDKKw1Ha#ekR*isMghyAG090%A)b zW`c@)Jlp)s2*~DyVg(7=$JRi$3=pdVF-*TC-v>1y7i@Mc}BPT|3JV11Z+Ue1H`OAtN_GfK+Fim(IW2yflLNoD29pW w9XrkH0u*D1VkRIBlKZ)9p&>}EITXiD*Sg^iWUE3k$S!#xE?{7o{DiR<09J7p6#xJL delta 148 zcmaFJ@{nbNG$Tu)Sz_X3c}BN-1|VPqVgVrj4+N}0S^ public partial class Packsack : RigidBody2D, IItem { - public string? Id { get; set; } - public int Quantity { get; set; } - public int MaxStackQuantity { get; set; } - public Texture2D? Icon { get; set; } - public new string? Name { get; set; } - public string? Description { get; set; } - public Action? OnUse { get; set; } - public Func? OnInstantiation { get; set; } + [Export] public string Id { get; protected set; } = "place_holder_id"; + + protected Texture2D? UniqueIcon { get; set; } + public Texture2D Icon => UniqueIcon ?? ItemTypeManager.DefaultIconOf(Id); + + protected string? UniqueName { get; set; } + public new string Name => UniqueName ?? ItemTypeManager.DefaultNameOf(Id); + + protected string? UniqueDescription { get; set; } + public string? Description => UniqueDescription ?? ItemTypeManager.DefaultDescriptionOf(Id); + + public void Use(Node2D? owner, Vector2 targetGlobalPosition) { } + + public void Destroy() + { + if (_itemContainer == null) return; + foreach (var itemSlot in _itemContainer) + { + itemSlot.ClearSlot(); + } + + QueueFree(); + } private IItemContainer? _itemContainer; 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(); - Name = GetMeta("Name", "").AsString(); - Description = GetMeta("Description", "").AsString(); + // Id = GetMeta("ID", "1").AsString(); + // Quantity = GetMeta("Quantity", "1").AsInt32(); + // MaxStackQuantity = GetMeta("MaxStackQuantity", Config.MaxStackQuantity).AsInt32(); + // Icon = GetMeta("Icon", "").As(); + // Name = GetMeta("Name", "").AsString(); + // Description = GetMeta("Description", "").AsString(); _itemContainer = new UniversalItemContainer(); } diff --git a/scripts/item/ItemTypeManager.cs b/scripts/item/ItemTypeManager.cs index 663d736..c2e116d 100644 --- a/scripts/item/ItemTypeManager.cs +++ b/scripts/item/ItemTypeManager.cs @@ -12,8 +12,15 @@ public static class ItemTypeManager public static void StaticRegister() { var staffOfTheUndeadScene = ResourceLoader.Load("res://prefab/weapons/staffOfTheUndead.tscn"); - var staffOfTheUndead = new ItemType("staff_of_the_undead", () => staffOfTheUndeadScene.Instantiate(), null, 1); + var staffOfTheUndeadIcon = ResourceLoader.Load("res://sprites/weapon/staffOfTheUndead.png"); + var staffOfTheUndead = + new ItemType("staff_of_the_undead", () => staffOfTheUndeadScene.Instantiate(), staffOfTheUndeadIcon, 1); Register(staffOfTheUndead); + + var packsackScene = ResourceLoader.Load("res://prefab/packsacks/packsack.tscn"); + var packsackIcon = ResourceLoader.Load("res://sprites/Player.png"); + var packsack = new ItemType("packsack", () => packsackScene.Instantiate(), packsackIcon, 1); + Register(packsack); } private static Dictionary Registry { get; } = []; diff --git a/scripts/item/weapon/WeaponTemplate.cs b/scripts/item/weapon/WeaponTemplate.cs index e8bd693..b4be423 100644 --- a/scripts/item/weapon/WeaponTemplate.cs +++ b/scripts/item/weapon/WeaponTemplate.cs @@ -20,7 +20,7 @@ public abstract partial class WeaponTemplate : RigidBody2D, IItem //Implements IItem [Export] public virtual string Id { get; private set; } = "ID"; - protected virtual Texture2D? UniqueIcon { get; set; } + protected Texture2D? UniqueIcon { get; set; } public Texture2D Icon => UniqueIcon ?? ItemTypeManager.DefaultIconOf(Id); protected string? UniqueName { get; set; }