diff options
Diffstat (limited to 'client/player/character/character.gd')
| -rw-r--r-- | client/player/character/character.gd | 106 |
1 files changed, 54 insertions, 52 deletions
diff --git a/client/player/character/character.gd b/client/player/character/character.gd index 66a3435b..65275549 100644 --- a/client/player/character/character.gd +++ b/client/player/character/character.gd @@ -42,11 +42,16 @@ var current_animation := "idle" @onready var tie = $Main/Tie @onready var knife = $Main/HandRight/Knife -@onready var hairstyles := { - "Brown": $Main/HeadDefault/Hair, - "Blond": $Main/HeadDefault/Hair2, - "E. Parsley": $Main/HeadDefault/Hair3 -} +const NUM_COLORS = 5; +const NUM_HAIRS = 3; +@onready var hairstyles := [$Main/HeadDefault/Hair, $Main/HeadDefault/Hair2, $Main/HeadDefault/Hair3] +var colors = [ + Color(0.204, 0.361, 0.624), + Color(0.568, 0.256, 0.602), + Color(0.575, 0.341, 0.117), + Color(0.3, 0.455, 0.221), + Color(0.101, 0.452, 0.521) +] @onready var head_default: MeshInstance3D = $Main/HeadDefault @onready var head_robot: MeshInstance3D = $Main/HeadRobot @@ -54,28 +59,41 @@ var current_animation := "idle" @onready var step_sounds: PlayRandom = $Steps @onready var boost_sounds: PlayRandom = $Boosts +class ParsedStyle: + var color: int + var hair: int + var robot: bool + var customer: bool + func _init(n: int) -> void: + customer = n < 0 + if customer: n *= -1 + if n == 51: robot = true + else: + hair = n % NUM_HAIRS + color = n / NUM_HAIRS % NUM_COLORS + func pack() -> int: + if robot: return 51 + return (hair + color * NUM_HAIRS) * (-1 if customer else 1) + func _ready(): play_animation("idle") var t := 0.0 func _process(delta): - if walking: - t += delta - main_height_target = default_height + sin(t * WALK_ANIM_SPEED) * WALK_ANIM_STRENGTH - else: - t = 0 + t += delta + if walking: main_height_target = default_height + sin(t * WALK_ANIM_SPEED) * WALK_ANIM_STRENGTH + else: t = 0 main.position.y = main_height_target # Update animation: var next_animation: String - if holding: - next_animation = "hold" - elif cutting: - next_animation = "cut" - elif walking: - next_animation = "walk" - else: - next_animation = "idle" + if holding: next_animation = "hold" + elif cutting: next_animation = "cut" + elif walking: next_animation = "walk" + else: next_animation = "idle" + + if current_animation != next_animation: + play_animation(next_animation) walking_particles.emitting = walking if boosting and walking and not was_boosting: @@ -85,47 +103,31 @@ func _process(delta): boosting_particles.emitting = false was_boosting = boosting and walking - if current_animation != next_animation: - play_animation(next_animation) - -func select_hairstyle(id: int): - if id == 51: - toggle_robot(true) - return - if id < 0: - to_customer() - id *= -1 - var hairstyle_count = hairstyles.keys().size() - id = id % hairstyle_count - var target = hairstyles.keys()[id] - for k in hairstyles.keys(): - if k == target: - hairstyles[k].show() - else: - hairstyles[k].hide() - -func to_customer(): - main.mesh = CUSTOMER_MAIN_MESH - tie.queue_free() +func set_style(id: int): + var p = ParsedStyle.new(id) + set_customer(p.customer) + set_robot(p.robot) + for h in hairstyles: h.hide() + hairstyles[p.hair].show() + $Main.get_active_material(0).albedo_color = colors[p.color] -func toggle_robot(b: bool): +func set_customer(b: bool): if b: - head_robot.show() - head_default.hide() - main.mesh = ROBOT_MAIN_MESH - else: - head_robot.hide() - head_default.show() - main.mesh = DEFAULT_MAIN_MESH + main.mesh = CUSTOMER_MAIN_MESH + tie.queue_free() + else: pass # TODO + +func set_robot(b: bool): + head_robot.visible = b + head_default.visible = not b + main.mesh = ROBOT_MAIN_MESH if b else DEFAULT_MAIN_MESH func play_animation(name_: String): current_animation = name_ hand_animations.play(name_) - if name_ == "walk": - step_sounds.start_autoplay() - else: - step_sounds.stop_autoplay() + if name_ == "walk": step_sounds.start_autoplay() + else: step_sounds.stop_autoplay() knife.visible = name_ == "cut" |