-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLevelFileManager.py
54 lines (42 loc) · 1.44 KB
/
LevelFileManager.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
import yaml
import sys
class LevelFileManager:
PATH = "levels/beat_levels.yaml"
BEAT = {}
STORAGE_KEY = "HOPE_FALTERS_COMPLETED_LEVELS"
INITIALIZED = False
@staticmethod
def init():
if not LevelFileManager.is_web_build():
with open(LevelFileManager.PATH, "r") as f:
LevelFileManager.BEAT = yaml.safe_load(f)
else:
storage = window.localStorage.getItem(LevelFileManager.STORAGE_KEY)
if storage:
try:
LevelFileManager.BEAT = yaml.safe_load(storage)
except:
pass
LevelFileManager.INITIALIZED = True
@staticmethod
def beat_level(number):
LevelFileManager.BEAT[number]=True
LevelFileManager.save()
@staticmethod
def save():
if not LevelFileManager.is_web_build():
with open(LevelFileManager.PATH, "w") as f:
yaml.safe_dump(LevelFileManager.BEAT, f)
else:
storage = yaml.safe_dump(LevelFileManager.BEAT)
window.localStorage.setItem(LevelFileManager.STORAGE_KEY, storage)
@staticmethod
def level_has_been_beat(number):
if number not in LevelFileManager.BEAT:
return False
return LevelFileManager.BEAT[number]
@staticmethod
def is_web_build():
return sys.platform == "emscripten"
if LevelFileManager.is_web_build():
from platform import window