bool Game::LoadConfig(const std::string& str) { // default options options_.fps = APP_FPS; options_.verbosity = DEFAULT_VERBOSITY; options_.panel_on_top = 1; ConfigParser config; if (!config.LoadFromFile(str.c_str())) { printf("info: config file '%s' not found, using default configuration\n", str.c_str()); return false; } printf("info: configuration '%s' loaded\n", str.c_str()); // Engine options config.SeekSection("Engine"); config.ReadItem("fps", options_.fps); config.ReadItem("verbosity", options_.verbosity); Log::SetVerboseLevel(options_.verbosity); Output << "verbose: " << options_.verbosity << lEnd; // Game options config.SeekSection("Settings"); config.ReadItem("panel_on_top", options_.panel_on_top); bool music = false; if (config.ReadItem("enable_music", music) && !music) { SoundSystem::GetInstance().EnableMusic(false); } return true; }
bool Game::LoadProgression(const char* filename) { ConfigParser parser; if (parser.LoadFromFile(filename)) { parser.SeekSection("Location"); bool ok = true; std::string map_name; ok &= parser.ReadItem("map", map_name); int zx, zy; ok &= parser.ReadItem("zone_x", zx); ok &= parser.ReadItem("zone_y", zy); int x, y; ok &= parser.ReadItem("x", x); ok &= parser.ReadItem("y", y); parser.SeekSection("Status"); int hp, money, frags; ok &= parser.ReadItem("frags", frags); ok &= parser.ReadItem("money", money); ok &= parser.ReadItem("hp", hp); parser.SeekSection("Inventory"); int it1, it2, it3; ok &= parser.ReadItem("item1", it1); ok &= parser.ReadItem("item2", it2); ok &= parser.ReadItem("item3", it3); std::string stock; ok &= parser.ReadItem("stock", stock); if (ok) { map_.Load(map_name); map_.SetActiveZone(zx, zy, false); player_->SetPosition(x, y); player_->SetHP(hp); player_->AddGold(money); player_->AddFrag(frags); Inventory& inventory = player_->GetInventory(); inventory.SetItem1Type(it1); inventory.SetItem2Type(it2); inventory.SetItem3Type(it3); inventory.StockFromString(stock); return true; } printf("fail at loading player save: %s\n", SAVE_FILE); } return false; }