mirror of
https://github.com/vgstation-coders/vgstation13.git
synced 2025-12-10 10:21:11 +00:00
Adds a simple 'persistence' subsystem (#21553)
This commit is contained in:
committed by
jknpj
parent
2c327e71f4
commit
59f6973569
3
.gitignore
vendored
3
.gitignore
vendored
@@ -61,6 +61,9 @@ players2.sqlite
|
|||||||
# Round-end statistics
|
# Round-end statistics
|
||||||
/data/statfiles/*
|
/data/statfiles/*
|
||||||
|
|
||||||
|
# Persistence files
|
||||||
|
/data/persistence/*
|
||||||
|
|
||||||
cfg
|
cfg
|
||||||
|
|
||||||
.vscode
|
.vscode
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#define SS_INIT_TICKER -21
|
#define SS_INIT_TICKER -21
|
||||||
#define SS_INIT_FINISH -22
|
#define SS_INIT_FINISH -22
|
||||||
#define SS_INIT_MINIMAP -23
|
#define SS_INIT_MINIMAP -23
|
||||||
|
#define SS_INIT_PERSISTENCE -99
|
||||||
|
|
||||||
|
|
||||||
#define SS_PRIORITY_TICKER 200
|
#define SS_PRIORITY_TICKER 200
|
||||||
|
|||||||
42
code/controllers/subsystem/init/persistence.dm
Normal file
42
code/controllers/subsystem/init/persistence.dm
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
var/datum/subsystem/persistence/SSpersistence
|
||||||
|
|
||||||
|
/datum/subsystem/persistence
|
||||||
|
name = "Persistence"
|
||||||
|
init_order = SS_INIT_PERSISTENCE
|
||||||
|
flags = SS_NO_FIRE
|
||||||
|
|
||||||
|
var/const/round_count_file = "data/persistence/round_counts_per_year.json"
|
||||||
|
var/list/round_count_list = list()
|
||||||
|
|
||||||
|
|
||||||
|
/datum/subsystem/persistence/New()
|
||||||
|
NEW_SS_GLOBAL(SSpersistence)
|
||||||
|
|
||||||
|
/datum/subsystem/persistence/Recover()
|
||||||
|
round_count_list = SSpersistence.round_count_list
|
||||||
|
..()
|
||||||
|
|
||||||
|
|
||||||
|
/datum/subsystem/persistence/Initialize(timeofday)
|
||||||
|
read_round_count()
|
||||||
|
..()
|
||||||
|
|
||||||
|
/datum/subsystem/persistence/Shutdown()
|
||||||
|
bump_round_count()
|
||||||
|
write_round_count()
|
||||||
|
..()
|
||||||
|
|
||||||
|
/datum/subsystem/persistence/proc/read_round_count()
|
||||||
|
if(fexists(round_count_file))
|
||||||
|
round_count_list = json_decode(file2text(round_count_file))
|
||||||
|
|
||||||
|
/datum/subsystem/persistence/proc/bump_round_count()
|
||||||
|
var/itsthecurrentyear = time2text(world.realtime,"YY")
|
||||||
|
if(!(itsthecurrentyear in round_count_list))
|
||||||
|
round_count_list[itsthecurrentyear] = "0"
|
||||||
|
round_count_list[itsthecurrentyear] = num2text(text2num(round_count_list[itsthecurrentyear]) + 1)
|
||||||
|
|
||||||
|
/datum/subsystem/persistence/proc/write_round_count()
|
||||||
|
var/writing = file(round_count_file)
|
||||||
|
fdel(writing)
|
||||||
|
writing << json_encode(round_count_list)
|
||||||
@@ -194,8 +194,8 @@ var/global/datum/credits/end_credits = new
|
|||||||
rare_episode_name = TRUE
|
rare_episode_name = TRUE
|
||||||
|
|
||||||
/datum/credits/proc/finalize_episodestring()
|
/datum/credits/proc/finalize_episodestring()
|
||||||
var/season = rand(1,22)
|
var/season = time2text(world.realtime,"YY")
|
||||||
var/episodenum = rand(1,17) //Maybe we could do this cumulatively so that the round after 670 becomes 671 etc and the season is just the last 2 numbers of the current IRL year?
|
var/episodenum = SSpersistence.round_count_list[season]
|
||||||
episode_string = "<h1><span id='episodenumber'>SEASON [season] EPISODE [episodenum]</span><br><span id='episodename'>[episode_name]</span></h1><br><div style='padding-bottom: 75px;'></div>"
|
episode_string = "<h1><span id='episodenumber'>SEASON [season] EPISODE [episodenum]</span><br><span id='episodename'>[episode_name]</span></h1><br><div style='padding-bottom: 75px;'></div>"
|
||||||
log_game("So ends [is_rerun() ? "another rerun of " : ""]SEASON [season] EPISODE [episodenum] - [episode_name]")
|
log_game("So ends [is_rerun() ? "another rerun of " : ""]SEASON [season] EPISODE [episodenum] - [episode_name]")
|
||||||
|
|
||||||
|
|||||||
1
data/persistence/round_counts_per_year.json
Normal file
1
data/persistence/round_counts_per_year.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"19":"409"}
|
||||||
@@ -217,6 +217,7 @@
|
|||||||
#include "code\controllers\subsystem\init\map.dm"
|
#include "code\controllers\subsystem\init\map.dm"
|
||||||
#include "code\controllers\subsystem\init\minimaps.dm"
|
#include "code\controllers\subsystem\init\minimaps.dm"
|
||||||
#include "code\controllers\subsystem\init\more_init_stuff.dm"
|
#include "code\controllers\subsystem\init\more_init_stuff.dm"
|
||||||
|
#include "code\controllers\subsystem\init\persistence.dm"
|
||||||
#include "code\controllers\subsystem\init\rust.dm"
|
#include "code\controllers\subsystem\init\rust.dm"
|
||||||
#include "code\controllers\subsystem\init\spawn_ticker.dm"
|
#include "code\controllers\subsystem\init\spawn_ticker.dm"
|
||||||
#include "code\controllers\subsystem\init\xenoarch.dm"
|
#include "code\controllers\subsystem\init\xenoarch.dm"
|
||||||
|
|||||||
Reference in New Issue
Block a user