Skip to content

Commit b662f4e

Browse files
committed
Add option to load and backup your save file
1 parent e3b4741 commit b662f4e

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

save-editor.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import datetime
23
import json
34
import colorama
45
from colorama import Fore, Back, Style
@@ -95,7 +96,8 @@ def main():
9596
print("3) Edit Money")
9697
print("4) Edit Difficulty")
9798
print("5) Change Life/Death Symbol")
98-
print("6) Exit")
99+
print("6) Load/Backup Current Save File")
100+
print("7) Exit")
99101

100102
choice = input("Enter your choice: ")
101103

@@ -169,6 +171,33 @@ def main():
169171
print_status(save_data)
170172

171173
elif choice == "6":
174+
backup_file_path = save_file_path.replace('.save', '.bak')
175+
176+
if os.path.exists(backup_file_path):
177+
creation_time = os.path.getctime(backup_file_path)
178+
creation_date = datetime.datetime.fromtimestamp(creation_time).strftime("%Y-%m-%d %I:%M:%S %p")
179+
print(Fore.YELLOW + f"Backup file created on {creation_date}" + Style.RESET_ALL)
180+
181+
print("\nSave File Operations:")
182+
print(Fore.GREEN + "1) Backup current save file" + Style.RESET_ALL)
183+
print(Fore.RED + "2) Load from backup" + Style.RESET_ALL)
184+
print("3) Go back to main menu")
185+
186+
operation_choice = input("Enter your choice: ")
187+
188+
if operation_choice == "1":
189+
with open(save_file_path, 'r') as original: data = original.read()
190+
with open(backup_file_path, 'w') as backup: backup.write(data)
191+
print("Backup created.")
192+
elif operation_choice == "2":
193+
with open(backup_file_path, 'r') as backup: data = backup.read()
194+
with open(save_file_path, 'w') as original: original.write(data)
195+
print("Backup loaded.")
196+
else:
197+
clear_console()
198+
print_status(save_data)
199+
200+
elif choice == "7":
172201
break
173202

174203
else:

0 commit comments

Comments
 (0)