Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
doom committed Sep 28, 2023
1 parent 62865c5 commit 63e4a82
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
8 changes: 4 additions & 4 deletions code/_globalvars/global_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ GLOBAL_LIST_EMPTY(CMBFaxes)
GLOBAL_LIST_EMPTY(GeneralFaxes) //Inter-machine faxes
GLOBAL_LIST_EMPTY(fax_contents) //List of fax contents to maintain it even if source paper is deleted

//datum containing only the flat tacmap png asset
//datum containing only a reference to the flattend map png, the actual png is stored in the user's cache.
GLOBAL_LIST_EMPTY(uscm_flat_tacmap_png_asset)
GLOBAL_LIST_EMPTY(xeno_flat_tacmap_png_asset)

//datum containing flat tacmap and svg (snapshot in time with svg overlay) for viewing minimap drawings
GLOBAL_LIST_EMPTY(uscm_flat_tacmap)
GLOBAL_LIST_EMPTY(xeno_flat_tacmap)
//datum containing the svg overlay coords in array format.
GLOBAL_LIST_EMPTY(uscm_svg_overlay)
GLOBAL_LIST_EMPTY(xeno_svg_overlay)

GLOBAL_LIST_EMPTY(failed_fultons) //A list of fultoned items which weren't collected and fell back down
GLOBAL_LIST_EMPTY(larva_burst_by_hive)
Expand Down
56 changes: 31 additions & 25 deletions code/controllers/subsystem/minimap.dm
Original file line number Diff line number Diff line change
Expand Up @@ -338,21 +338,26 @@ SUBSYSTEM_DEF(minimaps)
hashed_minimaps[hash] = map
return map


/datum/tacmap/proc/get_current_map(mob/user, png_asset_only = FALSE)
/**
* Fetches either flattend map png asset or the svg coords datum
* Arguments:
* * user: to determine whivh faction get the map from.
* * asset_type: true for png, false for svg
*/
/datum/tacmap/proc/get_current_map(mob/user, asset_type)
var/list/map_list
if(ishuman(user))
if(png_asset_only)
if(asset_type)
map_list = GLOB.uscm_flat_tacmap_png_asset
else
map_list = GLOB.uscm_flat_tacmap
map_list = GLOB.uscm_svg_overlay
else
if(!isxeno(user))
return
if(png_asset_only)
if(asset_type)
map_list = GLOB.xeno_flat_tacmap_png_asset
else
map_list = GLOB.xeno_flat_tacmap
map_list = GLOB.uscm_svg_overlay

if(map_list.len == 0)
return
Expand Down Expand Up @@ -386,10 +391,12 @@ SUBSYSTEM_DEF(minimaps)
faction_clients += client
COOLDOWN_START(src, flatten_map_cooldown, flatten_map_cooldown_time)
var/flat_tacmap_png = icon2html(flat_map, faction_clients, sourceonly = TRUE)
var/datum/flattend_tacmap_png = new(flat_tacmap_png)
if(!isxeno(user))
GLOB.uscm_flat_tacmap_png_asset += flat_tacmap_png
GLOB.uscm_flat_tacmap_png_asset += flattend_tacmap_png
else
GLOB.xeno_flat_tacmap_png_asset += flat_tacmap_png
GLOB.xeno_flat_tacmap_png_asset += flattend_tacmap_png
qdel(flattend_tacmap_png)


/datum/controller/subsystem/minimaps/proc/fetch_tacmap_datum(zlevel, flags)
Expand Down Expand Up @@ -541,7 +548,7 @@ SUBSYSTEM_DEF(minimaps)

ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
current_map = get_current_map(user)
current_map = get_current_map(user, TRUE)
if(!current_map)
distribute_current_map_png(user)

Expand All @@ -552,9 +559,10 @@ SUBSYSTEM_DEF(minimaps)
/datum/tacmap/ui_data(mob/user)
var/list/data = list()
//todo: upon joining user should have the base map without layered icons as default. Otherwise loads failed png for a new user.
data["flatImage"] = get_current_map(user, TRUE)

data["svgData"] = null
// it's getting a datum of type
data["flatImage"] = get_current_map(user, TRUE).flat_tacmap

Check warning on line 564 in code/controllers/subsystem/minimap.dm

View workflow job for this annotation

GitHub Actions / Run Linters

field access requires static type: "flat_tacmap"
data["svgData"] = get_current_map(user, FALSE).svg_data

Check warning on line 565 in code/controllers/subsystem/minimap.dm

View workflow job for this annotation

GitHub Actions / Run Linters

field access requires static type: "svg_data"

data["mapRef"] = map_holder.map_ref
data["toolbarColorSelection"] = toolbar_color_selection
Expand All @@ -567,11 +575,6 @@ SUBSYSTEM_DEF(minimaps)
data["nextCanvasTime"] = canvas_cooldown_time
data["updatedCanvas"] = updated_canvas

current_map = get_current_map(user)
if(current_map)
data["flatImage"] = current_map.flat_tacmap
data["svgData"] = current_map.svg_data

return data

/datum/tacmap/ui_static_data(mob/user)
Expand Down Expand Up @@ -609,7 +612,7 @@ SUBSYSTEM_DEF(minimaps)
switch (action)
if ("menuSelect")
if(params["selection"] == "new canvas")
distribute_current_map_png(user)
distribute_current_map_png(user) // not updating?

. = TRUE

Expand Down Expand Up @@ -639,9 +642,7 @@ SUBSYSTEM_DEF(minimaps)
. = TRUE

if ("selectAnnouncement")

var/current_map_asset = get_current_map(user, TRUE)
var/datum/svg_overlay/svg_overlay = new(params["image"], current_map_asset)
var/datum/svg_overlay/svg_overlay = new(params["image"])

var/outgoing_message = stripped_multiline_input(user, "Optional message to announce with the tactical map", "Tactical Map Announcement", "")
if(!outgoing_message)
Expand All @@ -653,10 +654,10 @@ SUBSYSTEM_DEF(minimaps)
if(isxeno(user))
xeno = user
xeno_announcement(outgoing_message, xeno.hivenumber)
GLOB.xeno_flat_tacmap += svg_overlay
GLOB.xeno_svg_overlay += svg_overlay
COOLDOWN_START(GLOB, xeno_canvas_cooldown, canvas_cooldown_time)
else
GLOB.uscm_flat_tacmap += svg_overlay
GLOB.uscm_svg_overlay += svg_overlay
var/mob/living/carbon/human/H = user
var/obj/item/card/id/id = H.wear_id
if(istype(id))
Expand Down Expand Up @@ -707,10 +708,15 @@ SUBSYSTEM_DEF(minimaps)
map = null
return ..()

// datums for holding both the flattened png asset and overlay. It's best to keep them separate with the current implementation imo.
/datum/flat_tacmap_png
var/flat_tacmap

/datum/flat_tacmap_png/New(flat_tacmap)
src.flat_tacmap = flat_tacmap

/datum/svg_overlay
var/svg_data
var/flat_tacmap

/datum/svg_overlay/New(svg_data, flat_tacmap)
/datum/svg_overlay/New(svg_data)
src.svg_data = svg_data
src.flat_tacmap = flat_tacmap

0 comments on commit 63e4a82

Please sign in to comment.