IconForge: rust-g Spritesheet Generation (#89478)

## About The Pull Request

Replaces the asset subsystem's spritesheet generator with a rust-based
implementation (https://github.com/tgstation/rust-g/pull/160).

This is a rough port of
https://github.com/BeeStation/BeeStation-Hornet/pull/10404, but it
includes fixes for some cases I didn't catch that apply on TG.

(FWIW we've been using this system on prod for over a year and
encountered no major issues.)

### TG MAINTAINER NOTE


![image](https://github.com/user-attachments/assets/53bd2b44-9bb5-42d2-b33f-093651edebc0)

### Batched Spritesheets

`/datum/asset/spritesheet_batched`: A version of the spritesheet system
that collects a list of `/datum/universal_icon`s and sends them off to
rustg asynchronously, and the generation also runs on another thread, so
the game doesn't block during realize_spritesheet. The rust generation
is about 10x faster when it comes to actual icon generation, but the
biggest perk of the batched spritesheets is the caching system.

This PR notably does not convert a few things to the new spritesheet
generator.

- Species and antagonist icons in the preferences view because they use
getFlatIcon ~~which can't be converted to universal icons~~.
- Yes, this is still a *massive* cost to init, unfortunately. On Bee, I
actually enabled the 'legacy' cache on prod and development, which you
can see in my PR. That's why I added the 'clear cache' verb and the
`unregister()` procs, because it can force a regeneration at runtime. I
decided not to port this, since I think it would be detrimental to the
large amount of contributors here.
- It is *technically* possible to port parts of this to the uni_icon
system by making a uni_icon version of getFlatIcon. However, some
overlays use runtime-generated icons which are ~~completely unparseable
to IconForge, since they're stored in the RSC and don't exist as files
anywhere~~. This is most noticeable with things like hair (which blend
additively with the hair mask on the server, thus making them invisible
to `get_flat_uni_icon`). It also doesn't help that species and antag
icons will still need to generate a bunch of dummies and delete them to
even verify cache validity.
- It is actually possible to write the RSC icons to the filesystem
(using fcopy) and reference them in IconForge. However, I'm going to
wait on doing this until I port my GAGS implementation because it
requires GAGS to exist on the filesystem as well.

#### Caching

IconForge generates a cache based on the set of icons used, all
transform operations applied, and the source DMIs of each icon used
within the spritesheet. It can compare the hashes and invalidate the
cache automatically if any of these change. This means we can enable
caching on development, and have absolutely no downsides, because if
anything changes, the cache invalidates itself.

The caching has a mean cost of ~5ms and saves a lot of time compared to
generating the spritesheet, even with rust's faster generation. The main
downside is that the cache still requires building the list of icons and
their transforms, then json encoding it to send to rustg.

Here's an abbreviated example of a cache JSON. All of these need to
match for the cache to be valid. `input_hash` contains the transform
definitions for all the sprites in the spritesheet, so if the input to
iconforge changes, that hash catches it. The `sizes` and `sprites` are
loaded into DM.

```json
{
	"input_hash": "99f1bc67d590e000",
	"dmi_hashes": {
		"icons/ui/achievements/achievements.dmi": "771200c75da11c62"
	},
	"sizes": [
		"76x76"
	],
	"sprites": {
		"achievement-rustascend": {
			"size_id": "76x76",
			"position": 1
		}
	},
	"rustg_version": "3.6.0",
	"dm_version": 1
}
```

### Universal Icons

Universal icons are just a collection of DMI, Icon State, and any icon
transformation procs you apply (blends, crops, scales). They can be
convered to DM icons via `to_icon()`. I've included an implementation of
GAGS that produces universal icons, allowing GAGS items to be converted
into them. IconForge can read universal icons and add them to
spritesheets. It's basically just a wrapper that reimplements BYOND icon
procs.

### Other Stuff

Converts some uses of md5asfile within legacy spritesheets to use
rustg_hash_file instead, improving the performance of their generation.

Fixes lizard body markings not showing in previews, and re-adds eyes to
the ethereal color preview. This is a side effect of IconForge having
*much* better error handling than DM icon procs. Invalid stuff that gets
passed around will error instead of silently doing nothing.

Changes the CSS used in legacy spritesheet generation to split
`background: url(...) no-repeat` into separate props. This is necessary
for WebView2, as IE treats these properties differently - adding
`background-color` to an icon object (as seen in the R&D console) won't
work if you don't split these out.

Deletes unused spritesheets and their associated icons (condiments
spritesheet, old PDA spritesheet)

## Why It's Good For The Game

If you press "Character Setup", the 10-13sec of lag is now approximately
0.5-2 seconds.

Tracy profile showing the time spent on get_asset_datum. I pressed the
preferences button during init on both branches. Do note that this was
ran with a smart cache HIT, so no generation occurred.


![image](https://github.com/user-attachments/assets/3efa71ab-972b-4f5a-acab-0892496ef999)

Much lower worst-case for /datum/asset/New (which includes
`create_spritesheets()` and `register()`)


![image](https://github.com/user-attachments/assets/9ad8ceee-7bd6-4c48-b5f3-006520f527ef)

Here's a look at the internal costs from rustg - as you can see
`generate_spritesheet()` is very fast:


![image](https://github.com/user-attachments/assets/e6892c28-8c31-4af5-96d4-501e966d0ce9)

### Comparison for a single spritesheet - chat spritesheet:

**Before**


![image](https://github.com/user-attachments/assets/cbd65787-42ba-4278-a45c-bd3d538da986)

**After**


![image](https://github.com/user-attachments/assets/d750899a-bd07-4b57-80fb-420fcc0ae416)

## Changelog

🆑
fix: Fixed lizard body markings and ethereal feature previews in the
preference menu missing some overlays.
refactor: Optimized spritesheet asset generation greatly using rustg
IconForge, greatly reducing post-initialization lag as well as reducing
init times and saving server computation.
config: Added 'smart' asset caching, for batched rustg IconForge
spritesheets. It is persistent and suitable for use on local, with
automatic invalidation.
add: Added admin verbs - Debug -> Clear Smart/Legacy Asset Cache for
spritesheets.
fix: Fixed R&D console icons breaking on WebView2/516
/🆑
This commit is contained in:
itsmeow
2025-03-03 14:58:27 +01:00
committed by GitHub
parent 62a37ad555
commit cc335e7e9e
163 changed files with 1828 additions and 870 deletions
@@ -1,11 +1,13 @@
/datum/asset/spritesheet/simple/achievements
/datum/asset/spritesheet_batched/achievements
name = "achievements"
/datum/asset/spritesheet/simple/achievements/create_spritesheets()
InsertAll("achievement", ACHIEVEMENTS_SET)
/datum/asset/spritesheet_batched/achievements/create_spritesheets()
for(var/icon_state_name in icon_states(ACHIEVEMENTS_SET))
insert_icon("achievement-[icon_state_name]", uni_icon(ACHIEVEMENTS_SET, icon_state_name))
// catch achievements which are pulling icons from another file
for(var/datum/award/other_award as anything in subtypesof(/datum/award))
var/icon = initial(other_award.icon)
if (icon != ACHIEVEMENTS_SET)
var/icon_state = initial(other_award.icon_state)
Insert("achievement-[icon_state]", icon, icon_state=icon_state)
if (icon == ACHIEVEMENTS_SET)
continue
var/icon_state_name = initial(other_award.icon_state)
insert_icon("achievement-[icon_state_name]", uni_icon(icon, icon_state_name))
+7 -6
View File
@@ -1,10 +1,11 @@
/datum/asset/spritesheet/bibles
/datum/asset/spritesheet_batched/bibles
name = "bibles"
/datum/asset/spritesheet/bibles/create_spritesheets()
/datum/asset/spritesheet_batched/bibles/create_spritesheets()
var/obj/item/book/bible/holy_template = /obj/item/book/bible
InsertAll("display", initial(holy_template.icon))
var/target_icon = initial(holy_template.icon)
var/datum/icon_transformer/transform = new()
transform.scale(224, 224) // Scale up by 7x
/datum/asset/spritesheet/bibles/ModifyInserted(icon/pre_asset)
pre_asset.Scale(224, 224) // Scale up by 7x
return pre_asset
for (var/icon_state_name in icon_states(target_icon))
insert_icon("display-[icon_state_name]", uni_icon(target_icon, icon_state_name, transform=transform))
+6 -7
View File
@@ -1,14 +1,13 @@
/datum/asset/spritesheet/chat
/datum/asset/spritesheet_batched/chat
name = "chat"
/datum/asset/spritesheet/chat/create_spritesheets()
InsertAll("emoji", EMOJI_SET)
/datum/asset/spritesheet_batched/chat/create_spritesheets()
insert_all_icons("emoji", EMOJI_SET)
// pre-loading all lanugage icons also helps to avoid meta
InsertAll("language", 'icons/ui/chat/language.dmi')
insert_all_icons("language", 'icons/ui/chat/language.dmi')
// catch languages which are pulling icons from another file
for(var/path in typesof(/datum/language))
var/datum/language/L = path
for(var/datum/language/L as anything in subtypesof(/datum/language))
var/icon = initial(L.icon)
if (icon != 'icons/ui/chat/language.dmi')
var/icon_state = initial(L.icon_state)
Insert("language-[icon_state]", icon, icon_state=icon_state)
insert_icon("language-[icon_state]", uni_icon(icon, icon_state))
@@ -1,8 +1,8 @@
///Icons for containers printed in ChemMaster
/datum/asset/spritesheet/chemmaster
/datum/asset/spritesheet_batched/chemmaster
name = "chemmaster"
/datum/asset/spritesheet/chemmaster/create_spritesheets()
/datum/asset/spritesheet_batched/chemmaster/create_spritesheets()
var/list/ids = list()
for(var/category in GLOB.reagent_containers)
for(var/obj/item/reagent_containers/container as anything in GLOB.reagent_containers[category])
@@ -12,4 +12,4 @@
if(id in ids) // exclude duplicate containers
continue
ids += id
Insert(id, icon_file, icon_state)
insert_icon(id, uni_icon(icon_file, icon_state))
@@ -1,24 +0,0 @@
/datum/asset/spritesheet/simple/condiments
name = "condiments"
assets = list(
CONDIMASTER_STYLE_FALLBACK = 'icons/ui/condiments/bottle.png',
"flour" = 'icons/ui/condiments/flour.png',
"rice" = 'icons/ui/condiments/rice.png',
"sugar" = 'icons/ui/condiments/sugar.png',
"milk" = 'icons/ui/condiments/milk.png',
"enzyme" = 'icons/ui/condiments/enzyme.png',
"capsaicin" = 'icons/ui/condiments/hotsauce.png',
"frostoil" = 'icons/ui/condiments/coldsauce.png',
"bbqsauce" = 'icons/ui/condiments/bbqsauce.png',
"soymilk" = 'icons/ui/condiments/soymilk.png',
"soysauce" = 'icons/ui/condiments/soysauce.png',
"ketchup" = 'icons/ui/condiments/ketchup.png',
"mayonnaise" = 'icons/ui/condiments/mayonnaise.png',
"oliveoil" = 'icons/ui/condiments/oliveoil.png',
"cooking_oil" = 'icons/ui/condiments/cookingoil.png',
"peanut_butter" = 'icons/ui/condiments/peanutbutter.png',
"cherryjelly" = 'icons/ui/condiments/cherryjelly.png',
"honey" = 'icons/ui/condiments/honey.png',
"blackpepper" = 'icons/ui/condiments/peppermillsmall.png',
"sodiumchloride" = 'icons/ui/condiments/saltshakersmall.png',
)
+28 -28
View File
@@ -1,17 +1,17 @@
///Representative icons for the contents of each crafting recipe
/datum/asset/spritesheet/crafting
/datum/asset/spritesheet_batched/crafting
name = "crafting"
/datum/asset/spritesheet/crafting/create_spritesheets()
/datum/asset/spritesheet_batched/crafting/create_spritesheets()
var/id = 1
for(var/atom in GLOB.crafting_recipes_atoms)
add_atom_icon(atom, id++)
add_tool_icons()
/datum/asset/spritesheet/crafting/cooking
/datum/asset/spritesheet_batched/crafting/cooking
name = "cooking"
/datum/asset/spritesheet/crafting/cooking/create_spritesheets()
/datum/asset/spritesheet_batched/crafting/cooking/create_spritesheets()
var/id = 1
for(var/atom in GLOB.cooking_recipes_atoms)
add_atom_icon(atom, id++)
@@ -24,7 +24,7 @@
* If it a reagent, it will use the default container's icon state,
* OR if it has a glass style associated, it will use that
*/
/datum/asset/spritesheet/crafting/proc/add_atom_icon(ingredient_typepath, id)
/datum/asset/spritesheet_batched/crafting/proc/add_atom_icon(ingredient_typepath, id)
var/icon_file
var/icon_state
var/obj/preview_item = ingredient_typepath
@@ -43,32 +43,32 @@
if(!icon_exists_or_scream(icon_file, icon_state))
return
Insert("a[id]", icon(icon_file, icon_state, SOUTH))
insert_icon("a[id]", uni_icon(icon_file, icon_state, SOUTH))
///Adds tool icons to the spritesheet
/datum/asset/spritesheet/crafting/proc/add_tool_icons()
/datum/asset/spritesheet_batched/crafting/proc/add_tool_icons()
var/list/tool_icons = list(
TOOL_CROWBAR = icon('icons/obj/tools.dmi', "crowbar"),
TOOL_MULTITOOL = icon('icons/obj/devices/tool.dmi', "multitool"),
TOOL_SCREWDRIVER = icon('icons/obj/tools.dmi', "screwdriver_map"),
TOOL_WIRECUTTER = icon('icons/obj/tools.dmi', "cutters_map"),
TOOL_WRENCH = icon('icons/obj/tools.dmi', "wrench"),
TOOL_WELDER = icon('icons/obj/tools.dmi', "welder"),
TOOL_ANALYZER = icon('icons/obj/devices/scanner.dmi', "analyzer"),
TOOL_MINING = icon('icons/obj/mining.dmi', "minipick"),
TOOL_SHOVEL = icon('icons/obj/mining.dmi', "spade"),
TOOL_RETRACTOR = icon('icons/obj/medical/surgery_tools.dmi', "retractor"),
TOOL_HEMOSTAT = icon('icons/obj/medical/surgery_tools.dmi', "hemostat"),
TOOL_CAUTERY = icon('icons/obj/medical/surgery_tools.dmi', "cautery"),
TOOL_DRILL = icon('icons/obj/medical/surgery_tools.dmi', "drill"),
TOOL_SCALPEL = icon('icons/obj/medical/surgery_tools.dmi', "scalpel"),
TOOL_SAW = icon('icons/obj/medical/surgery_tools.dmi', "saw"),
TOOL_BONESET = icon('icons/obj/medical/surgery_tools.dmi', "bonesetter"),
TOOL_KNIFE = icon('icons/obj/service/kitchen.dmi', "knife"),
TOOL_BLOODFILTER = icon('icons/obj/medical/surgery_tools.dmi', "bloodfilter"),
TOOL_ROLLINGPIN = icon('icons/obj/service/kitchen.dmi', "rolling_pin"),
TOOL_RUSTSCRAPER = icon('icons/obj/tools.dmi', "wirebrush"),
TOOL_CROWBAR = uni_icon('icons/obj/tools.dmi', "crowbar"),
TOOL_MULTITOOL = uni_icon('icons/obj/devices/tool.dmi', "multitool"),
TOOL_SCREWDRIVER = uni_icon('icons/obj/tools.dmi', "screwdriver_map"),
TOOL_WIRECUTTER = uni_icon('icons/obj/tools.dmi', "cutters_map"),
TOOL_WRENCH = uni_icon('icons/obj/tools.dmi', "wrench"),
TOOL_WELDER = uni_icon('icons/obj/tools.dmi', "welder"),
TOOL_ANALYZER = uni_icon('icons/obj/devices/scanner.dmi', "analyzer"),
TOOL_MINING = uni_icon('icons/obj/mining.dmi', "minipick"),
TOOL_SHOVEL = uni_icon('icons/obj/mining.dmi', "spade"),
TOOL_RETRACTOR = uni_icon('icons/obj/medical/surgery_tools.dmi', "retractor"),
TOOL_HEMOSTAT = uni_icon('icons/obj/medical/surgery_tools.dmi', "hemostat"),
TOOL_CAUTERY = uni_icon('icons/obj/medical/surgery_tools.dmi', "cautery"),
TOOL_DRILL = uni_icon('icons/obj/medical/surgery_tools.dmi', "drill"),
TOOL_SCALPEL = uni_icon('icons/obj/medical/surgery_tools.dmi', "scalpel"),
TOOL_SAW = uni_icon('icons/obj/medical/surgery_tools.dmi', "saw"),
TOOL_BONESET = uni_icon('icons/obj/medical/surgery_tools.dmi', "bonesetter"),
TOOL_KNIFE = uni_icon('icons/obj/service/kitchen.dmi', "knife"),
TOOL_BLOODFILTER = uni_icon('icons/obj/medical/surgery_tools.dmi', "bloodfilter"),
TOOL_ROLLINGPIN = uni_icon('icons/obj/service/kitchen.dmi', "rolling_pin"),
TOOL_RUSTSCRAPER = uni_icon('icons/obj/tools.dmi', "wirebrush"),
)
for(var/tool in tool_icons)
Insert(replacetext(tool, " ", ""), tool_icons[tool])
insert_icon(replacetext(tool, " ", ""), tool_icons[tool])
@@ -1,5 +1,5 @@
/datum/asset/spritesheet/emojipedia
/datum/asset/spritesheet_batched/emojipedia
name = "emojipedia"
/datum/asset/spritesheet/emojipedia/create_spritesheets()
InsertAll("", EMOJI_SET)
/datum/asset/spritesheet_batched/emojipedia/create_spritesheets()
insert_all_icons("", EMOJI_SET)
+4 -5
View File
@@ -1,14 +1,13 @@
/datum/asset/spritesheet/fish
/datum/asset/spritesheet_batched/fish
name = "fish"
/datum/asset/spritesheet/fish/create_spritesheets()
/datum/asset/spritesheet_batched/fish/create_spritesheets()
var/list/id_list = list()
for (var/path in subtypesof(/obj/item/fish))
var/obj/item/fish/fish_type = path
for (var/obj/item/fish/fish_type as anything in subtypesof(/obj/item/fish))
var/fish_icon = initial(fish_type.icon)
var/fish_icon_state = initial(fish_type.icon_state)
var/id = sanitize_css_class_name("[fish_icon][fish_icon_state]")
if(id in id_list) //no dupes
continue
id_list += id
Insert(id, fish_icon, fish_icon_state)
insert_icon(id, uni_icon(fish_icon, fish_icon_state))
@@ -1,11 +1,7 @@
/datum/asset/spritesheet/lights
/datum/asset/spritesheet_batched/lights
name = "lights"
/datum/asset/spritesheet/lights/create_spritesheets()
// These two are required to ensure this spritesheet is not rendered with a fully white background
// No I have absolutely no idea why, something something alpha maybe? but it does work, so that's for LATER!!
Insert("light_dummy_start_fuckyoubyond", 'icons/obj/medical/bloodpack.dmi', "generic_bloodpack")
/datum/asset/spritesheet_batched/lights/create_spritesheets()
for(var/id in GLOB.light_types)
var/datum/light_template/template = GLOB.light_types[id]
Insert("light_fantastic_[template.id]", template.icon, template.icon_state)
Insert("light_dummy_end_fuckyoubyond", 'icons/mob/silicon/ai.dmi', "questionmark")
insert_icon("light_fantastic_[template.id]", uni_icon(template.icon, template.icon_state))
+3 -3
View File
@@ -1,5 +1,5 @@
/datum/asset/spritesheet/mafia
/datum/asset/spritesheet_batched/mafia
name = "mafia"
/datum/asset/spritesheet/mafia/create_spritesheets()
InsertAll("", 'icons/obj/mafia.dmi')
/datum/asset/spritesheet_batched/mafia/create_spritesheets()
insert_all_icons("", 'icons/obj/mafia.dmi')
+4 -4
View File
@@ -1,6 +1,6 @@
/datum/asset/spritesheet/mecha_equipment
/datum/asset/spritesheet_batched/mecha_equipment
name = "mecha_equipment"
/datum/asset/spritesheet/mecha_equipment/create_spritesheets()
InsertAll("", 'icons/obj/devices/mecha_equipment.dmi')
InsertAll("", 'icons/obj/ore.dmi')
/datum/asset/spritesheet_batched/mecha_equipment/create_spritesheets()
insert_all_icons("", 'icons/obj/devices/mecha_equipment.dmi')
insert_all_icons("", 'icons/obj/ore.dmi')
+16 -25
View File
@@ -1,27 +1,18 @@
/datum/asset/spritesheet/moods
/datum/asset/spritesheet_batched/moods
name = "moods"
var/iconinserted = 1
/datum/asset/spritesheet/moods/create_spritesheets()
for(var/i in 1 to 9)
var/target_to_insert = "mood"+"[iconinserted]"
Insert(target_to_insert, 'icons/hud/screen_gen.dmi', target_to_insert)
iconinserted++
/datum/asset/spritesheet/moods/ModifyInserted(icon/pre_asset)
var/blended_color
switch(iconinserted)
if(1)
blended_color = "#f15d36"
if(2 to 3)
blended_color = "#f38943"
if(4)
blended_color = "#dfa65b"
if(5)
blended_color = "#4b96c4"
if(6)
blended_color = "#86d656"
else
blended_color = "#2eeb9a"
pre_asset.Blend(blended_color, ICON_MULTIPLY)
return pre_asset
/datum/asset/spritesheet_batched/moods/create_spritesheets()
var/list/mood_colors = list(
"mood1" = "#f15d36",
"mood2" = "#f38943",
"mood3" = "#f38943",
"mood4" = "#dfa65b",
"mood5" = "#4b96c4",
"mood6" = "#86d656",
"mood7" = "#2eeb9a",
"mood8" = "#2eeb9a",
"mood9" = "#2eeb9a",
)
for(var/target_to_insert in mood_colors)
var/blended_color = mood_colors[target_to_insert]
insert_icon(target_to_insert, uni_icon('icons/hud/screen_gen.dmi', target_to_insert, color=blended_color))
-34
View File
@@ -1,34 +0,0 @@
/datum/asset/spritesheet/simple/pda
name = "pda"
assets = list(
"atmos" = 'icons/ui/pda/pda_atmos.png',
"back" = 'icons/ui/pda/pda_back.png',
"bell" = 'icons/ui/pda/pda_bell.png',
"blank" = 'icons/ui/pda/pda_blank.png',
"boom" = 'icons/ui/pda/pda_boom.png',
"bucket" = 'icons/ui/pda/pda_bucket.png',
"medbot" = 'icons/ui/pda/pda_medbot.png',
"floorbot" = 'icons/ui/pda/pda_floorbot.png',
"cleanbot" = 'icons/ui/pda/pda_cleanbot.png',
"crate" = 'icons/ui/pda/pda_crate.png',
"cuffs" = 'icons/ui/pda/pda_cuffs.png',
"eject" = 'icons/ui/pda/pda_eject.png',
"flashlight" = 'icons/ui/pda/pda_flashlight.png',
"honk" = 'icons/ui/pda/pda_honk.png',
"mail" = 'icons/ui/pda/pda_mail.png',
"medical" = 'icons/ui/pda/pda_medical.png',
"menu" = 'icons/ui/pda/pda_menu.png',
"mule" = 'icons/ui/pda/pda_mule.png',
"notes" = 'icons/ui/pda/pda_notes.png',
"power" = 'icons/ui/pda/pda_power.png',
"rdoor" = 'icons/ui/pda/pda_rdoor.png',
"reagent" = 'icons/ui/pda/pda_reagent.png',
"refresh" = 'icons/ui/pda/pda_refresh.png',
"scanner" = 'icons/ui/pda/pda_scanner.png',
"signaler" = 'icons/ui/pda/pda_signaler.png',
"skills" = 'icons/ui/pda/pda_skills.png',
"status" = 'icons/ui/pda/pda_status.png',
"dronephone" = 'icons/ui/pda/pda_dronephone.png',
"emoji" = 'icons/ui/pda/pda_emoji.png',
"droneblacklist" = 'icons/ui/pda/pda_droneblacklist.png',
)
+4 -3
View File
@@ -1,6 +1,7 @@
/datum/asset/spritesheet/pipes
/datum/asset/spritesheet_batched/pipes
name = "pipes"
ignore_dir_errors = TRUE
/datum/asset/spritesheet/pipes/create_spritesheets()
/datum/asset/spritesheet_batched/pipes/create_spritesheets()
for (var/each in list('icons/obj/pipes_n_cables/pipe_item.dmi', 'icons/obj/pipes_n_cables/disposal.dmi', 'icons/obj/pipes_n_cables/transit_tube.dmi', 'icons/obj/pipes_n_cables/hydrochem/fluid_ducts.dmi'))
InsertAll("", each, GLOB.alldirs)
insert_all_icons("", each, GLOB.alldirs)
+3 -3
View File
@@ -1,7 +1,7 @@
/datum/asset/spritesheet/plumbing
/datum/asset/spritesheet_batched/plumbing
name = "plumbing-tgui"
/datum/asset/spritesheet/plumbing/create_spritesheets()
/datum/asset/spritesheet_batched/plumbing/create_spritesheets()
//load only what we need from the icon files,format is icon_file_name = list of icon_states we need from this file
var/list/essentials = list(
'icons/obj/medical/iv_drip.dmi' = list("plumb"),
@@ -39,5 +39,5 @@
for(var/icon_file as anything in essentials)
for(var/icon_state as anything in essentials[icon_file])
Insert(sprite_name = icon_state, I = icon_file, icon_state = icon_state)
insert_icon(icon_state, uni_icon(icon_file, icon_state))
+13 -12
View File
@@ -1,7 +1,7 @@
/datum/asset/spritesheet/rcd
/datum/asset/spritesheet_batched/rcd
name = "rcd-tgui"
/datum/asset/spritesheet/rcd/create_spritesheets()
/datum/asset/spritesheet_batched/rcd/create_spritesheets()
for(var/root_category in GLOB.rcd_designs)
var/list/category_designs = GLOB.rcd_designs[root_category]
@@ -12,34 +12,35 @@
var/list/designs = category_designs[category]
var/sprite_name
var/icon/sprite_icon
for(var/list/design as anything in designs)
var/atom/movable/path = design[RCD_DESIGN_PATH]
if(!ispath(path))
continue
sprite_name = initial(path.name)
var/datum/universal_icon/sprite_icon
//icon for windows are blended with grills if required and loaded from radial menu
if(ispath(path, /obj/structure/window))
if(path == /obj/structure/window)
sprite_icon = icon(icon = 'icons/hud/radial.dmi', icon_state = "windowsize")
sprite_icon = uni_icon('icons/hud/radial.dmi', "windowsize")
else if(path == /obj/structure/window/reinforced)
sprite_icon = icon(icon = 'icons/hud/radial.dmi', icon_state = "windowtype")
sprite_icon = uni_icon('icons/hud/radial.dmi', "windowtype")
else if(path == /obj/structure/window/fulltile || path == /obj/structure/window/reinforced/fulltile)
sprite_icon = icon(icon = initial(path.icon), icon_state = initial(path.icon_state))
sprite_icon.Blend(icon(icon = 'icons/obj/structures.dmi', icon_state = "grille"), ICON_UNDERLAY)
sprite_icon = uni_icon(initial(path.icon), initial(path.icon_state))
sprite_icon.blend_icon(uni_icon('icons/obj/structures.dmi', "grille"), ICON_UNDERLAY)
//icons for solid airlocks have an added solid overlay on top of their glass icons
else if(ispath(path, /obj/machinery/door/airlock))
var/obj/machinery/door/airlock/airlock_path = path
var/airlock_icon = initial(airlock_path.icon)
sprite_icon = icon(icon = airlock_icon, icon_state = "closed")
if(!initial(airlock_path.glass))
sprite_icon.Blend(icon(icon = airlock_icon, icon_state = "fill_closed"), ICON_OVERLAY)
sprite_icon = uni_icon(airlock_icon, "closed")
if(!initial(airlock_path.glass) && initial(airlock_path.can_be_glass))
sprite_icon.blend_icon(uni_icon(airlock_icon, "fill_closed"), ICON_OVERLAY)
//for all other icons we load the paths default icon & icon state
else
sprite_icon = icon(icon = initial(path.icon), icon_state = initial(path.icon_state))
sprite_icon = uni_icon(initial(path.icon), initial(path.icon_state))
Insert(sanitize_css_class_name(sprite_name), sprite_icon)
insert_icon(sanitize_css_class_name(sprite_name), sprite_icon)
@@ -1,15 +1,15 @@
// Representative icons for each research design
/datum/asset/spritesheet/research_designs
/datum/asset/spritesheet_batched/research_designs
name = "design"
/datum/asset/spritesheet/research_designs/create_spritesheets()
/datum/asset/spritesheet_batched/research_designs/create_spritesheets()
for (var/datum/design/path as anything in subtypesof(/datum/design))
if(initial(path.id) == DESIGN_ID_IGNORE)
continue
var/icon_file
var/icon_state
var/icon/I
var/datum/icon_transformer/transform = null
if(initial(path.research_icon) && initial(path.research_icon_state)) //If the design has an icon replacement skip the rest
icon_file = initial(path.research_icon)
@@ -18,8 +18,6 @@
if(!icon_exists(icon_file, icon_state))
stack_trace("design [path] with icon '[icon_file]' missing state '[icon_state]'")
continue
I = icon(icon_file, icon_state, SOUTH)
else
// construct the icon and slap it into the resource cache
var/atom/item = initial(path.build_path)
@@ -38,30 +36,32 @@
if (machine)
item = machine
// Check for GAGS support where necessary
var/greyscale_config = initial(item.greyscale_config)
var/greyscale_colors = initial(item.greyscale_colors)
if (greyscale_config && greyscale_colors)
icon_file = SSgreyscale.GetColoredIconByType(greyscale_config, greyscale_colors)
// GAGS icon short-circuit the rest of the checks
if (initial(item.greyscale_config) && initial(item.greyscale_colors))
insert_icon(initial(path.id), gags_to_universal_icon(item))
continue
else
icon_file = initial(item.icon)
icon_state = initial(item.icon_state)
if(initial(item.color))
transform = color_transform(initial(item.color))
if (PERFORM_ALL_TESTS(focus_only/invalid_research_designs))
if(!icon_exists(icon_file, icon_state))
stack_trace("design [path] with icon '[icon_file]' missing state '[icon_state]'")
continue
I = icon(icon_file, icon_state, SOUTH)
// computers (and snowflakes) get their screen and keyboard sprites
if (ispath(item, /obj/machinery/computer) || ispath(item, /obj/machinery/power/solar_control))
if(!transform)
transform = new()
var/obj/machinery/computer/C = item
var/screen = initial(C.icon_screen)
var/keyboard = initial(C.icon_keyboard)
var/all_states = icon_states(icon_file)
if (screen && (screen in all_states))
I.Blend(icon(icon_file, screen, SOUTH), ICON_OVERLAY)
transform.blend_icon(uni_icon(icon_file, screen), ICON_OVERLAY)
if (keyboard && (keyboard in all_states))
I.Blend(icon(icon_file, keyboard, SOUTH), ICON_OVERLAY)
transform.blend_icon(uni_icon(icon_file, keyboard), ICON_OVERLAY)
Insert(initial(path.id), I)
insert_icon(initial(path.id), uni_icon(icon_file, icon_state, transform=transform))
+4 -6
View File
@@ -1,14 +1,12 @@
/datum/asset/spritesheet/rtd
/datum/asset/spritesheet_batched/rtd
name = "rtd"
/datum/asset/spritesheet/rtd/create_spritesheets()
//some tiles may share the same icon but have different properties to animate that icon
//so we keep track of what icons we registered
/datum/asset/spritesheet_batched/rtd/create_spritesheets()
var/list/registered = list()
for(var/main_root in GLOB.floor_designs)
for(var/sub_category in GLOB.floor_designs[main_root])
for(var/list/design in GLOB.floor_designs[main_root][sub_category])
for(var/list/design in GLOB.floor_designs[main_root][sub_category])
if(!design["datum"])
populate_rtd_datums()
var/datum/tile_info/tile_data = design["datum"]
@@ -17,5 +15,5 @@
var/sprite_name = sanitize_css_class_name("[tile_data.icon_file]-[tile_data.icon_state]-[dir2text(direction)]")
if(registered[sprite_name])
continue
Insert(sprite_name, icon(tile_data.icon_file, tile_data.icon_state, direction))
insert_icon(sprite_name, uni_icon(tile_data.icon_file, tile_data.icon_state, direction))
registered[sprite_name] = TRUE
+4 -5
View File
@@ -1,14 +1,13 @@
/datum/asset/spritesheet/seeds
/datum/asset/spritesheet_batched/seeds
name = "seeds"
/datum/asset/spritesheet/seeds/create_spritesheets()
/datum/asset/spritesheet_batched/seeds/create_spritesheets()
var/list/id_list = list()
for (var/path in subtypesof(/obj/item/seeds))
var/obj/item/seeds/seed_type = path
for (var/obj/item/seeds/seed_type as anything in subtypesof(/obj/item/seeds))
var/icon = initial(seed_type.icon)
var/icon_state = initial(seed_type.icon_state)
var/id = sanitize_css_class_name("[icon][icon_state]")
if(id in id_list) //no dupes
continue
id_list += id
Insert(id, icon, icon_state)
insert_icon(id, uni_icon(icon, icon_state))
@@ -1,6 +1,6 @@
/datum/asset/spritesheet/sheetmaterials
/datum/asset/spritesheet_batched/sheetmaterials
name = "sheetmaterials"
/datum/asset/spritesheet/sheetmaterials/create_spritesheets()
InsertAll("", 'icons/obj/stack_objects.dmi')
/datum/asset/spritesheet_batched/sheetmaterials/create_spritesheets()
insert_all_icons("", 'icons/obj/stack_objects.dmi')
@@ -1,27 +1,27 @@
/datum/asset/spritesheet/supplypods
/datum/asset/spritesheet_batched/supplypods
name = "supplypods"
/datum/asset/spritesheet/supplypods/create_spritesheets()
/datum/asset/spritesheet_batched/supplypods/create_spritesheets()
for (var/datum/pod_style/style as anything in typesof(/datum/pod_style))
if (ispath(style, /datum/pod_style/seethrough))
Insert("pod_asset[style::id]", icon('icons/obj/supplypods.dmi' , "seethrough-icon"))
insert_icon("pod_asset[style::id]", uni_icon('icons/obj/supplypods.dmi' , "seethrough-icon"))
continue
var/base = style::icon_state
if (!base)
Insert("pod_asset[style::id]", icon('icons/obj/supplypods.dmi', "invisible-icon"))
insert_icon("pod_asset[style::id]", uni_icon('icons/obj/supplypods.dmi', "invisible-icon"))
continue
var/icon/podIcon = icon('icons/obj/supplypods.dmi', base)
var/datum/universal_icon/pod_icon = uni_icon('icons/obj/supplypods.dmi', base, SOUTH)
var/door = style::has_door
if (door)
door = "[base]_door"
podIcon.Blend(icon('icons/obj/supplypods.dmi', door), ICON_OVERLAY)
pod_icon.blend_icon(uni_icon('icons/obj/supplypods.dmi', door), ICON_OVERLAY)
var/shape = style::shape
if (shape == POD_SHAPE_NORMAL)
var/decal = style::decal_icon
if (decal)
podIcon.Blend(icon('icons/obj/supplypods.dmi', decal), ICON_OVERLAY)
pod_icon.blend_icon(uni_icon('icons/obj/supplypods.dmi', decal), ICON_OVERLAY)
var/glow = style::glow_color
if (glow)
glow = "pod_glow_[glow]"
podIcon.Blend(icon('icons/obj/supplypods.dmi', glow), ICON_OVERLAY)
Insert("pod_asset[style::id]", podIcon)
pod_icon.blend_icon(uni_icon('icons/obj/supplypods.dmi', glow), ICON_OVERLAY)
insert_icon("pod_asset[style::id]", pod_icon)
+3 -3
View File
@@ -1,12 +1,12 @@
/datum/asset/spritesheet/telecomms
/datum/asset/spritesheet_batched/telecomms
name = "tcomms"
/datum/asset/spritesheet/telecomms/create_spritesheets()
/datum/asset/spritesheet_batched/telecomms/create_spritesheets()
var/list/inserted_states = list() // No need to send entire `telecomms.dmi`.
for(var/obj/machinery/telecomms/machine as anything in subtypesof(/obj/machinery/telecomms))
var/icon_state = machine::icon_state
if(icon_state in inserted_states)
continue
Insert(icon_state, machine::icon, icon_state)
insert_icon(icon_state, uni_icon(machine::icon, icon_state))
inserted_states += icon_state
+14 -19
View File
@@ -1,10 +1,10 @@
/datum/asset/spritesheet/vending
/datum/asset/spritesheet_batched/vending
name = "vending"
/datum/asset/spritesheet/vending/create_spritesheets()
/datum/asset/spritesheet_batched/vending/create_spritesheets()
// initialising the list of items we need
var/target_items = list()
for(var/obj/machinery/vending/vendor as anything in typesof(/obj/machinery/vending))
for(var/obj/machinery/vending/vendor as anything in subtypesof(/obj/machinery/vending))
vendor = new vendor() // It seems `initial(list var)` has nothing. need to make a type.
target_items |= vendor.products
target_items |= vendor.premium
@@ -16,21 +16,21 @@
if (!ispath(item, /atom))
continue
var/icon_file
var/icon_state = initial(item.icon_state)
var/icon_color = initial(item.color)
// GAGS icons must be pregenerated
if(initial(item.greyscale_config) && initial(item.greyscale_colors))
icon_file = SSgreyscale.GetColoredIconByType(initial(item.greyscale_config), initial(item.greyscale_colors))
// Colored atoms must be pregenerated
else if(icon_color && icon_state)
icon_file = initial(item.icon)
if(ispath(item, /obj))
var/obj/obj_atom = item
if(initial(obj_atom.icon_state_preview))
icon_state = initial(obj_atom.icon_state_preview)
var/has_gags = initial(item.greyscale_config) && initial(item.greyscale_colors)
var/has_color = initial(item.color) && icon_state
// GAGS and colored icons must be pregenerated
// Otherwise we can rely on DMIcon, so skip it to save init time
else
if(!has_gags && !has_color)
continue
if (PERFORM_ALL_TESTS(focus_only/invalid_vending_machine_icon_states))
if (!icon_exists(icon_file, icon_state))
if (!has_gags && !icon_exists(initial(item.icon), icon_state))
var/icon_file = initial(item.icon)
var/icon_states_string
for (var/an_icon_state in icon_states(icon_file))
if (!icon_states_string)
@@ -41,10 +41,5 @@
stack_trace("[item] does not have a valid icon state, icon=[icon_file], icon_state=[json_encode(icon_state)]([text_ref(icon_state)]), icon_states=[icon_states_string]")
continue
var/icon/produced = icon(icon_file, icon_state, SOUTH)
if (!isnull(icon_color) && icon_color != COLOR_WHITE)
produced.Blend(icon_color, ICON_MULTIPLY)
var/imgid = replacetext(replacetext("[item]", "/obj/item/", ""), "/", "-")
Insert(imgid, produced)
insert_icon(imgid, get_display_icon_for(item))