This commit is contained in:
Oscar
2025-06-10 20:45:40 +03:00
parent dd266b1a8a
commit de85b85b13
14 changed files with 196 additions and 273 deletions

View File

@@ -0,0 +1,12 @@
namespace Sasalka;
[GameResource( "Base Item Definition", "inv", "", Category = "Sasalka", Icon = "inventory_2" )]
public class BaseItemDefinition : GameResource
{
public string Name { get; set; }
public string Description { get; set; }
[ResourceType( "prefab" )] public GameObject Prefab { get; set; }
public Texture ImageTexture { get; set; }
public string ImageUrl { get; set; }
}

View File

@@ -0,0 +1,8 @@
namespace Sasalka;
[GameResource( "Clothing Item Definition", "clitem", "", Category = "Sasalka", Icon = "inventory_2" )]
public class ClothingItemDefinition : BaseItemDefinition, IEquipable
{
[Property] public string ClothUrl { get; set; }
public Inventar.InventorySlot Slot { get; set; }
}

View File

@@ -0,0 +1,6 @@
namespace Sasalka;
public interface IEquipable
{
Inventar.InventorySlot Slot { get; }
}

View File

@@ -2,23 +2,11 @@
namespace Sasalka;
[GameResource( "Inventory Item Definition", "inv", "", Category = "Sasalka", Icon = "inventory_2" )]
public class InventoryItemDefinition : GameResource
[GameResource( "Weapon Item Definition", "weapon", "", Category = "Sasalka", Icon = "inventory_2" )]
public class WeaponItemDefinition : BaseItemDefinition, IEquipable
{
public Inventar.InventorySlot Slot { get; set; }
public CitizenAnimationHelper.HoldTypes HoldType { get; set; } = CitizenAnimationHelper.HoldTypes.None;
public Texture ImageTexture { get; set; }
public string ImageUrl { get; set; }
public string ClothUrl { get; set; }
public string Name { get; set; }
public string Description { get; set; }
[ResourceType( "prefab" )] public GameObject Prefab { get; set; }
[InlineEditor, Space] public WeaponDefinition WeaponDefinition { get; set; }
}

View File

@@ -17,20 +17,12 @@ public class Inventar
public List<InventoryItem> Items { get; private set; } = new();
public static bool IsInventoryOpen = false;
// public Dictionary<InventorySlot, EquippedItem> EquippedItems { get; private set; } = new();
public Dictionary<InventorySlot, InventoryItem> EquippedItems { get; private set; } = new();
public event Action OnChanged;
public event Action<InventoryItem> OnEquipped;
public event Action<InventoryItem> OnUnEquipped;
// public class EquippedItem
// {
// public InventoryItem Item { get; set; }
// public GameObject SpawnedObject { get; set; }
// }
public void AddItem( InventoryItem item )
{
Items.Add( item );
@@ -44,15 +36,30 @@ public class Inventar
OnChanged?.Invoke();
}
// public void EquipItem( InventoryItem item )
// {
// if ( EquippedItems.ContainsValue( item ) )
// {
// UnEquipItem( item );
// }
// else
// {
// EquippedItems.Add( item.Definition.Slot, item );
// OnEquipped?.Invoke( item );
// }
// }
public void EquipItem( InventoryItem item )
{
if ( item.Definition is not IEquipable equipable ) return;
if ( EquippedItems.ContainsValue( item ) )
{
UnEquipItem( item );
}
else
{
EquippedItems.Add( item.Definition.Slot, item );
EquippedItems[equipable.Slot] = item;
OnEquipped?.Invoke( item );
}
}

View File

@@ -4,12 +4,7 @@ namespace Sasalka;
public class InventoryItem : Component
{
public InventoryItemDefinition Definition { get; set; }
public BaseItemDefinition Definition { get; set; }
public int Count { get; set; } = 1;
public int MaxCount { get; set; } = 1;
// public GameObject SpawnedObject { get; set; }
}
// public int Count { get; set; } = 1;
// public int MaxCount { get; set; } = 1;