14 using Serializer = bl::serial::json::Serializer<World>;
19 void World::init(bl::engine::Engine&) { bl::event::Dispatcher::subscribe(
this); }
21 void World::earlyCleanup() {
23 previousMap.release();
27 if (file ==
"LastMap") {
29 if (prevMapFile.empty()) {
30 BL_LOG_ERROR <<
"No previous map to return to";
34 if (!previousMap)
return false;
37 const bl::tmap::Position ppos = prevPlayerPos;
40 currentMap->exit(owner, previousMap->name());
41 owner.
engine().ecs().destroyAllWorldEntities();
42 if (!previousMap->enter(owner, 0, currentMap->name(), ppos))
return false;
43 std::swap(currentMap, previousMap);
44 std::swap(prevMapFile, currentMapFile);
54 if (!previousMap)
return false;
55 prevMapFile = currentMapFile;
56 currentMapFile = file;
59 currentMap->exit(owner, previousMap->name());
61 owner.
engine().ecs().destroyAllWorldEntities();
63 std::swap(currentMap, previousMap);
64 if (!currentMap->enter(
65 owner, spawn, previousMap ? previousMap->name() :
"NoPrevious", prevPlayerPos))
73 BL_LOG_INFO <<
"Whiting out to " << map <<
" (" << spawn <<
")";
74 previousMap.release();
76 bl::event::Dispatcher::dispatch<event::SwitchMapTriggered>({map, spawn});
88 void World::update(std::mutex&,
float dt,
float,
float,
float) {
89 if (currentMap) { currentMap->update(dt); }
103 load.
failMessage =
"Failed to load map: " + currentMapFile;
106 if (!currentMap->enter(owner, 0, prevMapFile, playerPos)) {
107 load.
failMessage =
"Failed to enter map: " + currentMapFile;
Core classes and functionality for both the editor and game.
bl::serial::json::Serializer< Player > Serializer
Fired when the game is saving or loading. Allows systems to hook in their data.
bool saving
True when saving, false when loading.
file::GameSave & gameSave
Game save being initialized.
Fired when a game save is loaded. Fired after the load is complete.
std::string failMessage
Modules can set this if they encounter a failure that should fail the entire load.
struct core::file::GameSave::WorldDataPointers world
bl::tmap::Position * prevPlayerPos
bl::tmap::Position * playerPos
The primary map class that represents a usable map in the game.
static std::string getMapFile(const std::string &partialFile)
Returns the full path to the map file from the given partial file. Accounts for missing extension.
unsigned int whiteoutSpawn
player::State & state()
Returns the state of the player.
const bl::tmap::Position & position() const
Returns the current position of the player.
Owns all primary systems and a reference to the engine.
const bl::engine::Engine & engine() const
Const accessor for the Engine.
Player & player()
Returns the player system.
World(Systems &systems)
Creates the world system.
void setWhiteoutMap(unsigned int spawn)
Sets the respawn point to the given spawn in the current map.
void whiteout(const std::string &newMap, int spawnId)
Switches to the new map and resets the last map to empty.
bool switchMaps(const std::string &newMap, int spawnId)
Switches the current map to the map in the given file.
map::Map & activeMap()
Returns a reference to the active map.
virtual void observe(const event::GameSaveInitializing &save) override
Adds saved world data to the save file.