Config and save system almost there.
This commit is contained in:
parent
71bc97a016
commit
da63f006c2
4 changed files with 31 additions and 26 deletions
7
gui.cpp
7
gui.cpp
|
@ -19,6 +19,7 @@
|
||||||
#include "systems.hpp"
|
#include "systems.hpp"
|
||||||
#include "events.hpp"
|
#include "events.hpp"
|
||||||
#include "render.hpp"
|
#include "render.hpp"
|
||||||
|
#include "save.hpp"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using namespace fmt;
|
using namespace fmt;
|
||||||
|
@ -57,10 +58,8 @@ void GUI::resize_map(int new_size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::save_world() {
|
void GUI::save_world() {
|
||||||
tser::BinaryArchive archive;
|
$log.log("Game saved!");
|
||||||
archive.save($world);
|
save::to_file("./savefile.world", $world);
|
||||||
std::string_view archive_view = archive.get_buffer();
|
|
||||||
$log.log(format("Game saved! {} bytes.", archive_view.size()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::create_renderer() {
|
void GUI::create_renderer() {
|
||||||
|
|
27
main.cpp
27
main.cpp
|
@ -6,8 +6,7 @@
|
||||||
#include "dbc.hpp"
|
#include "dbc.hpp"
|
||||||
#include "collider.hpp"
|
#include "collider.hpp"
|
||||||
#include "render.hpp"
|
#include "render.hpp"
|
||||||
#include "config.hpp"
|
#include "save.hpp"
|
||||||
|
|
||||||
#include "ftxui/screen/terminal.hpp" // for SetColorSupport, Color, TrueColor
|
#include "ftxui/screen/terminal.hpp" // for SetColorSupport, Color, TrueColor
|
||||||
|
|
||||||
using namespace ftxui;
|
using namespace ftxui;
|
||||||
|
@ -25,9 +24,6 @@ void configure_world(DinkyECS::World &world, Map &game_map) {
|
||||||
Player player{world.entity()};
|
Player player{world.entity()};
|
||||||
world.set_the<Player>(player);
|
world.set_the<Player>(player);
|
||||||
|
|
||||||
spatial_map collider;
|
|
||||||
world.set_the<spatial_map>(collider);
|
|
||||||
|
|
||||||
world.set<Position>(player.entity, {game_map.place_entity(0)});
|
world.set<Position>(player.entity, {game_map.place_entity(0)});
|
||||||
world.set<Motion>(player.entity, {0, 0});
|
world.set<Motion>(player.entity, {0, 0});
|
||||||
world.set<Combat>(player.entity, {100, 10});
|
world.set<Combat>(player.entity, {100, 10});
|
||||||
|
@ -55,27 +51,14 @@ void configure_world(DinkyECS::World &world, Map &game_map) {
|
||||||
int main() {
|
int main() {
|
||||||
DinkyECS::World world;
|
DinkyECS::World world;
|
||||||
|
|
||||||
Config config("./assets/config.json");
|
|
||||||
world.set_the<Config>(config);
|
|
||||||
|
|
||||||
auto map = config["map"];
|
|
||||||
world.set_the<MapConfig>({
|
|
||||||
map["WALL_TILE"],
|
|
||||||
map["FLOOR_TILE"],
|
|
||||||
map["PLAYER_TILE"],
|
|
||||||
map["ENEMY_TILE"],
|
|
||||||
map["BG_TILE"]
|
|
||||||
});
|
|
||||||
|
|
||||||
auto enemy = config["enemy"];
|
|
||||||
world.set_the<EnemyConfig>({
|
|
||||||
enemy["HEARING_DISTANCE"]
|
|
||||||
});
|
|
||||||
|
|
||||||
Map game_map(GAME_MAP_X, GAME_MAP_Y);
|
Map game_map(GAME_MAP_X, GAME_MAP_Y);
|
||||||
game_map.generate();
|
game_map.generate();
|
||||||
|
|
||||||
|
save::load_configs(world);
|
||||||
configure_world(world, game_map);
|
configure_world(world, game_map);
|
||||||
|
|
||||||
|
spatial_map collider;
|
||||||
|
world.set_the<spatial_map>(collider);
|
||||||
System::init_positions(world);
|
System::init_positions(world);
|
||||||
|
|
||||||
GUI gui(world, game_map);
|
GUI gui(world, game_map);
|
||||||
|
|
22
save.cpp
22
save.cpp
|
@ -2,6 +2,7 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include "dbc.hpp"
|
#include "dbc.hpp"
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
|
#include "config.hpp"
|
||||||
|
|
||||||
using namespace components;
|
using namespace components;
|
||||||
|
|
||||||
|
@ -62,4 +63,25 @@ void save::from_file(std::string path, DinkyECS::World &world_out) {
|
||||||
inject<Position>(world_out, save_data.position);
|
inject<Position>(world_out, save_data.position);
|
||||||
inject<Combat>(world_out, save_data.combat);
|
inject<Combat>(world_out, save_data.combat);
|
||||||
inject<Motion>(world_out, save_data.motion);
|
inject<Motion>(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>(config);
|
||||||
|
|
||||||
|
auto map = config["map"];
|
||||||
|
world.set_the<MapConfig>({
|
||||||
|
map["WALL_TILE"],
|
||||||
|
map["FLOOR_TILE"],
|
||||||
|
map["PLAYER_TILE"],
|
||||||
|
map["ENEMY_TILE"],
|
||||||
|
map["BG_TILE"]
|
||||||
|
});
|
||||||
|
|
||||||
|
auto enemy = config["enemy"];
|
||||||
|
world.set_the<EnemyConfig>({
|
||||||
|
enemy["HEARING_DISTANCE"]
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
1
save.hpp
1
save.hpp
|
@ -26,4 +26,5 @@ namespace save {
|
||||||
|
|
||||||
void to_file(std::string path, DinkyECS::World &world);
|
void to_file(std::string path, DinkyECS::World &world);
|
||||||
void from_file(std::string path, DinkyECS::World &world_out);
|
void from_file(std::string path, DinkyECS::World &world_out);
|
||||||
|
void load_configs(DinkyECS::World &world);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue