/
_persistence.dm
128 lines (112 loc) · 4.49 KB
/
_persistence.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#define FILE_RECENT_MAPS "data/RecentMaps.json"
#define KEEP_ROUNDS_MAP 3
SUBSYSTEM_DEF(persistence)
name = "Persistence"
init_order = INIT_ORDER_PERSISTENCE
flags = SS_NO_FIRE
///instantiated wall engraving components
var/list/wall_engravings = list()
///all saved persistent engravings loaded from JSON
var/list/saved_engravings = list()
///tattoo stories that we're saving.
var/list/prison_tattoos_to_save = list()
///tattoo stories that have been selected for this round.
var/list/prison_tattoos_to_use = list()
var/list/saved_messages = list()
var/list/saved_modes = list(1,2,3)
var/list/saved_maps = list()
var/list/blocked_maps = list()
var/list/saved_trophies = list()
var/list/picture_logging_information = list()
/// A json_database linking to data/photo_frames.json.
/// Schema is persistence_id => array of photo names.
var/datum/json_database/photo_frames_database
/// A lazy list of every picture frame that is going to be loaded with persistent photos.
/// Will be null'd once the persistence system initializes, and never read from again.
var/list/obj/structure/sign/picture_frame/queued_photo_frames
/// A json_database linking to data/photo_albums.json.
/// Schema is persistence_id => array of photo names.
var/datum/json_database/photo_albums_database
/// A lazy list of every photo album that is going to be loaded with persistent photos.
/// Will be null'd once the persistence system initializes, and never read from again.
var/list/obj/item/storage/photo_album/queued_photo_albums
/// A json_database to data/piggy banks.json
/// Schema is persistence_id => array of coins, space cash and holochips.
var/datum/json_database/piggy_banks_database
/// List of persistene ids which piggy banks.
var/list/queued_broken_piggy_ids
var/list/broken_piggy_banks
var/rounds_since_engine_exploded = 0
var/delam_highscore = 0
var/tram_hits_this_round = 0
var/tram_hits_last_round = 0
/datum/controller/subsystem/persistence/Initialize()
load_poly()
load_wall_engravings()
load_prisoner_tattoos()
load_trophies()
load_recent_maps()
load_photo_persistence()
load_randomized_recipes()
load_custom_outfits()
load_delamination_counter()
load_tram_counter()
load_adventures()
return SS_INIT_SUCCESS
///Collects all data to persist.
/datum/controller/subsystem/persistence/proc/collect_data()
save_wall_engravings()
save_prisoner_tattoos()
collect_trophies()
collect_maps()
save_randomized_recipes()
save_scars()
save_custom_outfits()
save_delamination_counter()
if(SStransport.can_fire)
for(var/datum/transport_controller/linear/tram/transport as anything in SStransport.transports_by_type[TRANSPORT_TYPE_TRAM])
save_tram_history(transport.specific_transport_id)
save_tram_counter()
///Loads up Poly's speech buffer.
/datum/controller/subsystem/persistence/proc/load_poly()
for(var/mob/living/basic/parrot/poly/bird in GLOB.alive_mob_list)
var/list/list_to_read = bird.get_static_list_of_phrases()
twitterize(list_to_read, "polytalk")
break //Who's been duping the bird?!
/// Loads up the amount of times maps appeared to alter their appearance in voting and rotation.
/datum/controller/subsystem/persistence/proc/load_recent_maps()
var/map_sav = FILE_RECENT_MAPS
if(!fexists(FILE_RECENT_MAPS))
return
var/list/json = json_decode(file2text(map_sav))
if(!json)
return
saved_maps = json["data"]
//Convert the mapping data to a shared blocking list, saves us doing this in several places later.
for(var/map in config.maplist)
var/datum/map_config/VM = config.maplist[map]
var/run = 0
if(VM.map_name == SSmapping.config.map_name)
run++
for(var/name in SSpersistence.saved_maps)
if(VM.map_name == name)
run++
if(run >= 2) //If run twice in the last KEEP_ROUNDS_MAP + 1 (including current) rounds, disable map for voting and rotation.
blocked_maps += VM.map_name
///Updates the list of the most recent maps.
/datum/controller/subsystem/persistence/proc/collect_maps()
if(length(saved_maps) > KEEP_ROUNDS_MAP) //Get rid of extras from old configs.
saved_maps.Cut(KEEP_ROUNDS_MAP+1)
var/mapstosave = min(length(saved_maps)+1, KEEP_ROUNDS_MAP)
if(length(saved_maps) < mapstosave) //Add extras if too short, one per round.
saved_maps += mapstosave
for(var/i = mapstosave; i > 1; i--)
saved_maps[i] = saved_maps[i-1]
saved_maps[1] = SSmapping.config.map_name
var/json_file = file(FILE_RECENT_MAPS)
var/list/file_data = list()
file_data["data"] = saved_maps
fdel(json_file)
WRITE_FILE(json_file, json_encode(file_data))
#undef FILE_RECENT_MAPS
#undef KEEP_ROUNDS_MAP