Load profile data by color

This commit is contained in:
Waldemar Tomme 2024-01-27 16:45:22 +01:00
parent c2192ffdb5
commit 473ed41338
6 changed files with 59 additions and 35 deletions

View File

@ -30,6 +30,8 @@ class ProfileData:
static func get_profile_data(index) -> ProfileData: static func get_profile_data(index) -> ProfileData:
var profiles = [ var profiles = [
ProfileData.new(3, -3, -10, 1, 10, { 0: 1, 1: 0, 2: -0.5 }), ProfileData.new(3, -3, -10, 1, 10, { 0: 1, 1: 0, 2: -0.5 }),
ProfileData.new(3, -3, -10, 1, 10, { 0: -0.5, 1: 1, 2: 0 }),
ProfileData.new(3, -3, -10, 1, 10, { 0: 0, 1: -0.5, 2: 1 }),
] ]
return profiles[index] return profiles[index]

View File

@ -7,7 +7,9 @@ func _ready():
var counter = 0 var counter = 0
var person = preload("res://scenes/crowd/person.tscn") var person = preload("res://scenes/crowd/person.tscn")
for seat in $Seats.get_children(): for seat in $Seats.get_children():
seat.add_child(person.instantiate()) var person_node = person.instantiate()
person_node.color = AudienceMember.get_random_color()
seat.add_child(person_node)
counter += 1 counter += 1
if counter == max_persons: if counter == max_persons:

View File

@ -6,6 +6,7 @@
[node name="Crowd" type="Node2D"] [node name="Crowd" type="Node2D"]
position = Vector2(240, 232) position = Vector2(240, 232)
script = ExtResource("1_y7wyj") script = ExtResource("1_y7wyj")
max_persons = null
[node name="Tables" type="Node" parent="."] [node name="Tables" type="Node" parent="."]

View File

@ -45,12 +45,30 @@ const laughter_duration : float = 2. # seconds
const laughter_bobs : int = 4 const laughter_bobs : int = 4
var laughter_left : float = 0. var laughter_left : float = 0.
func _map_color_to_profile_data_index(color):
match color:
"blue":
return 0
"green":
return 1
"red":
return 2
return 0
static func get_random_color():
var keys = ["blue", "green", "red"]
return keys[randi() % keys.size()]
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
laughter_left = 0. laughter_left = 0.
mood = randf_range(profile.lashout_threshold, profile.happy_threshold) mood = randf_range(profile.lashout_threshold, profile.happy_threshold)
update_expression() update_expression()
var profile_index = _map_color_to_profile_data_index(color)
var profile_data = AudienceProfile.get_profile_data(profile_index)
profile.load_data(profile_data)
if body_shape == null: if body_shape == null:
set_random_body(color) set_random_body(color)

View File

@ -1,20 +1,21 @@
[gd_scene load_steps=5 format=3 uid="uid://cl4fax7fbh2g7"] [gd_scene load_steps=4 format=3 uid="uid://cl4fax7fbh2g7"]
[ext_resource type="Script" path="res://scenes/crowd/person.gd" id="1_mx0i8"] [ext_resource type="Script" path="res://scenes/crowd/person.gd" id="1_mx0i8"]
[ext_resource type="Script" path="res://scenes/crowd/audience_profile.gd" id="2_bsodr"] [ext_resource type="Script" path="res://scenes/crowd/audience_profile.gd" id="2_bsodr"]
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_kbo53"]
size = Vector2(20, 30)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_5rd5b"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_5rd5b"]
[node name="Person" type="Sprite2D" node_paths=PackedStringArray("head", "profile")] [node name="Person" type="Node2D" node_paths=PackedStringArray("head", "body", "profile")]
texture = SubResource("PlaceholderTexture2D_kbo53")
script = ExtResource("1_mx0i8") script = ExtResource("1_mx0i8")
head = NodePath("Head") head = NodePath("Head")
body = NodePath("Body")
profile = NodePath("Profile") profile = NodePath("Profile")
expression = 1 expression = 1
[node name="Body" type="Node2D" parent="."]
position = Vector2(0, 15)
scale = Vector2(0.3, 0.3)
[node name="Head" type="Node2D" parent="."] [node name="Head" type="Node2D" parent="."]
position = Vector2(0, -16) position = Vector2(0, -16)
scale = Vector2(0.3, 0.3) scale = Vector2(0.3, 0.3)

File diff suppressed because one or more lines are too long