mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-22 04:30:44 +01:00
[READY] Bespoke Datum Mats (#55296)
* Bespoke Material Backend - Adds support for bespoke materials: - Reimplements [/datum/material/var/id] - Ports GetIdFromArguments from SSdcs - Adds a wrapper define for GetMaterialRef - Adds [MATERIAL_INIT_BESPOKE] - Adds [/datum/material/proc/Initialize] - Does not actually add any bespoke materials - [ ] TODO: Code docs - [ ] TODO: Actually adding bespoke materials * Some has_material procs and cleaning up some spaghetti - Adds a pair of has_material procs for use in checking whether a given atom has a given material * Adds meat - Adds bespoke meat variants - Does not make them accessible - Shuts up the linter * Implements bespoke meat - Makes the material container preserve bespoke materials - Makes the sheetifier accept bespoke materials - Makes the autolathe accept bespoke materials - Makes the gibber produce bespoke meats * Makes butchering produce bespoke meats This is jank and really needs to be folded into a unified butchering and gibbing system * Material documentation - Adds, fixes, and touches up some documentation * Material container insertion callback - Changes the proc used to expand the material container's material list ot a proc used to check whether a material fits into a material container - Instantiating new materials is no longer O(n) relative to the number of autolathes in existence. * Makes processing meat conserve materials - Makes bespoke meat carry over into meatballs * Makes preserving custom materials an option - Implements the ability to turn preserving custom materials _off_ for processor recipes * Fixes all bespoke materials of the same type using the same singleton - We use ids now, not just types. * Makes the fat sucker produce bespoke meats - Because consistency is good. * Fixes autolathes merging bespoke stacks into normal stacks. * Makes the callback to test materials for holdibility optional - @Floyd * GetMaterialRef -> GET_MATERIAL_REF - We capitalize macros. * Removes an extraneous callback - Makes the sheetifier use functionality I didn't notice I implemented a few commits ago. * Makes mob and species meat null compatible * Fixes the ore silo - The ore silo had really snowflake material handling that has been brought in line with the rest. - The materials should show up in the correct order. * Fixes minor lathe bugs - Fixes stack_traces caused when lathes tried to fetch materials using reagent typepaths - Fixed the selective reagent disposal topic. I have no idea how long this has been broken. * Various documentation fixes - Clarified a couple comments - Removes an extraneous ?. operator - Fixed mat floor tiles having bugged reagent temperatures * More fixes -/datum/material/meat/mob -> /datum/material/meat/mob_meat - Adds atom typecheck to material containers. * Fixes old typepaths
This commit is contained in:
@@ -8,12 +8,16 @@ These materials call on_applied() on whatever item they are applied to, common e
|
||||
SUBSYSTEM_DEF(materials)
|
||||
name = "Materials"
|
||||
flags = SS_NO_FIRE | SS_NO_INIT
|
||||
///Dictionary of material.type || material ref
|
||||
///Dictionary of material.id || material ref
|
||||
var/list/materials
|
||||
///Dictionary of type || list of material refs
|
||||
var/list/materials_by_type
|
||||
///Dictionary of type || list of material ids
|
||||
var/list/materialids_by_type
|
||||
///Dictionary of category || list of material refs
|
||||
var/list/materials_by_category
|
||||
///Dictionary of category || list of material types, mostly used by rnd machines like autolathes.
|
||||
var/list/materialtypes_by_category
|
||||
///Dictionary of category || list of material ids, mostly used by rnd machines like autolathes.
|
||||
var/list/materialids_by_category
|
||||
///A cache of all material combinations that have been used
|
||||
var/list/list/material_combos
|
||||
///List of stackcrafting recipes for materials using base recipes
|
||||
@@ -31,40 +35,131 @@ SUBSYSTEM_DEF(materials)
|
||||
///Ran on initialize, populated the materials and materials_by_category dictionaries with their appropiate vars (See these variables for more info)
|
||||
/datum/controller/subsystem/materials/proc/InitializeMaterials()
|
||||
materials = list()
|
||||
materials_by_type = list()
|
||||
materialids_by_type = list()
|
||||
materials_by_category = list()
|
||||
materialtypes_by_category = list()
|
||||
materialids_by_category = list()
|
||||
material_combos = list()
|
||||
for(var/type in subtypesof(/datum/material))
|
||||
var/datum/material/ref = type
|
||||
if(!(initial(ref.init_flags) & MATERIAL_INIT_MAPLOAD))
|
||||
continue // Do not initialize
|
||||
var/datum/material/mat_type = type
|
||||
if(!(initial(mat_type.init_flags) & MATERIAL_INIT_MAPLOAD))
|
||||
continue // Do not initialize at mapload
|
||||
InitializeMaterial(list(mat_type))
|
||||
|
||||
ref = new ref
|
||||
materials[type] = ref
|
||||
for(var/c in ref.categories)
|
||||
materials_by_category[c] += list(ref)
|
||||
materialtypes_by_category[c] += list(type)
|
||||
/** Creates and caches a material datum.
|
||||
*
|
||||
* Arugments:
|
||||
* - [arguments][/list]: The arguments to use to create the material datum
|
||||
* - The first element is the type of material to initialize.
|
||||
*/
|
||||
/datum/controller/subsystem/materials/proc/InitializeMaterial(list/arguments)
|
||||
var/datum/material/mat_type = arguments[1]
|
||||
if(initial(mat_type.init_flags) & MATERIAL_INIT_BESPOKE)
|
||||
arguments[1] = GetIdFromArguments(arguments)
|
||||
|
||||
/datum/controller/subsystem/materials/proc/GetMaterialRef(datum/material/fakemat)
|
||||
var/datum/material/mat_ref = new mat_type
|
||||
if(!mat_ref.Initialize(arglist(arguments)))
|
||||
return null
|
||||
|
||||
var/mat_id = mat_ref.id
|
||||
materials[mat_id] = mat_ref
|
||||
materials_by_type[mat_type] += list(mat_ref)
|
||||
materialids_by_type[mat_type] += list(mat_id)
|
||||
for(var/category in mat_ref.categories)
|
||||
materials_by_category[category] += list(mat_ref)
|
||||
materialids_by_category[category] += list(mat_id)
|
||||
|
||||
SEND_SIGNAL(src, COMSIG_MATERIALS_INIT_MAT, mat_ref)
|
||||
return mat_ref
|
||||
|
||||
/** Fetches a cached material singleton when passed sufficient arguments.
|
||||
*
|
||||
* Arguments:
|
||||
* - [arguments][/list]: The list of arguments used to fetch the material ref.
|
||||
* - The first element is a material datum, text string, or material type.
|
||||
* - [Material datums][/datum/material] are assumed to be references to the cached datum and are returned
|
||||
* - Text is assumed to be the text ID of a material and the corresponding material is fetched from the cache
|
||||
* - A material type is checked for bespokeness:
|
||||
* - If the material type is not bespoke the type is assumed to be the id for a material and the corresponding material is loaded from the cache.
|
||||
* - If the material type is bespoke a text ID is generated from the arguments list and used to load a material datum from the cache.
|
||||
* - The following elements are used to generate bespoke IDs
|
||||
*/
|
||||
/datum/controller/subsystem/materials/proc/_GetMaterialRef(list/arguments)
|
||||
if(!materials)
|
||||
InitializeMaterials()
|
||||
return materials[fakemat] || fakemat
|
||||
|
||||
///Returns a list to be used as an object's custom_materials. Lists will be cached and re-used based on the parameters.
|
||||
var/datum/material/key = arguments[1]
|
||||
if(istype(key))
|
||||
return key // We are assuming here that the only thing allowed to create material datums is [/datum/controller/subsystem/materials/proc/InitializeMaterial]
|
||||
|
||||
if(istext(key)) // Handle text id
|
||||
. = materials[key]
|
||||
if(!.)
|
||||
WARNING("Attempted to fetch material ref with invalid text id '[key]'")
|
||||
return
|
||||
|
||||
if(!ispath(key, /datum/material))
|
||||
CRASH("Attempted to fetch material ref with invalid key [key]")
|
||||
|
||||
if(!(initial(key.init_flags) & MATERIAL_INIT_BESPOKE))
|
||||
. = materials[key]
|
||||
if(!.)
|
||||
WARNING("Attempted to fetch reference to an abstract material with key [key]")
|
||||
return
|
||||
|
||||
key = GetIdFromArguments(arguments)
|
||||
return materials[key] || InitializeMaterial(arguments)
|
||||
|
||||
/** I'm not going to lie, this was swiped from [SSdcs][/datum/controller/subsystem/processing/dcs].
|
||||
* Credit does to ninjanomnom
|
||||
*
|
||||
* Generates an id for bespoke ~~elements~~ materials when given the argument list
|
||||
* Generating the id here is a bit complex because we need to support named arguments
|
||||
* Named arguments can appear in any order and we need them to appear after ordered arguments
|
||||
* We assume that no one will pass in a named argument with a value of null
|
||||
**/
|
||||
/datum/controller/subsystem/materials/proc/GetIdFromArguments(list/arguments)
|
||||
var/datum/material/mattype = arguments[1]
|
||||
var/list/fullid = list("[initial(mattype.id) || mattype]")
|
||||
var/list/named_arguments = list()
|
||||
for(var/i in 2 to length(arguments))
|
||||
var/key = arguments[i]
|
||||
var/value
|
||||
if(istext(key))
|
||||
value = arguments[key]
|
||||
if(!(istext(key) || isnum(key)))
|
||||
key = REF(key)
|
||||
key = "[key]" // Key is stringified so numbers dont break things
|
||||
if(!isnull(value))
|
||||
if(!(istext(value) || isnum(value)))
|
||||
value = REF(value)
|
||||
named_arguments["[key]"] = value
|
||||
else
|
||||
fullid += "[key]"
|
||||
|
||||
if(length(named_arguments))
|
||||
named_arguments = sortList(named_arguments)
|
||||
fullid += named_arguments
|
||||
return list2params(fullid)
|
||||
|
||||
|
||||
/// Returns a list to be used as an object's custom_materials. Lists will be cached and re-used based on the parameters.
|
||||
/datum/controller/subsystem/materials/proc/FindOrCreateMaterialCombo(list/materials_declaration, multiplier)
|
||||
if(!LAZYLEN(materials_declaration))
|
||||
return null // If we get a null we pass it right back, we don't want to generate stack traces just because something is clearing out its materials list.
|
||||
|
||||
if(!material_combos)
|
||||
InitializeMaterials()
|
||||
var/list/combo_params = list()
|
||||
for(var/x in materials_declaration)
|
||||
var/datum/material/mat = x
|
||||
var/path_name = ispath(mat) ? "[mat]" : "[mat.type]"
|
||||
combo_params += "[path_name]=[materials_declaration[mat] * multiplier]"
|
||||
combo_params += "[istype(mat) ? mat.id : mat]=[materials_declaration[mat] * multiplier]"
|
||||
sortTim(combo_params, /proc/cmp_text_asc) // We have to sort now in case the declaration was not in order
|
||||
var/combo_index = combo_params.Join("-")
|
||||
var/list/combo = material_combos[combo_index]
|
||||
if(!combo)
|
||||
combo = list()
|
||||
for(var/mat in materials_declaration)
|
||||
combo[GetMaterialRef(mat)] = materials_declaration[mat] * multiplier
|
||||
combo[GET_MATERIAL_REF(mat)] = materials_declaration[mat] * multiplier
|
||||
material_combos[combo_index] = combo
|
||||
return combo
|
||||
|
||||
Reference in New Issue
Block a user