freettrpg/scripts/mapscript.gd
Patrick_Pluto 6b2159b840 Code Refactoring: Part 2
Hopefully final refactoring, offloaded ui scripts to its own global .gd to prevent repetition.
2024-06-19 18:27:40 +02:00

58 lines
1.7 KiB
GDScript

extends Node2D
# Number of players and current player index
var playerAmount = 2
var playerIndex = 0
# Variable to hold the current player's object name
var objectName
# Kick the game off
func _ready():
# Hide character viewer GUI initially
$"../characterViewer".hideGet()
# Start cycling through players
next()
# Function to switch to the next player
func next():
if playerIndex >= playerAmount:
playerIndex = 0
# Construct object name based on player index
objectName = "player%d" % playerIndex
print(objectName) # Print current player's object name (for debugging)
# Start the current player's activity
get_node(objectName).start()
playerIndex += 1 # Move to the next player index
# Function to display statistics, lots of relative links, may change eventually
func stats():
visible = false # Hide game area
$"../characterViewer".visible = true
get_node(objectName).stop()
# Activate back button
$"../back".disabled = false
$"../back".visible = true
# Update player index display in character viewer
$"../characterViewer/ScrollContainer/VBoxContainer".get_child(0).text = str(playerIndex - 1)
$"../characterViewer/ScrollContainer/VBoxContainer".get_child(0).editable = false
# Simulate button press in character viewer (assuming this triggers further actions)
$"../characterViewer"._on_button_pressed()
# Function to restart the node's state
func restart():
visible = true # Show game area
$"../characterViewer".visible = false
get_node(objectName).start()
# Activate back button
$"../back".disabled = true
$"../back".visible = false
# Handler for when the back button is pressed
func _on_back_pressed():
restart() # Gives control back to the current player character