From 77f2e4e5e0933e6d665a75b79b5091e55e2db2f4 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 27 Sep 2024 23:30:27 +0200 Subject: clean up character.gd --- client/player/character/character.gd | 53 ++++++++++++------------------------ 1 file changed, 18 insertions(+), 35 deletions(-) (limited to 'client') diff --git a/client/player/character/character.gd b/client/player/character/character.gd index 66a3435b..b919d27c 100644 --- a/client/player/character/character.gd +++ b/client/player/character/character.gd @@ -59,23 +59,20 @@ func _ready(): 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,13 +82,9 @@ 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 == 51: return set_robot(true) if id < 0: to_customer() id *= -1 @@ -99,33 +92,23 @@ func select_hairstyle(id: int): id = id % hairstyle_count var target = hairstyles.keys()[id] for k in hairstyles.keys(): - if k == target: - hairstyles[k].show() - else: - hairstyles[k].hide() + hairstyles[k].visible = k == target func to_customer(): main.mesh = CUSTOMER_MAIN_MESH tie.queue_free() -func toggle_robot(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 +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" -- cgit v1.2.3-70-g09d2