-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsave_management.py
73 lines (62 loc) · 1.99 KB
/
save_management.py
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
import time
import os
from fa_paths import SAVES
from fa_menu import getAffirmation
def get_elapsed_time(t1):
t2 = time.time()
days = (t2 - t1) / 60 / 60 / 24
if days >= 1:
return str(int(days)) + " days"
hours = (t2 - t1) / 60 / 60
if hours >= 1:
return str(int(hours)) + " hours"
minutes = (t2 - t1) / 60
if minutes >= 1:
return str(int(minutes)) + " minutes"
return str(int(t2 - t1 + 0.999)) + " seconds"
def save_time(file):
return os.path.getmtime(os.path.join(SAVES, file))
def get_sorted_saves():
try:
all_files = os.listdir(SAVES)
zip_files = [f for f in all_files if f.lower().endswith(".zip")]
zip_files.sort(reverse=True, key=save_time)
return zip_files
except:
return []
def get_menu_saved_games():
games = get_sorted_saves()
return {
save[:-4] + " " + get_elapsed_time(save_time(save)) + " ago": (save,)
for save in games
}
def save_game_rename(if_after=None):
l = get_sorted_saves()
if len(l) > 0:
save = l[0]
save_t = save_time(save)
if if_after and save_t > if_after:
print(
"Would you like to name your last save? You saved "
+ get_elapsed_time(save_t)
+ " ago"
)
if not getAffirmation():
return
print("Enter a name for your save file:")
check = False
while check == False:
newName = input()
try:
dst = os.path.join(SAVES, newName + ".zip")
testFile = open(dst, "w")
testFile.close()
os.remove(dst)
check = True
except:
print("Invalid file name, please try again.")
src = os.path.join(SAVES, save)
os.replace(src, dst)
print("Renamed.")
return
print("Looks like you didn't save!")