Make packsack new interface, too.

This commit is contained in:
霧雨烨 2024-06-13 11:04:51 +08:00
parent c1aecf21d7
commit e307a58299
9 changed files with 46 additions and 16 deletions

View File

@ -8,4 +8,7 @@
<Nullable>enable</Nullable>
<LangVersion>12</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
</ItemGroup>
</Project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -10,6 +10,7 @@ size = Vector2(41, 57)
collision_layer = 8
collision_mask = 38
script = ExtResource("1_8ehup")
Id = "packsack"
metadata/Id = "Packsack"
metadata/MaxStackQuantity = 1
metadata/Icon = ExtResource("2_e1ale")

View File

@ -6,6 +6,7 @@ using ColdMint.scripts.damage;
using ColdMint.scripts.deathInfo;
using ColdMint.scripts.debug;
using ColdMint.scripts.inventory;
using ColdMint.scripts.item;
using ColdMint.scripts.map.events;
using ColdMint.scripts.utils;
using ColdMint.scripts.item.weapon;

View File

@ -1,5 +1,8 @@
using System;
using ColdMint.scripts.debug;
using ColdMint.scripts.item;
using Godot;
namespace ColdMint.scripts.inventory;
@ -10,26 +13,41 @@ namespace ColdMint.scripts.inventory;
/// </summary>
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<IItem>? OnUse { get; set; }
public Func<IItem, Node>? 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<Texture2D>();
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<Texture2D>();
// Name = GetMeta("Name", "").AsString();
// Description = GetMeta("Description", "").AsString();
_itemContainer = new UniversalItemContainer();
}

View File

@ -12,8 +12,15 @@ 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>(), null, 1);
var staffOfTheUndeadIcon = ResourceLoader.Load<Texture2D>("res://sprites/weapon/staffOfTheUndead.png");
var staffOfTheUndead =
new ItemType("staff_of_the_undead", () => staffOfTheUndeadScene.Instantiate<IItem>(), staffOfTheUndeadIcon, 1);
Register(staffOfTheUndead);
var packsackScene = ResourceLoader.Load<PackedScene>("res://prefab/packsacks/packsack.tscn");
var packsackIcon = ResourceLoader.Load<Texture2D>("res://sprites/Player.png");
var packsack = new ItemType("packsack", () => packsackScene.Instantiate<IItem>(), packsackIcon, 1);
Register(packsack);
}
private static Dictionary<string, ItemType> Registry { get; } = [];

View File

@ -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; }