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 <noreply@anthropic.com>
This commit is contained in:
parent
ea1e7a6492
commit
781aaf1be8
6 changed files with 114 additions and 0 deletions
|
|
@ -20,6 +20,7 @@ func _init() -> void:
|
||||||
_test_save_delete()
|
_test_save_delete()
|
||||||
await _test_dialog()
|
await _test_dialog()
|
||||||
_test_own_colours()
|
_test_own_colours()
|
||||||
|
await _test_sparkles()
|
||||||
print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures])
|
print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures])
|
||||||
quit(1 if _failures else 0)
|
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")
|
_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:
|
func _frames(n: int = 2) -> void:
|
||||||
for i in n:
|
for i in n:
|
||||||
await process_frame
|
await process_frame
|
||||||
|
|
|
||||||
|
|
@ -222,6 +222,7 @@ func _play_one(n: Dictionary, my: int, depth: int) -> void:
|
||||||
m._refresh_lit()
|
m._refresh_lit()
|
||||||
if card:
|
if card:
|
||||||
card.reveal(e.id)
|
card.reveal(e.id)
|
||||||
|
card.sparkle(e.id)
|
||||||
(m.current["steps"] as Array).append(Roller.step_of(n, depth))
|
(m.current["steps"] as Array).append(Roller.step_of(n, depth))
|
||||||
m.tray.render()
|
m.tray.render()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ var hover_key: String = ""
|
||||||
var select_key: String = ""
|
var select_key: String = ""
|
||||||
var pulse_key: String = ""
|
var pulse_key: String = ""
|
||||||
var pulse_t: float = 0.0
|
var pulse_t: float = 0.0
|
||||||
|
var _trail: CPUParticles2D
|
||||||
|
|
||||||
## pipe key -> polyline in world coordinates, from the last frame.
|
## pipe key -> polyline in world coordinates, from the last frame.
|
||||||
var _paths: Dictionary = {}
|
var _paths: Dictionary = {}
|
||||||
|
|
@ -62,12 +63,25 @@ func _init() -> void:
|
||||||
func _process(_delta: float) -> void:
|
func _process(_delta: float) -> void:
|
||||||
if main == null or main.board == null:
|
if main == null or main.board == null:
|
||||||
return
|
return
|
||||||
|
_move_trail()
|
||||||
var state := [main.board.geometry_rev, hover_key, select_key, pulse_key, pulse_t, main.board.cards.far, RulesView.plain(main)]
|
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:
|
if state != _drawn_state:
|
||||||
_drawn_state = state
|
_drawn_state = state
|
||||||
queue_redraw()
|
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) ----------
|
# ---------- Batched unlit pipes (performance) ----------
|
||||||
|
|
||||||
func _begin_batch() -> void:
|
func _begin_batch() -> void:
|
||||||
|
|
|
||||||
73
ui/sparkles.gd
Normal file
73
ui/sparkles.gd
Normal file
|
|
@ -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
|
||||||
1
ui/sparkles.gd.uid
Normal file
1
ui/sparkles.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://c154irysc26sw
|
||||||
|
|
@ -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)
|
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:
|
func hidden_has_pipes() -> bool:
|
||||||
for e in table.entries:
|
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()):
|
if not rows.has(e.id) and (not e.pipes.is_empty() or not main.ref_targets_for(e).is_empty()):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue