store pharse and show phrase send by server (on console)

This commit is contained in:
AleaJactaEst 2020-05-04 18:56:26 +02:00
parent 739d550043
commit 4bd2f16080
2 changed files with 59 additions and 15 deletions

View file

@ -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

View file

@ -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):