2019-12-12 16:32:49 +00:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
# Declare member variables here. Examples:
|
|
|
|
# var a = 2
|
|
|
|
# var b = "text"
|
|
|
|
|
2020-02-19 21:25:29 +00:00
|
|
|
#var _msg_xml = XMLParser.new()
|
2019-12-12 16:32:49 +00:00
|
|
|
var _msg_md5sum
|
2020-01-05 15:16:07 +00:00
|
|
|
var _msg_data = {}
|
2019-12-12 16:32:49 +00:00
|
|
|
|
|
|
|
func open_message_xml():
|
2020-04-10 16:09:06 +00:00
|
|
|
var file = File.new()
|
|
|
|
# Calculate MD5SUM
|
|
|
|
file.open("res://assets/Definition/msg.xml", File.READ)
|
|
|
|
var content = file.get_as_text()
|
|
|
|
_msg_md5sum = content.md5_text()
|
|
|
|
file.close()
|
|
|
|
print("[res://assets/Scripts/Definition/msg.gd:open_message_xml] checksum for msg.xml:" + _msg_md5sum)
|
|
|
|
#var NetworkConnexion = preload("res://networkconnexion.gdns").new()
|
|
|
|
var networkconnection = NetworkConnection.new()
|
|
|
|
networkconnection.define_checksum_msg_xml(content.md5_buffer())
|
|
|
|
# Load XML data
|
|
|
|
#_msg_xml.open("res://assets/Definition/msg.xml")
|
2019-12-12 16:32:49 +00:00
|
|
|
|
|
|
|
func is_correct_md5(value):
|
2020-04-10 16:09:06 +00:00
|
|
|
return (_msg_md5sum == value)
|
2019-12-12 16:32:49 +00:00
|
|
|
|
2020-03-30 20:20:59 +00:00
|
|
|
func load_node(_msg_xml, level):
|
2020-04-10 16:09:06 +00:00
|
|
|
var ret = _msg_xml.read()
|
|
|
|
var i
|
|
|
|
var name
|
|
|
|
var index = 0
|
|
|
|
var dico = {}
|
|
|
|
while ret == OK:
|
|
|
|
match _msg_xml.get_node_type():
|
|
|
|
XMLParser.NODE_NONE: # 0
|
|
|
|
# print("NODE_NONE")
|
|
|
|
pass
|
|
|
|
XMLParser.NODE_ELEMENT: # 1
|
|
|
|
i = 0
|
|
|
|
while i < _msg_xml.get_attribute_count() and _msg_xml.get_attribute_name(i) != "name":
|
|
|
|
i += 1
|
|
|
|
if i < _msg_xml.get_attribute_count():
|
|
|
|
name = _msg_xml.get_attribute_value(i)
|
|
|
|
#print("NODE_ELEMENT level:" + str(level) + " index:" + str(index) + " name:" + name)
|
|
|
|
if not _msg_xml.is_empty():
|
|
|
|
dico[str(index)+":"+name] = load_node(_msg_xml, level+1)
|
|
|
|
else:
|
|
|
|
dico[str(index)+":"+name] = {}
|
|
|
|
index += 1
|
|
|
|
XMLParser.NODE_ELEMENT_END: # 2
|
|
|
|
# print("NODE_ELEMENT_END")
|
|
|
|
# level -= 1
|
|
|
|
return dico
|
|
|
|
XMLParser.NODE_TEXT: # 3
|
|
|
|
#i = 0
|
|
|
|
#while i < _msg_xml.get_attribute_count() and _msg_xml.get_attribute_name(i) != "name":
|
|
|
|
# i += 1
|
|
|
|
#if i < _msg_xml.get_attribute_count():
|
|
|
|
# name = _msg_xml.get_attribute_value(i)
|
|
|
|
# print("NODE_TEXT level:" + str(level) + " name:" + name)
|
|
|
|
pass
|
|
|
|
XMLParser.NODE_COMMENT: # 4
|
|
|
|
# print("NODE_COMMENT")
|
|
|
|
pass
|
|
|
|
XMLParser.NODE_CDATA: # 5
|
|
|
|
# print("NODE_CDATA")
|
|
|
|
pass
|
|
|
|
XMLParser.NODE_UNKNOWN: # 6
|
|
|
|
# print("NODE_UNKNOWN")
|
|
|
|
pass
|
|
|
|
_:
|
|
|
|
# print("NODE_XXXXXXX")
|
|
|
|
pass
|
|
|
|
ret = _msg_xml.read()
|
|
|
|
return dico
|
2020-03-30 20:20:59 +00:00
|
|
|
|
2020-01-05 15:16:07 +00:00
|
|
|
|
2020-03-30 20:20:59 +00:00
|
|
|
func read_all_node():
|
2020-04-10 16:09:06 +00:00
|
|
|
var _msg_xml = XMLParser.new()
|
|
|
|
_msg_xml.open("res://assets/Definition/msg.xml")
|
|
|
|
_msg_xml.seek(0)
|
|
|
|
var dico = load_node(_msg_xml, 0)
|
|
|
|
var ref = ReferentialMessage.new()
|
|
|
|
#print(dico)
|
|
|
|
ref.read_referential(dico)
|
|
|
|
ref.show()
|
|
|
|
#print("---")
|
2019-12-12 16:32:49 +00:00
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
2020-04-10 16:09:06 +00:00
|
|
|
open_message_xml()
|
|
|
|
read_all_node()
|
|
|
|
print("[res://assets/Scripts/Definition/msg.gd] ready")
|
2020-01-19 19:13:57 +00:00
|
|
|
|
2019-12-12 16:32:49 +00:00
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
#func _process(delta):
|
|
|
|
# pass
|
2020-01-19 19:13:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
func read_msg(msgin):
|
2020-04-10 16:09:06 +00:00
|
|
|
pass
|
2020-01-19 19:13:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
func write_msg(value):
|
2020-04-10 16:09:06 +00:00
|
|
|
pass
|
2020-02-19 21:25:29 +00:00
|
|
|
|
|
|
|
func _exit_tree():
|
2020-04-10 16:09:06 +00:00
|
|
|
pass
|