bcirpggithubmirror/Godot/NewGame/Doug/bcirpg_newGame_20220227A/gamePlay/Game.gd

100 lines
4.0 KiB
GDScript3
Raw Normal View History

2022-02-27 20:27:22 +00:00
#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")
onready var command_processor = $CommandProcessor
onready var current_text = $Background/MarginContainer/Rows/GameInfo/CurrentText
onready var history_rows = $Background/MarginContainer/Rows/GameInfo/HistoryRows
onready var history_pager = $Background/MarginContainer/Rows/ItemList/But_History_Page
onready var locale_manager = $LocaleManager
onready var option_one = $Background/MarginContainer/Rows/InputArea/VBoxContainer/option1
onready var option_two= $Background/MarginContainer/Rows/InputArea/VBoxContainer/option2
onready var option_three = $Background/MarginContainer/Rows/InputArea/VBoxContainer/option3
#DKM TEMP: this is just a temp file solution for grabbing map/module, will be replaced with DB
# or desired load approach
onready var module_map = "user://temp_map.save"
2022-02-27 20:27:22 +00:00
func _ready() -> void:
load_module()
#DKM TEMP: for testing only -- this will be set in settings
theme=load("res://assets/ui_controlNode_dark_theme.tres")
2022-02-27 20:27:22 +00:00
history_pager.hide()
history_rows.hide()
current_text.show()
option_one.show()
option_two.show()
option_three.show()
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(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
func handleUserInput(user_choice: String) -> void:
var input_response = InputResponse.instance()
var inputText = "User selected: " + user_choice
var response = command_processor.process_command(user_choice)
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()
#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) + "; "
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)
func _on_option1_button_down() -> void:
var option1 = get_node("Background/MarginContainer/Rows/InputArea/VBoxContainer/option1")
handleUserInput(option1.get_text())
func _on_option2_button_down() -> void:
var option2 = get_node("Background/MarginContainer/Rows/InputArea/VBoxContainer/option2")
handleUserInput(option2.get_text())
func _on_option3_button_down() -> void:
var option3 = get_node("Background/MarginContainer/Rows/InputArea/VBoxContainer/option3")
handleUserInput(option3.get_text())
# DKM TEMP: Load module map needs to:
# 1. Add the needed Locale.tsns to the Locale Manager
# 2. Populate their names
# 3. Populate their descriptions
# 4. Populate their options
# 5. Link them directionally
#This will all be part of loading a set game -- built in the toolset. Also
# will need to have dialogues, combats, etc.
func load_module():
var file = File.net()
if file.file_exists(module_map):
file.open(module_map, File.READ)
file.close()