Skip to content

Commit

Permalink
system agnostic implementation, more robust naming, config implementa…
Browse files Browse the repository at this point in the history
…tion instead
  • Loading branch information
Metekillot committed Feb 23, 2025
1 parent 8dd5bc6 commit 89ba453
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
3 changes: 3 additions & 0 deletions code/controllers/configuration/entries/game_options.dm
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,6 @@
min_val = 0

/datum/config_entry/flag/dynamic_config_enabled

/datum/config_entry/string/json_conversion_path
protection = CONFIG_ENTRY_LOCKED | CONFIG_ENTRY_HIDDEN
1 change: 1 addition & 0 deletions code/controllers/configuration/entries/resources.dm
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
if (str_var && str_var[length(str_var)] != "/")
str_var += "/"
return ..(str_var)

6 changes: 4 additions & 2 deletions code/controllers/subsystem/ticker.dm
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,10 @@ SUBSYSTEM_DEF(ticker)
set waitfor = FALSE
if(usr && !check_rights(R_SERVER, TRUE))
return
/// Buckle up, we're gonna json it...
world.convert_saves_to_json()
/// Make sure to set json_conversion_path in config/config.txt! You can't set this in-game!
if(CONFIG_GET(string/json_conversion_path))
/// Buckle up, we're gonna json it...
world.convert_saves_to_json(CONFIG_GET(string/json_conversion_path))

if(!delay)
delay = CONFIG_GET(number/round_end_countdown) * 10
Expand Down
26 changes: 20 additions & 6 deletions code/game/world.dm
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,21 @@ GLOBAL_VAR(restart_counter)
/world/proc/on_tickrate_change()
SStimer?.reset_buckets()

/world/proc/convert_saves_to_json()
var/untrimmed_file_list = splittext(world.shelleo("find data/player_saves/ -type f")[2], "\n")
/world/proc/convert_saves_to_json(path_to_save)
/// Determine the path variables to use based on our host OS
var/regex/trimmer
var/shell_command
var/path_char
if(world.system_type == UNIX)
trimmer = regex("data/player_saves/.*")
shell_command = "find data/player_saves/ -type f"
path_char = "/"
else // We're on Windows
trimmer = regex("data\\\\player_saves\\\\.*")
shell_command = "dir /A-D /b /s data\\player_saves\\"
path_char = "\\"
var/untrimmed_file_list = splittext(world.shelleo("[shell_command]")[2], "\n")
/// Just in case the whole path gets returned instead of the relative
var/regex/trimmer = regex("data/player_saves/.*")
var/list/file_list = list()
for(var/file_path in untrimmed_file_list)
trimmer.Find(file_path)
Expand All @@ -371,7 +382,10 @@ GLOBAL_VAR(restart_counter)
var/datum/json_savefile/json_son = new
var/savefile/S = new(trimmed_path)
json_son.import_byond_savefile(S)
var/list/split_path = splittext(trimmed_path, "/")
var/file_name = split_path[split_path.len - 1]
json_son.path = ("/home/sftp_user/uploads/saves/" + file_name[1] + "/" + file_name + ".json")
var/list/split_path = splittext(trimmed_path, path_char)
var/dir_name = split_path[split_path.len - 1]
var/file_name = replacetext(split_path[split_path.len], ".sav", ".json")
// Path to save, first_char as a directory, path separator, file_name
// IE: path_to_save/a/apple.json
json_son.path = (path_to_save + dir_name[1] + path_char + dir_name + path_char + file_name)
json_son.save()
6 changes: 6 additions & 0 deletions config/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,9 @@ DEFAULT_VIEW_SQUARE 15x15

## Add the ID of the role you want assigning here
#DISCORD_ROLEID 000000000000000000

## The path to export current .sav format files to json. If commented out, has no effect.
## Assuming you're saving inside the directory where you have your .dme
## Windows: directory\to\save\ | Linux: directory/to/save/
## Don't forget the last path separator!
#JSON_CONVERSION_PATH data\player_saves\json_saves\

0 comments on commit 89ba453

Please sign in to comment.