Replace some icon2base64 with DmIcon (#26885)

* Vending DmIcon

* FloorPainter DmIcon

* Nuh uh
This commit is contained in:
Aylong
2024-09-26 10:13:31 +00:00
committed by GitHub
parent 1896ed9fd8
commit 3349e62bd8
5 changed files with 49 additions and 71 deletions
@@ -4,7 +4,7 @@
module_name = "floor painter"
module_state = "floor_painter"
var/floor_icon
var/floor_icon = 'icons/turf/floors.dmi'
var/floor_state = "floor"
var/floor_dir = SOUTH
@@ -21,23 +21,6 @@
"darkred", "darkredcorners", "darkredfull", "darkblue", "darkbluecorners", "darkbluefull", "darkgreen", "darkgreencorners",
"darkgreenfull", "darkyellow", "darkyellowcorners", "darkyellowfull", "darkbrown", "darkbrowncorners", "darkbrownfull")
// This is a double-list. First entry is the type key, second is the direction, with the final value being the b64 of the icon
var/static/list/lookup_cache = list()
/datum/painter/floor/New(obj/item/painter/parent_painter)
. = ..()
if(!length(lookup_cache))
for(var/style in allowed_states)
if(!(style in lookup_cache))
lookup_cache += style
lookup_cache[style] = list()
for(var/dir in GLOB.alldirs)
var/icon/floor_icon = icon('icons/turf/floors.dmi', style, dir)
// These indexes have to be strings otherwise it treats it as a list index not a map lookup index
lookup_cache[style] += "[dir]"
lookup_cache[style]["[dir]"] = icon2base64(floor_icon)
/datum/painter/floor/paint_atom(atom/target, mob/user)
if(!istype(target, /turf/simulated/floor/plasteel))
to_chat(user, "<span class='warning'>[holder] can only be used on station flooring.</span>")
@@ -65,31 +48,20 @@
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "FloorPainter", module_name)
// Disable automatic updates, because:
// 1) we are the only user of the item, and don't expect to observe external changes
// 2) generating and sending the icon each tick is a bit expensive, and creates small but noticeable lag
// Disable automatic updates, because we are the only user of the item, and don't expect to observe external changes
ui.set_autoupdate(FALSE)
ui.open()
/datum/painter/floor/ui_data(mob/user)
var/list/data = list()
data["availableStyles"] = allowed_states
data["selectedStyle"] = floor_state
data["selectedDir"] = dir2text(floor_dir)
data["directionsPreview"] = list()
for(var/dir in GLOB.alldirs)
data["directionsPreview"][dir2text(dir)] = lookup_cache[floor_state]["[dir]"]
data["selectedDir"] = floor_dir
return data
/datum/painter/floor/ui_static_data(mob/user)
var/list/data = list()
data["allStylesPreview"] = list()
for(var/style in allowed_states)
data["allStylesPreview"][style] = lookup_cache[style]["[SOUTH]"]
data["icon"] = floor_icon
data["availableStyles"] = allowed_states
return data
/datum/painter/floor/ui_act(action, params)
@@ -111,7 +83,7 @@
floor_state = allowed_states[index]
if(action == "select_direction")
var/dir = text2dir(params["direction"])
var/dir = params["direction"]
if(dir != 0)
floor_dir = dir