Skip to content

Commit

Permalink
refactor: replace some icon2base64 to DMicon (#6347)
Browse files Browse the repository at this point in the history
* refactor: replace some icon2base64 to DMicon

* Update tgui.bundle.js
  • Loading branch information
dageavtobusnick authored Jan 11, 2025
1 parent aa25abb commit 240753f
Show file tree
Hide file tree
Showing 24 changed files with 385 additions and 297 deletions.
3 changes: 2 additions & 1 deletion code/datums/elements/strippable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@
var/key = "[item.icon],[item.icon_state]"
if(!(key in base64_cache))
base64_cache[key] = icon2base64(icon(item.icon, item.icon_state, dir = SOUTH, frame = 1, moving = FALSE))
result["icon"] = base64_cache[key]
result["icon"] = item.icon
result["icon_state"] = item.icon_state
result["name"] = item.name

var/real_alts = item_data.get_alternate_actions(owner, user)
Expand Down
3 changes: 2 additions & 1 deletion code/game/gamemodes/clockwork/clockwork_workshop.dm
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@
"brass" = design.brass_cost,
"power" = design.power_cost,
"requirements" = matreq,
"image" = "[icon2base64(icon(initial(I.icon), initial(I.icon_state), SOUTH, 1))]"
"icon" = initial(I.icon),
"icon_state" = initial(I.icon_state),
)
static_data["items"][cat] = cat_items

Expand Down
9 changes: 5 additions & 4 deletions code/game/machinery/PDApainter.dm
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
// Get Base64 version of an icon for our TGUI needs.
// Always try to get first frame as it can be animation resulting in all frames in single image.
// pda-library as an example has 4 frames
var/base64icon = "[icon2base64(icon(initial(pda.icon), initial(pda.icon_state), frame = 1))]"
new_color_list[initial(pda.icon_state)] = list(base64icon, initial(pda.desc))
new_color_list[initial(pda.icon_state)] = list(initial(pda.icon), initial(pda.desc))

new_color_list = sortAssoc(new_color_list)
colorlist = new_color_list
Expand Down Expand Up @@ -152,12 +151,13 @@

if(storedpda)
data["hasPDA"] = TRUE
data["pdaIcon"] = storedpda.base64icon
data["pdaIconState"] = storedpda.icon_state
data["pdaOwnerName"] = storedpda.owner
data["pdaJobName"] = storedpda.ownjob
else
data["hasPDA"] = FALSE
data["pdaIcon"] = null
data["pdaIconState"] = null
data["pdaOwnerName"] = null
data["pdaJobName"] = null

Expand All @@ -171,6 +171,7 @@
/obj/machinery/pdapainter/ui_static_data(mob/user)
var/data = list()
data["pdaTypes"] = colorlist
data["pdaIcon"] = icon
data["allowErasePda"] = allowErasePda
return data

Expand All @@ -189,7 +190,7 @@
if(storedpda)
storedpda.remove_pda_case()
var/new_icon = params["selectedPda"]
storedpda.current_painting = list("icon" = new_icon, "base64" = colorlist[new_icon][1], "desc" = colorlist[new_icon][2])
storedpda.current_painting = list("icon" = new_icon, "desc" = colorlist[new_icon][2])
storedpda.update_appearance(UPDATE_ICON_STATE|UPDATE_DESC)
playsound(loc, 'sound/goonstation/machines/printer_thermal.ogg', 15, TRUE)
statusLabel = "Покраска завершена"
Expand Down
3 changes: 2 additions & 1 deletion code/game/machinery/autolathe.dm
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@
"requirements" = matreq,
"hacked" = ("hacked" in categories) ? TRUE : FALSE,
"max_multiplier" = maxmult,
"image" = "[icon2base64(icon(initial(I.icon), initial(I.icon_state), SOUTH, 1))]"
"icon" = initial(I.icon),
"icon_state" = initial(I.icon_state),
)))
recipiecache = recipes
data["recipes"] = recipiecache
Expand Down
8 changes: 6 additions & 2 deletions code/game/machinery/customat.dm
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
var/price = 0
///Icon in tgui
var/icon = ""
///Icon_state in tgui
var/icon_state = ""

/datum/data/customat_product/New(obj/item/I)
name = I.name
amount = 0
containtment = list()
price = 0
icon = icon2base64(icon(initial(I.icon), initial(I.icon_state), SOUTH, 1, FALSE))
icon = icon(initial(I.icon))
icon_state = initial(I.icon_state)


/obj/machinery/customat
Expand Down Expand Up @@ -565,7 +568,8 @@
price = product.price,
stock = product.amount,
icon = product.icon,
Key = product.key
icon_state = product.icon_state,
Key = product.key,
)
data["products"] += list(data_pr)

Expand Down
19 changes: 12 additions & 7 deletions code/game/machinery/vending.dm
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,6 @@
build_inventory(products, product_records)
build_inventory(contraband, hidden_records)
build_inventory(premium, coin_records)
for(var/datum/data/vending_product/R in (product_records + coin_records + hidden_records))
var/obj/item/I = R.product_path
var/pp = path2assetID(R.product_path)
imagelist[pp] = "[icon2base64(icon(initial(I.icon), initial(I.icon_state), SOUTH, 1, FALSE))]"
if(LAZYLEN(slogan_list))
// So not all machines speak at the exact same time.
// The first time this machine says something will be at slogantime + this random value,
Expand Down Expand Up @@ -802,10 +798,13 @@
data["product_records"] = list()
var/i = 1
for (var/datum/data/vending_product/R in product_records)
var/obj/item = R.product_path
var/list/data_pr = list(
path = replacetext(replacetext("[R.product_path]", "/obj/item/", ""), "/", "-"),
name = R.name,
price = (R.product_path in prices) ? prices[R.product_path] : 0,
price = (item in prices) ? prices[item] : 0,
icon = item.icon,
icon_state = item.icon_state,
max_amount = R.max_amount,
req_coin = FALSE,
is_hidden = FALSE,
Expand All @@ -815,10 +814,13 @@
i++
data["coin_records"] = list()
for (var/datum/data/vending_product/R in coin_records)
var/obj/item = R.product_path
var/list/data_cr = list(
path = replacetext(replacetext("[R.product_path]", "/obj/item/", ""), "/", "-"),
name = R.name,
price = (R.product_path in prices) ? prices[R.product_path] : 0,
price = (item in prices) ? prices[item] : 0,
icon = item.icon,
icon_state = item.icon_state,
max_amount = R.max_amount,
req_coin = TRUE,
is_hidden = FALSE,
Expand All @@ -829,10 +831,13 @@
i++
data["hidden_records"] = list()
for (var/datum/data/vending_product/R in hidden_records)
var/obj/item = R.product_path
var/list/data_hr = list(
path = replacetext(replacetext("[R.product_path]", "/obj/item/", ""), "/", "-"),
name = R.name,
price = (R.product_path in prices) ? prices[R.product_path] : 0,
price = (item in prices) ? prices[item] : 0,
icon = item.icon,
icon_state = item.icon_state,
max_amount = R.max_amount,
req_coin = FALSE,
is_hidden = TRUE,
Expand Down
19 changes: 5 additions & 14 deletions code/game/objects/items/devices/floor_painter.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
item_state = "floor_painter"
usesound = 'sound/effects/spray2.ogg'

var/floor_icon
var/floor_icon = 'icons/turf/floors.dmi'
var/floor_state = "floor"
var/floor_dir = SOUTH

Expand Down Expand Up @@ -70,33 +70,24 @@
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "FloorPainter", 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()

/obj/item/floor_painter/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)
var/icon/floor_icon = icon('icons/turf/floors.dmi', floor_state, dir)
data["directionsPreview"][dir2text(dir)] = icon2base64(floor_icon)
data["selectedDir"] = floor_dir

return data


/obj/item/floor_painter/ui_static_data(mob/user)
var/list/data = list()

data["allStylesPreview"] = list()
for (var/style in allowed_states)
var/icon/floor_icon = icon('icons/turf/floors.dmi', style, SOUTH)
data["allStylesPreview"][style] = icon2base64(floor_icon)
data["icon"] = floor_icon
data["availableStyles"] = allowed_states

return data

Expand Down
3 changes: 2 additions & 1 deletion code/game/objects/items/weapons/implants/implantpad.dm
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
"life" = implant_data.life,
"notes" = implant_data.notes,
"function" = implant_data.function,
"image" = "[icon2base64(icon(initial(case.imp.icon), initial(case.imp.icon_state), SOUTH, 1))]",
"icon" = initial(case.imp.icon),
"icon_state" = initial(case.imp.icon_state),
)
var/obj/item/implant/tracking/tracking_imp = case.imp
data["tag"] = istype(tracking_imp) ? tracking_imp.gps_tag : null
Expand Down
10 changes: 2 additions & 8 deletions code/modules/antagonists/space_ninja/suit/suit_SpiderOS.dm
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,10 @@
var/list/data = list()

//Превью абилок
data["allActionsPreview"] = list()
for (var/style in allowed_states)
var/icon/action_icon = icon('icons/mob/actions/actions_ninja.dmi', style, SOUTH, frame = 1)
data["allActionsPreview"][style] = icon2base64(action_icon)
data["actionsIcon"] = 'icons/mob/actions/actions_ninja.dmi'

//Превью костюмов
data["allStylesPreview"] = list()
for (var/style in allowed_preview_states)
var/icon/costume_icon = icon('icons/mob/ninja_previews.dmi', style, SOUTH, frame = 1)
data["allStylesPreview"][style] = icon2base64(costume_icon)
data["stylesIcon"] = 'icons/mob/ninja_previews.dmi'

return data

Expand Down
13 changes: 7 additions & 6 deletions code/modules/antagonists/vampire/vampire_powers/bestia_powers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,13 @@
var/list/data = list()
var/datum/antagonist/vampire/vampire = user.mind.has_antag_datum(/datum/antagonist/vampire)

data["icon_hearts"] = "[icon2base64(icon('icons/obj/surgery.dmi', "heart-off"))]"
data["icon_lungs"] = "[icon2base64(icon('icons/obj/surgery.dmi', "lungs"))]"
data["icon_livers"] = "[icon2base64(icon('icons/obj/surgery.dmi', "liver"))]"
data["icon_kidneys"] = "[icon2base64(icon('icons/obj/surgery.dmi', "kidneys"))]"
data["icon_eyes"] = "[icon2base64(icon('icons/obj/surgery.dmi', "eyes"))]"
data["icon_ears"] = "[icon2base64(icon('icons/obj/surgery.dmi', "ears"))]"
data["organs_icon"] = 'icons/obj/surgery.dmi'
data["icon_hearts"] = "heart-off"
data["icon_lungs"] = "lungs"
data["icon_livers"] = "liver"
data["icon_kidneys"] = "kidneys"
data["icon_eyes"] = "eyes"
data["icon_ears"] = "ears"

data["trophies_max_gen"] = MAX_TROPHIES_PER_TYPE_GENERAL
data["trophies_max_crit"] = MAX_TROPHIES_PER_TYPE_CRITICAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@

/obj/effect/proc_holder/spell/vampire/self/specialize/ui_static_data(mob/user)
var/list/data = list()
data["hemomancer"] = icon2base64(icon('icons/misc/vampire_tgui.dmi', "hemomancer"))
data["umbrae"] = icon2base64(icon('icons/misc/vampire_tgui.dmi', "umbrae"))
data["gargantua"] = icon2base64(icon('icons/misc/vampire_tgui.dmi', "gargantua"))
data["dantalion"] = icon2base64(icon('icons/misc/vampire_tgui.dmi', "dantalion"))
data["bestia"] = icon2base64(icon('icons/misc/vampire_tgui.dmi', "bestia"))
data["hemomancer"] = list('icons/misc/vampire_tgui.dmi', "hemomancer")
data["umbrae"] = list('icons/misc/vampire_tgui.dmi', "umbrae")
data["gargantua"] = list('icons/misc/vampire_tgui.dmi', "gargantua")
data["dantalion"] = list('icons/misc/vampire_tgui.dmi', "dantalion")
data["bestia"] = list('icons/misc/vampire_tgui.dmi', "bestia")

return data

Expand Down
2 changes: 1 addition & 1 deletion code/modules/client/preference/loadout/gear_tweaks.dm
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
if(!param)
return tgui_data
tgui_data["display_param"] = param
tgui_data["icon"] = parent.get_gear_icon(param)
tgui_data["icon"] = parent.base64icon
return tgui_data

/datum/gear_tweak/color/update_gear_intro(color)
Expand Down
8 changes: 0 additions & 8 deletions code/modules/pda/PDA.dm
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ GLOBAL_LIST_EMPTY(PDAs)
var/obj/item/pda/chameleon_skin
/// Custom job name used in chameleon PDA.
var/fakejob
/// Our icon saved in the text format for TGUI usage
var/base64icon
/// Custom PDA name used in update_name()
var/custom_name
/// Current PDA case
Expand All @@ -107,8 +105,6 @@ GLOBAL_LIST_EMPTY(PDAs)
GLOB.PDAs += src
GLOB.PDAs = sortAtom(GLOB.PDAs)

base64icon = "[icon2base64(icon(icon, icon_state, frame = 1))]"

update_programs()
if(default_cartridge)
cartridge = new default_cartridge(src)
Expand Down Expand Up @@ -356,16 +352,12 @@ GLOBAL_LIST_EMPTY(PDAs)
/obj/item/pda/update_icon_state()
if(chameleon_skin)
icon_state = initial(chameleon_skin.icon_state)
base64icon = "[icon2base64(icon(icon, icon_state, frame = 1))]"
else if(current_case?.new_icon_state)
icon_state = current_case.new_icon_state
base64icon = "[icon2base64(icon(icon, icon_state, frame = 1))]"
else if(current_painting)
icon_state = current_painting["icon"]
base64icon = current_painting["base64"]
else
icon_state = initial(icon_state)
base64icon = "[icon2base64(icon(icon, icon_state, frame = 1))]"

if(chameleon_skin)
item_state = initial(chameleon_skin.item_state)
Expand Down
6 changes: 4 additions & 2 deletions tgui/packages/tgui/interfaces/Autolathe.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Section,
Stack,
Dropdown,
DmIcon,
} from '../components';
import { Window } from '../layouts';
import { createSearch, toTitleCase } from 'common/string';
Expand Down Expand Up @@ -129,8 +130,9 @@ export const Autolathe = (props, context) => {
/>
{recipesToShow.map((recipe) => (
<Stack.Item grow key={recipe.ref}>
<img
src={`data:image/jpeg;base64,${recipe.image}`}
<DmIcon
icon={recipe.icon}
icon_state={recipe.icon_state}
style={{
'vertical-align': 'middle',
width: '32px',
Expand Down
Loading

0 comments on commit 240753f

Please sign in to comment.