test-client-godot/assets/Scripts/Definition/msg.gd

60 lines
2 KiB
GDScript3
Raw Normal View History

2019-12-12 16:32:49 +00:00
extends Node
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var _msg_xml = XMLParser.new()
var _msg_md5sum
func open_message_xml():
var file = File.new()
file.open("res://assets/Definition/msg.xml", File.READ)
var content = file.get_as_text()
_msg_md5sum = content.md5_text()
file.close()
_msg_xml.open("res://assets/Definition/msg.xml")
print("[msg:open_message_xml] " + _msg_md5sum)
func is_correct_md5(value):
return (_msg_md5sum == value)
func read_all_node():
var i
_msg_xml.seek(0)
var ret = _msg_xml.read()
var branch = ""
var leaf = ""
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
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():
print(_msg_xml.get_attribute_value(i))
branch = _msg_xml.get_attribute_value(i)
"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():
print(branch + ":" + _msg_xml.get_attribute_value(i))
ret = _msg_xml.read()
# Called when the node enters the scene tree for the first time.
func _ready():
open_message_xml()
read_all_node()
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass