Skip to content

Commit

Permalink
fix change map (MrMelbert#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMelbert authored Nov 25, 2021
1 parent 4ffb75a commit c0566e0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
3 changes: 3 additions & 0 deletions code/__DEFINES/maps.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ require only minor tweaks.

#define SPACERUIN_MAP_EDGE_PAD 15

/// Path for the next_map.json file, if someone, for some messed up reason, wants to change it.
#define PATH_TO_NEXT_MAP_JSON "data/next_map.json"

/// Special map path value for custom adminloaded stations.
#define CUSTOM_MAP_PATH "custom"

Expand Down
2 changes: 1 addition & 1 deletion code/_compile_options.dm
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
// 2 for preloading absolutely everything;

#ifdef LOWMEMORYMODE
#define FORCE_MAP "_maps/runtimestation.json"
#define FORCE_MAP "runtimestation"
#endif

//Update this whenever you need to take advantage of more recent byond features
Expand Down
6 changes: 3 additions & 3 deletions code/controllers/subsystem/mapping.dm
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ SUBSYSTEM_DEF(mapping)
var/old_config = config
config = global.config.defaultmap
if(!config || config.defaulted)
to_chat(world, span_boldannounce("Unable to load next or default map config, defaulting to Meta Station"))
to_chat(world, span_boldannounce("Unable to load next or default map config, defaulting to Meta Station."))
config = old_config
initialize_biomes()
loadWorld()
Expand Down Expand Up @@ -296,7 +296,7 @@ Used by the AI doomsday and the self-destruct nuke.
if(config.map_path == CUSTOM_MAP_PATH)
fdel("_maps/custom/[config.map_file]")
// And as the file is now removed set the next map to default.
next_map_config = load_map_config(default_to_box = TRUE)
next_map_config = load_default_map_config()

GLOBAL_LIST_EMPTY(the_station_areas)

Expand Down Expand Up @@ -384,7 +384,7 @@ GLOBAL_LIST_EMPTY(the_station_areas)

/datum/controller/subsystem/mapping/proc/changemap(datum/map_config/VM)
if(!VM.MakeNextMap())
next_map_config = load_map_config(default_to_box = TRUE)
next_map_config = load_default_map_config()
message_admins("Failed to set new map with next_map.json for [VM.map_name]! Using default as backup!")
return

Expand Down
31 changes: 23 additions & 8 deletions code/datums/map_config.dm
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,34 @@
/// Dictionary of job sub-typepath to template changes dictionary
var/job_changes = list()

// NON-MODULE CHANGE: Something's broken
/proc/load_map_config(filename = "data/next_map.json", default_to_box, delete_after, error_if_missing = TRUE)
var/datum/map_config/config = new
if (default_to_box)
return config
/**
* Proc that simply loads the default map config, which should always be functional.
*/
/proc/load_default_map_config()
return new /datum/map_config


/**
* Proc handling the loading of map configs. Will return the default map config using [/proc/load_default_map_config] if the loading of said file fails for any reason whatsoever, so we always have a working map for the server to run.
* Arguments:
* * filename - Name of the config file for the map we want to load. The .json file extension is added during the proc, so do not specify filenames with the extension.
* * error_if_missing - Bool that says whether failing to load the config for the map will be logged in log_world or not as it's passed to LoadConfig().
*
* Returns the config for the map to load.
*/
/proc/load_map_config(filename = null, error_if_missing = TRUE)
var/datum/map_config/config = load_default_map_config()
if(filename) // If none is specified, then go to look for next_map.json, for map rotation purposes.
filename = "_maps/[filename].json"
else
filename = PATH_TO_NEXT_MAP_JSON
if (!config.LoadConfig(filename, error_if_missing))
qdel(config)
config = new /datum/map_config // Fall back to Box
else if (delete_after)
fdel(filename)
return load_default_map_config()
return config

#define CHECK_EXISTS(X) if(!istext(json[X])) { log_world("[##X] missing from json!"); return; }

/datum/map_config/proc/LoadConfig(filename, error_if_missing)
if(!fexists(filename))
if(error_if_missing)
Expand Down
8 changes: 4 additions & 4 deletions code/modules/admin/verbs/maprotation.dm
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

VM.map_path = CUSTOM_MAP_PATH
VM.map_file = "[map_file]"
VM.config_filename = "data/next_map.json"
VM.config_filename = PATH_TO_NEXT_MAP_JSON
var/json_value = list(
"version" = MAP_CURRENT_VERSION,
"map_name" = VM.map_name,
Expand All @@ -92,9 +92,9 @@
)

// If the file isn't removed text2file will just append.
if(fexists("data/next_map.json"))
fdel("data/next_map.json")
text2file(json_encode(json_value), "data/next_map.json")
if(fexists(PATH_TO_NEXT_MAP_JSON))
fdel(PATH_TO_NEXT_MAP_JSON)
text2file(json_encode(json_value), PATH_TO_NEXT_MAP_JSON)

if(SSmapping.changemap(VM))
message_admins("[key_name_admin(usr)] has changed the map to [VM.map_name]")
Expand Down

0 comments on commit c0566e0

Please sign in to comment.