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

120
table/bandwidth_strip.gd Normal file
View file

@ -0,0 +1,120 @@
class_name BandwidthStrip
extends Node3D
## A player's Bandwidth as a neon loading bar along their edge of the mat (ui-plan.md §A5),
## mirrored small in the HUD (BandwidthBar). Bandwidth has no cap, so the scale is fixed: 20 cells
## of 1 Gb, with ticks at the Firewall costs, and the whole bar glows past 20 instead of clipping.
## For you, dimmer cells run on to what salvaging your hand could reach.
##
## Local axes: x runs along the bar (0 Gb at -x, as its owner sees it), z toward its owner.
const CELLS := 20
const LENGTH := 11.0
const CELL_DEPTH := 0.34
const LED_SHADER := preload("res://table/led.gdshader")
static var _material: ShaderMaterial
var color := Color("#56b4e9")
var gb := 0
var reach := 0
var _cells: Array[MeshInstance3D] = []
var _ticks: Array[Label3D] = []
var _value: Label3D
var _shown := 0.0
var _tween: Tween
var _pulse := 0.0
func _ready() -> void:
if _material == null:
_material = ShaderMaterial.new()
_material.shader = LED_SHADER
var step := LENGTH / CELLS
var mesh := BoxMesh.new()
mesh.size = Vector3(step * 0.8, 0.03, CELL_DEPTH)
for i in CELLS:
var c := MeshInstance3D.new()
c.mesh = mesh
c.material_override = _material
c.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
c.position = Vector3(-LENGTH / 2.0 + step * (i + 0.5), 0.015, 0)
add_child(c)
_cells.append(c)
var title := _label("BANDWIDTH", 40, Style.MUTED)
title.position = Vector3(-LENGTH / 2.0 - 0.15, 0.01, 0)
title.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
_value = _label("0 Gb", 64, color)
_value.position = Vector3(LENGTH / 2.0 + 0.2, 0.01, 0)
_value.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
_draw()
func _label(text: String, size: int, c: Color) -> Label3D:
var l := Label3D.new()
l.text = text
l.font = Style.body_font(700)
l.font_size = size
l.pixel_size = 0.004
l.rotation.x = -PI / 2
l.modulate = c
l.outline_size = 0
add_child(l)
return l
## The Firewall costs, marked under the bar.
func set_ticks(costs: Array) -> void:
for t in _ticks:
t.queue_free()
_ticks = []
var step := LENGTH / CELLS
for cost in costs:
if cost <= 0 or cost >= CELLS:
continue
var t := _label(str(cost), 30, Color(Style.SCREEN, 0.6))
t.position = Vector3(-LENGTH / 2.0 + step * cost, 0.01, CELL_DEPTH / 2.0 + 0.14)
_ticks.append(t)
## Shows `value` Gb (and the ghost to `reach_to`), filling cell by cell on the motion curve after
## `delay` seconds.
func set_value(value: int, reach_to: int, c: Color, delay := 0.0) -> void:
color = c
reach = maxi(reach_to, value)
_value.modulate = c
_value.text = "%d Gb" % value
if value == gb:
_draw()
return
gb = value
if _tween != null:
_tween.kill()
if Motion.instant() or not is_inside_tree():
_shown = value
_draw()
return
_tween = create_tween()
if delay > 0.0:
_tween.tween_interval(Motion.secs(delay))
_tween.tween_method(func(x):
_shown = x
_draw(), _shown, float(value), Motion.secs(0.6)).set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_OUT)
func _process(delta: float) -> void:
if gb > CELLS:
_pulse = fmod(_pulse + delta, 2.0)
_draw()
func _draw() -> void:
var lit := roundi(_shown)
var over := gb > CELLS
var k := 0.5 + 0.5 * sin(_pulse * PI)
for i in _cells.size():
var v := Color(0, 0, 0, 0)
if i < lit:
v = Color(color.lerp(Color.WHITE, 0.2 * float(i) / CELLS), 2.6 + k * 1.4 if over else 1.7)
elif i < reach:
v = Color(color, 0.09)
_cells[i].set_instance_shader_parameter("led", v)

View file

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

View file

@ -17,6 +17,8 @@ uniform bool rim_glow = true;
// rgb is the color, a the strength.
instance uniform vec4 highlight : source_color = vec4(0.0);
// A brief flash on top of the highlight (hits, reveals, rushes); Card3D fades it out.
instance uniform vec4 flash : source_color = vec4(0.0);
// 0 is normal, 1 dark gray: disabled Hardware and Programs.
instance uniform float dim = 0.0;
@ -36,5 +38,5 @@ void fragment() {
float border = min(min(uv.x, 1.0 - uv.x), min(uv.y, 1.0 - uv.y));
glow = mix(0.12, 1.6, 1.0 - smoothstep(0.0, 0.07, border));
}
EMISSION = highlight.rgb * highlight.a * glow;
EMISSION = highlight.rgb * highlight.a * glow + flash.rgb * flash.a * (0.35 + glow);
}

View file

@ -11,8 +11,16 @@ const BACK := 1
const EDGE := 2
## Half the card's thickness: a card at this height lies on the table.
const REST_HEIGHT := 0.005
## Seconds a card takes to slide to a new spot.
const GLIDE_TIME := 0.28
## Seconds a card takes to slide to a new spot (at normal speed; see Motion).
const GLIDE_TIME := 0.26
## Speed trails: ghosts left per unit moved, how fast a card must move to leave them, how long one
## lasts.
const TRAIL_DENSITY := 2.5
const TRAIL_MIN_SPEED := 10.0
const TRAIL_LIFE := 0.15
## Most ghosts a card keeps at once.
const TRAIL_MAX := 14
const TRAIL_SHADER := preload("res://present/trail.gdshader")
## Every card jumps instead of sliding (for tests).
static var instant := false
@ -61,15 +69,28 @@ var pick_key := "":
var _mesh: MeshInstance3D
var _body: StaticBody3D
var _tween: Tween
var _flash_tween: Tween
var _flash := Color(0, 0, 0, 0)
## Speed trail: whether one is on, its color, where the card was last frame, and the live ghosts.
var _trail := false
var _trail_color := Color("#22d3ee")
var _trail_from := Vector3.ZERO
var _ghosts: Array = []
static var _ghost_mesh: PlaneMesh
static var _ghost_material: ShaderMaterial
## Where the last glide was headed, so an unchanged target doesn't restart it.
var _goal := Transform3D()
var _goal_set := false
## On its way out of sight (into a hidden pile): freed when it gets there.
var _leaving := false
func _ready() -> void:
_mesh = $Model.find_children("*", "MeshInstance3D")[0]
_apply_materials()
_apply_uniforms()
# Only while a trail is on or fading (see _process).
set_process(false)
if not Engine.is_editor_hint():
_body = StaticBody3D.new()
var shape := CollisionShape3D.new()
@ -101,11 +122,140 @@ func glide(xf: Transform3D, instant := false) -> void:
_goal_set = true
if _tween != null:
_tween.kill()
if instant or Card3D.instant or not is_inside_tree():
if instant or Motion.instant() or not is_inside_tree():
transform = xf
return
_tween = create_tween().set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_OUT)
_tween.tween_property(self, "transform", xf, GLIDE_TIME)
_tween = create_tween()
Motion.rush_in(_tween, self, "transform", xf, GLIDE_TIME)
## Sends the card along `path` (transforms in its parent's space, the goal last) on the motion
## curve (gameplay-plan.md §B6): it starts at path[0], rushes to path[1], drifts to path[2] and
## rushes out to the goal. Shorter paths skip the drift. `times` are each leg's seconds, `delay`
## waits first (at path[0]), and `trail` leaves a speed trail in the rushes.
func travel(path: Array, times: Array, delay := 0.0, trail := true, color := Color("#22d3ee"), leave := false) -> void:
var goal: Transform3D = path.back()
_goal = goal
_goal_set = true
_leaving = leave
if _tween != null:
_tween.kill()
if Motion.instant() or not is_inside_tree():
transform = goal
if leave:
queue_free()
return
transform = path[0]
_tween = create_tween()
if delay > 0.0:
_tween.tween_interval(Motion.secs(delay))
_tween.tween_callback(func(): _start_trail(trail, color))
var legs := path.size() - 1
for i in legs:
var t: float = times[mini(i, times.size() - 1)]
if legs >= 3 and i == 1:
Motion.drift(_tween, self, "transform", path[i + 1], t)
elif i == legs - 1 and legs > 1:
Motion.rush_out(_tween, self, "transform", path[i + 1], t)
else:
Motion.rush_in(_tween, self, "transform", path[i + 1], t)
_tween.tween_callback(func(): _trail = false)
if leave:
_tween.tween_callback(queue_free)
## Whether the card is still on its way somewhere.
func moving() -> bool:
return _tween != null and _tween.is_valid() and _tween.is_running()
## Jumps to where the card is headed (skipping its animation).
func finish() -> void:
if moving():
_tween.kill()
transform = _goal
_trail = false
if _leaving:
queue_free()
if _flash_tween != null:
_flash_tween.kill()
_set_flash(Color(0, 0, 0, 0))
## A flash of `color` that fades out over `t` seconds, after `delay`.
func flash(color: Color, t := 0.5, delay := 0.0) -> void:
if Motion.instant() or not is_inside_tree():
return
if _flash_tween != null:
_flash_tween.kill()
_flash_tween = create_tween()
if delay > 0.0:
_flash_tween.tween_interval(Motion.secs(delay))
_flash_tween.tween_method(_set_flash, Color(color, 2.2), Color(color, 0.0), Motion.secs(t)).set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_OUT)
func _set_flash(c: Color) -> void:
_flash = c
if _mesh != null:
_mesh.set_instance_shader_parameter("flash", c)
func _start_trail(on: bool, color: Color) -> void:
_trail = on
_trail_color = color
_trail_from = position
if on:
set_process(true)
## Leaves ghosts along the way while the card rushes, and fades the old ones.
func _process(delta: float) -> void:
if Engine.is_editor_hint():
return
if _trail and get_parent() != null:
var step := position - _trail_from
var dist := step.length()
if delta > 0.0 and dist / delta >= TRAIL_MIN_SPEED:
var n := mini(3, ceili(dist * TRAIL_DENSITY))
for i in n:
_spawn_ghost(_trail_from.lerp(position, float(i + 1) / n), float(i + 1) / n)
_trail_from = position
var now := Time.get_ticks_msec() / 1000.0
while not _ghosts.is_empty() and now - _ghosts[0].born > TRAIL_LIFE:
_ghosts.pop_front().node.queue_free()
for g in _ghosts:
var k: float = 1.0 - (now - g.born) / TRAIL_LIFE
(g.node as GeometryInstance3D).set_instance_shader_parameter("fade", k * k * g.strength)
if not _trail and _ghosts.is_empty():
set_process(false)
func _spawn_ghost(at: Vector3, strength: float) -> void:
if _ghost_mesh == null:
_ghost_mesh = PlaneMesh.new()
_ghost_mesh.size = Vector2(1.27, 1.778)
_ghost_material = ShaderMaterial.new()
_ghost_material.shader = TRAIL_SHADER
var g := MeshInstance3D.new()
g.mesh = _ghost_mesh
g.material_override = _ghost_material
g.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
get_parent().add_child(g)
g.transform = Transform3D(transform.basis, at)
g.set_instance_shader_parameter("tint", _trail_color)
g.set_instance_shader_parameter("fade", strength)
# Cards held near the camera (your hand) leave fainter ghosts: they're large on screen.
var near := 0.35 if get_parent() is Node3D and get_parent().get_parent() is Camera3D else 1.0
_ghosts.append({"node": g, "born": Time.get_ticks_msec() / 1000.0, "strength": (0.15 + 0.35 * strength) * near})
if _ghosts.size() > TRAIL_MAX:
_ghosts.pop_front().node.queue_free()
func _exit_tree() -> void:
for g in _ghosts:
if is_instance_valid(g.node):
g.node.queue_free()
_ghosts = []
func _apply_materials() -> void:
@ -121,3 +271,4 @@ func _apply_uniforms() -> void:
return
_mesh.set_instance_shader_parameter("highlight", highlight)
_mesh.set_instance_shader_parameter("dim", dim)
_mesh.set_instance_shader_parameter("flash", _flash)

272
table/firewall_port.gd Normal file
View file

@ -0,0 +1,272 @@
class_name FirewallPort
extends Node3D
## A gateway as an ethernet port (gameplay-plan.md §B4): a socket printed on the mat, and a
## Firewall as a plug seated in it, with gold contacts (the cards' edge-connector motif: hardware
## plugs in here) and a row of LEDs, one per Firewall level the rules allow, lit up to its level.
## Firewalls have no Health, so the animations are plug in, swap up and unplug.
##
## Local axes: z runs along the line through the gateway, x across it.
const TILE_SHADER := preload("res://table/tile.gdshader")
const LED_SHADER := preload("res://table/led.gdshader")
const SOCKET := Vector2(0.62, 0.46)
const PLUG := Vector3(0.52, 0.2, 0.36)
const LED_SIZE := 0.1
const LED_STEP := 0.17
## Where the plug sits seated, and where it comes in from.
const SEATED := Vector3(0, PLUG.y / 2.0 + 0.004, 0)
const ABOVE := Vector3(0, 1.5, 0.25)
static var _socket_material: ShaderMaterial
static var _led_material: ShaderMaterial
static var _housing_material: StandardMaterial3D
static var _clip_material: StandardMaterial3D
static var _gold_material: StandardMaterial3D
## The level shown (0: no Firewall) and how many LEDs there are.
var level := 0
var levels := 3
var _socket: MeshInstance3D
var _tab: MeshInstance3D
var _plug: Node3D
var _leds: Array[MeshInstance3D] = []
var _tween: Tween
var _glow_tween: Tween
var _mark := Color(0, 0, 0, 0)
var _glow := 0.0
func _ready() -> void:
# A bit larger than life, so the LEDs read from across the table and in the top view.
scale = Vector3.ONE * 1.3
_make_materials()
_socket = _decal(SOCKET, 0.06)
_socket.position.y = 0.005
# The latch slot, on the socket's far side.
_tab = _decal(Vector2(0.24, 0.1), 0.025)
_tab.position = Vector3(0, 0.005, SOCKET.y / 2.0 + 0.04)
_plug = Node3D.new()
_plug.name = "Plug"
_plug.visible = false
add_child(_plug)
_plug.add_child(_box(PLUG, Vector3.ZERO, _housing_material))
_plug.add_child(_box(Vector3(0.2, 0.05, 0.16), Vector3(0, PLUG.y / 2.0 + 0.02, PLUG.z / 2.0 - 0.07), _clip_material))
for i in 8:
var x := (i - 3.5) * 0.052
_plug.add_child(_box(Vector3(0.03, 0.012, 0.1), Vector3(x, PLUG.y / 2.0 + 0.006, -PLUG.z / 2.0 + 0.06), _gold_material))
_build_leds()
_apply_socket()
func _make_materials() -> void:
if _socket_material != null:
return
_socket_material = ShaderMaterial.new()
_socket_material.shader = TILE_SHADER
_socket_material.set_shader_parameter("size", SOCKET)
_socket_material.set_shader_parameter("chamfer", 0.06)
_socket_material.set_shader_parameter("edge_width", 0.03)
_socket_material.set_shader_parameter("inner_line", 0.6)
_socket_material.render_priority = 0
_led_material = ShaderMaterial.new()
_led_material.shader = LED_SHADER
_housing_material = StandardMaterial3D.new()
_housing_material.albedo_color = Color(0.05, 0.13, 0.15, 0.78)
_housing_material.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
_housing_material.roughness = 0.12
_housing_material.metallic_specular = 0.8
_housing_material.rim_enabled = true
_housing_material.rim = 0.6
_housing_material.emission_enabled = true
_housing_material.emission = Style.ACCENT_DK
_housing_material.emission_energy_multiplier = 0.6
_clip_material = StandardMaterial3D.new()
_clip_material.albedo_color = Color(0.03, 0.06, 0.07)
_clip_material.roughness = 0.3
_gold_material = StandardMaterial3D.new()
_gold_material.albedo_color = Color("#ffd24a")
_gold_material.metallic = 1.0
_gold_material.roughness = 0.25
_gold_material.emission_enabled = true
_gold_material.emission = Color("#ffb02e")
_gold_material.emission_energy_multiplier = 0.12
## A flat chamfered decal on the mat, drawn with the tile shader.
func _decal(size: Vector2, chamfer: float) -> MeshInstance3D:
var m := MeshInstance3D.new()
var plane := PlaneMesh.new()
plane.size = size
m.mesh = plane
var mat: ShaderMaterial = _socket_material
if size != SOCKET:
mat = _socket_material.duplicate()
mat.set_shader_parameter("size", size)
mat.set_shader_parameter("chamfer", chamfer)
mat.set_shader_parameter("inner_line", 0.0)
m.material_override = mat
m.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
add_child(m)
return m
func _box(size: Vector3, at: Vector3, mat: Material) -> MeshInstance3D:
var m := MeshInstance3D.new()
var b := BoxMesh.new()
b.size = size
m.mesh = b
m.material_override = mat
m.position = at
return m
func _build_leds() -> void:
for l in _leds:
l.queue_free()
_leds = []
var mesh := BoxMesh.new()
mesh.size = Vector3(LED_SIZE, 0.035, LED_SIZE)
for i in levels:
var led := MeshInstance3D.new()
led.mesh = mesh
led.material_override = _led_material
led.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
led.position = Vector3((i - (levels - 1) / 2.0) * LED_STEP, PLUG.y / 2.0 + 0.018, 0.02)
_plug.add_child(led)
_leds.append(led)
_light(level, false)
## Shows Firewall `to` (0 for none) out of `max_levels`, animating from the shown level after
## `delay` seconds unless `animate` is false.
func set_level(to: int, max_levels: int, animate := true, delay := 0.0) -> void:
if max_levels != levels:
levels = maxi(1, max_levels)
_build_leds()
if to == level:
return
var from := level
level = to
if _tween != null:
_tween.kill()
if not animate or Motion.instant() or not is_inside_tree():
_plug.visible = to > 0
_plug.position = SEATED
_plug.scale = Vector3.ONE
_light(to, false)
return
_tween = create_tween()
if delay > 0.0:
_tween.tween_interval(Motion.secs(delay))
if from == 0:
_plug_in()
elif to == 0:
_unplug()
else:
_swap(to > from)
## The plug rushes in from above, hangs over the socket while it lines up, and snaps in; then
## the LEDs come on one by one.
func _plug_in() -> void:
_tween.tween_callback(func():
_plug.visible = true
_plug.scale = Vector3.ONE
_plug.position = ABOVE
_plug.rotation = Vector3(0.5, 0.35, 0)
_light(0, false))
var tw := _tween
tw.set_parallel(false)
Motion.rush_in(tw, _plug, "position", Vector3(0, 0.42, 0.02), 0.22)
tw.parallel()
Motion.rush_in(tw, _plug, "rotation", Vector3(0.08, 0, 0), 0.22)
Motion.drift(tw, _plug, "position", Vector3(0, 0.34, 0), 0.28)
tw.parallel()
Motion.drift(tw, _plug, "rotation", Vector3.ZERO, 0.28)
Motion.rush_out(tw, _plug, "position", SEATED, 0.1)
tw.tween_callback(func(): pulse(Style.firewall_color(level, levels), 2.6))
for i in level:
tw.tween_callback(_light.bind(i + 1, true))
tw.tween_interval(Motion.secs(0.08))
## Up a level: the plug lifts a little and reseats, and the new LEDs flash on. Down: they go out.
func _swap(up: bool) -> void:
var tw := _tween
Motion.rush_in(tw, _plug, "position", SEATED + Vector3(0, 0.14, 0), 0.12)
Motion.rush_out(tw, _plug, "position", SEATED, 0.1)
tw.tween_callback(func():
_light(level, true)
if up:
pulse(Style.firewall_color(level, levels), 2.0))
## Cleared: the LEDs go out, the plug lifts out of the socket and away.
func _unplug() -> void:
var tw := _tween
tw.tween_callback(_light.bind(0, true))
Motion.rush_in(tw, _plug, "position", SEATED + Vector3(0, 0.3, 0), 0.16)
Motion.drift(tw, _plug, "position", SEATED + Vector3(0, 0.42, 0), 0.22)
Motion.rush_out(tw, _plug, "position", ABOVE, 0.18)
tw.parallel()
Motion.rush_out(tw, _plug, "scale", Vector3.ONE * 0.4, 0.18)
tw.tween_callback(func(): _plug.visible = false)
## Lights the first `n` LEDs in the level's color; the rest stay dark.
func _light(n: int, flash: bool) -> void:
var c := Style.firewall_color(maxi(1, level), levels)
for i in _leds.size():
var on := i < n
_leds[i].set_instance_shader_parameter("led", Color(c, 3.4 if flash and i == n - 1 else 1.7) if on else Color(0.12, 0.16, 0.17, 0.0))
## A glow around the socket that fades out: a Firewall going in, or the gateway being picked.
func pulse(color: Color, strength: float) -> void:
if _glow_tween != null:
_glow_tween.kill()
_glow = strength
_mark = color
_apply_socket()
if Motion.instant():
_glow = 0.0
_apply_socket()
return
_glow_tween = create_tween()
_glow_tween.tween_method(func(g):
_glow = g
_apply_socket(), strength, 0.0, Motion.secs(0.7)).set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_OUT)
## Highlights the socket for a mark (a legal source or target), or clears it.
func set_mark(color: Color, strength: float) -> void:
_mark = color
_glow = strength
_apply_socket()
func _apply_socket() -> void:
if _socket == null:
return
var edge := Color(Style.ACCENT, 0.75) if level == 0 else Color(Style.firewall_color(level, levels), 0.9)
if _glow > 0.0:
edge = _mark
for d in [_socket, _tab]:
d.set_instance_shader_parameter("fill_color", Color(Style.BG, 0.92))
d.set_instance_shader_parameter("edge_color", edge)
d.set_instance_shader_parameter("glow", _glow)
## Whether an animation is playing.
func busy() -> bool:
return _tween != null and _tween.is_valid() and _tween.is_running()
func finish() -> void:
if busy():
_tween.kill()
_plug.visible = level > 0
_plug.position = SEATED
_plug.rotation = Vector3.ZERO
_plug.scale = Vector3.ONE
_light(level, false)

View file

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

View file

@ -7,25 +7,13 @@ extends Node3D
const CARD_SCENE := preload("res://table/card_3d.tscn")
const PLAYMAT_SCENE := preload("res://table/playmat.tscn")
const TILE_SHADER := preload("res://table/tile.gdshader")
const VOID_SHADER := preload("res://table/void_grid.gdshader")
## Okabe–Ito sky blue and orange, as in the browser app: they stay apart for color-blind players.
const OWNER_COLORS: Array[Color] = [Color("#56b4e9"), Color("#e69f00")]
const MARK_COLORS := {
"source": Color("#2de2c4"), "respond": Color("#ffb454"), "selected": Color("#ffffff"),
"target": Color("#2de2c4"), "attack": Color("#ff5c7a"), "fight": Color("#ff5c7a"),
}
const MARK_STRENGTH := {"source": 1.0, "respond": 1.2, "selected": 2.0, "target": 1.5, "attack": 1.8, "fight": 1.2}
const FIREWALL_COLORS: Array[Color] = [Color("#ffb454"), Color("#ff7a45"), Color("#ff3d3d")]
## Colors come from Style (ui-plan.md §0.1): owners, marks and the chrome.
## Your hand, held in front of the camera: distance and how much of a card shows at the bottom.
const HAND_DISTANCE := 9.0
const HAND_SHOWN := 0.62
## Screen space the 2D panels cover, in pixels at the 1600 × 900 base size. The camera fits the
## mat into what's left.
const PANEL_LEFT := 300.0
const PANEL_RIGHT := 345.0
const PANEL_TOP := 48.0
const PANEL_BOTTOM := 150.0
const HAND_DISTANCE := 8.2
const HAND_SHOWN := 0.74
## Hardware peeks out from under its wearer by this much each.
const HARDWARE_PEEK := 0.3
const PROGRAM_STEP := 0.42
@ -34,7 +22,15 @@ const BOT_HAND_SHOWN := 14
const POP_TIME := 2.2
const FLASH_TIME := 1.4
## Pop-ups showing at once; a new one past this drops the oldest.
const MAX_POPS := 6
const MAX_POPS := 8
## How each motion style moves a card (see _path_for): seconds for each leg of the curve.
const PATH_TIMES := {
"move": [0.2, 0.3, 0.16], "slam": [0.18, 0.12, 0.09], "reveal": [0.24, 0.7, 0.2],
"discard": [0.13, 0.2, 0.16], "destroy": [0.12, 0.34, 0.18], "draw": [0.22, 0.34, 0.18],
"deal": [0.2, 0.18], "stack": [0.24, 0.6, 0.2],
}
## How far in front of the camera a revealed card is held up.
const REVEAL_DISTANCE := 5.2
var camera: Camera3D
## The player sitting at the table (whose hand is held up, whose side the camera is on).
@ -48,19 +44,24 @@ var _hand_root: Node3D
var _board: Node3D
var _cards_root: Node3D
var _tile_material: ShaderMaterial
var _mat: Node3D
var _floor_material: ShaderMaterial
var _tiles := {}
var _gates := {}
var _lines := {}
var _cards := {}
var _piles := {}
var _hover_body: Object = null
## Your hand's cards in hand order.
## Your hand's cards in hand order, and the Executions waiting on the stack, oldest first.
var _hand_order: Array[Card3D] = []
var _stack_order: Array[Card3D] = []
var _zoom := 1.0
## Your hand drops out of sight while the HUD's hand-focus row shows it instead.
var _hand_tucked := false
var _cam_tween: Tween
var _view: Dictionary = {}
var _font: SystemFont
var _tag_font: SystemFont
var _font: Font
var _tag_font: Font
var _overlay: Control
## 2D readouts pinned to points on the table: key → {box, label, world, used}.
var _tags := {}
@ -69,13 +70,19 @@ var _pops: Array = []
## Tiles pulsing after a capture: location → {color, born}.
var _flashes := {}
var _last_marks := {}
## Set by the presenter just before a sync, used by it once: how a card should get to its new spot
## (node key → {style, delay, p, from}), and when each gateway's Firewall should change (line →
## seconds). Anything without one just glides.
var motions := {}
var gate_delays := {}
## Seconds before each player's Bandwidth bar on the mat moves (player → seconds); also the presenter's.
var bandwidth_delays := {}
var _strips: Array[BandwidthStrip] = []
func _ready() -> void:
_font = SystemFont.new()
_font.font_names = PackedStringArray(["DejaVu Sans", "Noto Sans", "sans-serif"])
_tag_font = SystemFont.new()
_tag_font.font_names = PackedStringArray(["DejaVu Sans Mono", "Adwaita Mono", "monospace"])
_font = Style.body_font(600)
_tag_font = Style.body_font(500)
_build_room()
var layer := CanvasLayer.new()
layer.layer = 0
@ -99,41 +106,21 @@ func _ready() -> void:
# Building
func _build_room() -> void:
var env := Environment.new()
env.background_mode = Environment.BG_COLOR
env.background_color = Color(0.035, 0.035, 0.045)
env.ambient_light_source = Environment.AMBIENT_SOURCE_COLOR
env.ambient_light_color = Color(0.72, 0.75, 0.82)
env.ambient_light_energy = 0.85
env.tonemap_mode = Environment.TONE_MAPPER_FILMIC
env.glow_enabled = true
env.glow_intensity = 0.4
env.glow_hdr_threshold = 1.2
var we := WorldEnvironment.new()
we.environment = env
add_child(we)
add_child(make_environment())
var sun := DirectionalLight3D.new()
sun.light_color = Color(0.9, 0.87, 0.82)
sun.light_energy = 1.35
sun.light_color = Color(0.9, 0.95, 1.0)
sun.light_energy = 1.2
sun.shadow_enabled = true
sun.shadow_opacity = 0.7
sun.directional_shadow_max_distance = 60.0
add_child(sun)
sun.look_at_from_position(Vector3(6, 20, 9), Vector3.ZERO, Vector3.UP)
var ground := make_floor()
_floor_material = ground.material_override
add_child(ground)
# The table under the mat: dark wood.
var top := MeshInstance3D.new()
var box := BoxMesh.new()
box.size = Vector3(64, 1, 52)
top.mesh = box
var wood := StandardMaterial3D.new()
wood.albedo_color = Color(0.16, 0.105, 0.07)
wood.roughness = 0.62
top.material_override = wood
top.position = Vector3(0, -0.6, 0)
add_child(top)
add_child(PLAYMAT_SCENE.instantiate())
_mat = PLAYMAT_SCENE.instantiate()
add_child(_mat)
camera = Camera3D.new()
camera.fov = 45.0
@ -147,6 +134,7 @@ func _build_room() -> void:
func _build_board() -> void:
BoardLayout.update()
_fit_grid()
_tile_material = ShaderMaterial.new()
_tile_material.shader = TILE_SHADER
_tile_material.set_shader_parameter("size", BoardLayout.tile_size)
@ -154,8 +142,9 @@ func _build_board() -> void:
var plane := PlaneMesh.new()
plane.size = BoardLayout.tile_size
# The lines between locations, as dim circuit traces.
var line_material := StandardMaterial3D.new()
line_material.albedo_color = Color(0.85, 0.88, 0.92, 0.32)
line_material.albedo_color = Color(Style.ACCENT, 0.42)
line_material.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
line_material.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
line_material.render_priority = -2
@ -187,8 +176,9 @@ func _build_board() -> void:
spot_material.shader = TILE_SHADER
var spot_size := BoardLayout.CARD_SIZE + Vector2(0.14, 0.14)
spot_material.set_shader_parameter("size", spot_size)
spot_material.set_shader_parameter("radius", 0.1)
spot_material.set_shader_parameter("edge_width", 0.04)
spot_material.set_shader_parameter("chamfer", BoardLayout.CARD_SIZE.x * Style.CHAMFER_RATIO * 2.0)
spot_material.set_shader_parameter("edge_width", 0.035)
spot_material.set_shader_parameter("inner_line", 0.0)
spot_material.render_priority = -1
var spot_plane := PlaneMesh.new()
spot_plane.size = spot_size
@ -202,9 +192,9 @@ func _build_board() -> void:
for i in spots.size():
var at: Vector3 = spots[i]
# The spot's name, printed in the gap between it and the first row.
var name := _flat_label(34)
var name := _flat_label(30)
name.text = names[i]
name.modulate = Color(OWNER_COLORS[p], 0.75)
name.modulate = Color(Style.OWNER[p], 0.8)
name.rotation.y = BoardLayout.yaw_for(p)
var inward := -1.0 if p == 0 else 1.0
name.position = Vector3(at.x, 0.004, at.z + inward * (BoardLayout.CARD_SIZE.y / 2 + 0.17))
@ -215,8 +205,18 @@ func _build_board() -> void:
m.position = Vector3(at.x, 0.003, at.z)
m.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
_board.add_child(m)
m.set_instance_shader_parameter("fill_color", Color(OWNER_COLORS[p], 0.06))
m.set_instance_shader_parameter("edge_color", Color(OWNER_COLORS[p], 0.5))
m.set_instance_shader_parameter("fill_color", Color(Style.OWNER[p] * 0.18, 0.55))
m.set_instance_shader_parameter("edge_color", Color(Style.OWNER[p], 0.6))
m.set_instance_shader_parameter("pattern", 1.0 + p)
# Each player's Bandwidth bar, just off their edge of the mat.
for p in [0, 1]:
var strip := BandwidthStrip.new()
var toward := 1.0 if p == 0 else -1.0
strip.position = Vector3(0, -0.1, toward * (BoardLayout.MAT_SIZE.y / 2.0 + 0.36))
strip.rotation.y = BoardLayout.yaw_for(p)
_board.add_child(strip)
_strips.append(strip)
for loc in GameMap.LOCATIONS:
var tile := MeshInstance3D.new()
@ -233,12 +233,69 @@ func _build_board() -> void:
body.add_child(shape)
body.set_meta("key", Moves.loc_key(loc))
tile.add_child(body)
var label := _flat_label(64)
label.position = BoardLayout.at[loc] + Vector3(BoardLayout.tile_size.x / 2 - 1.0, 0.004, 0)
# The location's id as microtext in the socket's corner.
var label := _flat_label(58)
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
label.vertical_alignment = VERTICAL_ALIGNMENT_TOP
label.modulate = Color(Style.SECONDARY, 0.85)
_board.add_child(label)
_tiles[loc] = {"mesh": tile, "label": label}
## Cyberspace (gameplay-plan.md §B1): a black void with a cool, even light so the cards stay
## readable; neon emission is what blooms. The menu uses it too, so both read as one world.
static func make_environment() -> WorldEnvironment:
var env := Environment.new()
env.background_mode = Environment.BG_COLOR
env.background_color = Color("#010304")
env.ambient_light_source = Environment.AMBIENT_SOURCE_COLOR
env.ambient_light_color = Color(0.66, 0.76, 0.86)
env.ambient_light_energy = 0.8
env.tonemap_mode = Environment.TONE_MAPPER_FILMIC
env.glow_enabled = true
env.glow_intensity = 0.75
env.glow_strength = 1.05
env.glow_bloom = 0.0
env.glow_hdr_threshold = 1.1
env.glow_blend_mode = Environment.GLOW_BLEND_MODE_ADDITIVE
for i in 7:
env.set_glow_level(i, [0.0, 1.0, 1.0, 0.7, 0.5, 0.0, 0.0][i])
var we := WorldEnvironment.new()
we.environment = env
return we
## The floor under the mat: the neon grid running out into the void.
static func make_floor(size := 240.0) -> MeshInstance3D:
var ground := MeshInstance3D.new()
var plane := PlaneMesh.new()
plane.size = Vector2(size, size)
ground.mesh = plane
var m := ShaderMaterial.new()
m.shader = VOID_SHADER
m.render_priority = -4
ground.material_override = m
ground.position = Vector3(0, -0.14, 0)
ground.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
return ground
## Lines the mat's and floor's grids up with the locations: half a column pitch across and a row
## pitch deep, crossing between the rows.
func _fit_grid() -> void:
var pitch := Vector2(BoardLayout.col_pitch / 2.0, BoardLayout.row_pitch)
var origin := Vector2(0, BoardLayout.row_pitch / 2.0)
var mats: Array = [_floor_material]
for mi in _mat.find_children("*", "MeshInstance3D", true, false):
var m: Material = (mi as MeshInstance3D).get_surface_override_material(0)
if m is ShaderMaterial:
mats.append(m)
for m in mats:
m.set_shader_parameter("pitch", pitch)
m.set_shader_parameter("origin", origin)
m.set_shader_parameter("half_size", BoardLayout.MAT_SIZE / 2.0)
## How far along d (from a tile's centre) the segment leaves a tile of half-size `half`.
static func _exit_t(d: Vector3, half: Vector2) -> float:
var tx := INF if is_zero_approx(d.x) else half.x / absf(d.x)
@ -248,37 +305,10 @@ static func _exit_t(d: Vector3, half: Vector2) -> float:
func _make_gate(line: Dictionary, yaw: float) -> Dictionary:
var at := BoardLayout.line_mid(line)
var diamond := MeshInstance3D.new()
var dm := PlaneMesh.new()
dm.size = Vector2(0.34, 0.34)
diamond.mesh = dm
var mat := StandardMaterial3D.new()
mat.albedo_color = Color(0.85, 0.88, 0.92, 0.55)
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
mat.emission_enabled = true
mat.emission = Color.BLACK
mat.render_priority = -1
diamond.material_override = mat
diamond.position = at + Vector3(0, 0.004, 0)
diamond.rotation.y = PI / 4
diamond.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
_board.add_child(diamond)
var wall := MeshInstance3D.new()
var wm := BoxMesh.new()
wm.size = Vector3(1.0, 1.0, 0.14)
wall.mesh = wm
var wall_mat := StandardMaterial3D.new()
wall_mat.albedo_color = FIREWALL_COLORS[0]
wall_mat.emission_enabled = true
wall_mat.emission = FIREWALL_COLORS[0]
wall_mat.emission_energy_multiplier = 0.35
wall_mat.roughness = 0.4
wall.material_override = wall_mat
wall.position = at
wall.rotation.y = yaw
wall.visible = false
_board.add_child(wall)
var port := FirewallPort.new()
port.position = at
port.rotation.y = yaw
_board.add_child(port)
var body := StaticBody3D.new()
var shape := CollisionShape3D.new()
var bs := BoxShape3D.new()
@ -288,7 +318,7 @@ func _make_gate(line: Dictionary, yaw: float) -> Dictionary:
body.position = at + Vector3(0, 0.2, 0)
body.set_meta("key", Moves.gate_key(line.id))
_board.add_child(body)
return {"diamond": diamond, "mat": mat, "wall": wall, "wall_mat": wall_mat, "at": at}
return {"port": port, "at": at}
func _flat_label(size: int) -> Label3D:
@ -297,7 +327,7 @@ func _flat_label(size: int) -> Label3D:
l.font_size = size
l.pixel_size = 0.004
l.rotation.x = -PI / 2
l.modulate = Color(0.85, 0.88, 0.92, 0.8)
l.modulate = Color(Style.SECONDARY, 0.8)
l.outline_size = 0
l.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
return l
@ -339,9 +369,7 @@ func _place_camera(instant: bool) -> void:
func _fit_camera() -> Transform3D:
var side := 1.0 if me == 0 else -1.0
var vp := get_viewport().get_visible_rect().size
var sx := vp.x / 1600.0
var sy := vp.y / 900.0
var region := Rect2(PANEL_LEFT * sx, PANEL_TOP * sy, vp.x - (PANEL_LEFT + PANEL_RIGHT) * sx, vp.y - (PANEL_TOP + PANEL_BOTTOM) * sy)
var region := Style.table_region(vp)
var hx := BoardLayout.MAT_SIZE.x / 2
var hz := BoardLayout.MAT_SIZE.y / 2
var points := [Vector3(-hx, 0, -hz), Vector3(hx, 0, -hz), Vector3(-hx, 0, hz), Vector3(hx, 0, hz),
@ -412,8 +440,13 @@ func _is_hand_body(body: Object) -> bool:
# ---------------------------------------------------------------------------------------------
# Syncing to a view
## The view the table shows now ({} before the first sync).
func shown_view() -> Dictionary:
return _view
## Snaps the table to `view` (as seen by `me`), with `marks` from key to a mark name (see
## MARK_COLORS).
## Style.MARK).
func sync(v: Dictionary, marks: Dictionary) -> void:
_view = v
_last_marks = marks
@ -421,11 +454,22 @@ func sync(v: Dictionary, marks: Dictionary) -> void:
_tags[k].used = false
_sync_tiles(v, marks)
_sync_gates(v, marks)
for p in [0, 1]:
var pl: Dictionary = v.players[p]
if _strips[p].get_meta("ticks", []) != v.rules.firewallCost:
_strips[p].set_ticks(v.rules.firewallCost)
_strips[p].set_meta("ticks", v.rules.firewallCost)
var reach := Query.reachable_bandwidth(v, p) if p == me else int(pl.bandwidth)
_strips[p].set_value(pl.bandwidth, reach, Style.OWNER[p], bandwidth_delays.get(p, 0.0))
bandwidth_delays = {}
var want := {}
_want_board_cards(v, want)
_want_zones(v, want)
_want_stack(v, want)
_apply_cards(want, marks)
_layout_hand()
_layout_stack()
motions = {}
for k in _tags.keys():
if not _tags[k].used:
_tags[k].box.queue_free()
@ -437,51 +481,49 @@ func _sync_tiles(v: Dictionary, marks: Dictionary) -> void:
for loc in GameMap.LOCATIONS:
var tile: MeshInstance3D = _tiles[loc].mesh
var owner = v.locations[loc].owner
var fill := Color(1, 1, 1, 0.018)
var edge := Color(0.82, 0.85, 0.9, 0.4)
# An open socket is dim chrome; a held one takes its owner's color and pattern.
var fill := Color(Style.BG, 0.62)
var edge := Color(Style.ACCENT, 0.5)
if owner != null:
fill = Color(OWNER_COLORS[owner], 0.075)
edge = Color(OWNER_COLORS[owner], 0.85)
fill = Color(Style.OWNER[owner] * 0.2, 0.72)
edge = Color(Style.OWNER[owner], 0.9)
tile.set_instance_shader_parameter("pattern", 0.0 if owner == null else 1.0 + owner)
var glow := 0.0
var mark = marks.get(Moves.loc_key(loc))
if mark != null:
edge = MARK_COLORS[mark]
glow = MARK_STRENGTH[mark]
edge = Style.MARK[mark]
glow = Style.MARK_STRENGTH[mark]
tile.set_instance_shader_parameter("fill_color", fill)
tile.set_instance_shader_parameter("edge_color", edge)
tile.set_instance_shader_parameter("glow", glow)
var label: Label3D = _tiles[loc].label
if GameMap.is_start(loc):
label.text = "%s · %s" % [loc, "your start" if loc == GameMap.START_LOC[me] else "start"]
label.text = "%s · %s" % [loc, "YOUR START" if loc == GameMap.START_LOC[me] else "START"]
else:
label.text = "%s · Lv %d" % [loc, GameMap.level_for(me, loc)]
label.text = "%s · LV %d" % [loc, GameMap.level_for(me, loc)]
# In the socket's far right corner as you sit.
var toward := 1.0 if me == 0 else -1.0
var half := BoardLayout.tile_size / 2.0 - Vector2(0.28, 0.16)
label.position = BoardLayout.at[loc] + Vector3(half.x * toward, 0.004, -half.y * toward)
label.rotation.y = 0.0 if me == 0 else PI
func _sync_gates(v: Dictionary, marks: Dictionary) -> void:
# The LED count comes from the rules, so a longer Firewall cost list shows every level.
var levels: int = v.rules.firewallCost.size()
for line_id in _gates:
var g: Dictionary = _gates[line_id]
var level: int = v.firewalls.get(line_id, 0)
var port: FirewallPort = g.port
port.set_level(level, levels, true, gate_delays.get(line_id, 0.0))
var mark = marks.get(Moves.gate_key(line_id))
var mat: StandardMaterial3D = g.mat
if mark != null:
mat.albedo_color = MARK_COLORS[mark]
mat.emission = MARK_COLORS[mark] * MARK_STRENGTH[mark]
else:
mat.albedo_color = Color(0.85, 0.88, 0.92, 0.55) if level == 0 else Color(FIREWALL_COLORS[level - 1], 0.9)
mat.emission = Color.BLACK
var wall: MeshInstance3D = g.wall
wall.visible = level > 0
if level > 0:
var h := 0.22 + 0.2 * level
wall.scale = Vector3(1, h, 1)
wall.position.y = h / 2.0
var c := FIREWALL_COLORS[mini(level, FIREWALL_COLORS.size()) - 1]
g.wall_mat.albedo_color = c
g.wall_mat.emission = c
_tag("gate:" + line_id, "Lv %d" % level, c.lightened(0.3), g.at + Vector3(0, h + 0.1, 0), true)
port.set_mark(Style.MARK[mark], Style.MARK_STRENGTH[mark])
elif not port.busy():
port.set_mark(Color(0, 0, 0, 0), 0.0)
var seg: MeshInstance3D = _lines[line_id]
seg.transparency = 0.6 if level > 0 else 0.0
gate_delays = {}
## Cards on the mat: Servers, Programs, Anomalies in play and their Hardware.
@ -584,6 +626,14 @@ func _want_zones(v: Dictionary, want: Dictionary) -> void:
"yaw": yaw, "face_down": true, "key": "pile:%d:hand" % p}
## Executions waiting on the stack, held up beside the table until they resolve: their card is in
## no zone meanwhile. Not clickable, so they never cover a click on the board.
func _want_stack(v: Dictionary, want: Dictionary) -> void:
for it in v.stack:
if it.kind == "execution" and it.get("card", -1) >= 0:
want["card:%d" % it.card] = {"name": State.name_of(v, it.card), "held": "stack", "key": ""}
## A pile: a block as tall as the count, with its top card on it (face up for the discard).
func _want_pile(p: int, zone: String, count: int, top: int, want: Dictionary) -> void:
var spot := BoardLayout.zone_spot(p, zone)
@ -621,9 +671,20 @@ func _make_pile(spot: Vector3) -> Dictionary:
## Creates, moves and removes Card3Ds to match `want` (node key → spot).
func _apply_cards(want: Dictionary, marks: Dictionary) -> void:
_hand_order = []
_stack_order = []
for key in _cards.keys():
if not want.has(key):
_cards[key].queue_free()
var card: Card3D = _cards[key]
var spec: Dictionary = motions.get(key, {})
if spec.get("style", "") == "leave":
# Back into a hidden pile: it goes there, then it's gone.
if card.get_parent() != _cards_root:
card.reparent(_cards_root, true)
card.pick_key = ""
var goal := _zone_xf(spec.get("p", me), spec.get("to", "deck"))
card.travel(_path_for(card, goal, {"style": "discard"}, false), PATH_TIMES.discard, spec.get("delay", 0.0), true, Style.ACCENT, true)
else:
card.queue_free()
_cards.erase(key)
for key in want:
var w: Dictionary = want[key]
@ -632,7 +693,8 @@ func _apply_cards(want: Dictionary, marks: Dictionary) -> void:
if fresh:
card = CARD_SCENE.instantiate()
_cards[key] = card
var parent: Node = _hand_root if w.get("hand", false) else _cards_root
var held: bool = w.get("hand", false) or w.has("held")
var parent: Node = _hand_root if held else _cards_root
if card.get_parent() != parent:
if card.get_parent() == null:
parent.add_child(card)
@ -641,24 +703,125 @@ func _apply_cards(want: Dictionary, marks: Dictionary) -> void:
card.set_shadows(parent != _hand_root)
card.card_name = w.name
card.pick_key = w.key
card.set_meta("node_key", key)
if w.get("hand", false):
_hand_order.append(card)
elif w.get("held", "") == "stack":
_stack_order.append(card)
card.dim = w.get("dim", 0.0)
var mark = marks.get(w.key) if not w.key.begins_with("loc:") else null
# Only the card a hand key names glows, and only an Anomaly's own card, not its Hardware.
if mark != null and w.key.begins_with("anomaly:") and key != w.key:
mark = null
var strength: float = MARK_STRENGTH[mark] * (0.55 if w.get("hand", false) else 1.0) if mark != null else 0.0
card.highlight = Color(MARK_COLORS[mark], strength) if mark != null else Color(0, 0, 0, 0)
if not w.get("hand", false):
var strength: float = Style.MARK_STRENGTH[mark] * (0.55 if w.get("hand", false) else 1.0) if mark != null else 0.0
card.highlight = Color(Style.MARK[mark], strength) if mark != null else Color(0, 0, 0, 0)
if not held:
var basis := Basis.from_euler(Vector3(0, w.yaw, PI if w.get("face_down", false) else 0.0))
var xf := Transform3D(basis, w.pos)
if fresh:
card.transform = xf
card.glide(xf, fresh)
var spec: Dictionary = motions.get(key, {})
if not spec.is_empty():
var style: String = spec.style
card.travel(_path_for(card, xf, spec, fresh), PATH_TIMES.get(style, PATH_TIMES.move), spec.get("delay", 0.0),
true, spec.get("color", Style.ACCENT))
if style == "destroy":
card.flash(Style.BAD, 0.6, spec.get("delay", 0.0))
else:
if fresh:
card.transform = xf
card.glide(xf, fresh)
_sync_badge(key, w)
## The way a card travels to `goal` (world space) for a motion spec. See PATH_TIMES for timing.
func _path_for(card: Card3D, goal: Transform3D, spec: Dictionary, fresh: bool) -> Array:
var start := goal if fresh else card.global_transform
if spec.get("from", "") != "":
start = _zone_xf(spec.get("p", me), spec.from)
var up := Vector3.UP
match spec.style:
"slam":
# Straight over its spot, then down hard.
var over := Transform3D(goal.basis, goal.origin + up * 1.5)
return [start, over, over.translated(-up * 0.25), goal]
"reveal":
# Up in front of you, face up, held there to read, then down to its spot.
var show := _present_xf()
return [start, show, show.translated(camera.global_transform.basis.z * 0.3), goal]
"discard", "destroy":
var rise := Transform3D(start.basis, start.origin + up * 0.7)
return [start, rise, Transform3D(goal.basis, goal.origin + up * 0.9), goal]
"deal":
return [start, Transform3D(goal.basis, start.origin.lerp(goal.origin, 0.5) + up * 0.8), goal]
# "move": lift off, drift over the destination, set down.
var lift := Transform3D(start.basis, start.origin.lerp(goal.origin, 0.2) + up * 1.3)
return [start, lift, Transform3D(goal.basis, goal.origin + up * 0.8), goal]
## Where a card held up for you to read sits: in front of the camera, upright.
func _present_xf() -> Transform3D:
return camera.global_transform * Transform3D(Basis(Vector3.RIGHT, PI / 2), Vector3(0, 0.45, -REVEAL_DISTANCE))
## The top of player `p`'s pile `zone` ("deck", "serverPile", "discard", "hand"), face down, in
## world space. Your own "hand" is the held hand in front of the camera.
func _zone_xf(p: int, zone: String) -> Transform3D:
if zone == "hand" and p == me:
var half_h := HAND_DISTANCE * tan(deg_to_rad(camera.fov / 2.0))
return camera.global_transform * Transform3D(Basis(Vector3.RIGHT, PI / 2), Vector3(0, -half_h, -HAND_DISTANCE))
if zone == "play":
zone = "hand"
var count := 1
if not _view.is_empty() and _view.players[p].has(zone):
count = maxi(1, _view.players[p][zone].size())
var h := (count - 1) * BoardLayout.LAYER + BoardLayout.CARD_Y if zone != "hand" else BoardLayout.CARD_Y
return Transform3D(Basis.from_euler(Vector3(0, BoardLayout.yaw_for(p), PI)), BoardLayout.zone_spot(p, zone) + Vector3(0, h, 0))
## A table point for a key ("anomaly:…", "card:…", "loc:…"): the card now, or the location.
func anchor_of(key: String) -> Variant:
var c: Card3D = _cards.get(key)
if c != null and is_instance_valid(c):
return c.global_position
if key.begins_with("loc:") and BoardLayout.at.has(key.substr(4)):
return BoardLayout.at[key.substr(4)]
if key.begins_with("gate:") and _gates.has(key.substr(5)):
return _gates[key.substr(5)].at
return null
## A flash on the card at node key `key`.
func flash_card(key: String, color: Color, delay := 0.0) -> void:
var c: Card3D = _cards.get(key)
if c != null and is_instance_valid(c):
c.flash(color, 0.55, delay)
## Whether anything on the table is still moving.
func animating() -> bool:
for k in _cards:
if is_instance_valid(_cards[k]) and _cards[k].moving():
return true
for g in _gates.values():
if g.port.busy():
return true
return false
## Jumps every animation to its end (a click skips the show).
func finish_animations() -> void:
for k in _cards:
if is_instance_valid(_cards[k]):
_cards[k].finish()
for g in _gates.values():
g.port.finish()
for pop in _pops:
pop.label.queue_free()
_pops = []
_flashes = {}
if not _view.is_empty():
_sync_tiles(_view, _last_marks)
## A readout under an Anomaly: Cores, Health and status.
func _sync_badge(key: String, w: Dictionary) -> void:
if not w.get("badge", false):
@ -668,7 +831,7 @@ func _sync_badge(key: String, w: Dictionary) -> void:
return
var toward := 1.0 if me == 0 else -1.0
var card: Card3D = _cards[key]
_tag(key, badge_text(_view, r), OWNER_COLORS[r.player].lightened(0.3), Vector3(0, 0.05, 0.72 * toward), false, card)
_tag(key, badge_text(_view, r), Style.OWNER[r.player].lightened(0.3), Vector3(0, 0.05, 0.72 * toward), false, card)
## Shows `text` in a small 2D box pinned under the table point `world`, or with `follow`, at
@ -679,9 +842,7 @@ func _tag(key: String, text: String, color: Color, world: Vector3, above := fals
if t.is_empty():
var box := PanelContainer.new()
box.mouse_filter = Control.MOUSE_FILTER_IGNORE
var sb := StyleBoxFlat.new()
sb.bg_color = Color(0.02, 0.03, 0.04, 0.78)
sb.set_corner_radius_all(4)
var sb := Style.chamfer_box(Color(color, 0.45), Color(Style.BG, 0.82), 1.0, 0.0, 4.0)
sb.content_margin_left = 5
sb.content_margin_right = 5
sb.content_margin_top = 1
@ -695,7 +856,10 @@ func _tag(key: String, text: String, color: Color, world: Vector3, above := fals
t = {"box": box, "label": label}
_tags[key] = t
t.label.text = text
t.label.add_theme_color_override("font_color", color)
# Only on a change: an override restyles the label, which reshapes its text.
if t.get("color") != color:
t.color = color
t.label.add_theme_color_override("font_color", color)
t.world = world
t.above = above
t.used = true
@ -723,7 +887,7 @@ func pop_damage(r: Dictionary, amount: int, destroyed: bool, loc: Variant, delay
world = BoardLayout.at[loc]
else:
return
pop_text(world, "−%d%s" % [amount, " destroyed" if destroyed else ""], Color("#ff6b6b"), delay, 26)
pop_text(world, "−%d%s" % [amount, " destroyed" if destroyed else ""], Style.BAD, delay, 26)
## A short message rising from a table point, e.g. who won a roll.
@ -740,13 +904,13 @@ func pop_text(world: Vector3, text: String, color: Color, delay := 0.0, size :=
_overlay.add_child(label)
while _pops.size() >= MAX_POPS:
_pops.pop_front().label.queue_free()
_pops.append({"label": label, "world": world, "born": Time.get_ticks_msec() + int(delay * 1000)})
_pops.append({"label": label, "world": world, "born": Time.get_ticks_msec() + int(Motion.secs(delay) * 1000)})
## The location at `loc` pulses in its new owner's color.
func flash_capture(loc: String, p: int) -> void:
if _tiles.has(loc):
_flashes[loc] = {"color": OWNER_COLORS[p], "born": Time.get_ticks_msec()}
## The location at `loc` pulses in its new owner's color, after `delay` seconds.
func flash_capture(loc: String, p: int, delay := 0.0) -> void:
if _tiles.has(loc) and not Motion.instant():
_flashes[loc] = {"color": Style.OWNER[p], "born": Time.get_ticks_msec() + int(Motion.secs(delay) * 1000)}
func _place_pops() -> void:
@ -776,6 +940,8 @@ func _pulse_tiles() -> void:
var f: Dictionary = _flashes[loc]
var age: float = (now - f.born) / 1000.0
var tile: MeshInstance3D = _tiles[loc].mesh
if age < 0.0:
continue
if age > FLASH_TIME:
_flashes.erase(loc)
_sync_tiles(_view, _last_marks)
@ -833,6 +999,46 @@ static func badge_text(v: Dictionary, r: Dictionary) -> String:
return " ".join(parts)
## Lays out the Executions on the stack at the right of the table, newest in front. One that
## just went on is held up in the middle for you to read first.
func _layout_stack() -> void:
var n := _stack_order.size()
if n == 0:
return
var vp := get_viewport().get_visible_rect().size
var d := HAND_DISTANCE + 2.2
var half_h := d * tan(deg_to_rad(camera.fov / 2.0))
var half_w := half_h * vp.x / vp.y
var region := Style.table_region(vp)
var right := half_w - 2.0 * half_w * (vp.x - region.end.x) / vp.x - BoardLayout.CARD_SIZE.x * 0.8
for i in n:
var c: Card3D = _stack_order[i]
if not is_instance_valid(c) or c.is_queued_for_deletion():
continue
var tilt := Basis(Vector3.RIGHT, PI / 2).rotated(Vector3.BACK, 0.06 - 0.05 * i)
var xf := Transform3D(tilt, Vector3(right - i * 0.6, half_h * 0.25 - i * 0.18, -d + i * 0.02))
var spec: Dictionary = motions.get(c.get_meta("node_key", ""), {})
if spec.get("style", "") == "stack":
var start := c.transform
if spec.get("from", "") != "":
start = camera.global_transform.affine_inverse() * _zone_xf(spec.get("p", me), spec.from)
var show := Transform3D(Basis(Vector3.RIGHT, PI / 2), Vector3(0, 0.45, -REVEAL_DISTANCE))
c.travel([start, show, show.translated(Vector3(0, 0, 0.25)), xf], PATH_TIMES.stack, spec.get("delay", 0.0),
true, spec.get("color", Style.ACCENT))
continue
if not c.has_goal():
c.transform = xf
c.glide(xf)
## Drops your held hand out of sight (true) or brings it back.
func set_hand_tucked(on: bool) -> void:
if on == _hand_tucked:
return
_hand_tucked = on
_layout_hand()
## Lays out your hand in front of the camera, the hovered card lifted.
func _layout_hand() -> void:
var cards := _hand_order.filter(func(c): return is_instance_valid(c) and not c.is_queued_for_deletion())
@ -842,9 +1048,10 @@ func _layout_hand() -> void:
var vp := get_viewport().get_visible_rect().size
var half_h := HAND_DISTANCE * tan(deg_to_rad(camera.fov / 2.0))
var half_w := half_h * vp.x / vp.y
# Keep clear of the side panels (see the HUD): 300 px on the left, 340 on the right.
var left := -half_w + 2.0 * half_w * 300.0 / vp.x + BoardLayout.CARD_SIZE.x / 2
var right := half_w - 2.0 * half_w * 340.0 / vp.x - BoardLayout.CARD_SIZE.x / 2
# Keep clear of the side panels (Style's panel geometry, as the HUD draws them).
var region := Style.table_region(vp)
var left := -half_w + 2.0 * half_w * region.position.x / vp.x + BoardLayout.CARD_SIZE.x / 2
var right := half_w - 2.0 * half_w * (vp.x - region.end.x) / vp.x - BoardLayout.CARD_SIZE.x / 2
var step := 1.34 if n == 1 else minf(1.34, (right - left) / (n - 1))
var mid := (left + right) / 2.0
var y0 := -half_h + BoardLayout.CARD_SIZE.y * (HAND_SHOWN - 0.5)
@ -856,8 +1063,17 @@ func _layout_hand() -> void:
var y := y0 + (BoardLayout.CARD_SIZE.y * 0.42 if lift else 0.0)
if c.highlight.a > 0 and not lift:
y += 0.12
if _hand_tucked:
y = -half_h - BoardLayout.CARD_SIZE.y
var pos := Vector3(x, y, -HAND_DISTANCE + i * 0.004 + (0.25 if lift else 0.0))
var xf := Transform3D(Basis(Vector3.RIGHT, PI / 2), pos)
var spec: Dictionary = motions.get(c.get_meta("node_key", ""), {})
if spec.get("style", "") == "draw":
# Drawn: off the deck, held up to you, then into the hand.
var deck := camera.global_transform.affine_inverse() * _zone_xf(me, "deck")
var hold := Transform3D(Basis(Vector3.RIGHT, PI / 2), Vector3(x * 0.45, -0.25, -REVEAL_DISTANCE - 0.3))
c.travel([deck, hold, hold.translated(Vector3(0, 0.06, 0.25)), xf], PATH_TIMES.draw, spec.get("delay", 0.0))
continue
if not c.has_goal():
# A card just drawn comes up from below.
c.transform = xf.translated(Vector3(0, -2.5, 0))
@ -868,8 +1084,7 @@ func _layout_hand() -> void:
## Tries spots across each object with that key and raycasts each, as a click would. For tests.
func screen_point_for(key: String) -> Variant:
var vp := get_viewport().get_visible_rect().size
var sx := vp.x / 1600.0
var region := Rect2(PANEL_LEFT * sx, PANEL_TOP * vp.y / 900.0, vp.x - (PANEL_LEFT + PANEL_RIGHT) * sx, vp.y)
var region := Style.table_region(vp, 0.0)
var points := []
var grid := func(xf: Transform3D, half: Vector2, y: float) -> void:
for fz in [0.0, -0.6, 0.6, -0.85, 0.85]:

15
table/led.gdshader Normal file
View file

@ -0,0 +1,15 @@
shader_type spatial;
render_mode blend_mix, unshaded, shadows_disabled;
// A Firewall LED (gameplay-plan.md §B4). One material for every LED; each one's color and how
// brightly it's lit (a, past 1 for bloom; 0 is off) are instance uniforms.
instance uniform vec4 led : source_color = vec4(0.12, 0.16, 0.17, 0.0);
void fragment() {
vec2 p = abs(UV - 0.5) * 2.0;
float core = 1.0 - smoothstep(0.35, 1.0, max(p.x, p.y));
vec3 off = vec3(0.05, 0.07, 0.075);
// Brightness follows a: a ghost (a < 0.5) is a dim tint, a lit LED (a ≥ 1.5) blooms at its core.
ALBEDO = led.a > 0.0 ? off + led.rgb * (0.1 + led.a * (0.45 + 0.55 * core)) : off;
}

1
table/led.gdshader.uid Normal file
View file

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

56
table/playmat.gdshader Normal file
View file

@ -0,0 +1,56 @@
shader_type spatial;
render_mode blend_mix, cull_back, diffuse_burley, specular_schlick_ggx;
// The playmat as dark glass with a neon grid inlay (gameplay-plan.md §B1). The grid is drawn in
// world space from the board layout (GameTable sets `pitch` and `origin` from BoardLayout), so its
// lines run between the locations instead of along the mat's UVs. The mat's edge is a neon rim.
uniform vec3 glass_color : source_color = vec3(0.010, 0.020, 0.026);
uniform float roughness : hint_range(0.0, 1.0) = 0.3;
uniform vec4 line_color : source_color = vec4(0.133, 0.827, 0.933, 1.0);
// Major grid: half a column pitch across, a row pitch deep; origin is a major crossing.
uniform vec2 pitch = vec2(2.96, 2.18);
uniform vec2 origin = vec2(0.0, 1.09);
// Minor lines per major cell.
uniform float minor = 4.0;
uniform float major_width = 0.018;
uniform float minor_width = 0.008;
uniform float major_energy = 1.25;
uniform float minor_energy = 0.28;
// Half the mat's size, for the rim.
uniform vec2 half_size = vec2(9.144, 7.62);
uniform float rim_energy = 2.6;
varying vec3 world_pos;
varying vec3 world_normal;
void vertex() {
world_pos = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
world_normal = normalize((MODEL_MATRIX * vec4(NORMAL, 0.0)).xyz);
}
float grid_line(vec2 p, vec2 cell, float width) {
vec2 g = abs(fract(p / cell + 0.5) - 0.5) * cell;
vec2 aa = fwidth(p) * 1.25;
vec2 l = 1.0 - smoothstep(vec2(width) - aa, vec2(width) + aa, g);
return max(l.x, l.y);
}
void fragment() {
vec2 p = world_pos.xz - origin;
float top = step(0.5, world_normal.y);
float major_l = grid_line(p, pitch, major_width);
float minor_l = grid_line(p, pitch / minor, minor_width) * (1.0 - major_l);
float edge_d = min(half_size.x - abs(world_pos.x), half_size.y - abs(world_pos.z));
float rim = 1.0 - smoothstep(0.0, 0.07, edge_d);
float band = (1.0 - smoothstep(0.0, 0.9, edge_d)) * 0.22;
ALBEDO = glass_color;
ROUGHNESS = roughness;
METALLIC = 0.25;
SPECULAR = 0.4;
vec3 e = line_color.rgb * (major_l * major_energy + minor_l * minor_energy) * top;
e += line_color.rgb * (rim * rim_energy + band * top);
// The sides are all rim.
e += line_color.rgb * (1.0 - top) * 0.9;
EMISSION = e;
}

View file

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

View file

@ -1,7 +1,7 @@
[gd_scene format=3]
[ext_resource type="PackedScene" uid="uid://dx42gyxom1dlb" path="res://assets/playmat.glb" id="1_model"]
[ext_resource type="Material" uid="uid://br7tudxocdqc5" path="res://assets/playmat.tres" id="2_fabric"]
[ext_resource type="Material" path="res://table/playmat_glass.tres" id="2_glass"]
[node name="Playmat" type="Node3D"]
@ -9,6 +9,6 @@
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.021875, 0)
[node name="Plane_003" parent="Model" index="0"]
surface_material_override/0 = ExtResource("2_fabric")
surface_material_override/0 = ExtResource("2_glass")
[editable path="Model"]

7
table/playmat_glass.tres Normal file
View file

@ -0,0 +1,7 @@
[gd_resource type="ShaderMaterial" format=3]
[ext_resource type="Shader" path="res://table/playmat.gdshader" id="1_shader"]
[resource]
render_priority = -3
shader = ExtResource("1_shader")

View file

@ -1,28 +1,72 @@
shader_type spatial;
render_mode blend_mix, depth_draw_opaque, cull_disabled, shadows_disabled, unshaded;
// A location printed on the playmat: a rounded rectangle with a tinted fill and an edge line.
// One material serves every tile; the owner tint and glow are instance uniforms.
// A location printed on the playmat, drawn as a socket in the cards' style (gameplay-plan.md §B2):
// a chamfered octagon like the cards' frames, a dim interior, an inset second line, brighter ticks
// on the chamfers and the owner's pattern (stripes for South, dots for North) as a cue beside the
// color. One material serves every tile and every printed card spot; the owner tint, pattern and
// glow are instance uniforms.
uniform vec2 size = vec2(5.6, 2.05);
uniform float radius = 0.2;
// The corner cut, in world units.
uniform float chamfer = 0.22;
uniform float edge_width = 0.07;
// The faint second line inside the edge, as a fraction of the edge's alpha; 0 for none.
uniform float inner_line = 0.45;
// Pattern pitch and size, in world units.
uniform float stripe_pitch = 0.3;
uniform float dot_pitch = 0.32;
instance uniform vec4 fill_color : source_color = vec4(1.0, 1.0, 1.0, 0.06);
instance uniform vec4 edge_color : source_color = vec4(1.0, 1.0, 1.0, 0.45);
// Highlights (legal targets, the combat) light up the edge.
instance uniform float glow = 0.0;
// The owner's pattern: 0 none, 1 stripes (South), 2 dots (North).
instance uniform float pattern = 0.0;
// Signed distance to a chamfered rectangle: exact inside, which is all the bands need.
float sd_octagon(vec2 p, vec2 half_size, float c, out bool on_chamfer) {
vec2 q = abs(p);
float box = max(q.x - half_size.x, q.y - half_size.y);
float diag = (q.x + q.y - (half_size.x + half_size.y - c)) * 0.70710678;
on_chamfer = diag > box;
return max(box, diag);
}
void fragment() {
vec2 p = (UV - 0.5) * size;
vec2 q = abs(p) - (size * 0.5 - vec2(radius));
float d = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - radius;
bool on_chamfer;
float d = sd_octagon(p, size * 0.5, chamfer, on_chamfer);
if (d > 0.0) {
discard;
}
float px = fwidth(d);
float w = edge_width * (1.0 + glow * 0.8);
float edge = 1.0 - smoothstep(w * 0.5, w, -d);
vec4 c = mix(fill_color, edge_color, edge);
// The chamfers carry a thicker tick, like the corner ticks on the cards.
float ew = on_chamfer ? w * 1.9 : w;
float edge = 1.0 - smoothstep(ew - px, ew + px, -d);
float inner_d = abs(-d - w * 2.6);
float inner = (1.0 - smoothstep(w * 0.18 - px, w * 0.18 + px, inner_d)) * inner_line;
vec4 fill = fill_color;
if (pattern > 0.5) {
float on = 0.0;
if (pattern < 1.5) {
float t = fract((p.x + p.y) / stripe_pitch);
float aa = fwidth((p.x + p.y) / stripe_pitch);
on = smoothstep(0.62 - aa, 0.62 + aa, t) * (1.0 - smoothstep(0.86 - aa, 0.86 + aa, t));
} else {
vec2 cell = fract(p / dot_pitch) - 0.5;
float r = length(cell) * dot_pitch;
float aa = fwidth(r);
on = 1.0 - smoothstep(0.045 - aa, 0.045 + aa, r);
}
// Keep the pattern off the frame so the edge reads cleanly.
on *= smoothstep(w * 3.0, w * 4.5, -d);
fill = mix(fill, vec4(edge_color.rgb, max(fill.a, edge_color.a * 0.32)), on * 0.75);
}
vec4 c = mix(fill, edge_color, max(edge, inner * edge_color.a));
c.a = max(c.a, fill.a);
// Unshaded, so the print reads the same under any light; glow brightens the edge for bloom.
ALBEDO = c.rgb * (1.0 + glow * edge * 1.5) + fill_color.rgb * glow * 0.1;
ALPHA = c.a;

40
table/void_grid.gdshader Normal file
View file

@ -0,0 +1,40 @@
shader_type spatial;
render_mode blend_mix, unshaded, cull_disabled, shadows_disabled;
// The floor of cyberspace under the playmat: a neon grid on black that fades into the void, with
// a slow scan ring running out from the table. It continues the mat's grid (same pitch, same
// origin), so the mat reads as a lit part of one floor.
uniform vec4 line_color : source_color = vec4(0.133, 0.827, 0.933, 1.0);
uniform vec3 floor_color : source_color = vec3(0.004, 0.008, 0.011);
uniform vec2 pitch = vec2(2.96, 2.18);
uniform vec2 origin = vec2(0.0, 1.09);
uniform float width = 0.014;
uniform float energy = 0.3;
// The grid fades between these distances from the table's centre.
uniform float fade_from = 6.0;
uniform float fade_to = 48.0;
uniform float scan_speed = 9.0;
uniform float scan_period = 9.0;
varying vec3 world_pos;
void vertex() {
world_pos = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
}
void fragment() {
vec2 p = world_pos.xz - origin;
vec2 g = abs(fract(p / pitch + 0.5) - 0.5) * pitch;
vec2 aa = fwidth(p) * 1.5;
vec2 l = 1.0 - smoothstep(vec2(width) - aa, vec2(width) + aa, g);
float line = max(l.x, l.y);
float r = length(world_pos.xz);
float fade = 1.0 - smoothstep(fade_from, fade_to, r);
// Lines get thin far away; fade them by their screen size too so they don't shimmer.
fade *= clamp(1.2 - length(aa) * 3.0, 0.0, 1.0);
float ring_r = mod(TIME * scan_speed, scan_period * scan_speed);
float ring = exp(-pow((r - ring_r) / 1.6, 2.0)) * (1.0 - ring_r / (scan_period * scan_speed));
float glow_floor = (1.0 - smoothstep(4.0, 22.0, r)) * 0.06;
ALBEDO = floor_color + line_color.rgb * (line * energy * (1.0 + ring * 1.6) * fade + glow_floor);
}

View file

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