-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBackend.gd
62 lines (48 loc) · 1.35 KB
/
Backend.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
extends Node
const SAVE_FILE := "user://network-config.json"
@export
var BACKEND_IP_ADRESS: String = "https://piperacer.mogyidev.com":
set(newAddress):
BACKEND_IP_ADRESS = newAddress
saveToFile()
get:
return BACKEND_IP_ADRESS
@export
var FRONTEND_IP_ADRESS: String = "https://piperacer.mogyidev.com/":
set(newAddress):
FRONTEND_IP_ADRESS = newAddress
saveToFile()
get:
return FRONTEND_IP_ADRESS
var OVERWRITE: bool = false
func _ready() -> void:
loadFromFile()
func saveToFile() -> void:
var jsonData = {
"BACKEND_IP_ADRESS": BACKEND_IP_ADRESS,
"FRONTEND_IP_ADRESS": FRONTEND_IP_ADRESS,
"OVERWRITE": OVERWRITE
}
var jsonText = JSON.stringify(jsonData, "\t")
var file = FileAccess.open(SAVE_FILE, FileAccess.WRITE)
file.store_string(jsonText)
func loadFromFile() -> void:
if FileAccess.file_exists(SAVE_FILE):
var file = FileAccess.open(SAVE_FILE, FileAccess.READ)
var jsonText = file.get_as_text()
var jsonData = JSON.parse_string(jsonText)
if !jsonData.has("OVERWRITE"):
saveToFile()
return
var overWrite = jsonData["OVERWRITE"]
if !overWrite:
return
BACKEND_IP_ADRESS = jsonData["BACKEND_IP_ADRESS"]
FRONTEND_IP_ADRESS = jsonData["FRONTEND_IP_ADRESS"]
OVERWRITE = jsonData["OVERWRITE"]
saveToFile()
else:
saveToFile()
func _notification(what):
if what == NOTIFICATION_WM_CLOSE_REQUEST:
saveToFile()