diff --git a/gui.cpp b/gui.cpp index ca667ee..d977969 100644 --- a/gui.cpp +++ b/gui.cpp @@ -19,6 +19,7 @@ #include "systems.hpp" #include "events.hpp" #include "render.hpp" +#include "save.hpp" using std::string; using namespace fmt; @@ -57,10 +58,8 @@ void GUI::resize_map(int new_size) { } void GUI::save_world() { - tser::BinaryArchive archive; - archive.save($world); - std::string_view archive_view = archive.get_buffer(); - $log.log(format("Game saved! {} bytes.", archive_view.size())); + $log.log("Game saved!"); + save::to_file("./savefile.world", $world); } void GUI::create_renderer() { diff --git a/main.cpp b/main.cpp index f604477..640484c 100644 --- a/main.cpp +++ b/main.cpp @@ -6,8 +6,7 @@ #include "dbc.hpp" #include "collider.hpp" #include "render.hpp" -#include "config.hpp" - +#include "save.hpp" #include "ftxui/screen/terminal.hpp" // for SetColorSupport, Color, TrueColor using namespace ftxui; @@ -25,9 +24,6 @@ void configure_world(DinkyECS::World &world, Map &game_map) { Player player{world.entity()}; world.set_the(player); - spatial_map collider; - world.set_the(collider); - world.set(player.entity, {game_map.place_entity(0)}); world.set(player.entity, {0, 0}); world.set(player.entity, {100, 10}); @@ -55,27 +51,14 @@ void configure_world(DinkyECS::World &world, Map &game_map) { int main() { DinkyECS::World world; - Config config("./assets/config.json"); - world.set_the(config); - - auto map = config["map"]; - world.set_the({ - map["WALL_TILE"], - map["FLOOR_TILE"], - map["PLAYER_TILE"], - map["ENEMY_TILE"], - map["BG_TILE"] - }); - - auto enemy = config["enemy"]; - world.set_the({ - enemy["HEARING_DISTANCE"] - }); - Map game_map(GAME_MAP_X, GAME_MAP_Y); game_map.generate(); + save::load_configs(world); configure_world(world, game_map); + + spatial_map collider; + world.set_the(collider); System::init_positions(world); GUI gui(world, game_map); diff --git a/save.cpp b/save.cpp index 59be989..036942b 100644 --- a/save.cpp +++ b/save.cpp @@ -2,6 +2,7 @@ #include #include "dbc.hpp" #include +#include "config.hpp" using namespace components; @@ -62,4 +63,25 @@ void save::from_file(std::string path, DinkyECS::World &world_out) { inject(world_out, save_data.position); inject(world_out, save_data.combat); inject(world_out, save_data.motion); + + save::load_configs(world_out); +} + +void save::load_configs(DinkyECS::World &world) { + Config config("./assets/config.json"); + world.set_the(config); + + auto map = config["map"]; + world.set_the({ + map["WALL_TILE"], + map["FLOOR_TILE"], + map["PLAYER_TILE"], + map["ENEMY_TILE"], + map["BG_TILE"] + }); + + auto enemy = config["enemy"]; + world.set_the({ + enemy["HEARING_DISTANCE"] + }); } diff --git a/save.hpp b/save.hpp index 93b9d9f..c7ea42b 100644 --- a/save.hpp +++ b/save.hpp @@ -26,4 +26,5 @@ namespace save { void to_file(std::string path, DinkyECS::World &world); void from_file(std::string path, DinkyECS::World &world_out); + void load_configs(DinkyECS::World &world); }