diff options
| author | thecharlesblake | 2018-01-04 11:41:32 +0000 |
|---|---|---|
| committer | thecharlesblake | 2018-01-04 11:44:57 +0000 |
| commit | 3f93158b539430a7cb08534fff19903acd56ff66 (patch) | |
| tree | 3253d0017045c471b1f32e2c4543bee91a9592c5 /src/main/input-output/input/json-parsing/deal_parser.cpp | |
| parent | Add rules parsing for (FF) foundations init card (diff) | |
| download | metasol-3f93158b539430a7cb08534fff19903acd56ff66.tar.gz metasol-3f93158b539430a7cb08534fff19903acd56ff66.zip | |
Add deal parsing for (FF) foundations init card
Diffstat (limited to 'src/main/input-output/input/json-parsing/deal_parser.cpp')
| -rw-r--r-- | src/main/input-output/input/json-parsing/deal_parser.cpp | 33 |
1 files changed, 33 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 0e89f43..e7f8209 100644 --- a/src/main/input-output/input/json-parsing/deal_parser.cpp +++ b/src/main/input-output/input/json-parsing/deal_parser.cpp @@ -27,6 +27,16 @@ void deal_parser::parse(game_state &gs, const rapidjson::Document& doc) { if (gs.rules.cells) { parse_cells(gs, doc); } + + // Construct stock + if (gs.rules.stock_size > 0) { + parse_stock(gs, doc); + } + + // If the foundations begin with cards in them, fill them + if (gs.rules.foundations_init_card) { + fill_foundations(gs); + } } void deal_parser::parse_tableau_piles(game_state &gs, const rapidjson::Document& doc) { @@ -80,3 +90,26 @@ void deal_parser::parse_cells(game_state &gs, const Document& doc) { } } } + +void deal_parser::parse_stock(game_state &gs, const Document& doc) { + if (doc.HasMember("stock")) { + const Value &json_stock = doc["stock"]; + assert(json_stock.IsArray()); + + if (gs.rules.stock_size != json_stock.Size()) { + json_helper::json_parse_err("Incorrect stock size"); + } + + for (const Value& json_card : json_stock.GetArray()) { + gs.piles[gs.stock].place(card(json_card.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( + card(card::to_suit(f_idx), 1) + ); + } +} |
