diff options
Diffstat (limited to 'src/main/input-output')
| -rw-r--r-- | src/main/input-output/input/json-parsing/deal_parser.cpp | 23 | ||||
| -rw-r--r-- | src/main/input-output/input/json-parsing/deal_parser.h | 1 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/main/input-output/input/json-parsing/deal_parser.cpp b/src/main/input-output/input/json-parsing/deal_parser.cpp index e7f8209..8bcb3b6 100644 --- a/src/main/input-output/input/json-parsing/deal_parser.cpp +++ b/src/main/input-output/input/json-parsing/deal_parser.cpp @@ -33,6 +33,11 @@ void deal_parser::parse(game_state &gs, const rapidjson::Document& doc) { parse_stock(gs, doc); } + // Construct reserve + if (gs.rules.reserve_size > 0) { + parse_reserve(gs, doc); + } + // If the foundations begin with cards in them, fill them if (gs.rules.foundations_init_card) { fill_foundations(gs); @@ -106,6 +111,24 @@ void deal_parser::parse_stock(game_state &gs, const Document& doc) { } } +void deal_parser::parse_reserve(game_state &gs, const Document& doc) { + assert(doc.HasMember("reserve")); + const Value& json_reserve_piles = doc["reserve"]; + assert(json_reserve_piles.IsArray()); + + if (gs.reserve.size() != gs.rules.reserve_size) { + json_helper::json_parse_err("Incorrect reserve size"); + } + + for (auto p = std::make_pair(begin(json_reserve_piles.GetArray()), begin(gs.reserve)); + p.second != end(gs.reserve); + ++p.first, ++p.second) { + + assert(p.first->IsString()); + gs.piles[*p.second].place(card(p.first->GetString())); + } +} + void deal_parser::fill_foundations(game_state &gs) { for (uint8_t f_idx = 0; f_idx < 4; f_idx++) { gs.piles[gs.foundations[f_idx]].place( diff --git a/src/main/input-output/input/json-parsing/deal_parser.h b/src/main/input-output/input/json-parsing/deal_parser.h index 5496eb2..ecb596c 100644 --- a/src/main/input-output/input/json-parsing/deal_parser.h +++ b/src/main/input-output/input/json-parsing/deal_parser.h @@ -23,6 +23,7 @@ private: static void parse_hole(game_state&, const rapidjson::Document&); static void parse_cells(game_state&, const rapidjson::Document&); static void parse_stock(game_state&, const rapidjson::Document&); + static void parse_reserve(game_state&, const rapidjson::Document&); static void fill_foundations(game_state&); }; |
