From 7278b68437d727ac3b9bbda67c29f0843831e2be Mon Sep 17 00:00:00 2001 From: Nitwel Date: Thu, 14 Mar 2024 14:14:48 +0100 Subject: [PATCH] use tweens for mini view --- content/system/house/house.gd | 32 +++++++++++++++----------------- content/system/house/house.tscn | 3 --- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/content/system/house/house.gd b/content/system/house/house.gd index d29ea00..2bb2016 100644 --- a/content/system/house/house.gd +++ b/content/system/house/house.gd @@ -6,7 +6,6 @@ const RoomType = preload ("./room/room.gd") @onready var levels = $Levels @onready var collision_shape = $Levels/CollisionShape3D @onready var align_reference = $AlignReference -@onready var animate_timer = $AnimateTimer var fixing_reference: bool = false var editing_room: RoomType = null @@ -15,20 +14,11 @@ var mini_view: bool = false: mini_view = value update_mini_view() -var target_size: float = 1.0 - func _ready(): Store.house.on_loaded.connect(func(): update_house() ) -func _physics_process(delta): - - if animate_timer.is_stopped() == false: - levels.scale.x = lerp(levels.scale.x, target_size, 10.0 * delta) - levels.scale.y = lerp(levels.scale.y, target_size, 10.0 * delta) - levels.scale.z = lerp(levels.scale.z, target_size, 10.0 * delta) - func update_house(): for old_room in get_rooms(0): old_room.queue_free() @@ -205,6 +195,10 @@ func create_entity_in(entity_id: String, room_name: String): func update_mini_view(): collision_shape.disabled = !mini_view + var tween = create_tween() + tween.set_parallel(true) + tween.set_trans(Tween.TRANS_CUBIC) + if mini_view: var aabb = get_level_aabb(0) aabb.position.y = -0.03 @@ -222,15 +216,19 @@ func update_mini_view(): camera_direction.y = 0.0 var target_position = camera_position + camera_direction.normalized() * 0.2 - levels.global_position = target_position - center * 0.1 + var new_position = target_position - center * 0.1 + tween.tween_property(levels, "global_position", new_position, 0.5) + tween.tween_property(levels, "scale", Vector3(0.1, 0.1, 0.1), 0.5) + + for room in get_rooms(0): + room.state_machine.change_to("Mini") else: - levels.position = Vector3(0, 0, 0) + tween.tween_property(levels, "global_position", Vector3(0, 0, 0), 0.5) + tween.tween_property(levels, "scale", Vector3(1.0, 1.0, 1.0), 0.5) + await tween.finished - target_size = 0.1 if mini_view else 1.0 - animate_timer.start() - - for room in get_rooms(0): - room.state_machine.change_to("Mini" if mini_view else "View") + for room in get_rooms(0): + room.state_machine.change_to("View") func edit_reference(): fixing_reference = false diff --git a/content/system/house/house.tscn b/content/system/house/house.tscn index 3e90713..b17ab66 100644 --- a/content/system/house/house.tscn +++ b/content/system/house/house.tscn @@ -25,6 +25,3 @@ lock_rotation = true [node name="AlignReference" parent="." instance=ExtResource("3_e1tcn")] visible = false disabled = true - -[node name="AnimateTimer" type="Timer" parent="."] -one_shot = true