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():
|
|
|
|
var file = File.new()
|
2020-01-19 19:13:57 +00:00
|
|
|
# Calculate MD5SUM
|
2019-12-12 16:32:49 +00:00
|
|
|
file.open("res://assets/Definition/msg.xml", File.READ)
|
|
|
|
var content = file.get_as_text()
|
|
|
|
_msg_md5sum = content.md5_text()
|
|
|
|
file.close()
|
2020-01-19 19:13:57 +00:00
|
|
|
print("[res://assets/Scripts/Definition/msg.gd:open_message_xml] checksum for msg.xml:" + _msg_md5sum)
|
2020-01-24 18:56:51 +00:00
|
|
|
#var NetworkConnexion = preload("res://networkconnexion.gdns").new()
|
|
|
|
var networkconnection = NetworkConnection.new()
|
|
|
|
networkconnection.define_checksum_msg_xml(content.md5_buffer())
|
2020-01-19 19:13:57 +00:00
|
|
|
# Load XML data
|
2020-02-19 21:25:29 +00:00
|
|
|
#_msg_xml.open("res://assets/Definition/msg.xml")
|
2019-12-12 16:32:49 +00:00
|
|
|
|
|
|
|
func is_correct_md5(value):
|
|
|
|
return (_msg_md5sum == value)
|
|
|
|
|
2020-03-30 20:20:59 +00:00
|
|
|
func load_node(_msg_xml, level):
|
2019-12-12 16:32:49 +00:00
|
|
|
var ret = _msg_xml.read()
|
2020-03-30 20:20:59 +00:00
|
|
|
var i
|
|
|
|
var name
|
|
|
|
var index = 0
|
|
|
|
var dico = {}
|
2019-12-12 16:32:49 +00:00
|
|
|
while ret == OK:
|
2020-03-30 20:20:59 +00:00
|
|
|
match _msg_xml.get_node_type():
|
|
|
|
XMLParser.NODE_NONE: # 0
|
|
|
|
# print("NODE_NONE")
|
|
|
|
pass
|
|
|
|
XMLParser.NODE_ELEMENT: # 1
|
2019-12-12 16:32:49 +00:00
|
|
|
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():
|
2020-03-30 20:20:59 +00:00
|
|
|
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
|
2019-12-12 16:32:49 +00:00
|
|
|
ret = _msg_xml.read()
|
2020-03-30 20:20:59 +00:00
|
|
|
return dico
|
|
|
|
|
2020-01-05 15:16:07 +00:00
|
|
|
|
2020-03-30 20:20:59 +00:00
|
|
|
func read_all_node():
|
|
|
|
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():
|
|
|
|
open_message_xml()
|
|
|
|
read_all_node()
|
2020-01-19 19:13:57 +00:00
|
|
|
print("[res://assets/Scripts/Definition/msg.gd] ready")
|
|
|
|
|
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):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
func write_msg(value):
|
2020-01-24 18:56:51 +00:00
|
|
|
pass
|
2020-02-19 21:25:29 +00:00
|
|
|
|
|
|
|
func _exit_tree():
|
|
|
|
pass
|