-
Notifications
You must be signed in to change notification settings - Fork 1
/
Env.gd
123 lines (101 loc) · 2.59 KB
/
Env.gd
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
extends Node
const fileSettings: String = "user://IWFIO.json"
"""
|--------------------
| Global elements.
|--------------------
|
| Check current slot and the global settings as controls and blood emision.
|
"""
var global: Dictionary = {}
var slot: Dictionary = {}
var nameSlot: String
"""
|--------------------
| In Game Variables
|--------------------
|
| All default in game variables like pause state or check if the player is dead.
|
"""
var paused: bool = false
var dead: bool = false
"""
|--------------------
| Default elements.
|--------------------
|
| Default values for reusing them accross the game.
|
"""
const defaults: Dictionary = {
"name": null,
"defeated": {
"loneliness": false,
"sadness": false,
"guiltiness": false,
"anger": false,
"negativity": false,
"oblivion": false,
},
"items": [],
"position": {},
"retries": 0,
"difficulty": 0, # 0: easy; 1: normal; 2: hard: 3; Very Hard: 4; Impossible: 5
"room": "roomStart",
}
func _ready():
if (!FileAccess.file_exists(fileSettings)):
global = {
"blood": true,
"controls": {
"jump": "up",
"left": "left",
"right": "right",
"shoot": "z",
},
"max_slots": null, # null means no limit.
"slots": [],
"volume": {
"music": 0,
"sfx": 0,
},
}
save(fileSettings, global)
return
readGlobal(fileSettings)
func findSlotOrCreate(date, position):
if position == null:
print("No position provided, exiting of method.")
return
var fallback = "user://%s.json" % date
if !FileAccess.open(fallback, FileAccess.READ):
createSlot(fallback, position, date)
return
readSlot(fallback)
func createSlot(filename, position, date):
# Check if the user has the max slots size activated.
# In that case we should prevent the creation of a new slot.
if global.max_slots != null and global.max_slots <= (global.slots.size() + 1):
return
slot = defaults.duplicate()
slot.name = date
slot.position = position
save(filename, slot)
global.slots.push_back(date)
save(fileSettings, global)
Env.nameSlot = date
func save(filename, object):
var handler = FileAccess.open(filename, FileAccess.WRITE_READ)
handler.store_string(JSON.stringify(object, " "))
handler = null
func readGlobal(filename):
var handler = FileAccess.open(filename, FileAccess.READ)
global = JSON.parse_string(handler.get_as_text())
handler = null
func readSlot(filename):
var handler = FileAccess.open(filename, FileAccess.READ)
slot = JSON.parse_string(handler.get_as_text())
Env.nameSlot = slot.name
handler = null