From 0482b38e4d98b4c89ebe64f0f643b350253826d2 Mon Sep 17 00:00:00 2001 From: MacDugRPG <57243055+MacDugRPG@users.noreply.github.com> Date: Sun, 18 Feb 2024 15:13:47 -0500 Subject: [PATCH] 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. --- .../UserInterface/But_Quit.gd | 10 ++- .../_userFiles/Module_Demo_002.xml | 86 +++++++++++++++++++ .../_userFiles/game_01.tscn | 16 ++-- .../gamePlay/Game.gd | 39 +++++++++ 4 files changed, 139 insertions(+), 12 deletions(-) create mode 100644 Phase2/Godot_GameCode/_MVP_Game_Demo/Doug/bcirpg_game_mvp_2024_0204A/_userFiles/Module_Demo_002.xml diff --git a/Phase2/Godot_GameCode/_MVP_Game_Demo/Doug/bcirpg_game_mvp_2024_0204A/UserInterface/But_Quit.gd b/Phase2/Godot_GameCode/_MVP_Game_Demo/Doug/bcirpg_game_mvp_2024_0204A/UserInterface/But_Quit.gd index dc65d05..d815389 100644 --- a/Phase2/Godot_GameCode/_MVP_Game_Demo/Doug/bcirpg_game_mvp_2024_0204A/UserInterface/But_Quit.gd +++ b/Phase2/Godot_GameCode/_MVP_Game_Demo/Doug/bcirpg_game_mvp_2024_0204A/UserInterface/But_Quit.gd @@ -12,11 +12,13 @@ var history_JSON = "res://_userFiles/history.json" func _on_But_Quit_button_up(): #Stops execution but broswer window remains get_tree().quit() + + #DKM TEMP: temporarily de-activating while working: #For web: redirect result: - if OS.get_name() == "HTML5": - JavaScript.eval("window.location.href='https://rpgresearch.com/'") - else: - var _openReturn= OS.shell_open("https://rpgresearch.com/") +# if OS.get_name() == "HTML5": +# JavaScript.eval("window.location.href='https://rpgresearch.com/'") +# else: +# var _openReturn= OS.shell_open("https://rpgresearch.com/") #JSON: requires dictionaries: diff --git a/Phase2/Godot_GameCode/_MVP_Game_Demo/Doug/bcirpg_game_mvp_2024_0204A/_userFiles/Module_Demo_002.xml b/Phase2/Godot_GameCode/_MVP_Game_Demo/Doug/bcirpg_game_mvp_2024_0204A/_userFiles/Module_Demo_002.xml new file mode 100644 index 0000000..920d629 --- /dev/null +++ b/Phase2/Godot_GameCode/_MVP_Game_Demo/Doug/bcirpg_game_mvp_2024_0204A/_userFiles/Module_Demo_002.xml @@ -0,0 +1,86 @@ + + + + Boat_000 + ShowText + + 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. + Examine Ship + Climb out through hatch + Play the fiddle! + Rest + Meditate + Boat_002 + Shore_001 + Misc_001 + Misc_002 + Misc_003 + + + Boat_001 + ShowText + + The boat rocks gently. You can leave the boat through a hatch. There is also now a test option. + Examine Ship + Climb out through hatch + Play the fiddle! + Rest + Meditate + Run die roll test + Boat_002 + Shore_001 + Misc_001 + Misc_002 + Misc_003 + Test_000 + + + Boat_002 + ShowText + + The boat is old and wrecked. + Continue + Boat_001 + + + Shore_001 + ShowText + + You've reached the shore! + Return to boat + Boat_001 + + + Misc_001 + ShowText + + You pull a fiddle from your sack and play it, while dancing around merrily. Great fun is had. + Resume your quest + Boat_001 + + + Misc_002 + ShowText + + You pull out a blanket, settle your burdens and take a short rest. + Resume your quest + Boat_001 + + + Misc_003 + ShowText + + 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'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. + Resume your quest + Boat_001 + + + Test_000 + TestDieRollAction + 4 + 6 + NA + NA + Boat_001 + + \ No newline at end of file diff --git a/Phase2/Godot_GameCode/_MVP_Game_Demo/Doug/bcirpg_game_mvp_2024_0204A/_userFiles/game_01.tscn b/Phase2/Godot_GameCode/_MVP_Game_Demo/Doug/bcirpg_game_mvp_2024_0204A/_userFiles/game_01.tscn index 32131cf..bd21ff7 100644 --- a/Phase2/Godot_GameCode/_MVP_Game_Demo/Doug/bcirpg_game_mvp_2024_0204A/_userFiles/game_01.tscn +++ b/Phase2/Godot_GameCode/_MVP_Game_Demo/Doug/bcirpg_game_mvp_2024_0204A/_userFiles/game_01.tscn @@ -1,16 +1,16 @@ [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=2] +[ext_resource path="res://gamePlay/Game.gd" type="Script" id=1] +[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://assets/ui_controlNode_dark_theme.tres" type="Theme" id=4] -[ext_resource path="res://assets/liberation_serif_30pt.tres" type="DynamicFont" id=5] +[ext_resource path="res://assets/liberation_serif_30pt.tres" type="DynamicFont" id=4] +[ext_resource path="res://assets/ui_controlNode_dark_theme.tres" type="Theme" id=5] [node name="Game" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 -theme = ExtResource( 4 ) -script = ExtResource( 2 ) +theme = ExtResource( 5 ) +script = ExtResource( 1 ) [node name="Background" type="PanelContainer" parent="."] anchor_right = 1.0 @@ -46,7 +46,7 @@ rect_min_size = Vector2( 0, 40 ) margin_right = 197.0 margin_bottom = 36.0 text = "More Options" -script = ExtResource( 1 ) +script = ExtResource( 2 ) __meta__ = { "_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 )] margin_right = 108.0 margin_bottom = 36.0 -custom_fonts/font = ExtResource( 5 ) +custom_fonts/font = ExtResource( 4 ) text = "Option 1" align = 0 __meta__ = { diff --git a/Phase2/Godot_GameCode/_MVP_Game_Demo/Doug/bcirpg_game_mvp_2024_0204A/gamePlay/Game.gd b/Phase2/Godot_GameCode/_MVP_Game_Demo/Doug/bcirpg_game_mvp_2024_0204A/gamePlay/Game.gd index c4fd4f0..6803e86 100644 --- a/Phase2/Godot_GameCode/_MVP_Game_Demo/Doug/bcirpg_game_mvp_2024_0204A/gamePlay/Game.gd +++ b/Phase2/Godot_GameCode/_MVP_Game_Demo/Doug/bcirpg_game_mvp_2024_0204A/gamePlay/Game.gd @@ -8,6 +8,8 @@ extends Control #export(String, FILE, "*.json") var module_file_path:String #DKM TEMP: 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 settings = get_node("/root/GlobalSaveInstance").settingsInstance @@ -35,6 +37,7 @@ func _ready() -> void: #DKM TEMP: testing: var moduleDict = loadJSONToDict(module_file_path) + loadXMLDemo(module_file_path_xml) #DKM TEMP: this needs to be refactored to reposition this initialization var i = 0 @@ -88,6 +91,42 @@ func loadJSONToDict(filepath:String)->Dictionary: 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 func create_response(response_text: String): var response = TextOutput.instance()