Skip to content

Commit

Permalink
Fix editor errors from saving with old mzx_world->version values.
Browse files Browse the repository at this point in the history
  • Loading branch information
AliceLR committed Dec 27, 2023
1 parent 5ecd828 commit e842e7d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
39 changes: 18 additions & 21 deletions src/world.c
Original file line number Diff line number Diff line change
Expand Up @@ -2516,13 +2516,13 @@ static void v1_store_globals_to_board(struct world *mzx_world);
static void v1_load_globals_from_board(struct world *mzx_world);

int save_world(struct world *mzx_world, const char *file, boolean savegame,
int world_version)
int file_version)
{
#ifdef CONFIG_DEBYTECODE
// TODO we'll cross this bridge when we need to. That shouldn't be
// until debytecode gets an actual release, though.

if(world_version == MZX_VERSION_PREV)
if(file_version < VERSION_SOURCE)
{
error("Downver. not currently supported by debytecode.",
ERROR_T_ERROR, ERROR_OPT_OK, 0x0000);
Expand Down Expand Up @@ -2584,33 +2584,30 @@ int save_world(struct world *mzx_world, const char *file, boolean savegame,
// Synchronize global variables in the current board.
v1_store_globals_to_board(mzx_world);

#ifdef CONFIG_EDITOR
if(world_version == MZX_VERSION_PREV)
// Supported file format versions are the current version (typical world or
// save files) and the previous version (downver export from the editor).
if(file_version == MZX_VERSION || file_version == MZX_VERSION_PREV)
{
// Temporarily replace the world version with the previous version
int actual_world_version = mzx_world->version;
int world_version = mzx_world->version;
int ret_val;
mzx_world->version = MZX_VERSION_PREV;

ret_val = save_world_zip(mzx_world, file, savegame, MZX_VERSION_PREV);
if(!savegame)
{
// Temporarily update the world version to the file version. For world
// files, these versions are the same, but permanently changing the world
// version needs to happen during specific actions in the editor only.
mzx_world->version = file_version;
}

mzx_world->version = actual_world_version;
return ret_val;
}
else
#endif
ret_val = save_world_zip(mzx_world, file, savegame, file_version);

if(world_version == MZX_VERSION)
{
return save_world_zip(mzx_world, file, savegame, MZX_VERSION);
mzx_world->version = world_version;
return ret_val;
}

else
{
fprintf(mzxerr,
"ERROR: Attempted to save incompatible world version %d.%d! Aborting!\n",
(world_version >> 8) & 0xFF, world_version & 0xFF);
fflush(mzxerr);
warn("Attempted to save incompatible world file version %d.%d! Aborting!\n",
(file_version >> 8) & 0xFF, file_version & 0xFF);

return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/world.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ CORE_LIBSPEC int save_magic(const char magic_string[5]);
CORE_LIBSPEC int get_version_string(char buffer[16], enum mzx_version version);

CORE_LIBSPEC int save_world(struct world *mzx_world, const char *file,
boolean savegame, int world_version);
boolean savegame, int file_version);
CORE_LIBSPEC boolean reload_world(struct world *mzx_world, const char *file,
boolean *faded);
CORE_LIBSPEC void clear_world(struct world *mzx_world);
Expand Down

0 comments on commit e842e7d

Please sign in to comment.