using Godot; using Godot.Collections; namespace TheLegendOfGustav.Magic; public partial class SpellBook : Node, ISaveable { public Godot.Collections.Array KnownSpells { get; private set; } = []; public bool KnowsSpell(SpellResource spell) => KnownSpells.Contains(spell); public void LearnSpell(SpellResource spell) { if (!KnownSpells.Contains(spell)) { KnownSpells.Add(spell); } } public void ForgetSpell(SpellResource spell) { KnownSpells.Remove(spell); } public Dictionary GetSaveData() { Array spellPaths = []; foreach(SpellResource spell in KnownSpells) { spellPaths.Add(spell.ResourcePath); } return new() { {"spells", spellPaths} }; } public bool LoadSaveData(Dictionary saveData) { Array paths = (Array)saveData["spells"]; foreach(string path in paths) { SpellResource spell = GD.Load(path); KnownSpells.Add(spell); } return true; } }