From 6d23bf28dda4a44f13ce150b8a601d00b5a507cc Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Fri, 18 Nov 2022 19:19:03 +0100 Subject: [PATCH] [MIRROR] Adding the ability to load the configuration of custom maps. [MDB IGNORE] (#17565) * Adding the ability to load the configuration of custom maps. (#71277) ## About The Pull Request By default, all custom maps are assigned one standard configuration. This option rather limits the possibilities for creating custom levels. For example, you can not use multilevel maps, because with this configuration will always be loaded only one level. With this PR I want to provide the ability to load a configuration file for a custom map similar to the standard map.json configs. ![ZpdpfZWq2V](https://user-images.githubusercontent.com/88540658/201946344-fdf8589c-0e20-475c-a9d8-b21c9ff32dd8.png) ## Why It's Good For The Game Allows administrators to flexibly configure custom maps. For example for events, etc. ## Changelog :cl: admin: Adding the ability to load the configuration of custom maps /:cl: Co-authored-by: twilightwanderer Co-authored-by: san7890 * Adding the ability to load the configuration of custom maps. Co-authored-by: twilightwanderer <88540658+twilightwanderer@users.noreply.github.com> Co-authored-by: twilightwanderer Co-authored-by: san7890 --- code/modules/admin/verbs/maprotation.dm | 111 +++++++++++++++--------- 1 file changed, 69 insertions(+), 42 deletions(-) diff --git a/code/modules/admin/verbs/maprotation.dm b/code/modules/admin/verbs/maprotation.dm index c985a835a11..c41677db37c 100644 --- a/code/modules/admin/verbs/maprotation.dm +++ b/code/modules/admin/verbs/maprotation.dm @@ -13,25 +13,25 @@ set name = "Change Map" var/list/maprotatechoices = list() for (var/map in config.maplist) - var/datum/map_config/VM = config.maplist[map] - var/mapname = VM.map_name - if (VM == config.defaultmap) + var/datum/map_config/virtual_map = config.maplist[map] + var/mapname = virtual_map.map_name + if (virtual_map == config.defaultmap) mapname += " (Default)" - if (VM.config_min_users > 0 || VM.config_max_users > 0) + if (virtual_map.config_min_users > 0 || virtual_map.config_max_users > 0) mapname += " \[" - if (VM.config_min_users > 0) - mapname += "[VM.config_min_users]" + if (virtual_map.config_min_users > 0) + mapname += "[virtual_map.config_min_users]" else mapname += "0" mapname += "-" - if (VM.config_max_users > 0) - mapname += "[VM.config_max_users]" + if (virtual_map.config_max_users > 0) + mapname += "[virtual_map.config_max_users]" else mapname += "inf" mapname += "\]" - maprotatechoices[mapname] = VM + maprotatechoices[mapname] = virtual_map var/chosenmap = tgui_input_list(usr, "Choose a map to change to", "Change Map", sort_list(maprotatechoices)|"Custom") if (isnull(chosenmap)) return @@ -39,11 +39,7 @@ if(chosenmap == "Custom") message_admins("[key_name_admin(usr)] is changing the map to a custom map") log_admin("[key_name(usr)] is changing the map to a custom map") - var/datum/map_config/VM = new - - VM.map_name = input("Choose the name for the map", "Map Name") as null|text - if(isnull(VM.map_name)) - VM.map_name = "Custom" + var/datum/map_config/virtual_map = new var/map_file = input("Pick file:", "Map File") as null|file if(isnull(map_file)) @@ -53,9 +49,10 @@ to_chat(src, span_warning("Filename must end in '.dmm': [map_file]")) return + if(fexists("_maps/custom/[map_file]")) + fdel("_maps/custom/[map_file]") if(!fcopy(map_file, "_maps/custom/[map_file]")) return - // This is to make sure the map works so the server does not start without a map. var/datum/parsed_map/M = new (map_file) if(!M) @@ -68,41 +65,71 @@ return qdel(M) + var/config_file = null + var/list/json_value = list() + var/config = tgui_alert(usr,"Would you like to upload an additional config for this map?", "Map Config", list("Yes", "No")) + if(config == "Yes") + config_file = input("Pick file:", "Config JSON File") as null|file + if(isnull(config_file)) + return + if(copytext("[config_file]", -5) != ".json") + to_chat(src, span_warning("Filename must end in '.json': [config_file]")) + return + if(fexists("data/custom_map_json/[config_file]")) + fdel("data/custom_map_json/[config_file]") + if(!fcopy(config_file, "data/custom_map_json/[config_file]")) + return + if (virtual_map.LoadConfig("data/custom_map_json/[config_file]", TRUE) != TRUE) + to_chat(src, span_warning("Failed to load config: [config_file]. Check that the fields are filled out correctly. \"map_path\": \"custom\" and \"map_file\": \"your_map_name.dmm\"")) + return + json_value = list( + "version" = MAP_CURRENT_VERSION, + "map_name" = virtual_map.map_name, + "map_path" = virtual_map.map_path, + "map_file" = virtual_map.map_file, + "shuttles" = virtual_map.shuttles, + "traits" = virtual_map.traits, + "job_changes" = virtual_map.job_changes, + "library_areas" = virtual_map.library_areas, + ) + else + virtual_map = load_map_config() + virtual_map.map_name = input("Choose the name for the map", "Map Name") as null|text + if(isnull(virtual_map.map_name)) + virtual_map.map_name = "Custom" - var/shuttles = tgui_alert(usr,"Do you want to modify the shuttles?", "Map Shuttles", list("Yes", "No")) - if(shuttles == "Yes") - for(var/s in VM.shuttles) - var/shuttle = input(s, "Map Shuttles") as null|text - if(!shuttle) - continue - if(!SSmapping.shuttle_templates[shuttle]) - to_chat(usr, span_warning("No such shuttle as '[shuttle]' exists, using default.")) - continue - VM.shuttles[s] = shuttle + var/shuttles = tgui_alert(usr,"Do you want to modify the shuttles?", "Map Shuttles", list("Yes", "No")) + if(shuttles == "Yes") + for(var/s in virtual_map.shuttles) + var/shuttle = input(s, "Map Shuttles") as null|text + if(!shuttle) + continue + if(!SSmapping.shuttle_templates[shuttle]) + to_chat(usr, span_warning("No such shuttle as '[shuttle]' exists, using default.")) + continue + virtual_map.shuttles[s] = shuttle - VM.map_path = CUSTOM_MAP_PATH - VM.map_file = "[map_file]" - VM.config_filename = PATH_TO_NEXT_MAP_JSON - var/json_value = list( - "version" = MAP_CURRENT_VERSION, - "map_name" = VM.map_name, - "map_path" = VM.map_path, - "map_file" = VM.map_file, - "shuttles" = VM.shuttles - ) + json_value = list( + "version" = MAP_CURRENT_VERSION, + "map_name" = virtual_map.map_name, + "map_path" = CUSTOM_MAP_PATH, + "map_file" = "[map_file]", + "shuttles" = virtual_map.shuttles, + ) // If the file isn't removed text2file will just append. 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]") + if(SSmapping.changemap(virtual_map)) + message_admins("[key_name_admin(usr)] has changed the map to [virtual_map.map_name]") SSmapping.map_force_chosen = TRUE + fdel("data/custom_map_json/[config_file]") else - var/datum/map_config/VM = maprotatechoices[chosenmap] - message_admins("[key_name_admin(usr)] is changing the map to [VM.map_name]") - log_admin("[key_name(usr)] is changing the map to [VM.map_name]") - if (SSmapping.changemap(VM)) - message_admins("[key_name_admin(usr)] has changed the map to [VM.map_name]") + var/datum/map_config/virtual_map = maprotatechoices[chosenmap] + message_admins("[key_name_admin(usr)] is changing the map to [virtual_map.map_name]") + log_admin("[key_name(usr)] is changing the map to [virtual_map.map_name]") + if (SSmapping.changemap(virtual_map)) + message_admins("[key_name_admin(usr)] has changed the map to [virtual_map.map_name]") SSmapping.map_force_chosen = TRUE