From ec8ac5f18f17ef741be68c766e61e96a0e5864de Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Sat, 6 Nov 2021 19:27:52 +0000 Subject: [PATCH] [MIRROR] Makes maps be able to load correctly again [MDB IGNORE] (#9276) * Makes maps be able to load correctly again * Feex Co-authored-by: GoldenAlpharex <58045821+GoldenAlpharex@users.noreply.github.com> --- code/__DEFINES/maps.dm | 3 +++ code/_compile_options.dm | 2 +- code/controllers/subsystem/mapping.dm | 6 ++--- code/datums/map_config.dm | 32 ++++++++++++++++++------- code/modules/admin/verbs/maprotation.dm | 8 +++---- 5 files changed, 35 insertions(+), 16 deletions(-) diff --git a/code/__DEFINES/maps.dm b/code/__DEFINES/maps.dm index 4b635445df4..3974d692e7c 100644 --- a/code/__DEFINES/maps.dm +++ b/code/__DEFINES/maps.dm @@ -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" diff --git a/code/_compile_options.dm b/code/_compile_options.dm index 1f219b2dc80..709f88268f9 100644 --- a/code/_compile_options.dm +++ b/code/_compile_options.dm @@ -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 diff --git a/code/controllers/subsystem/mapping.dm b/code/controllers/subsystem/mapping.dm index d96d3288853..d81dffaa7c4 100644 --- a/code/controllers/subsystem/mapping.dm +++ b/code/controllers/subsystem/mapping.dm @@ -67,7 +67,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() @@ -346,7 +346,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) @@ -434,7 +434,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 diff --git a/code/datums/map_config.dm b/code/datums/map_config.dm index c7eca13ec9d..dd278bbef53 100644 --- a/code/datums/map_config.dm +++ b/code/datums/map_config.dm @@ -34,19 +34,35 @@ /// Dictionary of job sub-typepath to template changes dictionary var/job_changes = list() -/proc/load_map_config(filename = "next_map.json", default_to_box, delete_after, error_if_missing = TRUE) - filename = "_maps/[filename].json" - 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) diff --git a/code/modules/admin/verbs/maprotation.dm b/code/modules/admin/verbs/maprotation.dm index c02d1df70a7..1b5352a9d1a 100644 --- a/code/modules/admin/verbs/maprotation.dm +++ b/code/modules/admin/verbs/maprotation.dm @@ -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, @@ -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]")