Separating state out of the location
This commit is contained in:
1 parent
5e9a663812
commit
297bd7377f
45 files changed
+2114
-778
No files matched your search
+6
-3
@@ -1,4 +1,5 @@
|
||||
#include "GameState.h"
|
||||
#include "utils/Utils.h"
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
@@ -209,8 +210,8 @@ void GameState::load(const nlohmann::json& in)
|
||||
|
||||
// --- Players ---
|
||||
const auto& playerValues = in.at("players");
|
||||
if (!playerValues.is_object() || !playerValues.contains("player"))
|
||||
throw std::runtime_error("Game state requires players.player");
|
||||
if (!playerValues.is_object())
|
||||
throw std::runtime_error("Game state players must be an object");
|
||||
for (const auto& [id, value] : playerValues.items()) {
|
||||
auto& player = players[id];
|
||||
if (!player) player = std::make_shared<CharacterState>();
|
||||
@@ -224,7 +225,9 @@ void GameState::load(const nlohmann::json& in)
|
||||
|
||||
// --- Locations ---
|
||||
const auto& locationValues = in.at("locations");
|
||||
if (!locationValues.is_object() ||
|
||||
if (!locationValues.is_object())
|
||||
throw std::runtime_error("Game state locations must be an object");
|
||||
if (!currentLocationName.empty() &&
|
||||
!locationValues.contains(currentLocationName))
|
||||
throw std::runtime_error(
|
||||
"Game state does not contain current location '" +
|
||||
|
||||
Reference in new issue
Block a user