103 lines
3.7 KiB
GDScript3
103 lines
3.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 read_all_node():
|
|
var _msg_xml = XMLParser.new()
|
|
_msg_xml.open("res://assets/Definition/msg.xml")
|
|
|
|
var i
|
|
_msg_xml.seek(0)
|
|
var ret = _msg_xml.read()
|
|
var branch = ""
|
|
var leaf = ""
|
|
var ibranch = 0
|
|
var ileaf = 0
|
|
while ret == OK:
|
|
#print("Node: Name:" + _msg_xml.get_node_name() + ", Type:" + str(_msg_xml.get_node_type()) + ", Data:" + str(_msg_xml.get_node_data()) + ", attribut count:" + str(_msg_xml.get_attribute_count()) )
|
|
#i = 0
|
|
#while i < _msg_xml.get_attribute_count():
|
|
# print(" -- Attribut Name:" + _msg_xml.get_attribute_name(i) + " Value:" + _msg_xml.get_attribute_value(i))
|
|
# i += 1
|
|
if _msg_xml.get_node_type() != XMLParser.NODE_ELEMENT:
|
|
ret = _msg_xml.read()
|
|
continue
|
|
|
|
match _msg_xml.get_node_name():
|
|
"branch":
|
|
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():
|
|
branch = _msg_xml.get_attribute_value(i)
|
|
#print(branch + " " + str(_msg_xml.get_node_type()))
|
|
_msg_data[branch] = {"leaf": {}, "pos": ibranch}
|
|
ibranch += 1
|
|
ileaf = 0
|
|
"leaf":
|
|
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():
|
|
leaf = _msg_xml.get_attribute_value(i)
|
|
#print(branch + ":" + leaf + str(_msg_xml.get_node_type()))
|
|
_msg_data[branch]["leaf"][leaf] = ileaf
|
|
ileaf += 1
|
|
ret = _msg_xml.read()
|
|
#var networkConnexion = NetworkConnexion.new()
|
|
if ProjectSettings.get_setting("khaganat/debug_mode"):
|
|
#print("Branch:" + str(_msg_data.size()))
|
|
var sizebranch = _msg_data.size()
|
|
#NetworkConnexion.get_master_message_description_node().->set_name("Master")
|
|
for key in _msg_data:
|
|
var sizeleaf = _msg_data[key]["leaf"].size()
|
|
print(" " + key + " -> " + str(_msg_data[key]["pos"]) + "/" + str(sizebranch))
|
|
for leaf in _msg_data[key]["leaf"]:
|
|
var opt = str(_msg_data[key]["pos"]) + "/" + str(sizebranch) + " : " + str(_msg_data[key]["leaf"][leaf]) + "/" + str(sizeleaf)
|
|
print(" " + key + ":" + leaf + " -> " + opt)
|
|
|
|
|
|
# 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
|