void PingusWorldmap::parse_file(const ReaderObject& reader_object) { if (reader_object.get_name() != "pingus-worldmap") { raise_exception(std::runtime_error, "Worldmap:" << impl->filename << ": not a Worldmap file"); } else { ReaderMapping reader = reader_object.get_mapping(); if (!reader.read_mapping("graph", impl->path_graph)) { raise_exception(std::runtime_error, "Worldmap: " << impl->filename << " is missed 'graph' section"); } impl->objects = reader.read_collection("objects").get_objects(); parse_properties(reader.read_mapping("head")); std::string intro_story; std::string end_story; if (reader.read_string("intro-story", intro_story)) { impl->intro_story = FileReader::parse(Pathname(intro_story, Pathname::DATA_PATH)); } if (reader.read_string("end-story", end_story)) { impl->end_story = FileReader::parse(Pathname(end_story, Pathname::DATA_PATH)); } } }
void StoryDot::on_click() { try { ReaderObject reader = Reader::parse(Pathname(m_story, Pathname::DATA_PATH)); ScreenManager::instance()->push_screen(std::make_shared<StoryScreen>(reader.get_mapping(), m_credits)); } catch(const std::exception& err) { log_error("%1%", err.what()); } }
std::unique_ptr<Pointer> CoreDriver::create_pointer(const ReaderObject& reader_object, Control* parent) { if (reader_object.get_name() == "core:axis-pointer") { ReaderMapping reader = reader_object.get_mapping(); auto axis = util::make_unique<AxisPointer>(parent); ReaderObject x_reader; if (!reader.read_object("x-axis", x_reader)) { log_error("CoreDriver: Couldn't find x-axis"); return {}; } ReaderObject y_reader; if (!reader.read_object("y-axis", y_reader)) { log_error("CoreDriver: Couldn't find y-axis"); return {}; } std::unique_ptr<Axis> x_axis = manager->create_axis(x_reader, axis.get()); std::unique_ptr<Axis> y_axis = manager->create_axis(y_reader, axis.get()); std::unique_ptr<Button> button; ReaderObject button_reader; if (reader.read_object("button", button_reader)) { button = manager->create_button(button_reader, axis.get()); } if (x_axis && y_axis) { axis->setup(std::move(x_axis), std::move(y_axis), std::move(button)); return std::move(axis); } else { return {}; } } else { return {}; } }
ServerEvent::ServerEvent(const ReaderObject& reader_object) : type(PINGU_ACTION_EVENT), time_stamp(0), pingu_id(0), pos(), pingu_action(ActionName::WALKER) { ReaderMapping reader = reader_object.get_mapping(); if (reader_object.get_name() == "armageddon") { type = ARMAGEDDON_EVENT; reader.read_int("time", time_stamp); } else if (reader_object.get_name() == "end") { type = END_EVENT; reader.read_int("time", time_stamp); } else if (reader_object.get_name() == "finish") { type = FINISH_EVENT; reader.read_int("time", time_stamp); } else if (reader_object.get_name() == "pingu-action") { std::string raw_x; std::string raw_y; type = PINGU_ACTION_EVENT; reader.read_int ("time", time_stamp); int pingu_id_tmp; reader.read_int ("id", pingu_id_tmp); pingu_id = static_cast<unsigned int>(pingu_id_tmp); if (reader.read_string("raw-x", raw_x)) pos.x = Math::string2float(raw_x); if (reader.read_string("raw-y", raw_y)) pos.y = Math::string2float(raw_y); reader.read_enum("action", pingu_action, &ActionName::from_string); } else { raise_exception(std::runtime_error, "ServerEvent: Parse error: Unknown event: " << reader_object.get_name()); } }
void PingusMenu::do_start(const std::string &filename) { // Start the story or worldmap mode Sound::PingusSound::play_sound ("letsgo"); std::shared_ptr<WorldmapNS::WorldmapScreen> worldmap_screen = std::make_shared<WorldmapNS::WorldmapScreen>(); worldmap_screen->load(Pathname(filename, Pathname::DATA_PATH)); ScreenManager::instance()->push_screen(worldmap_screen); bool story_seen = false; StatManager::instance()->get_bool("tutorial-startstory-seen", story_seen); // FIXME: Hardcoding tutorial is evil if (!story_seen) { ReaderObject reader = Reader::parse(Pathname("stories/tutorial_intro.story", Pathname::DATA_PATH)); ScreenManager::instance()->push_screen(std::make_shared<StoryScreen>(reader.get_mapping())); StatManager::instance()->set_bool("tutorial-startstory-seen", true); } }
SavegameManager::SavegameManager(const std::string& arg_filename) : filename(System::get_userdir() + arg_filename), savegames() { assert(instance_ == 0); instance_ = this; if (!System::exist(filename)) { log_info("%1%: savegame file not found", filename); } else { ReaderObject reader = Reader::parse(filename); if (reader.get_name() != "pingus-savegame") { log_error("%1%: not a 'pingus-savegame' file", filename); } else { ReaderCollection levels_collection; reader.get_mapping().read_collection("levels", levels_collection); for(auto const& level_object : levels_collection.get_objects()) { auto savegame = util::make_unique<Savegame>(level_object.get_mapping()); SavegameTable::iterator it = find(savegame->get_filename()); if (it != savegames.end()) { // overwrite duplicates, shouldn't happen, but harmless log_info("name collision: %1%", savegame->get_filename()); *it = std::move(savegame); } else { savegames.push_back(std::move(savegame)); } } } } }
std::unique_ptr<Keyboard> Manager::create_keyboard(const ReaderObject& reader, Control* parent) { std::string driver = get_driver_part(reader.get_name()); Driver* drv = load_driver(driver); if (drv) { return drv->create_keyboard(reader, parent); } else { log_error("couldn't find driver: '%1%'", driver); return {}; } }
std::unique_ptr<Scroller> CoreDriver::create_scroller(const ReaderObject& reader_object, Control* parent) { if (reader_object.get_name() == "core:axis-scroller") { ReaderMapping reader = reader_object.get_mapping(); auto axis = util::make_unique<AxisScroller>(parent); ReaderObject x_reader; if (!reader.read_object("x-axis", x_reader)) { log_error("CoreDriver: Couldn't find x-axis"); return {}; } ReaderObject y_reader; if (!reader.read_object("y-axis", y_reader)) { log_error("CoreDriver: Couldn't find y-axis"); return {}; } std::unique_ptr<Axis> x_axis = manager->create_axis(x_reader, axis.get()); std::unique_ptr<Axis> y_axis = manager->create_axis(y_reader, axis.get()); std::unique_ptr<Button> button; ReaderObject button_reader; if (reader.read_object("button", button_reader)) { button = manager->create_button(button_reader, axis.get()); } if (x_axis && y_axis) { axis->setup(std::move(x_axis), std::move(y_axis), std::move(button)); return std::move(axis); } else { return {}; } } else if (reader_object.get_name() == "core:button-scroller") { ReaderMapping reader = reader_object.get_mapping(); auto scroller = util::make_unique<ButtonScroller>(parent); ReaderObject left_reader; if (!reader.read_object("left", left_reader)) { log_error("CoreDriver: core:button-scroller: Couldn't find 'left'"); return {}; } ReaderObject right_reader; if (!reader.read_object("right", right_reader)) { log_error("CoreDriver: core:button-scroller: Couldn't find 'right'"); return {}; } ReaderObject up_reader; if (!reader.read_object("up", up_reader)) { log_error("CoreDriver: core:button-scroller: Couldn't find 'up'"); return {}; } ReaderObject down_reader; if (!reader.read_object("down", down_reader)) { log_error("CoreDriver: core:button-scroller: Couldn't find 'down'"); return {}; } // FIXME: Add more error checking auto up_button = manager->create_button(up_reader, scroller.get()); auto down_button = manager->create_button(down_reader, scroller.get()); auto left_button = manager->create_button(left_reader, scroller.get()); auto right_button = manager->create_button(right_reader, scroller.get()); scroller->setup(std::move(up_button), std::move(down_button), std::move(left_button), std::move(right_button)); return std::move(scroller); } else { return {}; } }