From f4ed469fc9eaeebf39093fbf6601581cc10c6e2f Mon Sep 17 00:00:00 2001 From: Matheus Date: Sun, 26 Oct 2025 20:02:15 -0300 Subject: feat:save AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit O vazio dentro de mim é como uma xícara de café esquecida no canto da mesa. --- scripts/Magic/SpellBook.cs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'scripts/Magic/SpellBook.cs') 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 KnownSpells { get; private set; } = []; @@ -17,4 +18,31 @@ public partial class SpellBook : Node 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; + } } \ No newline at end of file -- cgit v1.2.3