-
Notifications
You must be signed in to change notification settings - Fork 4
/
save.py
43 lines (30 loc) · 987 Bytes
/
save.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
import cPickle as pickle
from genericpath import isfile
from os import getcwd, listdir
import os
from tools import time_it
__author__ = 'co'
def load_first_game():
save_file = open(get_save_files()[0], 'rb')
print save_file
game_state = time_it("load", (lambda: pickle.load(save_file)))
save_file.close()
return game_state
def get_save_file_name():
save_file = "game.sav"
return save_file
def save(game_state):
game_state.draw_loading_screen("Saving...")
save_file = open(get_save_file_name(), 'wb')
time_it("save", lambda: pickle.dump(game_state, save_file, -1))
save_file.close()
def get_save_files():
directory = getcwd()
return [f for f in listdir(directory)
if isfile(f) and f == get_save_file_name()]
def delete_save_file_of_game_state():
file_name = get_save_file_name()
if os.path.isfile(file_name):
os.remove(file_name)
def is_there_a_saved_game():
return len(get_save_files()) > 0