handle invalid config

This commit is contained in:
Nordup 2024-10-08 23:26:20 +04:00
parent d8baa21e4e
commit 085fbb4769
4 changed files with 6 additions and 1 deletions

View file

@ -3,11 +3,12 @@ class_name ConfigBase
var config: ConfigFile var config: ConfigFile
var config_path: String var config_path: String
var load_result: Error
func _init(path: String) -> void: func _init(path: String) -> void:
config = ConfigFile.new() config = ConfigFile.new()
config.load(path) load_result = config.load(path)
config_path = path config_path = path

View file

@ -17,6 +17,7 @@ func load_gate(config_url: String) -> void:
if config_path.is_empty(): return error(GateEvents.GateError.NOT_FOUND) if config_path.is_empty(): return error(GateEvents.GateError.NOT_FOUND)
c_gate = ConfigGate.new(config_path, config_url) c_gate = ConfigGate.new(config_path, config_url)
if c_gate.load_result != OK: return error(GateEvents.GateError.INVALID_CONFIG)
gate_events.gate_config_loaded_emit(config_url, c_gate) gate_events.gate_config_loaded_emit(config_url, c_gate)
var image_path = await FileDownloader.download(c_gate.image_url) var image_path = await FileDownloader.download(c_gate.image_url)

View file

@ -15,6 +15,7 @@ signal gate_error(code: GateError)
enum GateError enum GateError
{ {
NOT_FOUND, NOT_FOUND,
INVALID_CONFIG,
MISSING_PACK, MISSING_PACK,
MISSING_LIBS MISSING_LIBS
} }

View file

@ -28,6 +28,8 @@ func on_gate_error(code: GateEvents.GateError) -> void:
match code: match code:
GateEvents.GateError.NOT_FOUND: GateEvents.GateError.NOT_FOUND:
set_text("Gate not found") set_text("Gate not found")
GateEvents.GateError.INVALID_CONFIG:
set_text("Invalid gate config")
GateEvents.GateError.MISSING_PACK, GateEvents.GateError.MISSING_LIBS: GateEvents.GateError.MISSING_PACK, GateEvents.GateError.MISSING_LIBS:
set_text("Cannot load gate resources") set_text("Cannot load gate resources")
_: _: