From b02372afb027fe3d8a38cf65be562a40eb0c56b2 Mon Sep 17 00:00:00 2001 From: deathride58 Date: Sat, 4 Jun 2022 22:44:15 -0400 Subject: [PATCH] minimap refresh - high-detail, JS fixes, pixel-perfect scaling, and more! --- code/game/area/Space_Station_13_areas.dm | 4 + code/game/area/areas.dm | 4 + code/game/area/areas/ruins/_ruins.dm | 3 + code/game/objects/objs.dm | 2 + code/modules/mapping/minimaps.dm | 103 +++++++++++++++++------ code/modules/power/solar.dm | 1 + 6 files changed, 90 insertions(+), 27 deletions(-) diff --git a/code/game/area/Space_Station_13_areas.dm b/code/game/area/Space_Station_13_areas.dm index dd70825339..361c518073 100644 --- a/code/game/area/Space_Station_13_areas.dm +++ b/code/game/area/Space_Station_13_areas.dm @@ -212,6 +212,7 @@ NOTE: there are two lists of areas in the end of this file: centcom and station area_flags = BLOBS_ALLOWED | UNIQUE_AREA | CULT_PERMITTED // airlock_wires = /datum/wires/airlock/maint sound_environment = SOUND_AREA_TUNNEL_ENCLOSED + minimap_color = "#454545" //Maintenance - Departmental @@ -435,6 +436,7 @@ NOTE: there are two lists of areas in the end of this file: centcom and station /area/hallway nightshift_public_area = NIGHTSHIFT_AREA_PUBLIC sound_environment = SOUND_AREA_STANDARD_STATION + minimap_color = "#aaaaaa" /area/hallway/primary name = "Primary Hallway" @@ -490,6 +492,7 @@ NOTE: there are two lists of areas in the end of this file: centcom and station /area/hallway/secondary/exit name = "Escape Shuttle Hallway" icon_state = "escape" + minimap_color = "#baa0a0" /area/hallway/secondary/exit/departure_lounge name = "Departure Lounge" @@ -498,6 +501,7 @@ NOTE: there are two lists of areas in the end of this file: centcom and station /area/hallway/secondary/entry name = "Arrival Shuttle Hallway" icon_state = "entry" + minimap_color = "#a0a0ba" /area/hallway/secondary/service name = "Service Hallway" diff --git a/code/game/area/areas.dm b/code/game/area/areas.dm index 44916cf1d2..24b49a3af7 100644 --- a/code/game/area/areas.dm +++ b/code/game/area/areas.dm @@ -124,6 +124,10 @@ /// Color on minimaps, if it's null (which is default) it makes one at random. var/minimap_color + var/minimap_color2 // if this isn't null, then this will show as a checkerboard pattern mixed in with the above. works even if the above is null (for better or worse) + + var/minimap_show_walls = TRUE + /** * These two vars allow for multiple unique areas to be linked to a master area * and share some functionalities such as APC powernet nodes, fire alarms etc, without sacrificing diff --git a/code/game/area/areas/ruins/_ruins.dm b/code/game/area/areas/ruins/_ruins.dm index 6699e94129..f9af5c8ce4 100644 --- a/code/game/area/areas/ruins/_ruins.dm +++ b/code/game/area/areas/ruins/_ruins.dm @@ -9,6 +9,9 @@ ambientsounds = RUINS sound_environment = SOUND_ENVIRONMENT_STONEROOM var/valid_territory = FALSE // hey so what if we did not allow things like cult summons to appear on ruins + minimap_color = "#775940" + minimap_color2 = "#6b5d48" + minimap_show_walls = FALSE /area/ruin/unpowered diff --git a/code/game/objects/objs.dm b/code/game/objects/objs.dm index 46248c1ff8..4ea25bec96 100644 --- a/code/game/objects/objs.dm +++ b/code/game/objects/objs.dm @@ -7,6 +7,8 @@ var/obj_flags = CAN_BE_HIT var/set_obj_flags // ONLY FOR MAPPING: Sets flags from a string list, handled in Initialize. Usage: set_obj_flags = "EMAGGED;!CAN_BE_HIT" to set EMAGGED and clear CAN_BE_HIT. + var/minimap_override_color // allows this obj to set its own color on the minimap + var/damtype = BRUTE var/force = 0 diff --git a/code/modules/mapping/minimaps.dm b/code/modules/mapping/minimaps.dm index 51fde1f8db..8768ddd1e8 100644 --- a/code/modules/mapping/minimaps.dm +++ b/code/modules/mapping/minimaps.dm @@ -47,21 +47,43 @@ var/meta_color = area_to_color[A] if(!meta_color) - meta_color = rgb(rand(0, 255), rand(0, 255), rand(0, 255)) // technically conflicts could happen but it's like very unlikely and it's not that big of a deal if one happens + var/meta_x = LAZYLEN(area_to_color) + 1 + var/meta_y = (((meta_x + 1) - ((meta_x + 1) % 255)) / 255) + var/meta_z = (((meta_y + 1) - ((meta_y + 1) % 255)) / 255) + meta_color = rgb(meta_x % 255, meta_y % 255, meta_z % 255) //This supports exactly 16,581,374 areas with no conflicts whatsoever before it just gives up area_to_color[A] = meta_color color_area_names[meta_color] = A.name meta_icon.DrawBox(meta_color, img_x, img_y) - if(istype(T, /turf/closed/wall)) + if(A.minimap_show_walls && istype(T, /turf/closed/wall)) map_icon.DrawBox("#000000", img_x, img_y) else if(!istype(A, /area/space)) - var/color = A.minimap_color || "#FF00FF" - if(locate(/obj/machinery/power/solar) in T) - color = "#02026a" + var/color = (A.minimap_color2 ? (((img_x + img_y) % 2) ? A.minimap_color2 : A.minimap_color ) : A.minimap_color) || "#FF00FF" + if(A.minimap_show_walls) + var/overridden + for(var/obj/structure/O in T) + if(O.minimap_override_color) + color = O.minimap_override_color + overridden = TRUE + break + else if(O.density && O.anchored) + color = BlendRGB(color, "#000000", 0.5) + overridden = TRUE + break + + //In an ideal world, we'd be able to get away with just doing for(var/obj/O in T) up there, and calling it a day. However. HOWEVER! + //Doing that causes the code to also loop through items. and that uh. Kinda bloats minimap gen time. A LOT. We're talking straight-up doubling the time it takes to gen. + //So instead we take our ctrl+c. We copy the above code. And we ctrl+v. It's awful. We hate it. But it works. It's faster. Funny mapgen go vroom + if(!overridden) + for(var/obj/machinery/O in T) + if(O.minimap_override_color) + color = O.minimap_override_color + break + else if(O.density && O.anchored) + color = BlendRGB(color, "#000000", 0.25) + break - if((locate(/obj/effect/spawner/structure/window) in T) || (locate(/obj/structure/grille) in T)) - color = BlendRGB(color, "#000000", 0.5) map_icon.DrawBox(color, img_x, img_y) map_icon.Crop(crop_x1, crop_y1, crop_x2, crop_y2) @@ -102,22 +124,48 @@ var/list/datas = list() var/list/info = list() - - for(var/i in 1 to length(minimaps))// OLD: for(var/i in 1 to length(minimaps)) + var/buttonfield = "" + var/totalmaps = length(minimaps) + for(var/i in 1 to totalmaps)// OLD: for(var/i in 1 to length(minimaps)) var/datum/minimap/M = minimaps[i] var/map_name = "minimap-[M.id].png" var/meta_name = "minimap-[M.id]-meta.png" M.send(user) info += {" -
+
+ [totalmaps > 1 ? "

Layer [i]

" : ""]
-
+ [totalmaps <= 1 ? "
" : ""]
"} datas += json_encode(M.color_area_names); + buttonfield += "Layer [i] " + + if(totalmaps > 1) + info += "
[buttonfield]
" + + //This is a hacky workaround; the status display is extremely buggy when multiple z-levels are present. We couldn't figure out how to fix this after 7 hours of banging our head against the wall + //We're coder + var/mousemove_bit = {" + canvas.onmousemove = function(e){ + var rect = canvas.getBoundingClientRect(); + var x = Math.floor(e.offsetX * img.width / rect.width); + var y = Math.floor(e.offsetY * img.height / rect.height); + + var color_idx = x * 4 + (y * 4 * imagedata.width); + var color = "#" + hexify(imagedata.data\[color_idx]) + hexify(imagedata.data\[color_idx+1]) + hexify(imagedata.data\[color_idx+2]); + + label.textContent = data\[color]; + canvas.title = data\[color]; + } + canvas.onmouseout = function(e){ + label.textContent = " "; + canvas.title = ""; + } + "} info = info.Join() //this is bad. Too bad! @@ -133,6 +181,14 @@ } return num; } + function switchmap(mapid) { + var targetblock = document.getElementById(mapid); + for(var i = 0; i < [length(minimaps)]; i++) { + var currentblock = document.getElementById("layer-" + (i + 1)); + currentblock.style.display = 'none'; + } + targetblock.style.display = ''; + } window.onload = function() { if(!window.HTMLCanvasElement) { var label = document.getElementById("label-1"); @@ -150,6 +206,7 @@ var canvas = document.createElement("canvas"); canvas.width = img.width * 2; canvas.height = img.height * 2; + canvas.id = "canvas-" + (i+1); var ctx = canvas.getContext('2d'); ctx.msImageSmoothingEnabled = false; @@ -158,31 +215,23 @@ ctx = document.createElement("canvas").getContext('2d'); ctx.canvas.width = img.width; ctx.canvas.height = img.height; + ctx.id = "ctx-" + (i+1); ctx.drawImage(document.getElementById("map-" + (i+1) + "-meta"), 0, 0); var imagedata = ctx.getImageData(0, 0, img.width, img.height); - canvas.onmousemove = function(e){ - var rect = canvas.getBoundingClientRect(); - var x = Math.floor(e.offsetX * img.width / rect.width); - var y = Math.floor(e.offsetY * img.height / rect.height); - - var color_idx = x * 4 + (y * 4 * imagedata.width); - var color = "#" + hexify(imagedata.data\[color_idx]) + hexify(imagedata.data\[color_idx+1]) + hexify(imagedata.data\[color_idx+2]); - var label = document.getElementById("label-" + (i+1)); //label-String(n) - - label.textContent = data\[color]; - canvas.title = data\[color]; - } - canvas.onmouseout = function(e){ - canvas.title = ""; - } + var label = document.getElementById("label-" + (i+1)); //label-String(n); + [totalmaps <= 1 ? mousemove_bit : ""] } } diff --git a/code/modules/power/solar.dm b/code/modules/power/solar.dm index fad48b4854..27fb30a459 100644 --- a/code/modules/power/solar.dm +++ b/code/modules/power/solar.dm @@ -5,6 +5,7 @@ desc = "A solar panel. Generates electricity when in contact with sunlight." icon = 'goon/icons/obj/power.dmi' icon_state = "sp_base" + minimap_override_color = "#02026a" density = TRUE use_power = NO_POWER_USE idle_power_usage = 0