From 781aaf1be8155d78b6cb146cfd6da1c7e7957c2a Mon Sep 17 00:00:00 2001 From: RobinFiredrake Date: Tue, 10 Nov 2026 18:26:02 -0600 Subject: [PATCH] Magic sparkles on the thread pulse and on landing results Sparkles (CPU particles, mobile-safe) in the theme's GLOW colour: a trail follows the pulse up each thread, and a short burst plays over a result as it lands. Co-Authored-By: Claude Opus 5.5 --- tests/test_theme.gd | 16 ++++++++++ ui/main_rolling.gd | 1 + ui/pipe_layer.gd | 14 +++++++++ ui/sparkles.gd | 73 +++++++++++++++++++++++++++++++++++++++++++++ ui/sparkles.gd.uid | 1 + ui/table_card.gd | 9 ++++++ 6 files changed, 114 insertions(+) create mode 100644 ui/sparkles.gd create mode 100644 ui/sparkles.gd.uid diff --git a/tests/test_theme.gd b/tests/test_theme.gd index e302a33..1d79790 100644 --- a/tests/test_theme.gd +++ b/tests/test_theme.gd @@ -20,6 +20,7 @@ func _init() -> void: _test_save_delete() await _test_dialog() _test_own_colours() + await _test_sparkles() print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) quit(1 if _failures else 0) @@ -90,6 +91,21 @@ func _test_own_colours() -> void: _check(card.frame.material == CardFrame.material_for(Color("#b8382c")), "the frame takes the card's colour") +func _test_sparkles() -> void: + var card := main.card_for(main.data.tables[0].id) + var layer := card.get_parent() + var before := layer.find_children("*", "CPUParticles2D", false, false).size() + card.sparkle(card.table.entries[0].id) + _check(layer.find_children("*", "CPUParticles2D", false, false).size() == before + 1, "a landing result bursts sparkles") + var pipes := main.board.pipes + pipes.pulse_key = pipes._paths.keys()[0] if not pipes._paths.is_empty() else "" + await _frames() + _check(pipes._trail != null and pipes._trail.emitting, "the pulse trails sparkles") + pipes.pulse_key = "" + await _frames() + _check(not pipes._trail.emitting, "the trail stops with the pulse") + + func _frames(n: int = 2) -> void: for i in n: await process_frame diff --git a/ui/main_rolling.gd b/ui/main_rolling.gd index 0bc5e72..1c63784 100644 --- a/ui/main_rolling.gd +++ b/ui/main_rolling.gd @@ -222,6 +222,7 @@ func _play_one(n: Dictionary, my: int, depth: int) -> void: m._refresh_lit() if card: card.reveal(e.id) + card.sparkle(e.id) (m.current["steps"] as Array).append(Roller.step_of(n, depth)) m.tray.render() diff --git a/ui/pipe_layer.gd b/ui/pipe_layer.gd index 829e113..37ef922 100644 --- a/ui/pipe_layer.gd +++ b/ui/pipe_layer.gd @@ -25,6 +25,7 @@ var hover_key: String = "" var select_key: String = "" var pulse_key: String = "" var pulse_t: float = 0.0 +var _trail: CPUParticles2D ## pipe key -> polyline in world coordinates, from the last frame. var _paths: Dictionary = {} @@ -62,12 +63,25 @@ func _init() -> void: func _process(_delta: float) -> void: if main == null or main.board == null: return + _move_trail() var state := [main.board.geometry_rev, hover_key, select_key, pulse_key, pulse_t, main.board.cards.far, RulesView.plain(main)] if state != _drawn_state: _drawn_state = state queue_redraw() +## Sparkles follow the pulse up the thread (Sparkles.trail). +func _move_trail() -> void: + var on := pulse_key != "" and _paths.has(pulse_key) + if on and _trail == null: + _trail = Sparkles.trail() + add_child(_trail) + if _trail: + if on: + _trail.global_position = get_global_transform() * point_along(_paths[pulse_key], pulse_t) + _trail.emitting = on + + # ---------- Batched unlit pipes (performance) ---------- func _begin_batch() -> void: diff --git a/ui/sparkles.gd b/ui/sparkles.gd new file mode 100644 index 0000000..d16e745 --- /dev/null +++ b/ui/sparkles.gd @@ -0,0 +1,73 @@ +class_name Sparkles +extends RefCounted +## Magic sparkles (CPU particles, so they also run on mobile): a trail that +## follows the pulse up a thread, and a short burst over a result when it +## lands. Coloured with the theme's GLOW. + +static var _tex: ImageTexture + + +## A soft four-point star, made once. +static func texture() -> ImageTexture: + if _tex == null: + var n := 16 + var img := Image.create(n, n, false, Image.FORMAT_RGBA8) + var c := Vector2(n - 1, n - 1) / 2.0 + for y in n: + for x in n: + var d := Vector2(x, y) - c + var glow := clampf(1.0 - d.length() / c.x, 0.0, 1.0) + var star := clampf(1.0 - minf(absf(d.x), absf(d.y)) / 1.4, 0.0, 1.0) * glow + img.set_pixel(x, y, Color(1, 1, 1, clampf(glow * glow * 0.6 + star, 0.0, 1.0))) + _tex = ImageTexture.create_from_image(img) + return _tex + + +static func _base(amount: int, life: float) -> CPUParticles2D: + var p := CPUParticles2D.new() + p.texture = texture() + p.amount = amount + p.lifetime = life + p.local_coords = false + p.direction = Vector2(0, -1) + p.spread = 180.0 + p.gravity = Vector2(0, -18) + p.scale_amount_min = 0.35 + p.scale_amount_max = 0.9 + var fade := Gradient.new() + fade.set_color(0, Color(Style.GLOW, 0.95)) + fade.set_color(1, Color(Style.GLOW.lightened(0.5), 0.0)) + p.color_ramp = fade + var shrink := Curve.new() + shrink.add_point(Vector2(0, 1)) + shrink.add_point(Vector2(1, 0.2)) + p.scale_amount_curve = shrink + var mat := CanvasItemMaterial.new() + mat.blend_mode = CanvasItemMaterial.BLEND_MODE_ADD + p.material = mat + return p + + +## A continuous trail; move it and toggle `emitting`. +static func trail() -> CPUParticles2D: + var p := _base(36, 0.7) + p.initial_velocity_min = 4.0 + p.initial_velocity_max = 22.0 + p.emitting = false + return p + + +## A one-shot burst over `rect` (in the parent's coordinates); frees itself. +static func burst(parent: Node, rect: Rect2) -> void: + var p := _base(maxi(10, int(rect.size.x / 12.0)), 0.9) + p.one_shot = true + p.explosiveness = 0.55 + p.local_coords = true + p.emission_shape = CPUParticles2D.EMISSION_SHAPE_RECTANGLE + p.emission_rect_extents = rect.size / 2.0 + p.position = rect.get_center() + p.initial_velocity_min = 6.0 + p.initial_velocity_max = 30.0 + p.finished.connect(p.queue_free) + parent.add_child(p) + p.emitting = true diff --git a/ui/sparkles.gd.uid b/ui/sparkles.gd.uid new file mode 100644 index 0000000..a0c5446 --- /dev/null +++ b/ui/sparkles.gd.uid @@ -0,0 +1 @@ +uid://c154irysc26sw diff --git a/ui/table_card.gd b/ui/table_card.gd index 106af80..d3e1d51 100644 --- a/ui/table_card.gd +++ b/ui/table_card.gd @@ -456,6 +456,15 @@ func reveal(eid: String) -> void: list_scroll.scroll_vertical = int(row.position.y + 6.0 - list_scroll.size.y / 2.0 + row.size.y / 2.0) +## A burst of sparkles over a result as it lands. +func sparkle(eid: String) -> void: + var row: Control = rows.get(eid) + if row and row.is_inside_tree() and row.is_visible_in_tree(): + # Into the card layer, so a rebuild of this card doesn't cut it short. + var at := get_global_transform().affine_inverse() * row.get_global_transform().origin + Sparkles.burst(get_parent(), Rect2(position + at, row.size)) + + func hidden_has_pipes() -> bool: for e in table.entries: if not rows.has(e.id) and (not e.pipes.is_empty() or not main.ref_targets_for(e).is_empty()):