Make packsack new interface, too.
This commit is contained in:
parent
c1aecf21d7
commit
e307a58299
|
@ -8,4 +8,7 @@
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<LangVersion>12</LangVersion>
|
<LangVersion>12</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -10,6 +10,7 @@ size = Vector2(41, 57)
|
||||||
collision_layer = 8
|
collision_layer = 8
|
||||||
collision_mask = 38
|
collision_mask = 38
|
||||||
script = ExtResource("1_8ehup")
|
script = ExtResource("1_8ehup")
|
||||||
|
Id = "packsack"
|
||||||
metadata/Id = "Packsack"
|
metadata/Id = "Packsack"
|
||||||
metadata/MaxStackQuantity = 1
|
metadata/MaxStackQuantity = 1
|
||||||
metadata/Icon = ExtResource("2_e1ale")
|
metadata/Icon = ExtResource("2_e1ale")
|
||||||
|
|
|
@ -6,6 +6,7 @@ using ColdMint.scripts.damage;
|
||||||
using ColdMint.scripts.deathInfo;
|
using ColdMint.scripts.deathInfo;
|
||||||
using ColdMint.scripts.debug;
|
using ColdMint.scripts.debug;
|
||||||
using ColdMint.scripts.inventory;
|
using ColdMint.scripts.inventory;
|
||||||
|
using ColdMint.scripts.item;
|
||||||
using ColdMint.scripts.map.events;
|
using ColdMint.scripts.map.events;
|
||||||
using ColdMint.scripts.utils;
|
using ColdMint.scripts.utils;
|
||||||
using ColdMint.scripts.item.weapon;
|
using ColdMint.scripts.item.weapon;
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
using ColdMint.scripts.debug;
|
using ColdMint.scripts.debug;
|
||||||
|
using ColdMint.scripts.item;
|
||||||
|
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace ColdMint.scripts.inventory;
|
namespace ColdMint.scripts.inventory;
|
||||||
|
@ -10,26 +13,41 @@ namespace ColdMint.scripts.inventory;
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class Packsack : RigidBody2D, IItem
|
public partial class Packsack : RigidBody2D, IItem
|
||||||
{
|
{
|
||||||
public string? Id { get; set; }
|
[Export] public string Id { get; protected set; } = "place_holder_id";
|
||||||
public int Quantity { get; set; }
|
|
||||||
public int MaxStackQuantity { get; set; }
|
protected Texture2D? UniqueIcon { get; set; }
|
||||||
public Texture2D? Icon { get; set; }
|
public Texture2D Icon => UniqueIcon ?? ItemTypeManager.DefaultIconOf(Id);
|
||||||
public new string? Name { get; set; }
|
|
||||||
public string? Description { get; set; }
|
protected string? UniqueName { get; set; }
|
||||||
public Action<IItem>? OnUse { get; set; }
|
public new string Name => UniqueName ?? ItemTypeManager.DefaultNameOf(Id);
|
||||||
public Func<IItem, Node>? OnInstantiation { get; set; }
|
|
||||||
|
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;
|
private IItemContainer? _itemContainer;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
base._Ready();
|
base._Ready();
|
||||||
Id = GetMeta("ID", "1").AsString();
|
// Id = GetMeta("ID", "1").AsString();
|
||||||
Quantity = GetMeta("Quantity", "1").AsInt32();
|
// Quantity = GetMeta("Quantity", "1").AsInt32();
|
||||||
MaxStackQuantity = GetMeta("MaxStackQuantity", Config.MaxStackQuantity).AsInt32();
|
// MaxStackQuantity = GetMeta("MaxStackQuantity", Config.MaxStackQuantity).AsInt32();
|
||||||
Icon = GetMeta("Icon", "").As<Texture2D>();
|
// Icon = GetMeta("Icon", "").As<Texture2D>();
|
||||||
Name = GetMeta("Name", "").AsString();
|
// Name = GetMeta("Name", "").AsString();
|
||||||
Description = GetMeta("Description", "").AsString();
|
// Description = GetMeta("Description", "").AsString();
|
||||||
_itemContainer = new UniversalItemContainer();
|
_itemContainer = new UniversalItemContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,15 @@ public static class ItemTypeManager
|
||||||
public static void StaticRegister()
|
public static void StaticRegister()
|
||||||
{
|
{
|
||||||
var staffOfTheUndeadScene = ResourceLoader.Load<PackedScene>("res://prefab/weapons/staffOfTheUndead.tscn");
|
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);
|
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; } = [];
|
private static Dictionary<string, ItemType> Registry { get; } = [];
|
||||||
|
|
|
@ -20,7 +20,7 @@ public abstract partial class WeaponTemplate : RigidBody2D, IItem
|
||||||
//Implements IItem
|
//Implements IItem
|
||||||
[Export] public virtual string Id { get; private set; } = "ID";
|
[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);
|
public Texture2D Icon => UniqueIcon ?? ItemTypeManager.DefaultIconOf(Id);
|
||||||
|
|
||||||
protected string? UniqueName { get; set; }
|
protected string? UniqueName { get; set; }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user