diff options
author | tpart <tpart120@proton.me> | 2025-09-27 17:31:36 +0200 |
---|---|---|
committer | tpart <tpart120@proton.me> | 2025-09-27 17:31:36 +0200 |
commit | d832426d26a0368e7d7e0e03fadaf72828348fe7 (patch) | |
tree | 3a2d6471ce6c4aceb01587a3c7a07ddd7c4151c4 /client | |
parent | 9a5eb8ddf73fecc0ef5907983e136a1018937621 (diff) | |
download | hurrycurry-d832426d26a0368e7d7e0e03fadaf72828348fe7.tar hurrycurry-d832426d26a0368e7d7e0e03fadaf72828348fe7.tar.bz2 hurrycurry-d832426d26a0368e7d7e0e03fadaf72828348fe7.tar.zst |
Refactor chat bubble / item bubble / effect system to avoid instantiating nodes when not needed
Diffstat (limited to 'client')
-rw-r--r-- | client/player/chat_bubble.gd | 5 | ||||
-rw-r--r-- | client/player/chat_bubble.tscn | 1 | ||||
-rw-r--r-- | client/player/item_bubble.gd | 5 | ||||
-rw-r--r-- | client/player/item_bubble.tscn | 1 | ||||
-rw-r--r-- | client/player/particles/effect.gd | 8 | ||||
-rw-r--r-- | client/player/player.gd | 66 |
6 files changed, 46 insertions, 40 deletions
diff --git a/client/player/chat_bubble.gd b/client/player/chat_bubble.gd index cb4fac61..abeacc66 100644 --- a/client/player/chat_bubble.gd +++ b/client/player/chat_bubble.gd @@ -21,9 +21,4 @@ extends MeshInstance3D var editing := false func set_text(t: String): - visible = true label.text = t - -func remove_text(): - visible = false - label.text = "" diff --git a/client/player/chat_bubble.tscn b/client/player/chat_bubble.tscn index d7bdf4d2..12bbe3bf 100644 --- a/client/player/chat_bubble.tscn +++ b/client/player/chat_bubble.tscn @@ -19,7 +19,6 @@ billboard_mode = 1 [node name="ChatBubble" type="MeshInstance3D"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0) -visible = false mesh = SubResource("QuadMesh_u8lr5") surface_material_override/0 = SubResource("StandardMaterial3D_5iy0t") script = ExtResource("1_4v1cx") diff --git a/client/player/item_bubble.gd b/client/player/item_bubble.gd index e02272b7..92e6da87 100644 --- a/client/player/item_bubble.gd +++ b/client/player/item_bubble.gd @@ -24,9 +24,4 @@ var progress_style = preload("res://gui/resources/style/item_bubble_progress_sty @onready var item_message = $SubViewport/ItemMessage func set_item(item_name: String, timeout_initial_: float, timeout_remaining_: float): - visible = true item_message.set_item(item_name, timeout_initial_, timeout_remaining_) - -func remove_item(): - visible = false - item_message.remove_item() diff --git a/client/player/item_bubble.tscn b/client/player/item_bubble.tscn index 36d01b28..8d55ebd0 100644 --- a/client/player/item_bubble.tscn +++ b/client/player/item_bubble.tscn @@ -19,7 +19,6 @@ billboard_mode = 1 [node name="ItemBubble" type="MeshInstance3D"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0) -visible = false mesh = SubResource("QuadMesh_tlsxo") surface_material_override/0 = SubResource("StandardMaterial3D_5iy0t") script = ExtResource("1_84g24") diff --git a/client/player/particles/effect.gd b/client/player/particles/effect.gd index 7f0f6e19..1b221248 100644 --- a/client/player/particles/effect.gd +++ b/client/player/particles/effect.gd @@ -24,7 +24,6 @@ extends Node3D func set_effect(e: String): - clear_effect() match e: "satisfied": stars.emitting = true @@ -35,10 +34,3 @@ func set_effect(e: String): failure.play() _: push_warning("effect %s unknown" % e) - -func clear_effect(): - stars.emitting = false - success.stop() - angry.emitting = false - angry_grunt.stop_all() - failure.stop() diff --git a/client/player/player.gd b/client/player/player.gd index 1b17191b..624400db 100644 --- a/client/player/player.gd +++ b/client/player/player.gd @@ -16,6 +16,10 @@ class_name Player extends Node3D +const CHAT_BUBBLE: PackedScene = preload("res://player/chat_bubble.tscn") +const ITEM_BUBBLE: PackedScene = preload("res://player/item_bubble.tscn") +const EFFECT: PackedScene = preload("res://player/particles/effect.tscn") + const PLAYER_SIZE: float = 0.4 const SPEED: float = 25. @@ -32,12 +36,14 @@ var username: String var movement_base: Node3D = Node3D.new() var character: Character = preload("res://player/character/character.tscn").instantiate() -var chat_bubble: ChatBubble = preload("res://player/chat_bubble.tscn").instantiate() -var item_bubble: ItemBubble = preload("res://player/item_bubble.tscn").instantiate() -var effect: Effect = preload("res://player/particles/effect.tscn").instantiate() +var chat_bubble: ChatBubble = null +var item_bubble: ItemBubble = null +var effect: Effect = null var marker: Marker = preload("res://player/marker/marker.tscn").instantiate() -var clear_timer: Timer = Timer.new() +var clear_chat_timer: Timer = Timer.new() +var clear_item_timer: Timer = Timer.new() +var clear_effect_timer: Timer = Timer.new() var is_despawning: bool = false @@ -87,12 +93,13 @@ func _init(_id: int, name_: String, pos: Vector2, character_style_: Dictionary, for h in hand_base: movement_base.add_child(h) - movement_base.add_child(chat_bubble) - movement_base.add_child(item_bubble) - movement_base.add_child(effect) - - clear_timer.one_shot = true - add_child(clear_timer) + clear_chat_timer.one_shot = true + clear_item_timer.one_shot = true + clear_effect_timer.one_shot = true + add_child(clear_chat_timer) + add_child(clear_item_timer) + add_child(clear_effect_timer) + marker.visible = false add_child(marker) @@ -103,7 +110,10 @@ func _init(_id: int, name_: String, pos: Vector2, character_style_: Dictionary, func _ready(): character.set_style(character_style, player_class) - clear_timer.timeout.connect(clear_message) + + clear_chat_timer.timeout.connect(clear_text_message) + clear_item_timer.timeout.connect(clear_item_message) + clear_effect_timer.timeout.connect(clear_effect) Settings.hook_changed_init("gameplay.usernames", "main", update_username_tag) @@ -176,21 +186,37 @@ func _process(delta): else: movement_base.scale = Vector3.ONE * G.interpolate(movement_base.scale.x, 1, delta * 8) -func clear_message(): - item_bubble.remove_item() - chat_bubble.remove_text() - effect.clear_effect() - current_item_message = null - func item_message(item_name: String, timeout_initial: float, timeout_remaining: float): + if item_bubble != null: + item_bubble.queue_free() + item_bubble = ITEM_BUBBLE.instantiate() + movement_base.add_child(item_bubble) item_bubble.set_item(item_name, timeout_initial, timeout_remaining) - clear_timer.start(timeout_remaining) + clear_item_timer.start(timeout_remaining) current_item_message = item_name +func clear_item_message(): + current_item_message = null + item_bubble.queue_free() + func text_message(message: Game.TextMessage): + if chat_bubble != null: + chat_bubble.queue_free() + chat_bubble = CHAT_BUBBLE.instantiate() + movement_base.add_child(chat_bubble) chat_bubble.set_text(message.text) - clear_timer.start(message.timeout_remaining) + clear_chat_timer.start(message.timeout_remaining) + +func clear_text_message(): + chat_bubble.queue_free() func effect_message(effect_name: String): + if effect != null: + effect.queue_free() + effect = EFFECT.instantiate() + movement_base.add_child(effect) effect.set_effect(effect_name) - clear_timer.start(5) + clear_effect_timer.start(5) + +func clear_effect(): + effect.queue_free() |