Work on outputting history to file and loading; using singleton history object

WIP regarding history -- saving to file (also INI/Config for now) and loading in; applying this as a singleton.
This commit is contained in:
MacDugRPG
2022-01-30 15:43:22 -05:00
parent 6c9d371734
commit daf96e40f2
50 changed files with 181 additions and 433 deletions

View File

@ -1,7 +1,11 @@
#BUT_HISTORY:
# Unique script attached to the But_History to hide/show history versus
# current game page.
tool
extends Button
onready var game_history_array = get_node("../../../../../").history_array
onready var game_history_array = get_node("/root/History").historyScreensSingleton.output_history_array
var is_history = false
@ -15,7 +19,8 @@ func _on_But_History_button_up():
var option_three = get_node("../../InputArea/VBoxContainer/option3")
if(!is_history):
history_rows_node.add_child(game_history_array[0])
if(game_history_array != null):
history_rows_node.add_child(game_history_array[0])
history_pager_button.show()
history_rows_node.show()
current_text_node.hide()

View File

@ -1,12 +1,23 @@
#BUT_HISTORY_PAGE:
# Unique paging script for showing next page in the history game's history
# array.
tool
extends Button
onready var game_history_array = get_node("../../../../../").history_array
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
func _on_But_History_Page_button_up():
var history_rows_node = get_node("../../GameInfo/HistoryRows")
current_page += 1
if(current_page < game_history_array.size()-1):
current_page += 1
else:
current_page = 0
history_rows_node.remove_child(history_rows_node.get_child(0))
history_rows_node.add_child(game_history_array[current_page])

View File

@ -1,3 +1,6 @@
#COMMAND PROCESSOR:
# Handles player input, including navigation on the map
extends Node
@ -32,14 +35,6 @@ func go(destination: String) -> String:
else:
return "That is not a valid place to go!"
#DKM TEMP: string outputter
func optionResponse(optInt: int) -> String:
if(optInt == 1):
return "First option leads you down a hallway!"
if(optInt == 2):
return "Second option drops you in a pit!"
else:
return "Third option leads you to a hallway full of great food!"
#Helper:
func change_room(new_room: Locale) -> String:

View File

@ -1,16 +1,15 @@
#GAME:
# Controls output space, loading descriptions and options for each locale and
# appending to the history array.
extends Control
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")
const InputResponse = preload("res://UserInterface/InputResponse.tscn")
#TODO: offload this to file
#For storing history selections
var output_history_singleton = OutputHistory.new()
var history_array = output_history_singleton.output_history_array
#TODO: change 'HistoryRows' to better name for current use
var history_screens_array = Array()
onready var command_processor = $CommandProcessor
onready var current_text = $Background/MarginContainer/Rows/GameInfo/CurrentText
@ -35,7 +34,7 @@ func _ready() -> void:
var starting_locale_response = command_processor.initialize(locale_manager.get_child(0))
create_response(starting_locale_response)
#Below temporarily takes user selection and appends it to responses; adding new isntances
#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
func handleUserInput(user_choice: String) -> void:
var input_response = InputResponse.instance()
@ -44,16 +43,20 @@ func handleUserInput(user_choice: String) -> void:
input_response.set_text(inputText, response)
add_response_to_game(input_response)
#Handles input text
func create_response(response_text: String):
var response = TextOutput.instance()
response.text = response_text
add_response_to_game(response)
#Copies the response output to add to both current game output, and the
# history array.
func add_response_to_game(response: Control):
var response_history = response.duplicate()
history_array.append(response_history)
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_string = "Page " + str(history_page_number) + "; "
HISTORY_SOURCE.output_history_array.append(response_history)
current_text.remove_child(current_text.get_child(0))
current_text.add_child(response)

View File

@ -103,7 +103,7 @@ anchor_left = 1.0
anchor_right = 1.0
margin_left = -103.0
margin_bottom = 33.0
text = "History Page"
text = "Next Page"
script = ExtResource( 8 )
__meta__ = {
"_edit_use_anchors_": false

View File

@ -1,3 +1,13 @@
#LOCALE CLASS:
# Template script for the Locale scene; allows for connecting exits, and also
# maintains a visited bool (currently un-used) and takes additional
# options via the GUI:
# 1. Name
# 2. Description
# 3. The 3 option strings available at the location
#
extends PanelContainer
#Allows Godot to handle autocomplete and 'register' class
class_name Locale
@ -10,6 +20,8 @@ export (String) var option1 = "Option 1"
export (String) var option2 = "Option 2"
export (String) var option3 = "Option 3"
var visited = false;
var exits: Dictionary = {}
#DKM TEMP: right now connects both directions, but can make an alt func that c

View File

@ -1,3 +1,7 @@
#LOCALE MANAGER:
# Temporary script holds connections between map items, using the two-way
# connect_exit script available on Location class to wire up map.
extends Node

View File

@ -0,0 +1,34 @@
****************************
README.TXT:
****************************
Author: Doug McCord
Date: 30-Jan-2022
****************************
Intro notes:
I created this to help explain the current Godot file structure I'm using. An
effort has been made to use a consistent organization, though it can most
definitely be improved/made more consistent.
****************************
Project file structure:
Surface Layer:
Game scripts are located at this level, included unique history scripts
and the Game.gd script itself.
_toArchive:
Directory to serve as reference-only; precursor to trash
assets:
Images, fonts, TRES text resource data files
globalScripts:
For project-wide use, or scripts that are not either:
A. attached to a template scene, intended to go with all instances of that, or
B. unique, scene-specific scripts.
Screens:
Additional scenes that are not the main game; includes both .tscn scene files and
their associated scripts.
UserInterface: (note misnomer for text-based game)
Re-useable UI elements and their scripts, such as change-scene, input-response

View File

@ -1,3 +1,6 @@
#MENUSCREEN:
# Script purely to grab focus for tabbing control
extends Control

View File

@ -1,3 +1,8 @@
#SETTINGSINITIALIZE:
# Temp: manual connector between the input fields and the player settings
# singleton.
#
extends Control
onready var psCurrentSettings = get_node("/root/PlayerSettings")

View File

@ -1,4 +1,6 @@
#Tool lets you any code in editor, such as plugins
#BUT_CHANGESCENE:
# Generic template script allowing GUI linking of scenes by button press.
tool
extends Button

View File

@ -1,6 +1,23 @@
#BUT_QUIT:
# Unique script for ending a game. Will additionally perform or call needed
# shut down and close-out functionality.
extends Button
#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")

View File

@ -1,4 +1,7 @@
#Script for settings save button
#BUT_SAVESETTINGS:
# Unique script for saving settings on player settings scene.
#Tool lets you any code in editor, such as plugins
tool
extends Button

View File

@ -0,0 +1,9 @@
tool
extends Button
onready var history_rows = $Background/MarginContainer/Rows/GameInfo/ScrollContainer/HistoryRows
onready var current_text = $Background/MarginContainer/Rows/GameInfo/CurrentText
func _on_But_History_button_up():
print("History button pressed - temp")

View File

@ -0,0 +1,30 @@
#HISTORY:
# Unique handler script for root history singleton. May be adapted for
# history loading and saving functionality
extends Node
#DKM TEMP: not a cfg?
var history_file = "user://history.cfg"
var historyScreensSingleton = HistoryScreensTemplateSingleton.new()
func _ready() -> void:
pass
#load_history_file()
#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

View File

@ -0,0 +1,8 @@
#PLAYERSETTINGSTEMPLATE:
# Class for holding history screens
extends Node
class_name HistoryScreensTemplateSingleton
var output_history_array = Array()

View File

@ -1,6 +1,6 @@
#***PLAYER SETTINGS: a singleton to hold settings in-game. Currently for test
# purposes, initializes a playerSettingsTemplate class, and attempts to
# load in a saved player settings file. This then updates the singleton.
#PLAYER SETTINGS:
# Unique handler script for reading from file or saving to, using the
# playerSettingsTemplateSingleton object.
extends Node

View File

@ -1,3 +1,6 @@
#PLAYERSETTINGSTEMPLATE:
# Class for holding player settings for game purposes.
extends Node
class_name PlayerSettingsTemplate

View File

@ -9,24 +9,24 @@
config_version=4
_global_script_classes=[ {
"base": "Node",
"class": "HistoryScreensTemplateSingleton",
"language": "GDScript",
"path": "res://globalScripts/historyScreensTemplate.gd"
}, {
"base": "PanelContainer",
"class": "Locale",
"language": "GDScript",
"path": "res://Locale.gd"
}, {
"base": "Node",
"class": "OutputHistory",
"language": "GDScript",
"path": "res://globalScripts/outputHistory.gd"
}, {
"base": "Node",
"class": "PlayerSettingsTemplate",
"language": "GDScript",
"path": "res://globalScripts/playerSettingsTemplate.gd"
} ]
_global_script_class_icons={
"HistoryScreensTemplateSingleton": "",
"Locale": "",
"OutputHistory": "",
"PlayerSettingsTemplate": ""
}
@ -39,6 +39,7 @@ config/icon="res://icon.png"
[autoload]
PlayerSettings="*res://globalScripts/playerSettings.gd"
History="*res://globalScripts/history.gd"
[physics]