-
Notifications
You must be signed in to change notification settings - Fork 0
/
Events.gd
42 lines (35 loc) · 1.03 KB
/
Events.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
extends Node
signal mob_died(score_value)
signal player_health_changed(new_health)
signal player_buff_active(bufftime, bufftype)
signal selected_spell_changed(new_selected_spell_scene)
signal save_game(player_score)
signal player_shield_active
signal player_shield_changed(new_charges)
signal player_died
var next_level: bool = false
var current_score: int
var highscore_name: String
var current_player: String
const game_version = '1.3.5'
const Save_File = "user://game-data.save"
func _ready():
self.connect("save_game", self, "save_score")
func save_score(new_score: int, playername: String):
var save_game = File.new()
save_game.open(Save_File, File.WRITE)
var data := {
"name": playername,
"score": new_score
}
save_game.store_line(to_json(data))
save_game.close()
func load_score():
var save_game = File.new()
if not save_game.file_exists(Save_File):
return
save_game.open(Save_File, File.READ)
var data = parse_json(save_game.get_line())
print(data)
current_score = int(data['score'])
highscore_name = str(data['name'])