79 lines
2.2 KiB
GDScript
79 lines
2.2 KiB
GDScript
extends Node
|
|
|
|
|
|
var Weapons = {
|
|
"knife" = {
|
|
"number": 0,
|
|
"magazine": -1,
|
|
"ammo": -1
|
|
},
|
|
"pistol" = {
|
|
"number": 1,
|
|
"magazine": 50,
|
|
"ammo": 200
|
|
},
|
|
"ak-47" = {
|
|
"number": 2,
|
|
"magazine": 30,
|
|
"ammo": 100
|
|
}
|
|
}
|
|
|
|
var properties_example = {
|
|
HP = 100,
|
|
AP = 100,
|
|
HACK = 1.0,
|
|
class_type = 0,
|
|
is_playable = false,
|
|
internal_id = 0,
|
|
nickname = "Unnamed",
|
|
ready = false,
|
|
current_weapon = Weapons["knife"].duplicate(),
|
|
weapons = Weapons.duplicate(),
|
|
last_shot = 0,
|
|
reloading = false,
|
|
position = Vector3(0, 5, 0)
|
|
}
|
|
|
|
var client_settings
|
|
var server_settings
|
|
|
|
func apply_weapon_settings(s: Dictionary): #game/weapons/weapon
|
|
for weapon in s.values():
|
|
Weapons[s.find_key(weapon)] = weapon
|
|
print("New weapons: " + str(Weapons))
|
|
|
|
func _ready():
|
|
read_settings()
|
|
|
|
func read_settings():
|
|
var user_dir = DirAccess.open(".")
|
|
if(!user_dir.dir_exists("./settings")):
|
|
user_dir.make_dir("settings")
|
|
var client_settings_file
|
|
|
|
if(!FileAccess.file_exists("./settings/client-settings.json")):
|
|
print("Client-settings doesn't exist, creating one")
|
|
var example = FileAccess.open("res://settings/client-settings.json", FileAccess.READ)
|
|
client_settings_file = FileAccess.open("./settings/client-settings.json", FileAccess.WRITE_READ)
|
|
client_settings_file.store_string(example.get_as_text())
|
|
else:
|
|
client_settings_file = FileAccess.open("./settings/client-settings.json", FileAccess.READ)
|
|
client_settings = JSON.parse_string(client_settings_file.get_as_text())
|
|
|
|
|
|
var server_settings_file
|
|
if(!FileAccess.file_exists("./settings/server-settings.json")):
|
|
print("Server-settings doesn't exist, creating one")
|
|
var example = FileAccess.open("res://settings/server-settings.json", FileAccess.READ)
|
|
server_settings_file = FileAccess.open("./settings/server-settings.json", FileAccess.WRITE_READ)
|
|
server_settings_file.store_string(example.get_as_text())
|
|
else:
|
|
server_settings_file = FileAccess.open("./settings/server-settings.json", FileAccess.READ)
|
|
server_settings = JSON.parse_string(server_settings_file.get_as_text())
|
|
apply_weapon_settings(server_settings["game"]["weapons"])
|
|
|
|
func save_client_settings():
|
|
var client_settings_file = FileAccess.open("./settings/client-settings.json", FileAccess.WRITE)
|
|
client_settings_file.store_string(str(client_settings))
|