From 91281d9cb7718298f83c6536342fa7ca7a17ab53 Mon Sep 17 00:00:00 2001 From: Mikhail Aristov <12281487+MikhailAristov@users.noreply.github.com> Date: Sat, 27 Jan 2024 12:40:54 +0100 Subject: [PATCH] make it work --- godot/scenes/faces/face.gd | 28 ++++++++++------------------ godot/scenes/faces/face_curly.tscn | 9 +++++---- godot/scenes/faces/face_moritz.tscn | 7 ++++++- godot/scenes/faces/face_ronald.tscn | 7 ++++++- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/godot/scenes/faces/face.gd b/godot/scenes/faces/face.gd index 7ff43b2..fa93f50 100644 --- a/godot/scenes/faces/face.gd +++ b/godot/scenes/faces/face.gd @@ -2,19 +2,8 @@ extends Node2D @export_enum("angry", "neutral", "happy", "laugh") var expression -@export var sprite_laugh : Sprite2D -@export var sprite_happy : Sprite2D -@export var sprite_neutral : Sprite2D -@export var sprite_unhappy : Sprite2D - var person_controller : AudienceMember - -var expression_map = { - "angry" : sprite_unhappy, - "neutral" : sprite_neutral, - "happy" : sprite_happy, - "laugh" : sprite_laugh, -} +var expression_map = {} const expression_change_speed : float = 1.5 const color_transparent : Color = Color(1, 1, 1, 0) @@ -22,21 +11,24 @@ const color_visible : Color = Color(1, 1, 1, 1) # Called when the node enters the scene tree for the first time. func _ready(): - person_controller = null + expression_map = { + "angry" : $Unhappy, + "neutral" : $Neutral, + "happy" : $Happy, + "laugh" : $Laugh, + } + person_controller = get_node("../../../Person") expression = person_controller.expression reset_face() func _process(_delta): if expression != person_controller.expression: update_face(person_controller.expression) - expression != person_controller.expression + expression = person_controller.expression func reset_face(): for expr in expression_map: - if expr == expression: - expression_map[expr].modulate = color_visible - else: - expression_map[expr].modulate = color_transparent + expression_map[expr].modulate = color_transparent.lerp(color_visible, expr == expression) func update_face(new_expression: String): var tween = get_tree().create_tween().bind_node(self).set_parallel().set_trans(Tween.TRANS_LINEAR) diff --git a/godot/scenes/faces/face_curly.tscn b/godot/scenes/faces/face_curly.tscn index f0866f3..a39faaf 100644 --- a/godot/scenes/faces/face_curly.tscn +++ b/godot/scenes/faces/face_curly.tscn @@ -5,16 +5,17 @@ [ext_resource type="Texture2D" uid="uid://oeljmd05bkvj" path="res://sprites/faces/curly_neutral.png" id="2_54uqk"] [ext_resource type="Texture2D" uid="uid://5iygla17stpm" path="res://sprites/faces/curly_not_amused.png" id="3_2t0h4"] -[node name="FaceCurly" type="Node2D" node_paths=PackedStringArray("sprite_happy", "sprite_neutral", "sprite_unhappy")] +[node name="FaceCurly" type="Node2D"] script = ExtResource("1_vcbhp") -sprite_happy = NodePath("Happy") -sprite_neutral = NodePath("Neutral") -sprite_unhappy = NodePath("Unhappy") [node name="Happy" type="Sprite2D" parent="."] modulate = Color(1, 1, 1, 0) texture = ExtResource("1_7pet0") +[node name="Laugh" type="Sprite2D" parent="."] +modulate = Color(1, 1, 1, 0) +texture = ExtResource("1_7pet0") + [node name="Neutral" type="Sprite2D" parent="."] texture = ExtResource("2_54uqk") diff --git a/godot/scenes/faces/face_moritz.tscn b/godot/scenes/faces/face_moritz.tscn index 10c0885..3e9eadb 100644 --- a/godot/scenes/faces/face_moritz.tscn +++ b/godot/scenes/faces/face_moritz.tscn @@ -5,8 +5,9 @@ [ext_resource type="Texture2D" uid="uid://b0ppuni7v257g" path="res://sprites/faces/moritz_neutral.svg" id="3_s33ae"] [ext_resource type="Texture2D" uid="uid://7tn6ynr07tns" path="res://sprites/faces/moritz_not_amused.svg" id="4_0rss5"] -[node name="FaceMoritz" type="Node2D" node_paths=PackedStringArray("sprite_happy", "sprite_neutral", "sprite_unhappy")] +[node name="FaceMoritz" type="Node2D" node_paths=PackedStringArray("sprite_laugh", "sprite_happy", "sprite_neutral", "sprite_unhappy")] script = ExtResource("1_abnxg") +sprite_laugh = NodePath("Laugh") sprite_happy = NodePath("Happy") sprite_neutral = NodePath("Neutral") sprite_unhappy = NodePath("Unhappy") @@ -15,6 +16,10 @@ sprite_unhappy = NodePath("Unhappy") modulate = Color(1, 1, 1, 0) texture = ExtResource("2_0u1g1") +[node name="Laugh" type="Sprite2D" parent="."] +modulate = Color(1, 1, 1, 0) +texture = ExtResource("2_0u1g1") + [node name="Neutral" type="Sprite2D" parent="."] texture = ExtResource("3_s33ae") diff --git a/godot/scenes/faces/face_ronald.tscn b/godot/scenes/faces/face_ronald.tscn index 0644fc4..80de9bb 100644 --- a/godot/scenes/faces/face_ronald.tscn +++ b/godot/scenes/faces/face_ronald.tscn @@ -5,8 +5,9 @@ [ext_resource type="Texture2D" uid="uid://ijs3777dtv0n" path="res://sprites/faces/ronald_neutral.svg" id="3_ko187"] [ext_resource type="Texture2D" uid="uid://cn7dhkoupxvt8" path="res://sprites/faces/ronald_not_amused.svg" id="4_cf5hk"] -[node name="FaceCurly" type="Node2D" node_paths=PackedStringArray("sprite_happy", "sprite_neutral", "sprite_unhappy")] +[node name="FaceCurly" type="Node2D" node_paths=PackedStringArray("sprite_laugh", "sprite_happy", "sprite_neutral", "sprite_unhappy")] script = ExtResource("1_8nd6f") +sprite_laugh = NodePath("Laugh") sprite_happy = NodePath("Happy") sprite_neutral = NodePath("Neutral") sprite_unhappy = NodePath("Unhappy") @@ -21,3 +22,7 @@ texture = ExtResource("3_ko187") [node name="Unhappy" type="Sprite2D" parent="."] modulate = Color(1, 1, 1, 0) texture = ExtResource("4_cf5hk") + +[node name="Laugh" type="Sprite2D" parent="."] +modulate = Color(1, 1, 1, 0) +texture = ExtResource("2_512yk")