You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.2 KiB
94 lines
2.2 KiB
extends Node
|
|
|
|
const FILE_PATH = "user://local_storage"
|
|
|
|
const RESOLUTIONS = [Vector2(1920,1080),Vector2(1600,900),Vector2(1366,758),Vector2(1280,720),Vector2(1136,640),Vector2(1024,576)]
|
|
|
|
onready var view_port = get_tree().get_root()
|
|
|
|
|
|
func _ready():
|
|
apply_settings()
|
|
|
|
|
|
func read_config():
|
|
var f = File.new()
|
|
var err = f.open(FILE_PATH, File.READ)
|
|
var config = {}
|
|
if err == OK:
|
|
config = parse_json(f.get_as_text())
|
|
f.close()
|
|
if config == null:
|
|
config = {}
|
|
return config
|
|
|
|
|
|
func write_config(config:Dictionary):
|
|
var f = File.new()
|
|
var err = f.open(FILE_PATH, File.WRITE)
|
|
#var err = f.open_encrypted_with_pass(FILE_PATH, File.WRITE, OS.get_unique_id())
|
|
f.store_string(to_json(config))
|
|
f.close()
|
|
|
|
|
|
func write_value(key:String, value):
|
|
var config = read_config()
|
|
config[key] = value
|
|
write_config(config)
|
|
|
|
|
|
func read_value(key:String, default = null):
|
|
var config = read_config()
|
|
if config.has(key) && config.get(key) != null:
|
|
return config.get(key)
|
|
else:
|
|
return default
|
|
|
|
|
|
func delete_value(key:String):
|
|
var config = read_config()
|
|
config.erase(key)
|
|
write_config(config)
|
|
|
|
|
|
func write_values(new_config:Dictionary):
|
|
var config = read_config()
|
|
for key in new_config:
|
|
config[key] = new_config[key]
|
|
write_config(config)
|
|
|
|
|
|
func read_values():
|
|
return read_config()
|
|
|
|
|
|
func apply_settings():
|
|
apply_locale()
|
|
apply_game_server()
|
|
apply_resolution()
|
|
|
|
|
|
func apply_locale():
|
|
TranslationServer.set_locale(read_value("locale","en"))
|
|
|
|
|
|
func apply_game_server():
|
|
var server_addr = read_value("server_addr")
|
|
if server_addr != null && not server_addr.empty():
|
|
game_server.set_server_addr(server_addr)
|
|
var api_addr = read_value("api_addr")
|
|
if api_addr != null && not api_addr.empty():
|
|
game_server.set_api_addr(api_addr)
|
|
|
|
|
|
func apply_resolution():
|
|
OS.set_window_fullscreen(read_value("fullscreen", true))
|
|
|
|
if OS.is_window_fullscreen():
|
|
var base_size = Vector2(1920, 1080)
|
|
var scale= base_size.x / RESOLUTIONS[read_value("resolution",0)].x
|
|
|
|
get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_2D,SceneTree.STRETCH_ASPECT_EXPAND,base_size,scale)
|
|
else:
|
|
OS.set_window_size(RESOLUTIONS[read_value("resolution",0)])
|
|
get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_VIEWPORT,SceneTree.STRETCH_ASPECT_IGNORE,OS.get_window_size(),1)
|