From 4bd2f160800eed9dfc68c5c118b5899828fe7d17 Mon Sep 17 00:00:00 2001 From: AleaJactaEst Date: Mon, 4 May 2020 18:56:26 +0200 Subject: [PATCH] store pharse and show phrase send by server (on console) --- assets/Scripts/Config/string_manager.gd | 14 +++--- login_scene/message_system.gd | 60 ++++++++++++++++++++----- 2 files changed, 59 insertions(+), 15 deletions(-) diff --git a/assets/Scripts/Config/string_manager.gd b/assets/Scripts/Config/string_manager.gd index 4889ccf..f332d0e 100644 --- a/assets/Scripts/Config/string_manager.gd +++ b/assets/Scripts/Config/string_manager.gd @@ -27,7 +27,7 @@ func write(): var config_file = ConfigFile.new() config_file.set_value("config", "timestamp", self._timestamp) for i in _phrases: - config_file.set_value("phrases", i, _phrases[i]) + config_file.set_value("phrases", String(i), _phrases[i]) config_file.save(_config_filename) func read(): @@ -40,7 +40,7 @@ func read(): need_write = true self._timestamp = config_file.get_value("config", "timestamp", self._timestamp) for i in config_file.get_section_keys("phrases"): - _phrases[i] = config_file.get_value("phrases", i, "") + _phrases[int(i)] = config_file.get_value("phrases", i, "") if need_write: write() @@ -50,16 +50,20 @@ func _init(): func get_timestamp(): return self._timestamp -func check_phases(id): +func check_phrases(id): if _phrases.has(id): return true return false - -func get_phases(id): + +func get_phrases(id): if _phrases.has(id): return _phrases[id] return "" +func put_phrases(id, value): + _phrases[id] = value + write() + func set_timestamp(timestamp): if self._timestamp != timestamp: self._timestamp = timestamp diff --git a/login_scene/message_system.gd b/login_scene/message_system.gd index 1c33654..37a4eb9 100644 --- a/login_scene/message_system.gd +++ b/login_scene/message_system.gd @@ -15,6 +15,51 @@ var _phrases_not_decoded = Array() func _ready(): pass # Replace with function body. +func phrase_send(message): + var decoded = true + var tmp = Array() + for i in range(0,message['string_id'].size()): + var id = message['string_id'][i] + if _string_manager.check_phrases(id) == false: + decoded = false + var command = {'action': Action.ACTION_GENERIC_CODE, 'impulse': ImpulseBase.STRING_MANAGER_STRING_RQ, "string_id": id} + _networkconnection.put_command(command); + else: + tmp.append(_string_manager.get_phrases(id)) + if decoded == false: + _phrases_not_decoded.append(message) + else: + if tmp.size() == 1: + print(tmp[0]) + else: + var template = tmp.pop_front() + print(template % tmp) + +func string_resp(message): + var _phrases_not_decoded_new = Array() + _string_manager.put_phrases(message['string_id'], message['str_utf8']) + for ii in range(0, _phrases_not_decoded.size()): + var decoded = true + var tmp = Array() + var msg = _phrases_not_decoded.pop_front() + for i in range(0,msg['string_id'].size()): + var id = msg['string_id'][i] + if _string_manager.check_phrases(id) == false: + decoded = false + var command = {'action': Action.ACTION_GENERIC_CODE, 'impulse': ImpulseBase.STRING_MANAGER_STRING_RQ, "string_id": id} + _networkconnection.put_command(command); + else: + tmp.append(_string_manager.get_phrases(id)) + if decoded == false: + _phrases_not_decoded_new.append(msg) + else: + if tmp.size() == 1: + print(tmp[0]) + else: + var template = tmp.pop_front() + print(template % tmp) + _phrases_not_decoded = _phrases_not_decoded_new + func analyze_message(message): if message['action'] == Action.ACTION_POSITION_CODE: pass @@ -23,16 +68,11 @@ func analyze_message(message): print(message['timestamp']) _string_manager.set_timestamp(message['timestamp']) elif message['impulse'] == ImpulseBase.STRING_MANAGER_PHRASE_SEND: - if _string_manager.check_phases(message['dyn_id']) == false: - _phrases_not_decoded.append(message) - var i - for i in range(0,message['string_id'].size()): - var id = message['string_id'][i] - print(id) - var command = {'action': Action.ACTION_GENERIC_CODE, 'impulse': ImpulseBase.STRING_MANAGER_STRING_RQ, "string_id": id} - _networkconnection.put_command(command); - #_networkconnection.put_command(command); - return + phrase_send(message) + elif message['impulse'] == ImpulseBase.STRING_MANAGER_STRING_RESP: + string_resp(message) + elif message['impulse'] == ImpulseBase.CONNECTION_USER_CHARS: + pass # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta):