Updates MVP Game Code for XML

Adds working XML file and initial parser; currently navigating nodes and printing. Will need to transfer this to dict to use JSON code for module loading.
This commit is contained in:
MacDugRPG 2024-02-18 15:13:47 -05:00
parent 1cad1c26d7
commit 0482b38e4d
4 changed files with 139 additions and 12 deletions

View File

@ -12,11 +12,13 @@ var history_JSON = "res://_userFiles/history.json"
func _on_But_Quit_button_up(): func _on_But_Quit_button_up():
#Stops execution but broswer window remains #Stops execution but broswer window remains
get_tree().quit() get_tree().quit()
#DKM TEMP: temporarily de-activating while working:
#For web: redirect result: #For web: redirect result:
if OS.get_name() == "HTML5": # if OS.get_name() == "HTML5":
JavaScript.eval("window.location.href='https://rpgresearch.com/'") # JavaScript.eval("window.location.href='https://rpgresearch.com/'")
else: # else:
var _openReturn= OS.shell_open("https://rpgresearch.com/") # var _openReturn= OS.shell_open("https://rpgresearch.com/")
#JSON: requires dictionaries: #JSON: requires dictionaries:

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<Node_Boat0>
<Id>Boat_000</Id>
<Action>ShowText</Action>
<A_Params></A_Params>
<Text>The game has begun! You may select from the options below. You are in a boat. You have been shipwrecked. You can leave the boat through a hatch.</Text>
<Option_Labels>Examine Ship</Option_Labels>
<Option_Labels>Climb out through hatch</Option_Labels>
<Option_Labels>Play the fiddle!</Option_Labels>
<Option_Labels>Rest</Option_Labels>
<Option_Labels>Meditate</Option_Labels>
<Option_GoTos>Boat_002</Option_GoTos>
<Option_GoTos>Shore_001</Option_GoTos>
<Option_GoTos>Misc_001</Option_GoTos>
<Option_GoTos>Misc_002</Option_GoTos>
<Option_GoTos>Misc_003</Option_GoTos>
</Node_Boat0>
<Node_Boat1>
<Id>Boat_001</Id>
<Action>ShowText</Action>
<A_Params></A_Params>
<Text>The boat rocks gently. You can leave the boat through a hatch. There is also now a test option.</Text>
<Option_Labels>Examine Ship</Option_Labels>
<Option_Labels>Climb out through hatch</Option_Labels>
<Option_Labels>Play the fiddle!</Option_Labels>
<Option_Labels>Rest</Option_Labels>
<Option_Labels>Meditate</Option_Labels>
<Option_Labels>Run die roll test</Option_Labels>
<Option_GoTos>Boat_002</Option_GoTos>
<Option_GoTos>Shore_001</Option_GoTos>
<Option_GoTos>Misc_001</Option_GoTos>
<Option_GoTos>Misc_002</Option_GoTos>
<Option_GoTos>Misc_003</Option_GoTos>
<Option_GoTos>Test_000</Option_GoTos>
</Node_Boat1>
<Node_Boat_002>
<Id>Boat_002</Id>
<Action>ShowText</Action>
<A_Params></A_Params>
<Text>The boat is old and wrecked.</Text>
<Option_Labels>Continue</Option_Labels>
<Option_GoTos>Boat_001</Option_GoTos>
</Node_Boat_002>
<Node_Shore_001>
<Id>Shore_001</Id>
<Action>ShowText</Action>
<A_Params></A_Params>
<Text>You&#x27;ve reached the shore!</Text>
<Option_Labels>Return to boat</Option_Labels>
<Option_GoTos>Boat_001</Option_GoTos>
</Node_Shore_001>
<Node_Misc_001>
<Id>Misc_001</Id>
<Action>ShowText</Action>
<A_Params></A_Params>
<Text>You pull a fiddle from your sack and play it, while dancing around merrily. Great fun is had.</Text>
<Option_Labels>Resume your quest</Option_Labels>
<Option_GoTos>Boat_001</Option_GoTos>
</Node_Misc_001>
<Node_Misc_002>
<Id>Misc_002</Id>
<Action>ShowText</Action>
<A_Params></A_Params>
<Text>You pull out a blanket, settle your burdens and take a short rest.</Text>
<Option_Labels>Resume your quest</Option_Labels>
<Option_GoTos>Boat_001</Option_GoTos>
</Node_Misc_002>
<Node_Misc_003>
<Id>Misc_003</Id>
<Action>ShowText</Action>
<A_Params></A_Params>
<Text>You find a quiet corner on the boat, put down your burden, and feel the rocking of the boat. You rest mind and body, and really I&#x27;m experimenting with options and sizes of them, added via JSON here. So in your meditation you have a vision: a sparrow flies high over the mountains and reveals a castle! After this reverie, you awake.</Text>
<Option_Labels>Resume your quest</Option_Labels>
<Option_GoTos>Boat_001</Option_GoTos>
</Node_Misc_003>
<Node_Test0>
<Id>Test_000</Id>
<Action>TestDieRollAction</Action>
<A_Params>4</A_Params>
<A_Params>6</A_Params>
<Text>NA</Text>
<Option_Labels>NA</Option_Labels>
<Option_GoTos>Boat_001</Option_GoTos>
</Node_Test0>
</root>

View File

@ -1,16 +1,16 @@
[gd_scene load_steps=6 format=2] [gd_scene load_steps=6 format=2]
[ext_resource path="res://gamePlay/But_MoreOptions.gd" type="Script" id=1] [ext_resource path="res://gamePlay/Game.gd" type="Script" id=1]
[ext_resource path="res://gamePlay/Game.gd" type="Script" id=2] [ext_resource path="res://gamePlay/But_MoreOptions.gd" type="Script" id=2]
[ext_resource path="res://gamePlay/But_Option.tscn" type="PackedScene" id=3] [ext_resource path="res://gamePlay/But_Option.tscn" type="PackedScene" id=3]
[ext_resource path="res://assets/ui_controlNode_dark_theme.tres" type="Theme" id=4] [ext_resource path="res://assets/liberation_serif_30pt.tres" type="DynamicFont" id=4]
[ext_resource path="res://assets/liberation_serif_30pt.tres" type="DynamicFont" id=5] [ext_resource path="res://assets/ui_controlNode_dark_theme.tres" type="Theme" id=5]
[node name="Game" type="Control"] [node name="Game" type="Control"]
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
theme = ExtResource( 4 ) theme = ExtResource( 5 )
script = ExtResource( 2 ) script = ExtResource( 1 )
[node name="Background" type="PanelContainer" parent="."] [node name="Background" type="PanelContainer" parent="."]
anchor_right = 1.0 anchor_right = 1.0
@ -46,7 +46,7 @@ rect_min_size = Vector2( 0, 40 )
margin_right = 197.0 margin_right = 197.0
margin_bottom = 36.0 margin_bottom = 36.0
text = "More Options" text = "More Options"
script = ExtResource( 1 ) script = ExtResource( 2 )
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
@ -87,7 +87,7 @@ custom_constants/separation = 5
[node name="option1" type="Button" parent="Background/MarginContainer/Rows/InputArea/ScrollContainer/OptionsContainer" instance=ExtResource( 3 )] [node name="option1" type="Button" parent="Background/MarginContainer/Rows/InputArea/ScrollContainer/OptionsContainer" instance=ExtResource( 3 )]
margin_right = 108.0 margin_right = 108.0
margin_bottom = 36.0 margin_bottom = 36.0
custom_fonts/font = ExtResource( 5 ) custom_fonts/font = ExtResource( 4 )
text = "Option 1" text = "Option 1"
align = 0 align = 0
__meta__ = { __meta__ = {

View File

@ -8,6 +8,8 @@ extends Control
#export(String, FILE, "*.json") var module_file_path:String #export(String, FILE, "*.json") var module_file_path:String
#DKM TEMP: #DKM TEMP:
var module_file_path = "res://_userFiles/Module_Demo_001.json" var module_file_path = "res://_userFiles/Module_Demo_001.json"
#DKM TEMP:
var module_file_path_xml = "res://_userFiles/Module_Demo_002.xml"
onready var history_source = get_node("/root/History").historyScreensSingleton onready var history_source = get_node("/root/History").historyScreensSingleton
onready var settings = get_node("/root/GlobalSaveInstance").settingsInstance onready var settings = get_node("/root/GlobalSaveInstance").settingsInstance
@ -35,6 +37,7 @@ func _ready() -> void:
#DKM TEMP: testing: #DKM TEMP: testing:
var moduleDict = loadJSONToDict(module_file_path) var moduleDict = loadJSONToDict(module_file_path)
loadXMLDemo(module_file_path_xml)
#DKM TEMP: this needs to be refactored to reposition this initialization #DKM TEMP: this needs to be refactored to reposition this initialization
var i = 0 var i = 0
@ -88,6 +91,42 @@ func loadJSONToDict(filepath:String)->Dictionary:
return moduleDict return moduleDict
#DKM TEMP (XML):
func loadXMLDemo(filepath:String):
print("TEST! Trying to open xml at " + filepath)
var test_array = []
var parser = XMLParser.new()
var error = parser.open(filepath)
if error != OK:
print("Error opening XML file ", error)
return
#DKM TEMP: initial testing only:
# else:
# parser.read()
# #Skip encoding:
# parser.skip_section()
# print(parser.get_node_name())
#DKM TEMP: printer; probably don't need the strip_edges, was looking to remove white space.
# Looks like it reads the closing tags, too, which is a bummer.
while true:
if parser.read() != OK:
print("Parser read not okay!")
return
else:
var px = parser.get_node_name()
px.strip_edges(true,true)
if(!px.empty()):
print("Node Named: " + px)
px = parser.get_node_data()
px.strip_edges(true,true)
if(!px.empty()):
print("Data: " + px)
#Handles input text #Handles input text
func create_response(response_text: String): func create_response(response_text: String):
var response = TextOutput.instance() var response = TextOutput.instance()