Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,29 @@ extends CharacterBody2D
## Also can look at sides. Defaults to look at left, and scales everything by -1 to look
## at right.

const CEL_SHADING_RECOLOR_MATERIAL = preload("uid://b7kf0suo0sc7k")

## The random seed of this character. Setting another character to the same seed
## will make them identical. Setting it to zero will reset the skin color.
@export var character_seed: int

## The recoloring behavior to use in all sprites.
@export var cel_shading_recolor: CelShadingRecolor

## Where is the character facing. Relative to the character.
@export var look_at_side: Enums.LookAtSide = Enums.LookAtSide.LEFT:
set = _set_look_at_side

## The shader material that will be set to all the sprites, the parts that conform the character.
## If none, a duplicate of the corresponding material will be set.
@export var shader_material: ShaderMaterial

## Click this button to create a random character.
@export_tool_button("Randomize") var randomize_character_button: Callable = randomize_character

## The inner AnimatedSprite2D nodes.
var animated_sprites: Array[AnimatedSprite2D] = []

## The inner nodes that recolor the character skin.
var skin_recolor_nodes: Array[CelShadingRecolor] = []

## The inner nodes that randomize sprites textures.
var random_texture_nodes: Array[RandomTextureSpriteBehavior] = []

Expand All @@ -54,13 +60,8 @@ var _previous_look_at_side: Enums.LookAtSide = Enums.LookAtSide.UNSPECIFIED
func apply_character_randomizations() -> void:
_random_number_generator.seed = character_seed

if skin_recolor_nodes:
var new_skin_medium_color: Color
skin_recolor_nodes[-1].set_random_skin_color(_random_number_generator)
new_skin_medium_color = skin_recolor_nodes[-1].medium_color
for n in skin_recolor_nodes:
n.automatic_shades = true
n.medium_color = new_skin_medium_color
if cel_shading_recolor:
cel_shading_recolor.set_random_skin_color(_random_number_generator)

for n in random_texture_nodes:
n.randomize_texture(_random_number_generator)
Expand All @@ -86,6 +87,14 @@ func randomize_character() -> void:
func _ready() -> void:
_setup_nodes()

if not shader_material:
shader_material = (CEL_SHADING_RECOLOR_MATERIAL as ShaderMaterial).duplicate()

for node in animated_sprites:
node.material = shader_material

cel_shading_recolor.shader_material = shader_material

if character_seed:
apply_character_randomizations()

Expand All @@ -109,15 +118,12 @@ func _traverse(node: Node) -> void:
animated_sprites.append(node)
for child in node.get_children():
_traverse(child)
elif node is CelShadingRecolor:
skin_recolor_nodes.append(node)
elif node is RandomTextureSpriteBehavior:
random_texture_nodes.append(node)


func _setup_nodes() -> void:
animated_sprites = []
skin_recolor_nodes = []
random_texture_nodes = []
for child in get_children():
_traverse(child)
Expand Down
Loading
Loading