mirror of
https://github.com/Louis-CFM/coucou.git
synced 2026-12-06 23:24:20 +09:00
* feat: Mochi wardrobe — right-click for outfits, auto seasonal dressing Outfit model (MochiWardrobe.swift): - 17 outfits with stable UserDefaults rawValues (mochiOutfit key) - seasonal() with Meeus/Jones/Butcher Easter algorithm - Windows: witch hat Oct1-Nov1, santa Dec1-26, party hat Dec31-Jan2, hearts Feb13-15, bunny ears Easter±2/+1, sunglasses Jun21-Aug31 - resolved() respects manual selection or falls back to seasonal Drawing (MochiOutfitDrawing.swift): - All accessories drawn in code: hats follow head yaw (sin/cos foreshortening), glasses at eye level, scarf on lower body, bunny ears behind body - Fade during mailbox morph (>0.3), heavy roll, and R≤14 (compact) - Pumpkin: orange body gradient overlay + ribs + stem/leaf - isMini bots never wear outfits Wardrobe view: - Right-click bot head → expands to .wardrobe; right-click again closes - 30pt pill grid with static Canvas accessory icons, scroll + bottom fade - Hover previews outfit on live Mochi; click selects + saves + pop sound - Escape or house tab closes; header shows current/seasonal selection Tests: 52 cases (seasonal boundaries, Easter 2026/2027/2028, rawValue stability, unknown UserDefaults value → .auto) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * redesign: complete wardrobe visual overhaul Visual iteration loop via new render script (scripts/render-outfits.sh + scripts/RenderOutfits.swift): produces /tmp/coucou-outfits.png showing all outfits at 5 angles (yaw ±0.45, front, pitch −0.45, compact). Catalog: remove topHat, cap, strawHat, heartsHeadband (4 outfits dropped, 13 remain). Feb 13–15 seasonal now returns .none. MochiOutfitDrawing.swift — full rewrite: - mochiEyePositions() shared helper: glasses anchored to exact eye positions - Hat mount system: hatBrimY/hatXS/hatBrimW helpers + split-brim technique (back brim drawn behind body, front brim + crown drawn in front) - Party hat: pink bezier cone, white dots, round pompom (not star) - Beanie: blue gradient, ribbed cuff, white pompom springing with sy - Crown: gold base band, 3 rounded arch points (taller ptH=R*0.56), 3 pearls - Witch hat: purple droopy bezier cone, orange ribbon, gold buckle, wide brim - Santa hat: red droopy cone, puffy white ellipse band, white pompom - Sunglasses: 2.3× eye width dark lenses on actual eye positions, bridge - Round glasses: brown #92400E circular frames on actual eye positions - Scarf: thinner (ry*0.22), lower (ry*0.55), red + two white stripes + fringe - Pumpkin: 4 soft ribs + curved green stem + leaf; guard changed to !isMini - Bow: bezier wings with highlights BotEngine.swift: - Pumpkin guard: bodyColor == nil → !isMini (works with integration pills) - lerp: private → internal (shared with MochiOutfitDrawing) - triggerEmote(.proud): add squash() for pop effect on wardrobe tap BotCanvasView.swift: - Remove .onChange(of: resolvedOutfit) block (was firing on hover/scroll not just explicit clicks) AppState.swift: - resolvedOutfit: per-day seasonal cache avoids recomputing Easter math on every frame IslandViewContent.swift: - .none icon: horizontal dash → circle with diagonal slash (⊘) - Remove drawTopHatIcon, drawCapIcon, drawHeartsHeadbandIcon, drawStrawHatIcon - Remove their cases from drawOutfitIcon() - Remove outfitIconHeart (only used by removed functions) tests/MochiWardrobeTests.swift: - Feb 13–15 seasonal: heartsHeadband → none - Remove topHat/cap/heartsHeadband/strawHat rawValue tests - Add: removed rawValues ("topHat", "cap", "heartsHeadband", "strawHat") stored in UserDefaults → .auto (backwards compat) - 57/57 tests pass Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: port outfit drawing to 3D reference implementation Replace the hand-crafted outfit drawers with a faithful Swift port of design/outfits/mochi-outfits.js — a Canvas 2D reference that reproduces the exact same body geometry as BotEngine (same R/rx/ry, superellipse, drawEyes formula). Key concepts ported from the JS: - MochiH struct: head geometry + physDx/physDy spring offsets - EyeFrame / mEyeFrames(): shared eye-position helper (replaces mochiEyePositions), used by both BotEngine.drawEyes and glasses drawers - 3D projection: mRingR, mRot3, mProj, mSurf — accessories follow the head with VIEW_TILT = -0.30 and ACC_PITCH = 0.4 (hats don't flip over) - Arc helpers: mFrontArc, mCapClip, mFrontRun — front-visible arcs of spherical rings for realistic 3D wrapping - mInvert + FillStyle(eoFill:true) — even-odd clip for beanie cuff etc. - drawPompom: 11 overlapping radial-gradient bumps - drawFuzzyBand: layered stroke with bump highlights (santa trim) Outfit improvements: - Beanie: knit meridian ribs, folded cuff via invert clip, physDx pompom - Santa hat: bezier bag shape, fuzzy trim arc, physDx/physDy tip spring - Party hat: 3D ring base, apex with physDx lean, polka dots, gold rim - Crown: back half behind body, front half with coloured gems + gold tips - Witch hat: witchBrimPts wobble + droop, physDx/physDy bent cone tip - Sunglasses: temples to head edge, body-clipped lenses, glare stroke - Round glasses: curved bridge, per-eye foreshortening, inner arc shine - Scarf: frontArc-wrapped band, meridional stripes, physDx hanging knot - Pumpkin: bodyColors ['#FFA94D','#E8590C'] replace the body gradient (not an overlay), 5 meridional ribs following proj - Bow: 3D anchor at surf(0.86, 0.55, 1.02), rotates + scales with yaw BotEngine.swift: - physDx/physDy/physVx/physVy: damped spring (stiffness 60, damp 9) driven by yaw velocity and oy velocity; updated each frame - drawBody: pumpkinColors param replaces the orange overlay approach - drawEyes: refactored to call mEyeFrames(), keeping roll in eyePitch - drawOutfitBehind/Front: build MochiH with physDx/physDy, call new sigs IslandViewContent.swift: - Wardrobe pill icons: each outfit shows a tiny Mochi wearing it (yaw=0, pitch=0, same render pipeline as live app, R=W*0.62*0.3) - .auto: sparkles, .none: circle-slash — unchanged - All individual draw*Icon functions removed (~200 lines deleted) scripts/RenderOutfits.swift: - Columns match sheet.html exactly: L(-0.5), front, R(0.5), up(p0.4), down(p-0.5), tilt(y0.3/p-0.25/t0.12) + small pill preview - Outfit order matches reference: none, beanie, santaHat, partyHat, crown, witchHat, sunglasses, roundGlasses, scarf, pumpkin, bow - Scale 0.62, W=190 (same as sheet.html), small=64 design/outfits/: - mochi-outfits.js: JS Canvas 2D reference implementation - mochi-outfits-reference.png: target planche (7 columns × 11 outfits) - sheet.html: page that generates the reference planche Both schemes build clean. All 9 test scripts pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: outfit integration bugs, physics spring, presence transitions, roll §1a — pumpkin body color: skip integration pill bodyColor when pumpkinColors=true §1b — remove R>14 size guards; add simplified mode (no ribs/dots/gems) for R<16 §1c — rewrite mFrontArc/mFrontRun: silhouette tangent split (min-x / max-x), pick the higher-z arc — eliminates left-edge jump on yaw §1d — wardrobe pill icons: R=10, cy+0.62×R shift gives hat headroom §2 — outfit only on main pill, compact/peek, or wardrobe view; hidden otherwise §3 — physics impulses: slap (physVy−=1.2, dx±=0.7), squash (physVy+=0.6), greet (physVx+=0.2) §4 — outfitPresence (0→1 Ease.back 350ms / 1→0 180ms) via BotEngine.setOutfit(); outfit change: exit old then enter new; wardrobe preview: instant §5 — add roll to MochiH; mProjRoll for roll-following accessories (scarf, glasses, bow, pumpkin); z-based rollFade replaces fixed threshold for those accessories; hats keep fixed 1.2rad threshold §6 — auto pill icon: seasonal Mochi + AUTO badge (capsule, 60% black, 7pt semibold) renderer: add roll planche (6 angles 0..5π/3) and transition planche (p=0..1) Visually verified via rendered planches: outfits, roll, transition all look correct. Both schemes build (NotchBuddy + CoucouAppStore). All tests pass (57/57). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: outfit transitions with movement, hat fly-off, roll front/behind switching, wardrobe hover header §1 Transitions — movement, not just opacity - outfitPresence tween uses Ease.inOut; Ease.back applied to position offsets in drawing code - Hats / crown / bunnyEars: enter from (1-posP)×0.6ry above with (1-posP)×0.3rad rotation - Glasses: slide down (1-p)×0.15ry on entry/exit - Scarf: slide down (1-p)×0.2ry - Bow: scale by p; pumpkin opacity only (body color driven by drawBody) - squash() fired in entry tween completion for landing bounce §2 Hat fly-off during doRoll - rollTurns stored in BotEngine; squash() called at roll end - Progress = roll / (2π × rollTurns); hat rises 0.9ry × sin(progress×π), self-rotates by H.roll, drifts physDx×0.4rx × sin(progress×π) - Removed abs(roll)>1.2 threshold; crown and witch hat back parts fly in sync §3 Roll-following accessories switch front/behind (no z-fade) - Front pass: roll-following outfits (sunglasses, roundGlasses, bow, scarf, pumpkin, bunnyEars) skip when mProjRoll(H,(0,0,1)).z < 0 - Behind pass: draws them when anchorZ < 0 using same drawing functions - bunnyEars: now uses mProjRoll for ear positions (ear width foreshortened from projected spread); included in roll-following set §5 Wardrobe hover header - hoveredOutfit takes priority over selection in headerRight - Auto hover → "Auto · follows the seasons (now: <name>)" - Any outfit hover → outfit displayName Transition planche (p=0,0.3,0.6,1): hats enter from above with overshoot bounce; scarf slides up into position; bunnyEars rise in; all invisible at p=0. Roll planche (6 angles): hats spin above head and land; glasses/bow/scarf/pumpkin/bunnyEars follow roll and flip between front/behind at anchor-z zero-crossing, no fade artifacts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: hat roll is a flat 2D spin, bunnyEars flatten; drawLayer removes ghost overlap Roll corrections: - Hat fly-off (beanie, santaHat, partyHat, crown, witchHat): drawn with mProj at roll=0 (no 3D twist), then ctx-translated up (0.9ry × sin(πu)), rotated 2πu around the hat's own pivot (-1.4ry in body space), drifted physDx×0.3rx×sin(πu). Crown and witchHat back parts fly in sync with the same transform. - bunnyEars: removed from roll-following set; always drawn behind body via drawBunnyEarsBack with mProj (not mProjRoll). During roll: height × (1 - 0.8×sin(πu)), outward tilt ±0.6×sin(πu) rad per ear; snap-back squash comes from doRoll completion. Transition corrections: - All accessories rendered inside ctx.drawLayer { } to prevent internal alpha bleed (overlapping shapes no longer show through each other or through the head). - Opacity = min(1, p × 2.5): fully opaque by p = 0.4; movement carries the entry. - Movement scaled up: hats/crown/ears → (1-posP)×1.0ry up + scale 0.85+0.15×posP; glasses → (1-p)×0.25ry down; scarf → (1-p)×0.3ry down. - morphFade (mailbox morph) applied to layer so no ghost during that fade either. Roll planche: hats above head, upright → spin flat → land; bunnyEars squash at roll=π. Transition planche: no head visible through witchHat/santaHat at p=0.3; scarf slides up. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: hat roll — gentle swing instead of full spin, reduced rise to 0.45ry - Rise: sin(πu) × 0.45ry (was 0.9ry) — hat stays within the Mochi canvas bounds - Rotation: sin(2πu) × 0.35 rad flat swing — hat never goes upside-down - Drift: physDx × 0.2rx (was 0.3rx) - Same values applied to crown and witchHat back parts in behind dispatcher Roll planche: all hats visible and upright across all 6 angles. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: rigid-plane roll for outfit-wearing Mochi When resolvedOutfit != .none and outfitPresence > 0.05, the entire character (hands, outfit-behind, body, eyes, outfit-front) is drawn inside a context rotated by `roll` around the body centre. The body genuinely turns in screen space rather than producing an eye illusion. - BotCanvasView: branch on rigid vs illusion roll; badge+particles (drawHandsAndExtras) remain outside the rotated context. - BotEngine.drawOutfitBehind/Front: pass roll=0 to MochiH and the static dispatchers when outfit is present, so accessories sit fixed on the head and co-rotate with the body transform. Hat fly-off and bunnyEar flatten code auto-disables (triggered by H.roll, now 0). - BotEngine.drawEyes: suppress roll addition to eyePitch when outfit is shown (no roll-through illusion needed; body rotates for real). - BotEngine.bodyCenter(size:): new helper exposing cx/cy to callers. - BotEngine.update: centrifugal physDx impulse proportional to roll angular velocity when Mochi wears an outfit (coefficient 0.18). - Outfit .none kept on illusion path exactly as before. - Roll planche: added .none row to verify illusion unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * docs(SPEC): update wardrobe section and activity grid Wardrobe: - Add outfit visibility rule (only shown when focusId == mainPillId, island not expanded, or view == .wardrobe). - Document transitions (presence, drawLayer, Ease.back, per-accessory offsets) and physics (physDx/physDy spring, squash impulse, centrifugal force during roll). - Document rigid-roll mechanic (outfit present) vs illusion roll (none). - Auto pill: badge "AUTO" + season name on hover. - Stable IDs updated to current set; removed values migrate to auto. - Remove Valentine's Day from season calendar. - Add design/outfits/ and scripts/render-outfits.sh as visual reference. Activity grid: correct cell size to 7 pt, spacing 1.5 pt, ~23 weeks (calculated from available width). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
332 lines
13 KiB
Swift
332 lines
13 KiB
Swift
// RenderOutfits.swift — standalone planche renderer for Mochi outfits
|
||
// Compile + run via: bash scripts/render-outfits.sh
|
||
// Output: /tmp/coucou-outfits.png
|
||
|
||
import Foundation
|
||
import SwiftUI
|
||
import AppKit
|
||
|
||
// MARK: - Stubs (substitutes for app-only types)
|
||
|
||
@MainActor
|
||
final class SoundEngine {
|
||
static let shared = SoundEngine()
|
||
var enabled: Bool = false
|
||
func play(_ name: String) {}
|
||
}
|
||
|
||
extension Notification.Name {
|
||
static let botDizzy = Notification.Name("notchBuddy.botDizzy")
|
||
static let botGreet = Notification.Name("notchBuddy.botGreet")
|
||
static let botBlink = Notification.Name("notchBuddy.botBlink")
|
||
static let botSetTgEs = Notification.Name("notchBuddy.botSetTgEs")
|
||
static let botGulp = Notification.Name("notchBuddy.botGulp")
|
||
static let botMorphTo = Notification.Name("notchBuddy.botMorphTo")
|
||
static let triggerEmote = Notification.Name("notchBuddy.triggerEmote")
|
||
static let triggerSlap = Notification.Name("notchBuddy.triggerSlap")
|
||
static let greetComplete = Notification.Name("notchBuddy.greetComplete")
|
||
static let greetingHover = Notification.Name("notchBuddy.greetingHover")
|
||
static let greetingInterrupt = Notification.Name("notchBuddy.greetingInterrupt")
|
||
static let islandAction = Notification.Name("notchBuddy.islandAction")
|
||
static let islandCollapse = Notification.Name("notchBuddy.islandCollapse")
|
||
static let hookReveal = Notification.Name("notchBuddy.hookReveal")
|
||
static let musicReveal = Notification.Name("notchBuddy.musicReveal")
|
||
static let openFullSettings = Notification.Name("notchBuddy.openFullSettings")
|
||
}
|
||
|
||
extension Color {
|
||
init(hex: String) {
|
||
let h = hex.trimmingCharacters(in: CharacterSet(charactersIn: "#"))
|
||
let val = UInt64(h, radix: 16) ?? 0
|
||
let r = Double((val >> 16) & 0xFF) / 255
|
||
let g = Double((val >> 8) & 0xFF) / 255
|
||
let b = Double( val & 0xFF) / 255
|
||
self.init(red: r, green: g, blue: b)
|
||
}
|
||
}
|
||
|
||
// MARK: - Cell view — one outfit at one pose
|
||
|
||
struct MochiCell: View {
|
||
let outfit: Outfit
|
||
let yaw: CGFloat
|
||
let pitch: CGFloat
|
||
let tilt: CGFloat
|
||
let phys: (dx: CGFloat, dy: CGFloat)
|
||
let cellSize: CGFloat
|
||
var roll: CGFloat = 0
|
||
var presence: CGFloat = 1
|
||
|
||
var body: some View {
|
||
Canvas { context, sz in
|
||
let W = sz.width, H = sz.height
|
||
// scale=0.62, R = W * 0.62 * 0.3
|
||
let R = W * 0.62 * 0.3
|
||
let rx = R * 1.14
|
||
let ry = R * 0.88
|
||
let cx = W / 2
|
||
let cy = H / 2 + R * 0.06
|
||
let sx: CGFloat = 1, sy: CGFloat = 1
|
||
let morph: CGFloat = 0
|
||
|
||
let mH = MochiH(R: R, yaw: yaw, pitch: pitch, physDx: phys.dx, physDy: phys.dy, roll: roll)
|
||
|
||
// 1. Behind-body outfit
|
||
drawOutfitBehindStatic(
|
||
context: context, outfit: outfit, H: mH,
|
||
cx: cx, cy: cy, tilt: tilt, sx: sx, sy: sy,
|
||
roll: roll, morph: morph, isMini: false, presence: presence
|
||
)
|
||
|
||
// 2. Body (replicate BotEngine.drawBody for idle / pumpkin state)
|
||
var bCtx = context
|
||
bCtx.translateBy(x: cx, y: cy)
|
||
if tilt != 0 { bCtx.rotate(by: .radians(tilt)) }
|
||
bCtx.scaleBy(x: sx, y: sy)
|
||
let body = mochiOutfitPath(rx, ry)
|
||
|
||
// Base gradient (pumpkin-aware)
|
||
let pumpkin = outfit == .pumpkin
|
||
let cTop: Color = pumpkin ? Color(hex: "#FFA94D") : Color(red: 0.929, green: 0.929, blue: 0.937)
|
||
let cBot: Color = pumpkin ? Color(hex: "#E8590C") : Color(red: 0.769, green: 0.773, blue: 0.792)
|
||
bCtx.fill(body, with: .linearGradient(
|
||
Gradient(colors: [cTop, cBot]),
|
||
startPoint: CGPoint(x: rx * 0.7, y: -ry * 0.85),
|
||
endPoint: CGPoint(x: -rx * 0.8, y: ry * 0.9)
|
||
))
|
||
// Shadow rim
|
||
bCtx.fill(body, with: .radialGradient(
|
||
Gradient(stops: [
|
||
.init(color: .clear, location: 0.6),
|
||
.init(color: Color.black.opacity(0.2), location: 1)
|
||
]),
|
||
center: .zero, startRadius: R * 0.15, endRadius: R * 1.25
|
||
))
|
||
// Top-left highlight
|
||
bCtx.fill(body, with: .radialGradient(
|
||
Gradient(stops: [
|
||
.init(color: Color.white.opacity(0.55), location: 0),
|
||
.init(color: .clear, location: 1)
|
||
]),
|
||
center: CGPoint(x: rx * 0.34, y: -ry * 0.46),
|
||
startRadius: 0, endRadius: R * 0.42
|
||
))
|
||
|
||
// 3. Eyes (clipped to body)
|
||
var eyeBase = bCtx
|
||
eyeBase.clip(to: body)
|
||
let ink = Color(red: 0.102, green: 0.082, blue: 0.071)
|
||
for f in mEyeFrames(mH) {
|
||
guard f.visible else { continue }
|
||
var eCtx = eyeBase
|
||
eCtx.translateBy(x: f.x, y: f.y)
|
||
eCtx.scaleBy(x: f.fx, y: f.fy)
|
||
let hh = max(f.h, f.w * 0.3)
|
||
var pill = Path()
|
||
pill.addRoundedRect(
|
||
in: CGRect(x: -f.w / 2, y: -hh / 2, width: f.w, height: hh),
|
||
cornerSize: CGSize(width: min(f.w / 2, hh / 2), height: min(f.w / 2, hh / 2))
|
||
)
|
||
eCtx.fill(pill, with: .color(ink))
|
||
}
|
||
|
||
// 4. Front outfit
|
||
drawOutfitFrontStatic(
|
||
context: context, outfit: outfit, H: mH,
|
||
cx: cx, cy: cy, tilt: tilt, sx: sx, sy: sy,
|
||
roll: roll, morph: morph, isMini: false, presence: presence
|
||
)
|
||
}
|
||
.frame(width: cellSize, height: cellSize)
|
||
}
|
||
}
|
||
|
||
// MARK: - Grid view
|
||
|
||
// Outfit order matching sheet.html
|
||
private let targetOutfits: [Outfit] = [
|
||
.none, .beanie, .santaHat, .partyHat, .crown, .witchHat,
|
||
.sunglasses, .roundGlasses, .scarf, .pumpkin, .bow,
|
||
]
|
||
|
||
private struct PoseSpec {
|
||
let label: String
|
||
let yaw: CGFloat
|
||
let pitch: CGFloat
|
||
let tilt: CGFloat
|
||
let phys: (dx: CGFloat, dy: CGFloat)
|
||
let size: CGFloat
|
||
}
|
||
|
||
// Columns matching sheet.html cols array + small pill-preview column (W=190, scale=0.62; small=64)
|
||
private let poses: [PoseSpec] = [
|
||
PoseSpec(label: "L", yaw: -0.5, pitch: 0, tilt: 0, phys: (0.6, 0), size: 190),
|
||
PoseSpec(label: "front", yaw: 0, pitch: 0, tilt: 0, phys: (0, 0), size: 190),
|
||
PoseSpec(label: "R", yaw: 0.5, pitch: 0, tilt: 0, phys: (-0.6, 0), size: 190),
|
||
PoseSpec(label: "up", yaw: 0.15, pitch: 0.4, tilt: 0, phys: (0, 0.4), size: 190),
|
||
PoseSpec(label: "down", yaw: -0.2, pitch: -0.5, tilt: 0, phys: (0, -0.4), size: 190),
|
||
PoseSpec(label: "tilt", yaw: 0.3, pitch: -0.25, tilt: 0.12, phys: (-0.3, 0), size: 190),
|
||
PoseSpec(label: "mini", yaw: 0, pitch: 0, tilt: 0, phys: (0, 0), size: 64),
|
||
]
|
||
|
||
private let labelW: CGFloat = 90
|
||
private let gap: CGFloat = 6
|
||
|
||
struct OutfitGrid: View {
|
||
var body: some View {
|
||
VStack(alignment: .leading, spacing: gap) {
|
||
// Column headers
|
||
HStack(spacing: gap) {
|
||
Spacer().frame(width: labelW)
|
||
ForEach(poses.indices, id: \.self) { i in
|
||
Text(poses[i].label)
|
||
.font(.system(size: 9, design: .monospaced))
|
||
.foregroundColor(.gray)
|
||
.frame(width: poses[i].size, alignment: .center)
|
||
}
|
||
}
|
||
// One row per outfit
|
||
ForEach(targetOutfits.indices, id: \.self) { oi in
|
||
let outfit = targetOutfits[oi]
|
||
HStack(spacing: gap) {
|
||
Text(outfit.rawValue)
|
||
.font(.system(size: 10))
|
||
.foregroundColor(.white)
|
||
.frame(width: labelW, alignment: .trailing)
|
||
ForEach(poses.indices, id: \.self) { pi in
|
||
let p = poses[pi]
|
||
MochiCell(outfit: outfit, yaw: p.yaw, pitch: p.pitch,
|
||
tilt: p.tilt, phys: p.phys, cellSize: p.size)
|
||
.background(pi == poses.count - 1
|
||
? Color.black
|
||
: Color(red: 0.083, green: 0.090, blue: 0.106))
|
||
.clipShape(RoundedRectangle(cornerRadius: pi == poses.count - 1 ? 0 : 8))
|
||
}
|
||
}
|
||
}
|
||
}
|
||
.padding(12)
|
||
.background(Color(red: 0.043, green: 0.047, blue: 0.055))
|
||
}
|
||
}
|
||
|
||
// MARK: - Roll planche
|
||
|
||
private let rollOutfits: [Outfit] = [
|
||
.none, .beanie, .santaHat, .witchHat, .crown,
|
||
.sunglasses, .roundGlasses, .scarf, .bow, .pumpkin, .bunnyEars
|
||
]
|
||
|
||
private let rollValues: [CGFloat] = [0, CGFloat.pi/3, CGFloat.pi*2/3, CGFloat.pi, CGFloat.pi*4/3, CGFloat.pi*5/3]
|
||
|
||
struct RollGrid: View {
|
||
var body: some View {
|
||
VStack(alignment: .leading, spacing: gap) {
|
||
// Column headers
|
||
HStack(spacing: gap) {
|
||
Spacer().frame(width: labelW)
|
||
ForEach(rollValues.indices, id: \.self) { i in
|
||
Text(String(format: "%.2fπ", rollValues[i] / .pi))
|
||
.font(.system(size: 9, design: .monospaced))
|
||
.foregroundColor(.gray)
|
||
.frame(width: 120, alignment: .center)
|
||
}
|
||
}
|
||
ForEach(rollOutfits.indices, id: \.self) { oi in
|
||
let outfit = rollOutfits[oi]
|
||
HStack(spacing: gap) {
|
||
Text(outfit.rawValue)
|
||
.font(.system(size: 10))
|
||
.foregroundColor(.white)
|
||
.frame(width: labelW, alignment: .trailing)
|
||
ForEach(rollValues.indices, id: \.self) { ri in
|
||
MochiCell(outfit: outfit, yaw: 0, pitch: 0, tilt: 0, phys: (0, 0),
|
||
cellSize: 120, roll: rollValues[ri])
|
||
.background(Color(red: 0.083, green: 0.090, blue: 0.106))
|
||
.clipShape(RoundedRectangle(cornerRadius: 8))
|
||
}
|
||
}
|
||
}
|
||
}
|
||
.padding(12)
|
||
.background(Color(red: 0.043, green: 0.047, blue: 0.055))
|
||
}
|
||
}
|
||
|
||
// MARK: - Transition planche
|
||
|
||
private let transitionOutfits: [Outfit] = [.witchHat, .santaHat, .bunnyEars, .scarf]
|
||
private let presenceValues: [CGFloat] = [0, 0.3, 0.6, 1]
|
||
|
||
struct TransitionGrid: View {
|
||
var body: some View {
|
||
VStack(alignment: .leading, spacing: gap) {
|
||
// Column headers
|
||
HStack(spacing: gap) {
|
||
Spacer().frame(width: labelW)
|
||
ForEach(presenceValues.indices, id: \.self) { i in
|
||
Text(String(format: "p=%.1f", presenceValues[i]))
|
||
.font(.system(size: 9, design: .monospaced))
|
||
.foregroundColor(.gray)
|
||
.frame(width: 120, alignment: .center)
|
||
}
|
||
}
|
||
ForEach(transitionOutfits.indices, id: \.self) { oi in
|
||
let outfit = transitionOutfits[oi]
|
||
HStack(spacing: gap) {
|
||
Text(outfit.rawValue)
|
||
.font(.system(size: 10))
|
||
.foregroundColor(.white)
|
||
.frame(width: labelW, alignment: .trailing)
|
||
ForEach(presenceValues.indices, id: \.self) { pi in
|
||
MochiCell(outfit: outfit, yaw: 0, pitch: 0, tilt: 0, phys: (0, 0),
|
||
cellSize: 120, presence: presenceValues[pi])
|
||
.background(Color(red: 0.083, green: 0.090, blue: 0.106))
|
||
.clipShape(RoundedRectangle(cornerRadius: 8))
|
||
}
|
||
}
|
||
}
|
||
}
|
||
.padding(12)
|
||
.background(Color(red: 0.043, green: 0.047, blue: 0.055))
|
||
}
|
||
}
|
||
|
||
// MARK: - Helper to render and save a view
|
||
|
||
@MainActor
|
||
private func renderAndSave<V: View>(_ view: V, path: String) {
|
||
let renderer = ImageRenderer(content: view)
|
||
renderer.scale = 2.0
|
||
guard let nsImage = renderer.nsImage else {
|
||
print("Error: ImageRenderer returned nil for \(path)")
|
||
return
|
||
}
|
||
guard let tiff = nsImage.tiffRepresentation,
|
||
let rep = NSBitmapImageRep(data: tiff),
|
||
let png = rep.representation(using: .png, properties: [:])
|
||
else {
|
||
print("Error: PNG conversion failed for \(path)")
|
||
return
|
||
}
|
||
do {
|
||
try png.write(to: URL(fileURLWithPath: path))
|
||
print("✓ \(path) — \(Int(nsImage.size.width))×\(Int(nsImage.size.height)) @ 2×")
|
||
} catch {
|
||
print("Error writing \(path): \(error)")
|
||
}
|
||
}
|
||
|
||
// MARK: - Entry point
|
||
|
||
@main
|
||
struct RenderOutfits {
|
||
static func main() {
|
||
MainActor.assumeIsolated {
|
||
renderAndSave(OutfitGrid(), path: "/tmp/coucou-outfits.png")
|
||
renderAndSave(RollGrid(), path: "/tmp/coucou-roll.png")
|
||
renderAndSave(TransitionGrid(), path: "/tmp/coucou-transition.png")
|
||
}
|
||
}
|
||
}
|