Adds a simple 'persistence' subsystem (#21553)

This commit is contained in:
I-VAPE-VOX-CLOACA-EVERY-DAY-OF-MY-LIFE
2019-02-06 15:08:31 -03:00
committed by jknpj
parent 2c327e71f4
commit 59f6973569
6 changed files with 50 additions and 2 deletions

3
.gitignore vendored
View File

@@ -61,6 +61,9 @@ players2.sqlite
# Round-end statistics
/data/statfiles/*
# Persistence files
/data/persistence/*
cfg
.vscode

View File

@@ -24,6 +24,7 @@
#define SS_INIT_TICKER -21
#define SS_INIT_FINISH -22
#define SS_INIT_MINIMAP -23
#define SS_INIT_PERSISTENCE -99
#define SS_PRIORITY_TICKER 200

View 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)

View File

@@ -194,8 +194,8 @@ var/global/datum/credits/end_credits = new
rare_episode_name = TRUE
/datum/credits/proc/finalize_episodestring()
var/season = rand(1,22)
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/season = time2text(world.realtime,"YY")
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>"
log_game("So ends [is_rerun() ? "another rerun of " : ""]SEASON [season] EPISODE [episodenum] - [episode_name]")

View File

@@ -0,0 +1 @@
{"19":"409"}

View File

@@ -217,6 +217,7 @@
#include "code\controllers\subsystem\init\map.dm"
#include "code\controllers\subsystem\init\minimaps.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\spawn_ticker.dm"
#include "code\controllers\subsystem\init\xenoarch.dm"