diff --git a/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/But_History_Page.gd b/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/But_History_Page.gd index df9e529..136da2e 100644 --- a/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/But_History_Page.gd +++ b/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/But_History_Page.gd @@ -7,8 +7,6 @@ tool extends Button onready var game_history_array = get_node("/root/History").historyScreensSingleton.output_history_array -#DKM TEMP: conversion to global -- prior method -#onready var game_history_array = get_node("../../../../../").history_array var current_page = 0 @@ -21,3 +19,4 @@ func _on_But_History_Page_button_up(): history_rows_node.remove_child(history_rows_node.get_child(0)) history_rows_node.add_child(game_history_array[current_page]) + diff --git a/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/CommandProcessor.gd b/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/CommandProcessor.gd index be92184..3804dfd 100644 --- a/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/CommandProcessor.gd +++ b/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/CommandProcessor.gd @@ -18,23 +18,44 @@ func initialize(starting_locale) -> String: current_opt1.grab_focus() return change_room(starting_locale) +#DKM TEMP: this must load from files written by toolset #Function that loads response from the option string chosen func process_command(option: String) -> String: - var optionArr = option.split(" ", false) - if optionArr.size() < 2: - return "Error: no valid command in option!" - if(optionArr[0] == "Go"): - return go(optionArr[1]) - else: - return "Nothing happens! Command word was: " + optionArr[0] + var optCmd_Action = option.split(": ", false) + if (optCmd_Action.size() < 2): + return "Error: no valid command and action in option!" + match optCmd_Action[0]: + "Go": + return go(optCmd_Action[1]) + "Wait": + return "You rest a bit. Now what?" + "Talk": + return talk(optCmd_Action[1]) + "Examine": + return examine(optCmd_Action[1]) + "Scream": + return "You yell :'" + optCmd_Action[1].to_upper() +"'!!" + _: + return "Nothing happens! Command word was: " + optCmd_Action[0] -func go(destination: String) -> String: + + +func go(action: String) -> String: + var destination = action.split(" ", false)[0] if current_locale.exits.keys().has(destination): var change_response = change_room(current_locale.exits[destination]) return PoolStringArray(["You go %s." % destination, change_response]).join("\n") else: return "That is not a valid place to go!" +#DKM TEMP: do an examination dictionary lookup here? +func examine(action: String) -> String: + return action.to_upper() + " looks about how you'd expect. [Dictionary lookup forthcoming]" + +#DKM TEMP: dialog entry needed -- temp +func talk(action: String) -> String: + var target = action.split("to ", false)[0].to_upper() + return target + " has little to say! [Dialog forthcoming]" #Helper: func change_room(new_room: Locale) -> String: diff --git a/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/Game.gd b/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/Game.gd index 0685186..3475548 100644 --- a/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/Game.gd +++ b/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/Game.gd @@ -4,7 +4,7 @@ extends Control -onready var HISTORY_SOURCE = get_node("/root/History").historyScreensSingleton +onready var history_source = get_node("/root/History").historyScreensSingleton #Abstract class we instance when wanted in game as child of HistoryReference const TextOutput = preload("res://UserInterface/Response.tscn") @@ -29,10 +29,11 @@ func _ready() -> void: option_two.show() option_three.show() - create_response("The game has begun! You can select from the available options below.") + var opening_text = "The game has begun! You can select from the available options below. " + #create_response("The game has begun! You can select from the available options below.") var starting_locale_response = command_processor.initialize(locale_manager.get_child(0)) - create_response(starting_locale_response) + create_response(opening_text + " " + starting_locale_response) #Below temporarily takes user selection and appends it to responses; adding new instances # of our input row with an input and response pair for each @@ -53,11 +54,14 @@ func create_response(response_text: String): # history array. func add_response_to_game(response: Control): var response_history = response.duplicate() - var history_page_number = HISTORY_SOURCE.output_history_array.size() + 1 + #DKM TEMP: stopped here, trying to add page number to history text + #var history_page_number = HISTORY_SOURCE.output_history_array.size() + 1 #var history_string = "Page " + str(history_page_number) + "; " - HISTORY_SOURCE.output_history_array.append(response_history) - current_text.remove_child(current_text.get_child(0)) + if(history_source.output_history_array != null): + history_source.output_history_array.append(response_history) + if(current_text.get_child_count() > 0): + current_text.remove_child(current_text.get_child(0)) current_text.add_child(response) diff --git a/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/Game.tscn b/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/Game.tscn index bcf4e9d..9491144 100644 --- a/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/Game.tscn +++ b/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/Game.tscn @@ -32,27 +32,71 @@ script = ExtResource( 4 ) [node name="LocaleManager" type="Node" parent="."] script = ExtResource( 6 ) -[node name="HouseLocale" parent="LocaleManager" instance=ExtResource( 5 )] +[node name="Loc_Boat" parent="LocaleManager" instance=ExtResource( 5 )] margin_left = 41.38 margin_top = -513.913 margin_right = 291.381 margin_bottom = -313.913 -locale_name = "a house." -locale_description = "The house has no windows, but is illuminated by an odd-looking lamp. There is a staircase descending, and a door made of stone. " -option1 = "Go east" -option2 = "Try to open stone door?" -option3 = "Descend the stair in the floor?" +locale_name = "a boat" +locale_description = "You have been shipwrecked." +option1 = "Go: east off the boat" +option2 = "Examine: this boat" +option3 = "Wait: a while" -[node name="HouseOutside" parent="LocaleManager" instance=ExtResource( 5 )] +[node name="Loc_Shore" parent="LocaleManager" instance=ExtResource( 5 )] margin_left = 509.38 margin_top = -512.913 margin_right = 759.381 margin_bottom = -312.913 -locale_name = "outside a house" -locale_description = "You are standing outside a house." -option1 = "Go west" -option2 = "Try to open stone door?" -option3 = "Descend the stair in the floor?" +locale_name = "the beach outside the wrecked ship" +locale_description = "You are standing on a white sand beach beside the crashing waves. You can go west, back onto the boat, or go north into the woods." +option1 = "Go: west to boat" +option2 = "Go: north to woods" +option3 = "Talk: to yourself" + +[node name="Loc_WoodsA1" parent="LocaleManager" instance=ExtResource( 5 )] +margin_left = 510.439 +margin_top = -806.384 +margin_right = 760.44 +margin_bottom = -606.384 +locale_name = "the island woods" +locale_description = "These woods get thick!" +option1 = "Go: south back to the beach" +option2 = "Go: north deeper in" +option3 = "Scream: for help" + +[node name="Loc_WoodsA2" parent="LocaleManager" instance=ExtResource( 5 )] +margin_left = 509.439 +margin_top = -1083.38 +margin_right = 759.44 +margin_bottom = -883.384 +locale_name = "deeper into the woods" +locale_description = "The woods are very thick. You feel like someone -- or something, may be watching you." +option1 = "Go: south back in the direction of the beach" +option2 = "Go: east into the thicket" +option3 = "Examine: the woods" + +[node name="Loc_WoodsA3" parent="LocaleManager" instance=ExtResource( 5 )] +margin_left = 882.439 +margin_top = -1084.38 +margin_right = 1132.44 +margin_bottom = -884.38 +locale_name = "a clearing" +locale_description = "There is a clearing here in the woods. You hear strange sounds, and musics. Something skitters north into the woods" +option1 = "Go: north after the creature" +option2 = "Go: west back into the thicket" +option3 = "Listen: to the sounds" + +[node name="Loc_WoodsA4" parent="LocaleManager" instance=ExtResource( 5 )] +margin_left = 878.439 +margin_top = -1361.38 +margin_right = 1128.44 +margin_bottom = -1161.38 +locale_name = "a cliff top" +locale_description = "The strange animal darts through and vanishes in front of you. There is a serious drop off here, plunging a long ways to rocks below. A figure moves along the rocks, moaning and cursing, grumpily." +option1 = "Go: south back to the clearing " +option2 = "Talk: to the grumpy figure" +option3 = "Examine: the grumpy figure" [node name="Background" type="PanelContainer" parent="."] anchor_right = 1.0 diff --git a/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/LocaleManager.gd b/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/LocaleManager.gd index 96966ea..0917933 100644 --- a/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/LocaleManager.gd +++ b/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/LocaleManager.gd @@ -5,8 +5,13 @@ extends Node +#DKM TEMP: must load from toolset func _ready() -> void: - $HouseLocale.connect_exit("east", $HouseOutside) + $Loc_Boat.connect_exit("east", $Loc_Shore) + $Loc_Shore.connect_exit("north", $Loc_WoodsA1) + $Loc_WoodsA1.connect_exit("north", $Loc_WoodsA2) + $Loc_WoodsA2.connect_exit("east", $Loc_WoodsA3) + $Loc_WoodsA3.connect_exit("north", $Loc_WoodsA4) diff --git a/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/UserInterface/But_Quit.gd b/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/UserInterface/But_Quit.gd index 244ab5b..e33d9a7 100644 --- a/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/UserInterface/But_Quit.gd +++ b/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/UserInterface/But_Quit.gd @@ -4,20 +4,31 @@ extends Button +var history_JSON = "user://history.json" + #DKM TEMP: save history is only here temporarily -- needs to move upstream. func _on_But_Quit_button_up(): - _saveHistory() get_tree().quit() -func _saveHistory() -> void: - var history = get_node("/root/History") - var config = ConfigFile.new() - #DKM TEMP: yet to parse out useful values - var i = 0 - for page in history.historyScreensSingleton.output_history_array: - config.set_value("Temp player history",str(i), page) - i = i+1 - - config.save("user://history.cfg") +#JSON: requires dictionaries: +#func _saveHistory_JSON() -> void: +# var history_screens_arr = get_node("/root/History").historyScreensSingleton.output_history_array +# var file = File.new() +# file.open(history_JSON, File.WRITE) +# file.store_string(to_json(history_screens_arr)) +# +# file.close() +# # #DKM TEMP: +# print("Saved history array size should be: " + str(history_screens_arr.size())) + + +#DKM TEMP: +#tres file: +#func _saveHistory() -> void: +# var history_screens = get_node("/root/History").historyScreensSingleton +# assert(ResourceSaver.save("user://history.tres", history_screens)==OK) +# #DKM TEMP: +# print("Saved history array size: " + str(history_screens.output_history_array.size())) + diff --git a/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/globalScripts/history.gd b/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/globalScripts/history.gd index e3585af..0fe7e5a 100644 --- a/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/globalScripts/history.gd +++ b/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/globalScripts/history.gd @@ -6,25 +6,26 @@ extends Node #DKM TEMP: not a cfg? -var history_file = "user://history.cfg" -var historyScreensSingleton = HistoryScreensTemplateSingleton.new() - +var history_file = "user://history.tres" +var historyScreensSingleton +var testing = false func _ready() -> void: - pass - #load_history_file() + if(testing): + historyScreensSingleton = load_history_file() + if (historyScreensSingleton == null): + historyScreensSingleton = HistoryScreensTemplateSingleton.new() -#Config/ini: -func load_history_file(): - var config = ConfigFile.new() - # Load data from a file. - var err = config.load(history_file) - # If the file didn't load, ignore it. - if err != OK: - return - for player in config.get_sections(): - var history_zero = config.get_value(player, "HistoryArray[0]") - - print("HistoryArray[0] loaded as: " + history_zero) - - historyScreensSingleton.output_history_array[0] = history_zero + #DKM temp: + print("Loaded history array size is: " + str(historyScreensSingleton.output_history_array.size())) + +#DKM TEMP: tres format: +func load_history_file() -> HistoryScreensTemplateSingleton: + if ResourceLoader.exists(history_file): + var history = ResourceLoader.load(history_file) + if history is HistoryScreensTemplateSingleton: + return history + else: return null + else: + return null + diff --git a/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/globalScripts/historyScreensTemplate.gd b/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/globalScripts/historyScreensTemplate.gd index 4d84a32..6ab536f 100644 --- a/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/globalScripts/historyScreensTemplate.gd +++ b/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/globalScripts/historyScreensTemplate.gd @@ -1,7 +1,7 @@ #PLAYERSETTINGSTEMPLATE: # Class for holding history screens +extends Resource -extends Node class_name HistoryScreensTemplateSingleton var output_history_array = Array() diff --git a/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/project.godot b/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/project.godot index 3ccb974..022b318 100644 --- a/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/project.godot +++ b/Godot/MainMenu/GodotUserInterface_Doug/rpgr_gameWork_20220102A/project.godot @@ -9,7 +9,7 @@ config_version=4 _global_script_classes=[ { -"base": "Node", +"base": "Resource", "class": "HistoryScreensTemplateSingleton", "language": "GDScript", "path": "res://globalScripts/historyScreensTemplate.gd"