Skip to content

Commit

Permalink
bug: handle version changes by resetting the config
Browse files Browse the repository at this point in the history
  • Loading branch information
goblinhack committed Aug 12, 2023
1 parent 562a1f1 commit 4ae1e37
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
28 changes: 28 additions & 0 deletions src/game_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1168,88 +1168,116 @@ std::istream &operator>>(std::istream &in, Bits< Config & > my)
in >> bits(eol);
if (eol != GAME_SAVE_MARKER_CONFIG) {
game_load_error += "end of config marker not found";
return in;
}

if (my.t.ascii_gl_height < 0) {
game_load_error += "ascii_gl_height is invalid";
return in;
}
if (my.t.ascii_gl_width < 0) {
game_load_error += "ascii_gl_width is invalid";
return in;
}
if (my.t.config_pix_height < 0) {
game_load_error += "config_pix_height is invalid";
return in;
}
if (my.t.config_pix_width < 0) {
game_load_error += "config_pix_width is invalid";
return in;
}
if (my.t.game_pix_height < 0) {
game_load_error += "game_pix_height is invalid";
return in;
}
if (my.t.game_pix_scale_height < 0) {
game_load_error += "game_pix_scale_height is invalid";
return in;
}
if (my.t.game_pix_scale_width < 0) {
game_load_error += "game_pix_scale_width is invalid";
return in;
}
if (my.t.game_pix_width < 0) {
game_load_error += "game_pix_width is invalid";
return in;
}
if (! my.t.game_pix_zoom) {
game_load_error += "game_pix_zoom is invalid";
return in;
}
if (my.t.one_pixel_height < 0) {
game_load_error += "one_pixel_height is invalid";
return in;
}
if (my.t.one_pixel_width < 0) {
game_load_error += "one_pixel_width is invalid";
return in;
}
if (my.t.tile_height < 0) {
game_load_error += "tile_height is invalid";
return in;
}
if (my.t.tile_pixel_height < 0) {
game_load_error += "tile_pixel_height is invalid";
return in;
}
if (my.t.tile_pixel_width < 0) {
game_load_error += "tile_pixel_width is invalid";
return in;
}
if (my.t.tile_pix_height < 0) {
game_load_error += "tile_pix_height is invalid";
return in;
}
if (my.t.tile_pix_width < 0) {
game_load_error += "tile_pix_width is invalid";
return in;
}
if (my.t.tile_width < 0) {
game_load_error += "tile_width is invalid";
return in;
}
if (my.t.ui_ascii_term_height < 0) {
game_load_error += "ui_ascii_term_height is invalid";
return in;
}
if (my.t.ui_ascii_term_width < 0) {
game_load_error += "ui_ascii_term_width is invalid";
return in;
}
if (my.t.ui_gfx_term_height < 0) {
game_load_error += "ui_gfx_term_height is invalid";
return in;
}
if (my.t.ui_gfx_term_width < 0) {
game_load_error += "ui_gfx_term_width is invalid";
return in;
}
if (my.t.ui_pix_height < 0) {
game_load_error += "ui_pix_height is invalid";
return in;
}
if (my.t.ui_pix_width < 0) {
game_load_error += "ui_pix_width is invalid";
return in;
}
if (my.t.ui_pix_zoom < 0) {
game_load_error += "ui_pix_zoom is invalid";
return in;
}
if (my.t.video_w_h_ratio < 0) {
game_load_error += "video_w_h_ratio is invalid";
return in;
}
if (my.t.window_pix_height < 0) {
game_load_error += "window_pix_height is invalid";
return in;
}
if (my.t.window_pix_width < 0) {
game_load_error += "window_pix_width is invalid";
return in;
}

return in;
Expand Down
2 changes: 1 addition & 1 deletion src/level_monst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Tpp Level::get_random_monst(point p, monst_environ_t monst_environ, monst_class_
// Roll the dice and see if we get to place a monster.
//
auto roll = d1000();
con("get random monst: roll %d -- biome %d type %d class %d -- %d", roll, biome, monst_environ, monst_class,
dbg("get random monst: roll %d -- biome %d type %d class %d -- %d", roll, biome, monst_environ, monst_class,
d1000_chance_creating_monst[ monst_environ ][ monst_class ] + difficulty_offset);

if (roll <= d1000_chance_creating_monst[ monst_environ ][ monst_class ] + difficulty_offset) {
Expand Down
24 changes: 13 additions & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,18 +829,20 @@ int main(int argc, char *argv[])
CON("INI: Load config");
game = new Game(std::string(appdata));
auto config_error = game->load_config();
if (! config_error.empty()) {
std::string version = "" MYVER "";
if (game->config.version.c_str() != version.c_str()) {
SDL_MSG_BOX(
"Config version change error: %s. Will need to reset config. Found version [%s]. Expected version [%s].",
config_error.c_str(), game->config.version.c_str(), version.c_str());
} else {
SDL_MSG_BOX("Config load error: %s. Will need to reset config. Found version [%s]. Expected version [%s].",
config_error.c_str(), game->config.version.c_str(), version.c_str());
}

game->config.reset();
std::string version = "" MYVER "";

if (game->config.version != version) {
SDL_MSG_BOX("Config version change. Will need to reset config. Found version [%s]. Expected version [%s].",
game->config.version.c_str(), version.c_str());
delete game;
game = new Game(std::string(appdata));
game->save_config();
g_errored = false;
} else if (! config_error.empty()) {
SDL_MSG_BOX("Config error: %s. Will need to reset config.", config_error.c_str());
delete game;
game = new Game(std::string(appdata));
game->save_config();
g_errored = false;
}
Expand Down

0 comments on commit 4ae1e37

Please sign in to comment.