110 lines
2.7 KiB
GDScript3
110 lines
2.7 KiB
GDScript3
extends Node
|
|
|
|
# Declare member variables here. Examples:
|
|
# var a = 2
|
|
# var b = "text"
|
|
|
|
#var _msg_xml = XMLParser.new()
|
|
var _msg_md5sum
|
|
var _msg_data = {}
|
|
|
|
func open_message_xml():
|
|
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")
|
|
|
|
func is_correct_md5(value):
|
|
return (_msg_md5sum == value)
|
|
|
|
func load_node(_msg_xml, level):
|
|
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
|
|
|
|
|
|
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("---")
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
open_message_xml()
|
|
read_all_node()
|
|
print("[res://assets/Scripts/Definition/msg.gd] ready")
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
#func _process(delta):
|
|
# pass
|
|
|
|
|
|
func read_msg(msgin):
|
|
pass
|
|
|
|
|
|
func write_msg(value):
|
|
pass
|
|
|
|
func _exit_tree():
|
|
pass
|