mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 00:35:53 +00:00
State persistance between scenes
This commit is contained in:
parent
1e38945f63
commit
35254935e4
13 changed files with 142 additions and 27 deletions
|
|
@ -8,6 +8,9 @@ using Cirno.Scripts.Resources;
|
|||
public partial class InventoryManager : Node2D
|
||||
{
|
||||
public static InventoryManager Instance { get; private set; }
|
||||
|
||||
public ItemsDatabase ItemsDatabase { get; set; }
|
||||
|
||||
public bool RedKeycard { get; set; }
|
||||
|
||||
private Dictionary<string, ItemContainer> _itemsDict = new();
|
||||
|
|
@ -35,6 +38,8 @@ public partial class InventoryManager : Node2D
|
|||
public override void _Ready()
|
||||
{
|
||||
Instance = this;
|
||||
GD.Print("Loading items");
|
||||
Load(GlobalState.Session.Items);
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
|
|
@ -154,6 +159,32 @@ public partial class InventoryManager : Node2D
|
|||
{
|
||||
EmitSignal(SignalName.LoadedAmmoChanged, weaponDataItemKey, loadedAmmo);
|
||||
}
|
||||
|
||||
public Godot.Collections.Dictionary<string, int> Save()
|
||||
{
|
||||
Godot.Collections.Dictionary<string, int> dict = new();
|
||||
foreach (var item in _itemsDict)
|
||||
{
|
||||
dict.Add(item.Key, item.Value.Count);
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
public void Load(Godot.Collections.Dictionary<string, int> items)
|
||||
{
|
||||
ItemsDatabase = ResourceLoader.Load<ItemsDatabase>("uid://cdi84udi6gldt");
|
||||
|
||||
_itemsDict.Clear();
|
||||
|
||||
_itemsDict = items.ToDictionary(x => x.Key, x => new ItemContainer()
|
||||
{
|
||||
Item = ItemsDatabase.LootItems.FirstOrDefault(y => y.ItemKey == x.Key),
|
||||
Count = x.Value
|
||||
});
|
||||
|
||||
GD.Print($"Items after loading: {_itemsDict.Count}");
|
||||
}
|
||||
}
|
||||
|
||||
public class ItemContainer
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue