Implement saving and loading inventory items
parent
97cdf26751
commit
48dcee72b4
|
@ -838,11 +838,6 @@ y_sort_enabled = true
|
|||
script = ExtResource("30_y2wmw")
|
||||
Hotbar = [null, null, null]
|
||||
Items = Array[Object]([ExtResource("33_3qyfl"), ExtResource("34_70ron"), ExtResource("35_4pap1")])
|
||||
InventoryMap = {
|
||||
"equip_1": 0,
|
||||
"equip_2": 1,
|
||||
"equip_3": 2
|
||||
}
|
||||
|
||||
[node name="Hurtbox" parent="." node_paths=PackedStringArray("InvincibilityTimer") instance=ExtResource("9_avyu4")]
|
||||
visible = false
|
||||
|
|
|
@ -12,10 +12,7 @@ public partial class Inventory : Node2D, IItemCollection<ItemMetadata>
|
|||
public Array<Item> Hotbar { get; private set; }
|
||||
|
||||
[Export]
|
||||
public Array<ItemMetadata> Items { get; private set; }
|
||||
|
||||
[Export]
|
||||
public Dictionary<string, int> InventoryMap { get; set; }
|
||||
public Array<ItemMetadata> Items { get; set; }
|
||||
|
||||
[Signal]
|
||||
public delegate void UsedItemEventHandler(Item item);
|
||||
|
@ -130,21 +127,6 @@ public partial class Inventory : Node2D, IItemCollection<ItemMetadata>
|
|||
return EquipIndex(index);
|
||||
}
|
||||
|
||||
[System.Obsolete]
|
||||
public Item GetItemByMap(string keymap)
|
||||
{
|
||||
if (InventoryMap.ContainsKey(keymap))
|
||||
{
|
||||
int idx = InventoryMap[keymap];
|
||||
if (idx < Hotbar.Count)
|
||||
{
|
||||
return Hotbar[InventoryMap[keymap]];
|
||||
}
|
||||
}
|
||||
else GD.Print(keymap + " does not exist");
|
||||
return null;
|
||||
}
|
||||
|
||||
public Item AddToHotbar(ItemMetadata metadata)
|
||||
{
|
||||
//AddItemMetadata(metadata);
|
||||
|
|
|
@ -76,6 +76,8 @@ public partial class GlobalState : Node
|
|||
Progression = save.Progression;
|
||||
MapState = save.MapState;
|
||||
Stats = save.Stats;
|
||||
|
||||
World.Instance.CurrentPlayer.Inventory.Items = Stats.Items;
|
||||
}
|
||||
|
||||
public void ExportToSave(Save save)
|
||||
|
@ -83,5 +85,7 @@ public partial class GlobalState : Node
|
|||
save.Progression = Progression;
|
||||
save.MapState = MapState;
|
||||
save.Stats = Stats;
|
||||
|
||||
Stats.Items = World.Instance.CurrentPlayer.Inventory.Items;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace SupaLidlGame.State.Global;
|
||||
|
||||
|
@ -13,4 +14,7 @@ public partial class Stats : Resource
|
|||
|
||||
[Export]
|
||||
public int DeathCount { get; set; } = 0;
|
||||
|
||||
[Export]
|
||||
public Array<Items.ItemMetadata> Items { get; set; } = new();
|
||||
}
|
||||
|
|
|
@ -84,6 +84,13 @@ public partial class World : Node
|
|||
{
|
||||
throw new System.Exception("Another World instance is running.");
|
||||
}
|
||||
|
||||
Debug = new DebugCommands(this);
|
||||
}
|
||||
|
||||
~World()
|
||||
{
|
||||
Debug.Free();
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
|
@ -335,4 +342,23 @@ public partial class World : Node
|
|||
}
|
||||
|
||||
public Node FindEntity(string name) => CurrentMap.Entities.GetNode(name);
|
||||
|
||||
internal DebugCommands Debug { get; set; }
|
||||
}
|
||||
|
||||
internal partial class DebugCommands : GodotObject
|
||||
{
|
||||
private World _world;
|
||||
|
||||
internal DebugCommands(World world)
|
||||
{
|
||||
_world = world;
|
||||
}
|
||||
|
||||
internal void GiveItem(string item)
|
||||
{
|
||||
var itemMetadata = ResourceLoader
|
||||
.Load<Items.ItemMetadata>($"res://Items/{item}.tres");
|
||||
_world.CurrentPlayer.Inventory.Items.Add(itemMetadata);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue