diff options
Diffstat (limited to 'scripts/Magic/SpellBook.cs')
| -rw-r--r-- | scripts/Magic/SpellBook.cs | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/scripts/Magic/SpellBook.cs b/scripts/Magic/SpellBook.cs index 8ccba71..914add6 100644 --- a/scripts/Magic/SpellBook.cs +++ b/scripts/Magic/SpellBook.cs @@ -1,8 +1,9 @@ using Godot; +using Godot.Collections; namespace TheLegendOfGustav.Magic; -public partial class SpellBook : Node +public partial class SpellBook : Node, ISaveable { public Godot.Collections.Array<SpellResource> KnownSpells { get; private set; } = []; @@ -17,4 +18,31 @@ public partial class SpellBook : Node public void ForgetSpell(SpellResource spell) { KnownSpells.Remove(spell); } + + public Dictionary<string, Variant> GetSaveData() + { + Array<string> spellPaths = []; + foreach(SpellResource spell in KnownSpells) + { + spellPaths.Add(spell.ResourcePath); + } + + return new() + { + {"spells", spellPaths} + }; + } + + public bool LoadSaveData(Dictionary<string, Variant> saveData) + { + Array<string> paths = (Array<string>)saveData["spells"]; + + foreach(string path in paths) + { + SpellResource spell = GD.Load<SpellResource>(path); + KnownSpells.Add(spell); + } + + return true; + } }
\ No newline at end of file |
