Files
Bubberstation/code/modules/mapping/modular_map_loader/modular_map_loader.dm
SkyratBot 8f047b2bf5 [MIRROR] Fixes Modular Map Loading Runtimes [MDB IGNORE] (#10822)
* Fixes Modular Map Loading Runtimes (#64212)

## About The Pull Request

Moves the modmap root object's load_map() call to New(). This changes something about where it falls in init order that stops it from causing a flood of lighting runtimes. Don't ask my why, it just does.

## Why It's Good For The Game

Fixes #64192

* Fixes Modular Map Loading Runtimes

Co-authored-by: Thunder12345 <Thunder12345@users.noreply.github.com>
2022-01-20 02:52:23 +00:00

78 lines
2.0 KiB
Plaintext

/obj/modular_map_root
invisibility = INVISIBILITY_ABSTRACT
icon = 'icons/obj/device.dmi'
icon_state = "pinonclose"
resistance_flags = INDESTRUCTIBLE | LAVA_PROOF | FIRE_PROOF | UNACIDABLE | ACID_PROOF
anchored = TRUE
/// Points to a .toml file storing configuration data about the modules associated with this root
var/config_file = null
/// Key used to look up the appropriate map paths in the associated .toml file
var/key = null
INITIALIZE_IMMEDIATE(/obj/modular_map_root)
/obj/modular_map_root/Initialize(mapload)
. = ..()
INVOKE_ASYNC(src, .proc/load_map)
/// Randonly selects a map file from the TOML config specified in config_file, loads it, then deletes itself.
/obj/modular_map_root/proc/load_map()
var/turf/spawn_area = get_turf(src)
var/datum/map_template/map_module/map = new()
if(!config_file)
return
if(!key)
return
var/config = rustg_read_toml_file(config_file)
var/mapfile = config["directory"] + pick(config["rooms"][key]["modules"])
map.load(spawn_area, FALSE, mapfile)
qdel(src, force=TRUE)
/datum/map_template/map_module
name = "Base Map Module Template"
var/x_offset = 0
var/y_offset = 0
/datum/map_template/map_module/load(turf/T, centered = FALSE, mapfile = null)
if(!mapfile)
return
mappath = mapfile
preload_size(mappath) // We need to run this here as the map path has been null until now
T = locate(T.x - x_offset, T.y - y_offset, T.z)
. = ..()
/datum/map_template/map_module/preload_size(path, cache)
. = ..(path, TRUE) // Done this way because we still want to know if someone actualy wanted to cache the map
if(!cached_map)
return
var/list/offset = discover_offset(/obj/modular_map_connector)
x_offset = offset[1] - 1
y_offset = offset[2] - 1
if(!cache)
cached_map = null
/obj/modular_map_connector
invisibility = INVISIBILITY_ABSTRACT
icon = 'icons/obj/device.dmi'
icon_state = "pinonclose"
resistance_flags = INDESTRUCTIBLE | LAVA_PROOF | FIRE_PROOF | UNACIDABLE | ACID_PROOF
anchored = TRUE