Skip to content

Commit

Permalink
Updates MVP Game Code for Location Hierarchy
Browse files Browse the repository at this point in the history
Updates the following:
1. Modifies Dice Roller to convert passed strings to int
2. Finishes XML read conversion from JSON
3. Adds new testing XML with region/location/space hierarchy
4. Begins modification of the game code to handle location hierarchy
  • Loading branch information
MacDugRPG committed Apr 21, 2024
1 parent 988382d commit 368fdd3
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 37 deletions.
Expand Up @@ -13,12 +13,13 @@ extends PanelContainer
class_name Locale

var locale_name = "Location Name"
var locale_type = "Space"
var locale_description = "This is the description of the location."
var locale_action = "Default action"
var locale_action_params = []
var options_array = []
var destinations_array = []

var contained_subLocations = []

var visited = false;

Expand Down
Expand Up @@ -70,7 +70,7 @@
<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>
<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 XML 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_001>Resume your quest</Option_Labels_001>
<Option_GoTos_001>Boat_001</Option_GoTos_001>
</Location>
Expand Down
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<Region>
<Name>Realm of Tempestia</Name>
<Description>A mystical fantasy landscape, where characters speak often in verse!</Description>
<Location>
<Name>Island of Sorrows</Name>
<Description>Setting for this module</Description>
<Space>
<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_001>Examine Ship</Option_Labels_001>
<Option_Labels_002>Climb out through hatch</Option_Labels_002>
<Option_Labels_003>Play the fiddle!</Option_Labels_003>
<Option_Labels_004>Rest</Option_Labels_004>
<Option_Labels_005>Meditate</Option_Labels_005>
<Option_GoTos_001>Boat_002</Option_GoTos_001>
<Option_GoTos_002>Shore_001</Option_GoTos_002>
<Option_GoTos_003>Misc_001</Option_GoTos_003>
<Option_GoTos_004>Misc_002</Option_GoTos_004>
<Option_GoTos_005>Misc_003</Option_GoTos_005>
</Space>
<Space>
<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_001>Examine Ship</Option_Labels_001>
<Option_Labels_002>Climb out through hatch</Option_Labels_002>
<Option_Labels_003>Play the fiddle!</Option_Labels_003>
<Option_Labels_004>Rest</Option_Labels_004>
<Option_Labels_005>Meditate</Option_Labels_005>
<Option_Labels_006>Run die roll test</Option_Labels_006>
<Option_GoTos_001>Boat_002</Option_GoTos_001>
<Option_GoTos_002>Shore_001</Option_GoTos_002>
<Option_GoTos_003>Misc_001</Option_GoTos_003>
<Option_GoTos_004>Misc_002</Option_GoTos_004>
<Option_GoTos_005>Misc_003</Option_GoTos_005>
<Option_GoTos_006>Test_000</Option_GoTos_006>
</Space>
<Space>
<Id>Boat_002</Id>
<Action>ShowText</Action>
<A_Params></A_Params>
<Text>The boat is old and wrecked.</Text>
<Option_Labels_001>Continue</Option_Labels_001>
<Option_GoTos_001>Boat_001</Option_GoTos_001>
</Space>
<Space>
<Id>Shore_001</Id>
<Action>ShowText</Action>
<A_Params></A_Params>
<Text>You&#x27;ve reached the shore!</Text>
<Option_Labels_001>Return to boat</Option_Labels_001>
<Option_GoTos_001>Boat_001</Option_GoTos_001>
</Space>
<Space>
<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_001>Resume your quest</Option_Labels_001>
<Option_GoTos_001>Boat_001</Option_GoTos_001>
</Space>
<Space>
<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_001>Resume your quest</Option_Labels_001>
<Option_GoTos_001>Boat_001</Option_GoTos_001>
</Space>
<Space>
<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 XML 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_001>Resume your quest</Option_Labels_001>
<Option_GoTos_001>Boat_001</Option_GoTos_001>
</Space>
<Space>
<Id>Test_000</Id>
<Action>TestDieRollAction</Action>
<A_Params>4</A_Params>
<A_Params>6</A_Params>
<Text>NA</Text>
<Option_Labels_001>NA</Option_Labels_001>
<Option_GoTos_001>Boat_001</Option_GoTos_001>
</Space>
</Location>
</Region>
</root>
@@ -1,8 +1,8 @@
[gd_scene load_steps=6 format=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://gamePlay/But_Option.tscn" type="PackedScene" id=2]
[ext_resource path="res://gamePlay/But_MoreOptions.gd" type="Script" 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]

Expand Down Expand Up @@ -46,7 +46,7 @@ rect_min_size = Vector2( 0, 40 )
margin_right = 197.0
margin_bottom = 36.0
text = "More Options"
script = ExtResource( 2 )
script = ExtResource( 3 )
__meta__ = {
"_edit_use_anchors_": false
}
Expand Down Expand Up @@ -84,7 +84,7 @@ margin_right = 108.0
margin_bottom = 36.0
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( 2 )]
margin_right = 108.0
margin_bottom = 36.0
custom_fonts/font = ExtResource( 5 )
Expand Down
Expand Up @@ -9,7 +9,7 @@ extends Control
#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"
var module_file_path_xml = "res://_userFiles/Module_Demo_003_Loc.xml"

onready var history_source = get_node("/root/History").historyScreensSingleton
onready var settings = get_node("/root/GlobalSaveInstance").settingsInstance
Expand All @@ -31,7 +31,7 @@ onready var module_map = "res://_userFiles/temp_map.save"

#Name: nodeArray
#Use: Contains the loaded module. Each array item is a
# Location instance, instantiated from the Location.gd script.
# Location instance, instantiated from the UserInterface/Location.gd script.
var nodeArray

func _ready() -> void:
Expand All @@ -44,7 +44,7 @@ func _ready() -> void:
#DKM TEMP: look at nodearry
print("Temp: Looking at nodeArray:")
for loc in nodeArray:
print ("Location named: " + loc.locale_name)
print ("Space named: " + loc.locale_name)

current_text.show()
#Load character sheet:
Expand All @@ -62,14 +62,56 @@ func loadJSONToDict(filepath:String)->Dictionary:


#DKM TEMP (XML version of JSON, manually imports and fills the nodeArray with locations):
# 4/21/24 (1454): In the middle of this refactor; while we're making connections we're
# just passing out the space array, but this will be fixed when finished to navigate whole
# regions, locations, and so on.
func loadXMLDemo(filepath:String)->Array:
var spaceNode = Locale.new()

var nodeArray_XML
var parser = XMLParser.new()
var error = parser.open(filepath)
var parser_ext = XMLParser.new()
var error = parser_ext.open(filepath)
if error != OK:
print("Error opening XML file ", error)
return nodeArray_XML
return spaceNode.contained_subLocations

while parser_ext.read() == OK:
if parser_ext.get_node_type() == XMLParser.NODE_ELEMENT:
var node_name = parser_ext.get_node_name()

if node_name.strip_edges(true,true).to_upper() == "REGION":
var newNode = Locale.new()
newNode.locale_type = node_name.strip_edges(true,true).to_upper()

while parser_ext.read() == OK:
if parser_ext.get_node_type() == XMLParser.NODE_ELEMENT:
var child_node_name_raw = parser_ext.get_node_name().strip_edges(true,true).to_upper()
var child_node_name = child_node_name_raw
match child_node_name:
"NAME":
parser_ext.read()
if parser_ext.get_node_type() == XMLParser.NODE_TEXT:
var id_node_data = parser_ext.get_node_data()
newNode.locale_name = id_node_data.strip_edges(true,true)
"DESCRIPTION":
parser_ext.read()
if parser_ext.get_node_type() == XMLParser.NODE_TEXT:
var id_node_data = parser_ext.get_node_data()
newNode.locale_description = id_node_data.strip_edges(true,true)
"LOCATION":
var subNode = Locale.new()
subNode.locale_type = child_node_name
newNode.contained_subLocations.append(subNode)
"SPACE":
spaceNode = loadGameNode(parser_ext)
"SCENE":
break
print("Found area of type: " + newNode.locale_type +"; with description: " + newNode.locale_description)

return spaceNode.contained_subLocations

func loadGameNode(parser:XMLParser)->Locale:
var gameNodeLocale = Locale.new()
var nodeArray_XML

#Instantiate counter, initial locations for our module node of locations
var i = 0
Expand All @@ -80,44 +122,104 @@ func loadXMLDemo(filepath:String)->Array:
if parser.get_node_type() == XMLParser.NODE_ELEMENT:
var node_name = parser.get_node_name()

if node_name.strip_edges(true,true).to_upper() == "LOCATION":
if node_name.strip_edges(true,true).to_upper() == "REGION":
var newNode = Locale.new()
newNode.locale_type = node_name.strip_edges(true,true).to_upper()

while parser.read() == OK:
if parser.get_node_type() == XMLParser.NODE_ELEMENT:
var child_node_name_raw = parser.get_node_name().strip_edges(true,true).to_upper()
var child_node_name = child_node_name_raw
match child_node_name:
"NAME":
parser.read()
if parser.get_node_type() == XMLParser.NODE_TEXT:
var id_node_data = parser.get_node_data()
newNode.locale_name = id_node_data.strip_edges(true,true)
"DESCRIPTION":
parser.read()
if parser.get_node_type() == XMLParser.NODE_TEXT:
var id_node_data = parser.get_node_data()
newNode.locale_description = id_node_data.strip_edges(true,true)
"LOCATION":
var subNode = Locale.new()
subNode.locale_type = child_node_name
newNode.contained_subLocations.append(subNode)
"SPACE":
break
"SCENE":
break
print("Found area of type: " + newNode.locale_type +"; with description: " + newNode.locale_description)

if node_name.strip_edges(true,true).to_upper() == "SPACE":
if nodeArray_XML.size() <= i:
print("Adding new node to array")
var newNode = Locale.new()
newNode.locale_type = "SPACE"
nodeArray_XML.append(newNode)
while parser.read() == OK:
if parser.get_node_type() == XMLParser.NODE_ELEMENT:
var child_node_name = parser.get_node_name().strip_edges(true,true).to_upper()
if "OPTION_LABELS" in child_node_name:
var child_node_name_raw = parser.get_node_name().strip_edges(true,true).to_upper()
var child_node_name = child_node_name_raw

#DKM TEMP/TODO: Note that the code currently expects an even number of labels and go-tos,
# and in the correct order. Ideally we split on the underscore, match the numbers
# and handle cases of mismatches (by number mismatch or failure to match numbers of
# labels with numbers of gotos. But for now works as JSON version did.
# I'm using the child_node_name_raw to preserve the full name with suffix number if we
# want to use.
# NOTE: XMLParser throws errors on get node name and type if not within the expected
# type; these are being checked against in the match after read, but not output.
#
if "OPTION_LABELS" in child_node_name_raw:
child_node_name = "OPTION_LABELS"
elif "OPTION_GOTOS" in child_node_name:
elif "OPTION_GOTOS" in child_node_name_raw:
child_node_name = "OPTION_GOTOS"
match child_node_name:
"ID":
parser.read()
var id_node_data = parser.get_node_data()
print("Found Id named: " + id_node_data + "; at i: " + str(i))
if(i < nodeArray_XML.size()):
nodeArray_XML[i].locale_name = id_node_data.strip_edges(true,true)
if parser.get_node_type() == XMLParser.NODE_TEXT:
var id_node_data = parser.get_node_data()
print("Found Id named: " + id_node_data + "; at i: " + str(i))
if(i < nodeArray_XML.size()):
nodeArray_XML[i].locale_name = id_node_data.strip_edges(true,true)
"ACTION":
parser.read()
var action_node_data = parser.get_node_data()
if(i < nodeArray_XML.size()):
nodeArray_XML[i].locale_action = action_node_data.strip_edges(true,true)
if parser.get_node_type() == XMLParser.NODE_TEXT:
var action_node_data = parser.get_node_data()
if(i < nodeArray_XML.size()):
nodeArray_XML[i].locale_action = action_node_data.strip_edges(true,true)
"TEXT":
parser.read()
var descr_node_data = parser.get_node_data()
if(i < nodeArray_XML.size()):
nodeArray_XML[i].locale_description = descr_node_data.strip_edges(true,true)
#"OPTION_LABELS":
#Break on ending tag for current location, increasing count
elif parser.get_node_name().strip_edges(true,true).to_upper() == "LOCATION" && parser.get_node_type() == XMLParser.NODE_ELEMENT_END:
if parser.get_node_type() == XMLParser.NODE_TEXT:
var descr_node_data = parser.get_node_data()
if(i < nodeArray_XML.size()):
nodeArray_XML[i].locale_description = descr_node_data.strip_edges(true,true)
"OPTION_LABELS":
parser.read()
if parser.get_node_type() == XMLParser.NODE_TEXT:
var action_node_data = parser.get_node_data()
if(i < nodeArray_XML.size()):
nodeArray_XML[i].options_array.append(action_node_data.strip_edges(true,true))
"OPTION_GOTOS":
parser.read()
if parser.get_node_type() == XMLParser.NODE_TEXT:
var action_node_data = parser.get_node_data()
if(i < nodeArray_XML.size()):
nodeArray_XML[i].destinations_array.append(action_node_data.strip_edges(true,true))
"A_PARAMS":
parser.read()
if parser.get_node_type() == XMLParser.NODE_TEXT:
var action_node_data = parser.get_node_data()
if(i < nodeArray_XML.size()):
nodeArray_XML[i].locale_action_params.append(action_node_data.strip_edges(true,true))
elif parser.get_node_type() == XMLParser.NODE_ELEMENT_END && parser.get_node_name().strip_edges(true,true).to_upper() == "SPACE":
#DKM_TEMP:
print("Found location break at i: " + str(i))
print("Found space break at i: " + str(i))
i = i+1
break
return nodeArray_XML
gameNodeLocale.contained_subLocations = nodeArray_XML
return gameNodeLocale



Expand Down
Expand Up @@ -5,7 +5,6 @@
extends Node


#DKM TEMP: must load from toolset
func _ready() -> void:
#load_module()
$Loc_Boat.connect_exit("east", $Loc_Shore)
Expand Down
Expand Up @@ -44,12 +44,16 @@ func setDieManager(dice, percent):
#Load the diceInPlay array
func loadData():
for elem in desiredDice:
if elem in validDieTypes:
diceUsed.append(Die.new(elem))
if int(elem) in validDieTypes:
diceUsed.append(Die.new(int(elem)))

#conditional to check if two D10s are being used
#if so, we know that a percentage roll is taking place
if len(desiredDice) == 2 && desiredDice[0] == 10 && desiredDice[1] == 10:
#if len(desiredDice) == 2 && desiredDice[0] == 10 && desiredDice[1] == 10:
# isPercentageRoll = true
#DKM TEMP: this is crashing 4/21/24 with strings coming through unchecked. Not sure what happened to the check that
# was functional here before. TODO on this is type-safe this DieRoller entirely.
if desiredDice.size() == 2 && int(desiredDice[0]) == 10 && int(desiredDice[1]) == 10:
isPercentageRoll = true

#Resets the data in the script
Expand Down

0 comments on commit 368fdd3

Please sign in to comment.