[MIRROR] Adds persistent smartfridges for garden products, material sheets

This commit is contained in:
Chompstation Bot
2021-05-13 20:53:58 +00:00
parent 83a2fdc561
commit 643e532256
19 changed files with 622124 additions and 191 deletions

View File

@@ -3,7 +3,7 @@
// of persistent data like graffiti and round to round filth.
/datum/persistent
var/name
var/name = null
var/filename
var/tokens_per_line
var/entries_expire_at // Set in rounds, this controls when the item is finally removed permanently regardless if cleaned or not.
@@ -24,6 +24,7 @@
if(!isnull(entries_decay_at) && !isnull(entries_expire_at))
entries_decay_at = round(entries_expire_at * entries_decay_at)
// Reads in list of text tokens taken from file, generates labelled list of actual token values
/datum/persistent/proc/LabelTokens(var/list/tokens)
var/list/labelled_tokens = list()
labelled_tokens["x"] = text2num(tokens[1])
@@ -48,6 +49,7 @@
tokens["age"] <= entries_expire_at \
)
// Restores saved data to world
/datum/persistent/proc/CreateEntryInstance(var/turf/creating, var/list/tokens)
return
@@ -96,7 +98,7 @@
/datum/persistent/proc/CompileEntry(var/atom/entry)
var/turf/T = get_turf(entry)
. = list(
return list(
T.x,
T.y,
T.z,
@@ -123,7 +125,8 @@
for(var/thing in SSpersistence.tracking_values[type])
if(IsValidEntry(thing))
var/list/entry = CompileEntry(thing)
if(LAZYLEN(entry) == tokens_per_line)
if(tokens_per_line == PERSISTENCE_VARIABLE_TOKEN_LENGTH || \
LAZYLEN(entry) == tokens_per_line)
for(var/i = 1 to LAZYLEN(entry))
if(istext(entry[i]))
entry[i] = replacetext(entry[i], file_entry_split_character, file_entry_substitute_character)

View File

@@ -0,0 +1,81 @@
/datum/persistent/storage/smartfridge/get_storage_list(var/obj/machinery/smartfridge/entry)
if(!istype(entry))
return ..()
. = list()
for(var/datum/stored_item/I in entry.item_records)
.[I.item_path] = I.get_amount()
/datum/persistent/storage/smartfridge/CreateEntryInstance(var/turf/creating, var/list/tokens)
var/obj/machinery/smartfridge/S = find_specific_instance(creating)
var/list/L = generate_items(tokens["items"])
for(var/atom/A in L)
if(S.accept_check(A))
S.stock(A)
else
qdel(A) // Should clean this up here, it couldn't be stocked
/datum/persistent/storage/smartfridge/sheet_storage
name = "sheet_storage"
max_storage = 50
store_per_type = TRUE
target_type = /obj/machinery/smartfridge/sheets
/datum/persistent/storage/smartfridge/sheet_storage/generate_items(var/list/L)
. = list()
for(var/obj/item/stack/material/S as anything in L)
if(!ispath(S, /obj/item/stack/material))
log_debug("Warning: Sheet_storage persistent datum tried to create [S]")
continue
var/count = L[S]
while(count > 0)
S = new S
S.amount = min(count, S.get_max_amount())
count -= S.get_amount()
. += S
/datum/persistent/storage/smartfridge/produce
name = "fruit_storage"
max_storage = 50
store_per_type = FALSE
target_type = /obj/machinery/smartfridge/produce
/datum/persistent/storage/smartfridge/produce/assemble_token(var/T)
var/list/subtok = splittext(T, " ")
if(subtok.len != 2)
return null
if(!istype(SSplants)) // No seed controller means the fruit will come out all wonky if at all
return null
subtok[2] = text2num(subtok[2])
// Ensure we've found a token describing the quantity of a path
if(subtok.len != 2 || \
!istype(SSplants.seeds[subtok[1]], /datum/seed) || \
!isnum(subtok[2]))
return null
return subtok
/datum/persistent/storage/smartfridge/produce/create_item(var/seedtype)
return new /obj/item/weapon/reagent_containers/food/snacks/grown(null, seedtype) // Smartfridge will be stock()ed with it, loc is unimportant
/datum/persistent/storage/smartfridge/produce/get_storage_list(var/obj/machinery/smartfridge/produce/entry)
if(!istype(entry))
return ..()
. = list()
for(var/datum/stored_item/I in entry.item_records)
if(LAZYLEN(I.instances))
var/obj/item/weapon/reagent_containers/food/snacks/grown/G = I.instances[1]
if(!istype(G))
continue
.[G.plantname] = I.get_amount() // Store the seed type, because that's what's used to generate the fruit

View File

@@ -0,0 +1,81 @@
/datum/persistent/storage
entries_expire_at = 1
entries_decay_at = 0
entry_decay_weight = 0
tokens_per_line = PERSISTENCE_VARIABLE_TOKEN_LENGTH
var/max_storage = 0
var/store_per_type = FALSE // If true, will store up to max_storage for each type stored
var/target_type = null // Path of the thing that this expects to put stuff into
/datum/persistent/storage/SetFilename()
if(name)
filename = "data/persistent/storage/[lowertext(using_map.name)]-[lowertext(name)].txt"
/datum/persistent/storage/LabelTokens(var/list/tokens)
. = ..()
.["items"] = list()
for(var/T in tokens)
var/list/L = assemble_token(T)
if(LAZYLEN(L))
.["items"][L[1]] = text2num(L[2])
/datum/persistent/storage/proc/assemble_token(var/T)
var/list/subtok = splittext(T, " ")
if(subtok.len != 2)
return null
subtok[1] = text2path(subtok[1])
subtok[2] = text2num( subtok[2])
// Ensure we've found a token describing the quantity of a path
if(subtok.len != 2 || \
!ispath(subtok[1]) || \
!isnum(subtok[2]))
return null
return subtok
/datum/persistent/storage/IsValidEntry(var/atom/entry)
return ..() && istype(entry, target_type)
/datum/persistent/storage/CompileEntry(var/atom/entry)
. = ..()
var/stored = max_storage
var/list/item_list = get_storage_list(entry)
var/list/storage_list = list()
for(var/item in item_list)
storage_list[item] = min(stored, storage_list[item] + item_list[item]) // Can't store more than max_storage
// stored gets reduced by qty stored, if greater than stored,
// previous assignment will handle overage, and we set to 0
if(!store_per_type)
stored = max(stored - item_list[item], 0)
for(var/item in storage_list)
. += "[item] [storage_list[item]]"
// Usage: returns list with structure:
// list(
// [type1] = [stored_quantity],
// [type2] = [stored_quantity]
// )
/datum/persistent/storage/proc/get_storage_list(var/atom/entry)
return list() // Subtypes define list structure
/datum/persistent/storage/proc/find_specific_instance(var/turf/T)
return locate(target_type) in T
/datum/persistent/storage/CheckTurfContents(var/turf/T, var/list/tokens)
return istype(find_specific_instance(T), target_type)
/datum/persistent/storage/proc/generate_items(var/list/L)
. = list()
for(var/path in L)
for(var/i in 1 to L[path])
var/atom/A = create_item(path)
if(!QDELETED(A))
. += A
/datum/persistent/storage/proc/create_item(var/path)
return new path()