TableTower/ui/thread_strip.gd
RobinFiredrake 61a548902f Theme tiers 1-2: theme folders, mascot recolour, background scene and tile, frame sets, picture threads, sounds; nine new built-in themes
- ThemeAssets loads a theme's files; FrameSet + GradientMap (3-stop) generalise the card frame;
  ThreadStrip draws threads from a picture; BoardBackdrop draws scene and tile; MascotArt
  recolours Morgan by role (logo SVG now uses the Keep File importer); SoundBoard plays
  roll / card turn / thread / click / ambient with View > Sound levels.
- Vaporwave, Synthwave, Cozy Autumn, Rustic, Woodsy, Sky Blue, Frutiger Aero, Gothic, Terminal:
  generated art (tools/theme_art), sounds (tools/theme_sounds), settings (tools/theme_defs).
- Ten OFL fonts; --theme=<id> flag; docs/THEMES.md format spec; test_theme_assets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 15:05:40 -06:00

78 lines
3.1 KiB
GDScript

class_name ThreadStrip
extends RefCounted
## A theme's thread picture: one greyscale strip repeated along a thread's
## curve and recoloured by GradientMap (the thread's colour, else THREAD; lit
## threads use ACCENT), with an optional pin picture at both ends.
## See docs/THEMES.md, "Thread strip".
## The strip for the theme in use, or null for the drawn threads. ThemeStore.apply sets it.
static var active: ThreadStrip = null
var texture: Texture2D
var pin: Texture2D
## Source size of one tile [length, height]; drawn `width` px thick.
var strip_size := Vector2(64, 16)
var width := 10.0
var pin_size := 14.0
var lo := 0.05
var mid := 0.5
var highlight := 0.45
static func for_theme(theme_set: Dictionary) -> ThreadStrip:
var keys: Dictionary = theme_set.get("thread", {})
var tex := ThemeAssets.texture(theme_set, str(keys.get("strip", "")))
if tex == null:
return null
var ts := ThreadStrip.new()
ts.texture = tex
ts.strip_size = ThemeAssets.vec2(keys.get("strip_size"), tex.get_size())
ts.width = float(keys.get("width", 10.0))
ts.pin = ThemeAssets.texture(theme_set, str(keys.get("pin", "")))
ts.pin_size = float(keys.get("pin_size", 14.0))
ts.lo = float(keys.get("lo", 0.05))
ts.mid = float(keys.get("mid", 0.5))
ts.highlight = float(keys.get("highlight", 0.45))
return ts
## Draws the strip along `pts` into the canvas item `rid`, coloured `trim`
## over `dark`. `rid` gets the recolouring material, so draw nothing else in it.
func add_to(rid: RID, pts: PackedVector2Array, trim: Color, dark: Color) -> void:
var count := pts.size()
if count < 2:
return
var tile_length := strip_size.x * width / strip_size.y
var half := width / 2.0
var points := PackedVector2Array()
var uvs := PackedVector2Array()
var colors := PackedColorArray()
var indices := PackedInt32Array()
var along := 0.0
for i in count:
if i > 0:
along += pts[i].distance_to(pts[i - 1])
var dir := (pts[mini(i + 1, count - 1)] - pts[maxi(i - 1, 0)]).normalized()
var normal := Vector2(-dir.y, dir.x) * half
points.append(pts[i] + normal)
points.append(pts[i] - normal)
uvs.append(Vector2(along / tile_length, 0.0))
uvs.append(Vector2(along / tile_length, 1.0))
colors.append(Color.WHITE)
colors.append(Color.WHITE)
for i in count - 1:
var a := i * 2
indices.append_array([a, a + 1, a + 2, a + 1, a + 3, a + 2])
RenderingServer.canvas_item_set_default_texture_repeat(rid, RenderingServer.CANVAS_ITEM_TEXTURE_REPEAT_ENABLED)
RenderingServer.canvas_item_set_default_texture_filter(rid, RenderingServer.CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS)
RenderingServer.canvas_item_set_material(rid, GradientMap.material(dark, trim, lo, mid, highlight).get_rid())
RenderingServer.canvas_item_add_triangle_array(rid, indices, points, colors, uvs, PackedInt32Array(), PackedFloat32Array(), texture.get_rid())
## Draws the end pins (uncoloured) into `rid`, if the theme has a pin.
func add_pins(rid: RID, pts: PackedVector2Array) -> void:
if pin == null or pts.size() < 2:
return
for at: Vector2 in [pts[0], pts[pts.size() - 1]]:
var box := Rect2(at - Vector2.ONE * pin_size / 2.0, Vector2.ONE * pin_size)
RenderingServer.canvas_item_add_texture_rect(rid, box, pin.get_rid())