This commit is contained in:
Forrest 2026-10-01 23:01:56 -04:00
parent 0cba7f5ee0
commit 32ed347b58
172 changed files with 5464 additions and 582 deletions

68
present/motion.gd Normal file
View file

@ -0,0 +1,68 @@
class_name Motion
## The animation language (gameplay-plan.md §B6): things rush in, hold or drift slowly, then rush
## out. Every animation in the game takes its timing from here, so the speed setting (and the
## tests' instant switch, Card3D.instant) reach all of them.
## Multiplies every duration; 0 is instant. Set from the animation-speed setting.
static var speed_scale := 1.0
static func instant() -> bool:
return speed_scale <= 0.0 or Card3D.instant
## `t` seconds at the current speed.
static func secs(t: float) -> float:
return 0.0 if instant() else t * speed_scale
## Rush to `to`: a fast start and a soft landing.
static func rush_in(tw: Tween, obj: Object, prop: NodePath, to: Variant, t: float) -> PropertyTweener:
return tw.tween_property(obj, prop, to, secs(t)).set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_OUT)
## Drift slowly to `to`, easing at both ends: the hold between two rushes.
static func drift(tw: Tween, obj: Object, prop: NodePath, to: Variant, t: float) -> PropertyTweener:
return tw.tween_property(obj, prop, to, secs(t)).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN_OUT)
## Rush away to `to`: a slow start that snaps at the end.
static func rush_out(tw: Tween, obj: Object, prop: NodePath, to: Variant, t: float) -> PropertyTweener:
return tw.tween_property(obj, prop, to, secs(t)).set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_IN)
## The whole curve on one property: rush to `hold_a`, drift to `hold_b`, rush out to `to`.
static func rush_hold_rush(tw: Tween, obj: Object, prop: NodePath, hold_a: Variant, hold_b: Variant, to: Variant,
t_in := 0.18, t_hold := 0.45, t_out := 0.16) -> void:
rush_in(tw, obj, prop, hold_a, t_in)
drift(tw, obj, prop, hold_b, t_hold)
rush_out(tw, obj, prop, to, t_out)
## The curve as a function, for things driven by hand (shaders, pop-ups): progress `u` (0–1) of an
## animation whose middle `hold` share is the drift. Returns how far along the path it is (0–1):
## it covers `reach` of the way during the rush in, and the rest in the rush out.
static func curve(u: float, hold := 0.5, reach := 0.86) -> float:
u = clampf(u, 0.0, 1.0)
var a := (1.0 - hold) / 2.0
if u < a:
var k := u / a
return reach * (1.0 - pow(2.0, -10.0 * k)) / (1.0 - pow(2.0, -10.0))
if u < a + hold:
var k := (u - a) / hold
return reach + (1.0 - reach) * 0.25 * (0.5 - 0.5 * cos(PI * k))
var k := (u - a - hold) / a
var from := reach + (1.0 - reach) * 0.25
return from + (1.0 - from) * pow(2.0, 10.0 * (k - 1.0))
## How strong a streak behind something moving on the curve should be at progress `u`: high in
## the rushes, low in the hold.
static func streak(u: float, hold := 0.5) -> float:
u = clampf(u, 0.0, 1.0)
var a := (1.0 - hold) / 2.0
if u < a:
return 1.0 - u / a * 0.6
if u < a + hold:
return 0.15
return 0.4 + 0.6 * (u - a - hold) / a

1
present/motion.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://c7kpegf65ne4o

264
present/presenter.gd Normal file
View file

@ -0,0 +1,264 @@
class_name Presenter
extends Node
## Acts the game out (gameplay-plan.md §B5). Each change to the match comes with the engine's
## events for it (s.events, filtered for you); the presenter lays them out on a timeline, one beat
## after another, and turns them into how cards travel (motion styles the table applies in its
## next sync) and cues that need the new positions (pop-ups, flashes, the turn banner).
##
## The table still snaps to the view in that sync: every card's goal is its real spot, and the
## events only choose the way there and when. So a missed or misdrawn animation can never leave
## the table showing the wrong state (godot-plan.md §3). This lives outside engine/ and match/,
## which use no nodes.
## Seconds each kind of event holds the timeline at normal speed before the next one starts.
## Kinds that come in runs (draws, discards) have short beats, so a run fans out.
const BEATS := {
"turn": 0.3, "drew": 0.11, "hand": 0.1, "discard": 0.16, "install": 0.42, "placed": 0.34,
"moved": 0.4, "recalled": 0.32, "flipped": 0.28, "combat": 0.32, "rolled": 0.62, "rerolled": 0.5,
"damaged": 0.3, "destroyed": 0.45, "captured": 0.5, "firewall": 0.55, "bandwidth": 0.0, "counter": 0.12,
"stack": 0.75, "pile": 0.12,
}
## An opponent's card held up for you to read takes longer than your own.
const REVEAL_BEAT := 0.85
## The longest one change may take; longer ones are squeezed to fit.
const MAX_BATCH := 3.4
## Extra time after the last beat for its animation to land.
const TAIL := 0.45
var table: GameTable
var hud: Hud
## When the show for the last change ends, in engine seconds.
var _until := 0.0
## Cues waiting for the sync: Callables taking no arguments.
var _cues: Array[Callable] = []
## Before the table syncs to `after`: plans the show for `events` (as `me` sees them). `before` is
## the view the table shows now ({} for a new game).
func stage(events: Array, before: Dictionary, after: Dictionary, me: int) -> void:
_cues = []
if events.is_empty() or Motion.instant():
return
var plan := []
var t := 0.0
for ev in events:
var beat: float = BEATS.get(ev.k, 0.0)
if (ev.k == "install" or ev.k == "discard") and ev.get("p", me) != me and _from_hidden(ev):
beat = REVEAL_BEAT
plan.append({"ev": ev, "at": t})
t += beat
var squeeze := 1.0 if t <= MAX_BATCH else MAX_BATCH / t
var bot_draws: Array[float] = []
# What earlier events in this change did, for the later ones: cards that went on the stack,
# Anomalies destroyed.
var seen := {"stacked": {}, "destroyed": {}}
for step in plan:
var at: float = step.at * squeeze
_stage_one(step.ev, at, before, after, me, bot_draws, seen)
_deal_bot_hand(before, after, me, bot_draws)
_until = Time.get_ticks_msec() / 1000.0 + Motion.secs(t * squeeze + TAIL)
## Whether `ev` brings out a card the viewer couldn't see: from a hand or the deck.
static func _from_hidden(ev: Dictionary) -> bool:
var from: String = ev.get("from", "hand")
return from in ["hand", "deck", ""]
func _stage_one(ev: Dictionary, at: float, before: Dictionary, after: Dictionary, me: int, bot_draws: Array[float], seen: Dictionary) -> void:
var motions := table.motions
match ev.k:
"drew":
if ev.p == me and ev.card >= 0:
motions["card:%d" % ev.card] = {"style": "draw", "delay": at}
else:
bot_draws.append(at)
"discard":
var key := "card:%d" % ev.card
if ev.card < 0:
return
var from: String = ev.get("from", "")
if ev.get("why", "") == "destroyed":
motions[key] = {"style": "destroy", "delay": at}
elif ev.p != me and (_from_hidden(ev) or (from == "stack" and seen.stacked.has(ev.card))):
# A card of theirs you hadn't seen: held up for you to read on its way.
motions[key] = {"style": "reveal", "delay": at, "p": ev.p, "from": "deck" if from == "deck" else "hand", "color": Style.OWNER[ev.p]}
else:
var spec := {"style": "discard", "delay": at}
if ev.get("from", "") == "deck":
spec.merge({"p": ev.p, "from": "deck"})
motions[key] = spec
"stack":
# An Execution played: up in front of you, then beside the table until it resolves.
if ev.get("kind", "") == "execution" and ev.card >= 0:
seen.stacked[ev.card] = true
var spec := {"style": "stack", "delay": at, "color": Style.OWNER[ev.p]}
if ev.p != me:
spec.merge({"p": ev.p, "from": "hand"})
motions["card:%d" % ev.card] = spec
"pile":
# Back into a hidden pile (a Server going home, a card shuffled in).
if ev.card >= 0:
motions["card:%d" % ev.card] = {"style": "leave", "delay": at, "p": ev.p, "to": ev.zone}
"install":
if ev.card < 0:
return
var key := "card:%d" % ev.card
var d: Dictionary = after.defs.get(State.name_of(after, ev.card), {}) if ev.card < after.cards.size() else {}
if d.get("kind", "") == "server":
motions[key] = {"style": "slam", "delay": at, "p": ev.p, "from": "serverPile"}
elif ev.p != me:
motions[key] = {"style": "reveal", "delay": at, "p": ev.p, "from": "hand", "color": Style.OWNER[ev.p]}
else:
motions[key] = {"style": "slam", "delay": at}
"placed", "moved", "recalled", "flipped":
var key := Moves.anomaly_key(ev.ref)
motions[key] = {"style": "move", "delay": at, "color": Style.OWNER[ev.ref.player]}
# Its Hardware rides along, just behind.
if after.players[ev.ref.player].anomalies.size() >= ev.ref.slot:
for id in State.hardware_of(after, ev.ref):
motions["card:%d" % id] = {"style": "move", "delay": at + 0.04, "color": Style.OWNER[ev.ref.player]}
if ev.k == "flipped":
_cue(func(): table.flash_card(key, Style.ACCENT, at + 0.2))
"destroyed":
var key := Moves.anomaly_key(ev.ref)
seen.destroyed[key] = true
motions[key] = {"style": "destroy", "delay": at}
var loc = ev.get("loc")
_cue(func():
var w = table.anchor_of(Moves.loc_key(loc)) if loc != null else table.anchor_of(key)
if w != null:
table.pop_text(w, "DESTROYED", Style.BAD, at, 24))
"combat":
_cue(func():
var w = table.anchor_of(Moves.loc_key(ev.loc))
if w != null:
table.pop_text(w, "// COMBAT", Style.ATTACK, at, 22))
"rolled":
for rk in ev.dice:
var dice: Array = ev.dice[rk]
if dice.is_empty():
continue
var parts: PackedStringArray = rk.split(":")
var key := "anomaly:%s:%s" % [parts[0], parts[1]] if parts.size() == 2 else ""
var owner := int(parts[0]) if parts.size() == 2 else me
var text := "⚄ %s = %d" % [" ".join(dice.map(func(x): return str(x))), Util.sum(dice)]
_cue(func():
var w = table.anchor_of(key)
if w == null:
w = table.anchor_of(Moves.loc_key(ev.loc))
if w != null:
table.pop_text(w + Vector3(0, 0.3, 0), text, Style.OWNER[owner].lightened(0.3), at, 20)
table.flash_card(key, Style.OWNER[owner], at))
"rerolled":
var key := Moves.anomaly_key(ev.ref)
var text := "REROLL ⚄ %s" % " ".join(ev.dice.map(func(x): return str(x)))
_cue(func():
var w = table.anchor_of(key)
if w != null:
table.pop_text(w + Vector3(0, 0.3, 0), text, Style.WARN, at, 20))
"damaged":
var key := Moves.anomaly_key(ev.ref)
var r: Dictionary = ev.ref
var amount: int = ev.amount
var loc = ev.get("loc")
_cue(func():
table.pop_damage(r, amount, false, loc, at)
table.flash_card(key, Style.BAD, at))
"captured":
var loc: String = ev.loc
var p: int = ev.p
_cue(func():
table.flash_capture(loc, p, at)
var w = table.anchor_of(Moves.loc_key(loc))
if w != null:
table.pop_text(w, "%s TAKES %s" % [State.player_name(p).to_upper(), loc], Style.OWNER[p].lightened(0.25), at + 0.1, 22))
"firewall":
table.gate_delays[ev.line] = at
var to: int = ev.to
var line: String = ev.line
_cue(func():
var w = table.anchor_of("gate:" + line)
if w != null:
var text := "FIREWALL CLEARED" if to == 0 else "FIREWALL LV %d" % to
table.pop_text(w + Vector3(0, 0.4, 0), text, Style.firewall_color(maxi(1, to), after.rules.firewallCost.size()), at + 0.45, 18))
"bandwidth":
var delta: int = ev.to - ev.from
if delta != 0:
var p: int = ev.p
if not table.bandwidth_delays.has(p):
table.bandwidth_delays[p] = at
_cue(func(): hud.pulse_bandwidth(p, delta, at))
"counter":
var key := Moves.anomaly_key(ev.ref)
var what: String = ev.get("what", "")
var delta: int = ev.to - ev.from
var text := ""
var color: Color = Style.CLASS_ACCENT.G
if what == "damage":
# Damage itself pops when dealt; a counter going down is a heal, unless the Anomaly
# was just destroyed and is being reset.
if delta < 0 and not seen.destroyed.has(key):
text = "+%d HEAL" % -delta
color = Style.TYPE_ACCENT.server
elif delta != 0:
text = "%+d %s" % [delta, {"infection": "☣", "bugs": "✱"}.get(what, "•")]
if text != "":
_cue(func():
var w = table.anchor_of(key)
if w != null:
table.pop_text(w + Vector3(0, 0.2, 0), text, color, at, 18))
"turn":
var p: int = ev.p
var turn: int = ev.turn
var title := "YOUR COMMAND" if p == me else "%s'S COMMAND" % State.player_name(p).to_upper()
var sub := "ROUND %d · COMMAND %d" % [State.round_of(after, turn), turn] if after.rules.commands.on else "TURN %d" % turn
_cue(func(): hud.banner(title, sub, Style.OWNER[p], at))
## The bot's hand is face-down placeholders by position: the new ones are dealt off its deck, at
## the times its draws came.
func _deal_bot_hand(before: Dictionary, after: Dictionary, me: int, bot_draws: Array[float]) -> void:
if before.is_empty():
return
var p := State.other(me)
var n0: int = mini(before.players[p].hand.size(), GameTable.BOT_HAND_SHOWN)
var n1: int = mini(after.players[p].hand.size(), GameTable.BOT_HAND_SHOWN)
for i in range(n0, n1):
var j := i - n0
var at: float = bot_draws[j] if j < bot_draws.size() else 0.0
table.motions["bothand:%d:%d" % [p, i]] = {"style": "deal", "delay": at, "p": p, "from": "deck"}
func _cue(fn: Callable) -> void:
_cues.append(fn)
## After the table's sync: the cues, which read the new positions.
func run() -> void:
var cues := _cues
_cues = []
for fn in cues:
fn.call()
## Whether a show is playing.
func busy() -> bool:
if Motion.instant():
return false
return Time.get_ticks_msec() / 1000.0 < _until or table.animating()
## Seconds until the planned show ends (0 when none is playing).
func time_left() -> float:
if Motion.instant():
return 0.0
return maxf(0.0, _until - Time.get_ticks_msec() / 1000.0)
## Skips to the end of the show.
func skip() -> void:
_until = 0.0
_cues = []
table.finish_animations()
hud.finish_banner()

1
present/presenter.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://cjjv056maonj2

18
present/trail.gdshader Normal file
View file

@ -0,0 +1,18 @@
shader_type spatial;
render_mode blend_add, unshaded, cull_disabled, depth_draw_never, shadows_disabled;
// A speed-trail ghost (gameplay-plan.md §B6): a soft card-shaped glow a card leaves behind while it
// rushes, fading fast. Every ghost shares this material; the fade and color are per instance, so
// trails never duplicate materials.
uniform float energy = 0.9;
instance uniform vec4 tint : source_color = vec4(0.133, 0.827, 0.933, 1.0);
instance uniform float fade = 1.0;
void fragment() {
vec2 p = abs(UV - 0.5) * 2.0;
float edge = max(p.x, p.y);
// Bright at the rim, faint inside: an afterimage of the card's frame.
float a = (1.0 - smoothstep(0.82, 1.0, edge)) * (0.22 + 0.78 * smoothstep(0.55, 0.96, edge));
ALBEDO = tint.rgb * energy * a * fade;
}

View file

@ -0,0 +1 @@
uid://i0ievq6wjbpv