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

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]: