Skip to content

Commit 81b667f

Browse files
committed
CharacterRandomizer: Recolor once the whole group of sprites
1 parent 42a350f commit 81b667f

4 files changed

Lines changed: 104 additions & 102 deletions

File tree

scenes/game_elements/characters/components/character_randomizer.gd

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ extends CharacterBody2D
3434
## The inner AnimatedSprite2D nodes.
3535
var animated_sprites: Array[AnimatedSprite2D] = []
3636

37-
## The inner nodes that recolor the character skin.
38-
var skin_recolor_nodes: Array[CelShadingRecolor] = []
39-
4037
## The inner nodes that randomize sprites textures.
4138
var random_texture_nodes: Array[RandomTextureSpriteBehavior] = []
4239

@@ -46,6 +43,12 @@ var _random_number_generator := RandomNumberGenerator.new()
4643

4744
var _previous_look_at_side: Enums.LookAtSide = Enums.LookAtSide.UNSPECIFIED
4845

46+
## Group containing all sprites. For applying a shader to all at once.
47+
@onready var canvas_group: CanvasGroup = %CanvasGroup
48+
49+
## Node to recolor the character.
50+
@onready var cel_shading_recolor: CelShadingRecolor = %CelShadingRecolor
51+
4952

5053
## Randomize the skin color and textures of the character.
5154
## [br][br]
@@ -54,13 +57,7 @@ var _previous_look_at_side: Enums.LookAtSide = Enums.LookAtSide.UNSPECIFIED
5457
func apply_character_randomizations() -> void:
5558
_random_number_generator.seed = character_seed
5659

57-
if skin_recolor_nodes:
58-
var new_skin_medium_color: Color
59-
skin_recolor_nodes[-1].set_random_skin_color(_random_number_generator)
60-
new_skin_medium_color = skin_recolor_nodes[-1].medium_color
61-
for n in skin_recolor_nodes:
62-
n.automatic_shades = true
63-
n.medium_color = new_skin_medium_color
60+
cel_shading_recolor.set_random_skin_color(_random_number_generator)
6461

6562
for n in random_texture_nodes:
6663
n.randomize_texture(_random_number_generator)
@@ -109,17 +106,14 @@ func _traverse(node: Node) -> void:
109106
animated_sprites.append(node)
110107
for child in node.get_children():
111108
_traverse(child)
112-
elif node is CelShadingRecolor:
113-
skin_recolor_nodes.append(node)
114109
elif node is RandomTextureSpriteBehavior:
115110
random_texture_nodes.append(node)
116111

117112

118113
func _setup_nodes() -> void:
119114
animated_sprites = []
120-
skin_recolor_nodes = []
121115
random_texture_nodes = []
122-
for child in get_children():
116+
for child in canvas_group.get_children():
123117
_traverse(child)
124118

125119

scenes/game_elements/characters/components/character_randomizer_test.tscn

Lines changed: 60 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,158 +5,158 @@
55
[ext_resource type="Script" uid="uid://du8wfijr35r35" path="res://scenes/game_elements/props/interact_area/interact_area.gd" id="3_p47ir"]
66
[ext_resource type="Script" uid="uid://edcifob4jc4s" path="res://scenes/game_logic/talk_behavior.gd" id="4_qr3fq"]
77
[ext_resource type="PackedScene" uid="uid://iu2q66clupc6" path="res://scenes/game_elements/characters/player/player.tscn" id="5_jsubs"]
8-
[ext_resource type="Texture2D" uid="uid://y3xp5d8timm0" path="res://scenes/game_elements/characters/npcs/components/townie-legs_002.dy_-6.png" id="6_bonk8"]
8+
[ext_resource type="Texture2D" uid="uid://daymgmvarx2ew" path="res://scenes/game_elements/characters/npcs/components/townie-legs_003.dy_-12.png" id="6_bonk8"]
99
[ext_resource type="SpriteFrames" uid="uid://07di3updrwh0" path="res://scenes/game_elements/characters/components/sprite_frames/storyweaver_purple.tres" id="6_hfrhi"]
10-
[ext_resource type="Texture2D" uid="uid://0t1eptqlcb8t" path="res://scenes/game_elements/characters/npcs/components/townie-body_001.png" id="7_22pcm"]
10+
[ext_resource type="Texture2D" uid="uid://iq21xkckyvi1" path="res://scenes/game_elements/characters/npcs/components/townie-body_003.dx_-4.dy_-16.png" id="7_22pcm"]
1111
[ext_resource type="Resource" uid="uid://n5gf3o4mmxlu" path="res://scenes/game_elements/characters/components/character_randomizer_test.dialogue" id="8_qr3fq"]
1212
[ext_resource type="Texture2D" uid="uid://csxn66qqmfcqu" path="res://scenes/game_elements/characters/npcs/components/townie-head_004.png" id="8_tokus"]
1313
[ext_resource type="Texture2D" uid="uid://bucvumn3fkygf" path="res://scenes/game_elements/characters/npcs/components/townie-hair_001.png" id="9_htwo5"]
1414

1515
[sub_resource type="RectangleShape2D" id="RectangleShape2D_22pcm"]
1616
size = Vector2(52, 50)
1717

18-
[sub_resource type="AtlasTexture" id="AtlasTexture_jsa2b"]
18+
[sub_resource type="AtlasTexture" id="AtlasTexture_tokus"]
1919
atlas = ExtResource("6_bonk8")
2020
region = Rect2(0, 0, 96, 96)
2121

22-
[sub_resource type="AtlasTexture" id="AtlasTexture_kpq1x"]
22+
[sub_resource type="AtlasTexture" id="AtlasTexture_htwo5"]
2323
atlas = ExtResource("6_bonk8")
2424
region = Rect2(96, 0, 96, 96)
2525

26-
[sub_resource type="AtlasTexture" id="AtlasTexture_y666u"]
26+
[sub_resource type="AtlasTexture" id="AtlasTexture_jsa2b"]
2727
atlas = ExtResource("6_bonk8")
2828
region = Rect2(192, 0, 96, 96)
2929

30-
[sub_resource type="AtlasTexture" id="AtlasTexture_l7t43"]
30+
[sub_resource type="AtlasTexture" id="AtlasTexture_kpq1x"]
3131
atlas = ExtResource("6_bonk8")
3232
region = Rect2(96, 0, 96, 96)
3333

34-
[sub_resource type="SpriteFrames" id="SpriteFrames_n7dtb"]
34+
[sub_resource type="SpriteFrames" id="SpriteFrames_jsa2b"]
3535
resource_local_to_scene = true
3636
animations = [{
3737
"frames": [{
3838
"duration": 10.0,
39-
"texture": SubResource("AtlasTexture_jsa2b")
39+
"texture": SubResource("AtlasTexture_tokus")
4040
}, {
4141
"duration": 1.0,
42-
"texture": SubResource("AtlasTexture_kpq1x")
42+
"texture": SubResource("AtlasTexture_htwo5")
4343
}, {
4444
"duration": 8.0,
45-
"texture": SubResource("AtlasTexture_y666u")
45+
"texture": SubResource("AtlasTexture_jsa2b")
4646
}, {
4747
"duration": 1.0,
48-
"texture": SubResource("AtlasTexture_l7t43")
48+
"texture": SubResource("AtlasTexture_kpq1x")
4949
}],
5050
"loop": true,
5151
"name": &"idle",
5252
"speed": 10.0
5353
}]
5454

55-
[sub_resource type="AtlasTexture" id="AtlasTexture_ny4dp"]
55+
[sub_resource type="AtlasTexture" id="AtlasTexture_y666u"]
5656
atlas = ExtResource("7_22pcm")
5757
region = Rect2(0, 0, 96, 96)
5858

59-
[sub_resource type="AtlasTexture" id="AtlasTexture_e0ffc"]
59+
[sub_resource type="AtlasTexture" id="AtlasTexture_l7t43"]
6060
atlas = ExtResource("7_22pcm")
6161
region = Rect2(96, 0, 96, 96)
6262

63-
[sub_resource type="AtlasTexture" id="AtlasTexture_04pia"]
63+
[sub_resource type="AtlasTexture" id="AtlasTexture_n7dtb"]
6464
atlas = ExtResource("7_22pcm")
6565
region = Rect2(192, 0, 96, 96)
6666

67-
[sub_resource type="AtlasTexture" id="AtlasTexture_1uba5"]
67+
[sub_resource type="AtlasTexture" id="AtlasTexture_ny4dp"]
6868
atlas = ExtResource("7_22pcm")
6969
region = Rect2(96, 0, 96, 96)
7070

71-
[sub_resource type="SpriteFrames" id="SpriteFrames_n5uef"]
71+
[sub_resource type="SpriteFrames" id="SpriteFrames_ny4dp"]
7272
resource_local_to_scene = true
7373
animations = [{
7474
"frames": [{
7575
"duration": 10.0,
76-
"texture": SubResource("AtlasTexture_ny4dp")
76+
"texture": SubResource("AtlasTexture_y666u")
7777
}, {
7878
"duration": 1.0,
79-
"texture": SubResource("AtlasTexture_e0ffc")
79+
"texture": SubResource("AtlasTexture_l7t43")
8080
}, {
8181
"duration": 8.0,
82-
"texture": SubResource("AtlasTexture_04pia")
82+
"texture": SubResource("AtlasTexture_n7dtb")
8383
}, {
8484
"duration": 1.0,
85-
"texture": SubResource("AtlasTexture_1uba5")
85+
"texture": SubResource("AtlasTexture_ny4dp")
8686
}],
8787
"loop": true,
8888
"name": &"idle",
8989
"speed": 10.0
9090
}]
9191

92-
[sub_resource type="AtlasTexture" id="AtlasTexture_7wp2w"]
92+
[sub_resource type="AtlasTexture" id="AtlasTexture_e0ffc"]
9393
atlas = ExtResource("8_tokus")
9494
region = Rect2(0, 0, 96, 96)
9595

96-
[sub_resource type="AtlasTexture" id="AtlasTexture_7qyur"]
96+
[sub_resource type="AtlasTexture" id="AtlasTexture_04pia"]
9797
atlas = ExtResource("8_tokus")
9898
region = Rect2(96, 0, 96, 96)
9999

100-
[sub_resource type="AtlasTexture" id="AtlasTexture_fe8ke"]
100+
[sub_resource type="AtlasTexture" id="AtlasTexture_1uba5"]
101101
atlas = ExtResource("8_tokus")
102102
region = Rect2(192, 0, 96, 96)
103103

104-
[sub_resource type="AtlasTexture" id="AtlasTexture_ahibj"]
104+
[sub_resource type="AtlasTexture" id="AtlasTexture_n5uef"]
105105
atlas = ExtResource("8_tokus")
106106
region = Rect2(96, 0, 96, 96)
107107

108-
[sub_resource type="SpriteFrames" id="SpriteFrames_05rux"]
108+
[sub_resource type="SpriteFrames" id="SpriteFrames_7wp2w"]
109109
resource_local_to_scene = true
110110
animations = [{
111111
"frames": [{
112112
"duration": 10.0,
113-
"texture": SubResource("AtlasTexture_7wp2w")
113+
"texture": SubResource("AtlasTexture_e0ffc")
114114
}, {
115115
"duration": 1.0,
116-
"texture": SubResource("AtlasTexture_7qyur")
116+
"texture": SubResource("AtlasTexture_04pia")
117117
}, {
118118
"duration": 8.0,
119-
"texture": SubResource("AtlasTexture_fe8ke")
119+
"texture": SubResource("AtlasTexture_1uba5")
120120
}, {
121121
"duration": 1.0,
122-
"texture": SubResource("AtlasTexture_ahibj")
122+
"texture": SubResource("AtlasTexture_n5uef")
123123
}],
124124
"loop": true,
125125
"name": &"idle",
126126
"speed": 10.0
127127
}]
128128

129-
[sub_resource type="AtlasTexture" id="AtlasTexture_ue7og"]
129+
[sub_resource type="AtlasTexture" id="AtlasTexture_7wp2w"]
130130
atlas = ExtResource("9_htwo5")
131131
region = Rect2(0, 0, 96, 96)
132132

133-
[sub_resource type="AtlasTexture" id="AtlasTexture_aqb5i"]
133+
[sub_resource type="AtlasTexture" id="AtlasTexture_7qyur"]
134134
atlas = ExtResource("9_htwo5")
135135
region = Rect2(96, 0, 96, 96)
136136

137-
[sub_resource type="AtlasTexture" id="AtlasTexture_fj012"]
137+
[sub_resource type="AtlasTexture" id="AtlasTexture_fe8ke"]
138138
atlas = ExtResource("9_htwo5")
139139
region = Rect2(192, 0, 96, 96)
140140

141-
[sub_resource type="AtlasTexture" id="AtlasTexture_3lql5"]
141+
[sub_resource type="AtlasTexture" id="AtlasTexture_ahibj"]
142142
atlas = ExtResource("9_htwo5")
143143
region = Rect2(96, 0, 96, 96)
144144

145-
[sub_resource type="SpriteFrames" id="SpriteFrames_ft3li"]
145+
[sub_resource type="SpriteFrames" id="SpriteFrames_ue7og"]
146146
resource_local_to_scene = true
147147
animations = [{
148148
"frames": [{
149149
"duration": 10.0,
150-
"texture": SubResource("AtlasTexture_ue7og")
150+
"texture": SubResource("AtlasTexture_7wp2w")
151151
}, {
152152
"duration": 1.0,
153-
"texture": SubResource("AtlasTexture_aqb5i")
153+
"texture": SubResource("AtlasTexture_7qyur")
154154
}, {
155155
"duration": 8.0,
156-
"texture": SubResource("AtlasTexture_fj012")
156+
"texture": SubResource("AtlasTexture_fe8ke")
157157
}, {
158158
"duration": 1.0,
159-
"texture": SubResource("AtlasTexture_3lql5")
159+
"texture": SubResource("AtlasTexture_ahibj")
160160
}],
161161
"loop": true,
162162
"name": &"idle",
@@ -179,6 +179,7 @@ tile_set = ExtResource("1_ea78s")
179179
y_sort_enabled = true
180180

181181
[node name="Townie" parent="OnTheGround" unique_id=632242166 instance=ExtResource("2_2g5xe")]
182+
material = null
182183
position = Vector2(225, 152)
183184
character_seed = 138976455
184185

@@ -204,36 +205,32 @@ wait_time = 3.0
204205
autostart = true
205206

206207
[node name="Townie2" parent="OnTheGround" unique_id=645401180 instance=ExtResource("2_2g5xe")]
208+
material = null
207209
position = Vector2(415, 233)
208210

209-
[node name="AnimatedSprite2DLegs" parent="OnTheGround/Townie2" index="1" unique_id=385222684]
210-
sprite_frames = SubResource("SpriteFrames_n7dtb")
211+
[node name="CanvasGroup" parent="OnTheGround/Townie2" index="1" unique_id=693191174]
212+
instance_shader_parameters/shade_high_new = Color(0.30876952, 0.6945196, 0.81842786, 1)
213+
instance_shader_parameters/shade_low_new = Color(0.108769536, 0.49451956, 0.6184279, 1)
214+
instance_shader_parameters/shade_medium_new = Color(0.13596192, 0.61814946, 0.7730348, 1)
211215

212-
[node name="AnimatedSprite2DBody" parent="OnTheGround/Townie2/AnimatedSprite2DLegs" index="1" unique_id=2098127821]
213-
instance_shader_parameters/shade_high_new = Color(0.20000307, 0.7389693, 0.9595597, 1)
214-
instance_shader_parameters/shade_low_new = Color(3.080368e-06, 0.53896934, 0.7595597, 1)
215-
instance_shader_parameters/shade_medium_new = Color(3.85046e-06, 0.67371166, 0.9494496, 1)
216-
position = Vector2(0, -6)
217-
sprite_frames = SubResource("SpriteFrames_n5uef")
216+
[node name="AnimatedSprite2DLegs" parent="OnTheGround/Townie2/CanvasGroup" index="0" unique_id=385222684]
217+
sprite_frames = SubResource("SpriteFrames_jsa2b")
218218

219-
[node name="CelShadingRecolor" parent="OnTheGround/Townie2/AnimatedSprite2DLegs/AnimatedSprite2DBody" index="0" unique_id=1327679537]
220-
medium_color = Color(3.85046e-06, 0.67371166, 0.9494496, 1)
221-
high_color = Color(0.20000307, 0.7389693, 0.9595597, 1)
222-
low_color = Color(3.080368e-06, 0.53896934, 0.7595597, 1)
219+
[node name="AnimatedSprite2DBody" parent="OnTheGround/Townie2/CanvasGroup/AnimatedSprite2DLegs" index="1" unique_id=2098127821]
220+
position = Vector2(0, -12)
221+
sprite_frames = SubResource("SpriteFrames_ny4dp")
223222

224-
[node name="AnimatedSprite2DHead" parent="OnTheGround/Townie2/AnimatedSprite2DLegs/AnimatedSprite2DBody" index="2" unique_id=421503015]
225-
instance_shader_parameters/shade_high_new = Color(0.20000307, 0.7389693, 0.9595597, 1)
226-
instance_shader_parameters/shade_low_new = Color(3.080368e-06, 0.53896934, 0.7595597, 1)
227-
instance_shader_parameters/shade_medium_new = Color(3.85046e-06, 0.67371166, 0.9494496, 1)
228-
sprite_frames = SubResource("SpriteFrames_05rux")
223+
[node name="AnimatedSprite2DHead" parent="OnTheGround/Townie2/CanvasGroup/AnimatedSprite2DLegs/AnimatedSprite2DBody" index="1" unique_id=421503015]
224+
position = Vector2(-4, -16)
225+
sprite_frames = SubResource("SpriteFrames_7wp2w")
229226

230-
[node name="CelShadingRecolor" parent="OnTheGround/Townie2/AnimatedSprite2DLegs/AnimatedSprite2DBody/AnimatedSprite2DHead" index="0" unique_id=2000765677]
231-
medium_color = Color(3.85046e-06, 0.67371166, 0.9494496, 1)
232-
high_color = Color(0.20000307, 0.7389693, 0.9595597, 1)
233-
low_color = Color(3.080368e-06, 0.53896934, 0.7595597, 1)
227+
[node name="AnimatedSprite2DHair" parent="OnTheGround/Townie2/CanvasGroup/AnimatedSprite2DLegs/AnimatedSprite2DBody/AnimatedSprite2DHead" index="1" unique_id=2123781958]
228+
sprite_frames = SubResource("SpriteFrames_ue7og")
234229

235-
[node name="AnimatedSprite2DHair" parent="OnTheGround/Townie2/AnimatedSprite2DLegs/AnimatedSprite2DBody/AnimatedSprite2DHead" index="2" unique_id=2123781958]
236-
sprite_frames = SubResource("SpriteFrames_ft3li")
230+
[node name="CelShadingRecolor" parent="OnTheGround/Townie2/CanvasGroup" index="1" unique_id=1327679537]
231+
medium_color = Color(0.13596192, 0.61814946, 0.7730348, 1)
232+
high_color = Color(0.30876952, 0.6945196, 0.81842786, 1)
233+
low_color = Color(0.108769536, 0.49451956, 0.6184279, 1)
237234

238235
[node name="InteractArea" type="Area2D" parent="OnTheGround/Townie2" unique_id=1760778420]
239236
visible = false
@@ -253,6 +250,7 @@ title = "townie_2"
253250
interact_area = NodePath("../InteractArea")
254251

255252
[node name="Townie3" parent="OnTheGround" unique_id=1154886998 instance=ExtResource("2_2g5xe")]
253+
material = null
256254
position = Vector2(481, 101)
257255
scale = Vector2(-1, 1)
258256
character_seed = 132923783
@@ -276,6 +274,7 @@ title = "townie_3"
276274
interact_area = NodePath("../InteractArea")
277275

278276
[node name="Townie4" parent="OnTheGround" unique_id=1799136561 instance=ExtResource("2_2g5xe")]
277+
material = null
279278
position = Vector2(523, 130)
280279
scale = Vector2(-1, 1)
281280
character_seed = 1246173203

0 commit comments

Comments
 (0)