mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-07-19 02:54:41 +01:00
Port DmIcon & Image components from TG (#26623)
* Port DmIcon & Image components from TG * Documentation * Uh oh * I hate it * I will bang you
This commit is contained in:
@@ -5,18 +5,31 @@
|
||||
GLOBAL_LIST_EMPTY(asset_datums)
|
||||
|
||||
//get an assetdatum or make a new one
|
||||
/proc/get_asset_datum(type)
|
||||
//does NOT ensure it's filled, if you want that use get_asset_datum()
|
||||
/proc/load_asset_datum(type)
|
||||
return GLOB.asset_datums[type] || new type()
|
||||
|
||||
/proc/get_asset_datum(type)
|
||||
var/datum/asset/loaded_asset = GLOB.asset_datums[type] || new type()
|
||||
return loaded_asset.ensure_ready()
|
||||
|
||||
/datum/asset
|
||||
var/_abstract = /datum/asset
|
||||
var/cached_serialized_url_mappings
|
||||
var/cached_serialized_url_mappings_transport_type
|
||||
|
||||
/// Whether or not this asset should be loaded in the "early assets" SS
|
||||
var/early = FALSE
|
||||
|
||||
/datum/asset/New()
|
||||
GLOB.asset_datums[type] = src
|
||||
register()
|
||||
|
||||
/// Stub that allows us to react to something trying to get us
|
||||
/// Not useful here, more handy for sprite sheets
|
||||
/datum/asset/proc/ensure_ready()
|
||||
return src
|
||||
|
||||
/datum/asset/proc/get_url_mappings()
|
||||
return list()
|
||||
|
||||
@@ -26,7 +39,6 @@ GLOBAL_LIST_EMPTY(asset_datums)
|
||||
/datum/asset/proc/send(client)
|
||||
return
|
||||
|
||||
|
||||
/// If you don't need anything complicated.
|
||||
/datum/asset/simple
|
||||
_abstract = /datum/asset/simple
|
||||
@@ -68,7 +80,7 @@ GLOBAL_LIST_EMPTY(asset_datums)
|
||||
|
||||
/datum/asset/group/register()
|
||||
for(var/type in children)
|
||||
get_asset_datum(type)
|
||||
load_asset_datum(type)
|
||||
|
||||
/datum/asset/group/send(client/C)
|
||||
for(var/type in children)
|
||||
@@ -370,6 +382,32 @@ GLOBAL_LIST_EMPTY(asset_datums)
|
||||
assets = sorted_assets
|
||||
..()
|
||||
|
||||
/// A subtype to generate a JSON file from a list
|
||||
/datum/asset/json
|
||||
_abstract = /datum/asset/json
|
||||
/// The filename, will be suffixed with ".json"
|
||||
var/name
|
||||
|
||||
/datum/asset/json/send(client)
|
||||
return SSassets.transport.send_assets(client, "[name].json")
|
||||
|
||||
/datum/asset/json/get_url_mappings()
|
||||
return list(
|
||||
"[name].json" = SSassets.transport.get_asset_url("[name].json"),
|
||||
)
|
||||
|
||||
/datum/asset/json/register()
|
||||
var/filename = "data/[name].json"
|
||||
fdel(filename)
|
||||
text2file(json_encode(generate()), filename)
|
||||
SSassets.transport.register_asset("[name].json", fcopy_rsc(filename))
|
||||
fdel(filename)
|
||||
|
||||
/// Returns the data that will be JSON encoded
|
||||
/datum/asset/json/proc/generate()
|
||||
SHOULD_CALL_PARENT(FALSE)
|
||||
CRASH("generate() not implemented for [type]!")
|
||||
|
||||
/*
|
||||
* Get a html string that will load a html asset.
|
||||
* Needed because byond doesn't allow you to browse() to a url.
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/// Maps icon names to ref values
|
||||
/datum/asset/json/icon_ref_map
|
||||
name = "icon_ref_map"
|
||||
early = TRUE
|
||||
|
||||
/datum/asset/json/icon_ref_map/generate()
|
||||
var/list/data = list() //"icons/obj/drinks.dmi" => "[0xc000020]"
|
||||
|
||||
//var/start = "0xc000000"
|
||||
var/value = 0
|
||||
|
||||
while(TRUE)
|
||||
value += 1
|
||||
var/ref = "\[0xc[num2text(value,6,16)]\]"
|
||||
var/mystery_meat = locate(ref)
|
||||
|
||||
if(isicon(mystery_meat))
|
||||
if(!isfile(mystery_meat)) // Ignore the runtime icons for now
|
||||
continue
|
||||
var/path = get_icon_dmi_path(mystery_meat) //Try to get the icon path
|
||||
if(path)
|
||||
data[path] = ref
|
||||
else if(mystery_meat)
|
||||
continue; //Some other non-icon resource, ogg/json/whatever
|
||||
else //Out of resources end this, could also try to end this earlier as soon as runtime generated icons appear but eh
|
||||
break;
|
||||
|
||||
return data
|
||||
@@ -1,13 +0,0 @@
|
||||
/datum/asset/spritesheet/prize_counter
|
||||
name = "prize_counter"
|
||||
|
||||
/datum/asset/spritesheet/prize_counter/create_spritesheets()
|
||||
for(var/datum/prize_item/prize in GLOB.global_prizes.prizes)
|
||||
var/obj/item/prize_item = prize.typepath
|
||||
var/prize_icon = icon(icon = initial(prize_item.icon), icon_state = initial(prize_item.icon_state))
|
||||
var/imgid = replacetext(replacetext("[prize_item]", "/obj/item/", ""), "/", "-")
|
||||
Insert(imgid, prize_icon)
|
||||
|
||||
/datum/asset/spritesheet/prize_counter/ModifyInserted(icon/pre_asset)
|
||||
pre_asset.Scale(64, 64)
|
||||
return pre_asset
|
||||
Reference in New Issue
Block a user