Проверка и копирование/создание "config/setting_prd_control.json"
This commit is contained in:
@@ -2,6 +2,7 @@ class_name TestPRD
|
|||||||
extends Node
|
extends Node
|
||||||
# Константы
|
# Константы
|
||||||
const CONFIG_PATH = "user://config/setting_prd_control.json"
|
const CONFIG_PATH = "user://config/setting_prd_control.json"
|
||||||
|
const DEFAULT_CONFIG_PATH = "res://config/setting_prd_control.json"
|
||||||
|
|
||||||
const RAY_m5: String = "RAY_m5"
|
const RAY_m5: String = "RAY_m5"
|
||||||
const RAY_5: String = "RAY_5"
|
const RAY_5: String = "RAY_5"
|
||||||
@@ -109,12 +110,29 @@ func _get_ray_key(machine_state: int) -> String:
|
|||||||
return _ray_state_mapping.get(machine_state, "")
|
return _ray_state_mapping.get(machine_state, "")
|
||||||
|
|
||||||
|
|
||||||
|
func _ensure_config_exists() -> bool:
|
||||||
|
DirAccess.make_dir_recursive_absolute("user://config")
|
||||||
|
if FileAccess.file_exists(CONFIG_PATH):
|
||||||
|
return true
|
||||||
|
if not FileAccess.file_exists(DEFAULT_CONFIG_PATH):
|
||||||
|
return false
|
||||||
|
var src := FileAccess.open(DEFAULT_CONFIG_PATH, FileAccess.READ)
|
||||||
|
var dst := FileAccess.open(CONFIG_PATH, FileAccess.WRITE)
|
||||||
|
if src == null or dst == null:
|
||||||
|
return false
|
||||||
|
dst.store_string(src.get_as_text())
|
||||||
|
src.close()
|
||||||
|
dst.close()
|
||||||
|
return true
|
||||||
|
|
||||||
|
|
||||||
func _load_configuration() -> void:
|
func _load_configuration() -> void:
|
||||||
|
if not _ensure_config_exists():
|
||||||
|
return
|
||||||
var config_file = FileAccess.open(CONFIG_PATH, FileAccess.READ)
|
var config_file = FileAccess.open(CONFIG_PATH, FileAccess.READ)
|
||||||
if config_file:
|
if config_file:
|
||||||
var json_text = config_file.get_as_text()
|
var json_text = config_file.get_as_text()
|
||||||
config_file.close()
|
config_file.close()
|
||||||
|
|
||||||
var json = JSON.new()
|
var json = JSON.new()
|
||||||
var parse_result = json.parse(json_text)
|
var parse_result = json.parse(json_text)
|
||||||
if parse_result == OK:
|
if parse_result == OK:
|
||||||
|
|||||||
Reference in New Issue
Block a user