From 252c7398925b5267963c1a48251cd7ba2d4ec381 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Thu, 25 Jan 2018 15:20:54 +0000 Subject: Refactor game_state & cache to remove static hack --- .../input/json-parsing/deal_parser.cpp | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/main/input-output') 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 7cf5f45..09b2065 100644 --- a/src/main/input-output/input/json-parsing/deal_parser.cpp +++ b/src/main/input-output/input/json-parsing/deal_parser.cpp @@ -13,32 +13,32 @@ typedef sol_rules::build_policy pol; void deal_parser::parse(game_state &gs, const rapidjson::Document& doc) { // Construct tableau piles - if (game_state::rules.tableau_pile_count > 0) { + if (gs.rules.tableau_pile_count > 0) { parse_tableau_piles(gs, doc); } // Construct hole card - if (game_state::rules.hole) { + if (gs.rules.hole) { parse_hole(gs, doc); } // Construct filled cells - if (game_state::rules.cells) { + if (gs.rules.cells) { parse_cells(gs, doc); } // Construct stock - if (game_state::rules.stock_size > 0) { + if (gs.rules.stock_size > 0) { parse_stock(gs, doc); } // Construct reserve - if (game_state::rules.reserve_size > 0) { + if (gs.rules.reserve_size > 0) { parse_reserve(gs, doc); } // If the foundations begin with cards in them, fill them - if (game_state::rules.foundations_init_card) { + if (gs.rules.foundations_init_card) { fill_foundations(gs); } } @@ -48,7 +48,7 @@ void deal_parser::parse_tableau_piles(game_state &gs, const rapidjson::Document& const Value& json_tab_piles = doc["tableau piles"]; assert(json_tab_piles.IsArray()); - if (json_tab_piles.Size() != game_state::rules.tableau_pile_count ) { + if (json_tab_piles.Size() != gs.rules.tableau_pile_count ) { json_helper::json_parse_err("Incorrect number of tableau piles"); } @@ -81,7 +81,7 @@ void deal_parser::parse_cells(game_state &gs, const Document& doc) { const auto json_cell_arr = json_cells.GetArray(); if (json_cell_arr.Empty()) return; - else if (json_cell_arr.Size() != game_state::rules.cells) { + else if (json_cell_arr.Size() != gs.rules.cells) { json_helper::json_parse_err("Incorrect number of cells"); } @@ -101,7 +101,7 @@ void deal_parser::parse_stock(game_state &gs, const Document& doc) { const Value &json_stock = doc["stock"]; assert(json_stock.IsArray()); - if (json_stock.Size() != game_state::rules.stock_size) { + if (json_stock.Size() != gs.rules.stock_size) { json_helper::json_parse_err("Incorrect stock size"); } @@ -121,20 +121,20 @@ void deal_parser::parse_reserve(game_state &gs, const Document& doc) { // We treat a regular reserve like multiple single-card piles, // but a stacked reserve as a single multiple-card pile - if (json_reserve_piles.Size() != game_state::rules.reserve_size) { + if (json_reserve_piles.Size() != gs.rules.reserve_size) { json_helper::json_parse_err("Incorrect reserve size"); } for (game_state::pile_ref i = 0; i < json_card_arr.Size(); i++) { assert(json_card_arr[i].IsString()); game_state::pile_ref pr = gs.reserve[0]; - if (!game_state::rules.reserve_stacked) pr += i; + if (!gs.rules.reserve_stacked) pr += i; gs.piles[pr].place(card(json_card_arr[i].GetString())); } } void deal_parser::fill_foundations(game_state &gs) { - auto foundations_count = uint8_t(4 * (game_state::rules.two_decks ? 2:1)); + auto foundations_count = uint8_t(4 * (gs.rules.two_decks ? 2:1)); assert(gs.foundations.size() == foundations_count); for (uint8_t f_idx = 0; f_idx < foundations_count; f_idx++) { -- cgit v1.2.1