mirror of
https://github.com/Citadel-Station-13/Citadel-Station-13-RP.git
synced 2026-08-31 10:36:41 +01:00
element memes
This commit is contained in:
+16
-5
@@ -148,13 +148,24 @@
|
||||
to_chat(target, txt_changed_vars())
|
||||
#endif
|
||||
|
||||
///Return a LIST for serialize_datum to encode! Not the actual json!
|
||||
/**
|
||||
* Saves our data into a data list.
|
||||
*
|
||||
* @params
|
||||
* * options - associative list of options to use. Not yet particularly used/standardized, but can be easily implemented.
|
||||
*/
|
||||
/datum/proc/serialize_list(list/options)
|
||||
CRASH("Attempted to serialize datum [src] of type [type] without serialize_list being implemented!")
|
||||
return
|
||||
|
||||
///Accepts a LIST from deserialize_datum. Should return src or another datum.
|
||||
/datum/proc/deserialize_list(json, list/options)
|
||||
CRASH("Attempted to deserialize datum [src] of type [type] without deserialize_list being implemented!")
|
||||
/**
|
||||
* Takes a data list in and loads data into ourselves. Persistence elements currently use this.
|
||||
*
|
||||
* @params
|
||||
* * data - list of data for us to use
|
||||
* * options - associatve list of options to use. Not yet particularly used/standardized, but can be easily implemented.
|
||||
*/
|
||||
/datum/proc/deserialize_list(list/data, list/options)
|
||||
return
|
||||
|
||||
///Serializes into JSON. Does not encode type.
|
||||
/datum/proc/serialize_json(list/options)
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Simple object persistence elements
|
||||
* For now, it just attachs and detaches and all objects with it are recorded to disk based on map and stuff at round end
|
||||
* Can expand later for more functionality
|
||||
*
|
||||
* WARNING: All atoms recorded are stored to turf! This does not yet support things like loading into inventories. This is mostly for on-floor objects.
|
||||
*/
|
||||
/datum/element/persistence
|
||||
flags = ELEMENT_DETACH
|
||||
|
||||
/// List of persistent atoms. Associated list to their GUID
|
||||
var/list/atom/objects = list()
|
||||
|
||||
/**
|
||||
* Serializes all objects into a list for json encode or anything else needed.
|
||||
* Includes data the datum includes in serialize_list(), the GUID of the datum's entry, and its turf location.
|
||||
*/
|
||||
/datum/element/persistence/proc/SerializeAll()
|
||||
. = list()
|
||||
var/atom/A
|
||||
var/guid
|
||||
for(var/i in objects)
|
||||
A = i
|
||||
guid = objects[A]
|
||||
var/turf/location = get_turf(A)
|
||||
if(!A || !guid || !location)
|
||||
continue
|
||||
. += list(A.serialize_list(), guid, list(location.x, location.y, location.z), "[A.type]")
|
||||
|
||||
/**
|
||||
* Instantiates all objects from a data list and attaches to them.
|
||||
*/
|
||||
/datum/element/persistence/proc/DeserializeAndInstantiateAll(list/data)
|
||||
for(var/i in data)
|
||||
var/list/L = i
|
||||
if(!istype(L) || (length(L) < 3))
|
||||
continue
|
||||
var/list/datumdata = L[1]
|
||||
var/guid = L[2]
|
||||
var/coords = L[3]
|
||||
var/datumtype = text2path(L[4])
|
||||
if(!ispath(datumtype))
|
||||
continue
|
||||
var/turf/T = locate(coords[1], coords[2], coords[3])
|
||||
if(!T)
|
||||
continue
|
||||
var/atom/A = new datumtype(T)
|
||||
A.deserialize_list(datumdata)
|
||||
Attach(A, guid)
|
||||
|
||||
/datum/element/persistence/Attach(datum/D, guid = GUID())
|
||||
if(!isatom(D))
|
||||
return ELEMENT_INCOMPATIBLE
|
||||
. = ..()
|
||||
if(. == ELEMENT_INCOMPATIBLE)
|
||||
return
|
||||
objects[D] = guid
|
||||
|
||||
/datum/element/persistence/Detach(datum/D)
|
||||
objects -= D
|
||||
@@ -322,6 +322,7 @@
|
||||
#include "code\datums\components\_component.dm"
|
||||
#include "code\datums\components\orbiter.dm"
|
||||
#include "code\datums\elements\_element.dm"
|
||||
#include "code\datums\elements\persistence.dm"
|
||||
#include "code\datums\helper_datums\construction_datum.dm"
|
||||
#include "code\datums\helper_datums\events.dm"
|
||||
#include "code\datums\helper_datums\getrev.dm"
|
||||
@@ -2205,6 +2206,7 @@
|
||||
#include "code\modules\lore_codex\robutt_data\bybrand.dm"
|
||||
#include "code\modules\lore_codex\robutt_data\main_robutts.dm"
|
||||
#include "code\modules\lore_codex\robutt_data\more.dm"
|
||||
#include "code\modules\mapping\map_config.dm"
|
||||
#include "code\modules\mapping\minimaps.dm"
|
||||
#include "code\modules\mapping\preloader.dm"
|
||||
#include "code\modules\maps\tg\dmm_suite.dm"
|
||||
|
||||
Reference in New Issue
Block a user