-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.gd
59 lines (46 loc) · 1.79 KB
/
profile.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
extends Control
@onready var gui_events = get_node("/root/GuiEvents")
@onready var gui_state = get_node("/root/GuiState")
var sound_on = preload("res://resources/images/ui/volume.png")
var sound_off = preload("res://resources/images/ui/mute.png")
var current_avatar
# Called when the node enters the scene tree for the first time.
func _ready():
$Bg/Control/LineEdit.text = gui_state.player_name
current_avatar = get_node("Bg/Control/GridContainer//%s" % [gui_state.player_avatar])
current_avatar.select(true)
gui_events.connect("avatar_selected", _on_avatar_selected)
if gui_state.sound_on:
$Bg/Control/SoundButton.icon = sound_on
$AudioStreamPlayer.play()
else:
$Bg/Control/SoundButton.icon = sound_off
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _on_avatar_selected(avatar):
current_avatar.select(false)
current_avatar = avatar
current_avatar.select(true)
func _on_profile_button_pressed():
gui_state.player_name = $Bg/Control/LineEdit.text
gui_state.player_avatar = current_avatar.avatar_name
gui_state.player_deck = current_avatar.deck_id
save_profile()
get_tree().change_scene_to_file("res://MainMenu.tscn")
func save_profile():
var data_to_send = {"player_name": gui_state.player_name, \
"player_avatar": gui_state.player_avatar, \
"player_deck": gui_state.player_deck, \
"sound_on": gui_state.sound_on}
var json_string = JSON.stringify(data_to_send)
var file = FileAccess.open("fluffy_profile.json", FileAccess.WRITE)
file.store_string(json_string)
func _on_sound_button_pressed():
gui_state.sound_on = not gui_state.sound_on
if gui_state.sound_on:
$Bg/Control/SoundButton.icon = sound_on
$AudioStreamPlayer.play()
else:
$Bg/Control/SoundButton.icon = sound_off
$AudioStreamPlayer.stop()