freettrpg/scripts/mapscript.gd
2024-06-18 18:58:47 +02:00

56 lines
1.9 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
# Called when the node is added to the scene
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
func stats():
visible = false # Hide current node (assuming this node should hide itself)
$"../characterViewer".visible = true # Show character viewer GUI
get_node(objectName).stop() # Stop current player's activity
$"../back".disabled = false # Enable back button
$"../back".visible = true # Make back button visible
# 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 current node
$"../characterViewer".visible = false # Hide character viewer GUI
get_node(objectName).start() # Start current player's activity
$"../back".disabled = true # Disable back button
$"../back".visible = false # Hide back button
# Handler for when the back button is pressed
func _on_back_pressed():
restart() # Restart the node's state