Tough_Crowd/godot/scenes/Joke Button.gd

40 lines
1.0 KiB
GDScript3
Raw Permalink Normal View History

2024-01-27 10:38:38 +00:00
extends Node2D
2024-01-27 11:36:06 +00:00
signal button_pressed(joke)
2024-01-27 10:38:38 +00:00
@export_enum("joke_button_1", "joke_button_2", "joke_button_3") var action: String
2024-01-27 12:35:14 +00:00
@export var sprite: Sprite2D
@export var type_sprites: Array[Texture2D]
2024-01-27 10:38:38 +00:00
2024-01-27 18:58:18 +00:00
var stamina_label: RichTextLabel
2024-01-27 10:38:38 +00:00
var current_joke: Joke
2024-01-27 18:58:18 +00:00
func _map_action_to_joke_type():
2024-01-27 12:35:14 +00:00
match action:
"joke_button_1":
2024-01-27 18:58:18 +00:00
return Joke.JokeType.Joke1
2024-01-27 12:35:14 +00:00
"joke_button_2":
2024-01-27 18:58:18 +00:00
return Joke.JokeType.Joke2
2024-01-27 12:35:14 +00:00
"joke_button_3":
2024-01-27 18:58:18 +00:00
return Joke.JokeType.Joke3
func _get_joke(type):
return Joke.get_random_joke(type)
2024-01-27 10:38:38 +00:00
func _ready():
2024-01-27 18:58:18 +00:00
stamina_label = find_child("StaminaLabel")
set_current_joke(_get_joke(_map_action_to_joke_type()))
2024-01-27 10:38:38 +00:00
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if Input.is_action_just_pressed(action):
2024-01-27 11:36:06 +00:00
button_pressed.emit(current_joke)
2024-01-27 18:58:18 +00:00
set_current_joke(_get_joke(_map_action_to_joke_type()))
2024-01-27 12:35:14 +00:00
func set_current_joke(joke: Joke):
current_joke = joke
sprite.texture = type_sprites[joke.type]
2024-01-27 18:58:18 +00:00
stamina_label.text = "%s" % joke.required_stamina
print("stamina: ", joke.required_stamina)