upd
This commit is contained in:
12
Code/Inventory/Definitions/BaseItemDefinition.cs
Normal file
12
Code/Inventory/Definitions/BaseItemDefinition.cs
Normal 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; }
|
||||
}
|
||||
8
Code/Inventory/Definitions/ClothingItemDefinition.cs
Normal file
8
Code/Inventory/Definitions/ClothingItemDefinition.cs
Normal 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; }
|
||||
}
|
||||
6
Code/Inventory/Definitions/IEquipable.cs
Normal file
6
Code/Inventory/Definitions/IEquipable.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Sasalka;
|
||||
|
||||
public interface IEquipable
|
||||
{
|
||||
Inventar.InventorySlot Slot { get; }
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user