Add required joke stamina data

This commit is contained in:
Waldemar Tomme 2024-01-27 19:58:18 +01:00
parent 6c617708a0
commit 6628362c8c
3 changed files with 24 additions and 6 deletions

View File

@ -5,27 +5,37 @@ signal button_pressed(joke)
@export_enum("joke_button_1", "joke_button_2", "joke_button_3") var action: String @export_enum("joke_button_1", "joke_button_2", "joke_button_3") var action: String
@export var sprite: Sprite2D @export var sprite: Sprite2D
@export var stamina_categories: Array[int]
@export var type_sprites: Array[Texture2D] @export var type_sprites: Array[Texture2D]
var stamina_label: RichTextLabel
var current_joke: Joke var current_joke: Joke
func _map_action_to_joke(): func _map_action_to_joke_type():
match action: match action:
"joke_button_1": "joke_button_1":
return Joke.new(Joke.JokeType.Joke1) return Joke.JokeType.Joke1
"joke_button_2": "joke_button_2":
return Joke.new(Joke.JokeType.Joke2) return Joke.JokeType.Joke2
"joke_button_3": "joke_button_3":
return Joke.new(Joke.JokeType.Joke3) return Joke.JokeType.Joke3
func _get_joke(type):
return Joke.new(type, stamina_categories[randi_range(0, stamina_categories.size() - 1)])
func _ready(): func _ready():
set_current_joke(_map_action_to_joke()) stamina_label = find_child("StaminaLabel")
set_current_joke(_get_joke(_map_action_to_joke_type()))
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta): func _process(delta):
if Input.is_action_just_pressed(action): if Input.is_action_just_pressed(action):
button_pressed.emit(current_joke) button_pressed.emit(current_joke)
set_current_joke(_get_joke(_map_action_to_joke_type()))
func set_current_joke(joke: Joke): func set_current_joke(joke: Joke):
current_joke = joke current_joke = joke
sprite.texture = type_sprites[joke.type] sprite.texture = type_sprites[joke.type]
stamina_label.text = "%s" % joke.required_stamina
print("stamina: ", joke.required_stamina)

View File

@ -9,7 +9,13 @@
script = ExtResource("1_lofpb") script = ExtResource("1_lofpb")
action = "joke_button_1" action = "joke_button_1"
sprite = NodePath("Sprite2D") sprite = NodePath("Sprite2D")
stamina_categories = Array[int]([1, 5, 10])
type_sprites = Array[Texture2D]([ExtResource("3_26ki8"), ExtResource("2_ivsb5"), ExtResource("4_o1r21")]) type_sprites = Array[Texture2D]([ExtResource("3_26ki8"), ExtResource("2_ivsb5"), ExtResource("4_o1r21")])
[node name="Sprite2D" type="Sprite2D" parent="."] [node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("2_ivsb5") texture = ExtResource("2_ivsb5")
[node name="StaminaLabel" type="RichTextLabel" parent="."]
offset_right = 40.0
offset_bottom = 40.0
text = "xx"

View File

@ -7,6 +7,8 @@ enum JokeType {
} }
var type: JokeType var type: JokeType
var required_stamina: int
func _init(type): func _init(type, required_stamina):
self.type = type self.type = type
self.required_stamina = required_stamina