feat: consolidate unspool gameplay, 30 release levels, and 5 validation samples (026A/B, 038A, 039, 051)

This commit is contained in:
fannyxl committed 2026-11-26 09:45:05 +08:00
1 parent 96c19dca82
commit f02f9b085e
18 files changed
+2922 -39

No files matched your search

+86 -2
View File
@@ -1,12 +1,15 @@
import { Component, Game, game, Node, view, _decorator } from 'cc';
import { PREVIEW } from 'cc/env';
import { AtelierService } from './core/AtelierService';
import { RELEASE_LEVELS } from './core/ReleaseLevels';
import { SoundService } from './core/SoundService';
import { StorageService } from './core/StorageService';
import { findValidationSample, VALIDATION_SAMPLES, ValidationSampleEntry } from './core/ValidationSamples';
import { EmbroideryRenderer } from './render/EmbroideryRenderer';
import { LobbyView } from './ui/LobbyView';
import { PlayView } from './ui/PlayView';
import { applyResponsivePolicy, computeScreenMetrics, ScreenMetrics } from './ui/ScreenAdapter';
import { createLabel, createPanel, createUINode } from './ui/UiBuilder';
import { createButton, createLabel, createPanel, createUINode, hex, StyledButton } from './ui/UiBuilder';
const { ccclass } = _decorator;
@@ -19,6 +22,9 @@ export class MainController extends Component {
private lobbyView!: LobbyView;
private playView!: PlayView;
private mockCapsuleNode: Node | null = null;
private sampleBarNode: Node | null = null;
private sampleBarBtns: { key: string; btn: StyledButton }[] = [];
private activeSampleKey: string | null = null;
protected onLoad(): void {
applyResponsivePolicy();
@@ -53,7 +59,20 @@ export class MainController extends Component {
game.on(Game.EVENT_SHOW, this.onAppShow, this);
view.on('canvas-resize', this.onCanvasResize, this);
this.applyLayoutMetrics();
this.showLobby();
const sampleParam = PREVIEW && typeof window !== 'undefined'
? new URLSearchParams(window.location?.search ?? '').get('sample')
: null;
const sampleEntry = findValidationSample(sampleParam);
if (sampleEntry) {
this.enterValidationSample(sampleEntry);
} else if (sampleParam === '024') {
this.lobbyView.node.active = false;
this.playView.node.active = true;
this.playView.loadCustomLevel(RELEASE_LEVELS[23], '样板 024 · 晨露叶桥');
} else {
this.showLobby();
}
}
protected onDestroy(): void {
@@ -72,6 +91,70 @@ export class MainController extends Component {
this.lobbyView?.applyScreenMetrics(metrics);
this.playView?.applyScreenMetrics(metrics);
this.syncMockWeChatCapsule(metrics);
this.syncSampleBarPosition(metrics);
}
/** 仅在 PREVIEW 且 URL 带 ?sample= 时显示底部紧凑样板切换条,便于手机一指切换对照测试 */
private ensureSampleBar(): void {
if (!PREVIEW || this.sampleBarNode) return;
const bar = createPanel('SampleSwitcherBar', 726, 48, {
fill: '#2f1e10e8',
stroke: '#d8b06a',
strokeWidth: 1.6,
radius: 16,
depth: 3,
depthColor: '#1a0f07',
}, this.node);
this.sampleBarNode = bar.node;
this.sampleBarBtns = [];
const count = VALIDATION_SAMPLES.length;
const btnW = 134;
const gap = 8;
const totalW = count * btnW + (count - 1) * gap;
VALIDATION_SAMPLES.forEach((entry, idx) => {
const x = -totalW / 2 + btnW / 2 + idx * (btnW + gap);
const btn = createButton({
name: `SampleBtn_${entry.key}`,
text: entry.shortLabel,
w: btnW,
h: 34,
radius: 12,
fill: '#f3e5c7',
stroke: '#c9a367',
depth: 2,
depthColor: '#9c7843',
textColor: '#482e14',
fontSize: 15,
onClick: () => this.enterValidationSample(entry),
}, bar.node);
btn.node.setPosition(x, 0, 0);
this.sampleBarBtns.push({ key: entry.key, btn });
});
this.syncSampleBarPosition(computeScreenMetrics());
}
private syncSampleBarPosition(m: ScreenMetrics): void {
if (!this.sampleBarNode) return;
const bottomSafe = Math.min(54, Math.max(0, m.bottomInset));
this.sampleBarNode.setPosition(0, -m.visibleH / 2 + bottomSafe + 28, 0);
}
private refreshSampleBarHighlight(): void {
for (const item of this.sampleBarBtns) {
const active = item.key === this.activeSampleKey;
item.btn.label.color = hex(active ? '#9f2f23' : '#482e14');
item.btn.node.setScale(active ? 1.05 : 1, active ? 1.05 : 1, 1);
}
}
private enterValidationSample(entry: ValidationSampleEntry): void {
this.activeSampleKey = entry.key;
this.ensureSampleBar();
if (this.sampleBarNode) this.sampleBarNode.active = true;
this.refreshSampleBarHighlight();
this.lobbyView.node.active = false;
this.playView.node.active = true;
this.playView.loadCustomLevel(entry.level, entry.headerTitle);
}
/** 仅在浏览器 URL 带 ?wxsim=iphone15 或 ?wxsim=iphonese 时绘制模拟微信胶囊,方便真机前目视验收 */
@@ -110,6 +193,7 @@ export class MainController extends Component {
private showLobby(): void {
this.atelier?.settleIdle(Date.now());
if (this.sampleBarNode) this.sampleBarNode.active = false;
this.playView.node.active = false;
this.lobbyView.node.active = true;
this.lobbyView.refresh();
+123
View File
@@ -0,0 +1,123 @@
import { NEST } from './LevelData';
import { LEAF_BRIDGE_PREVIEW } from './UnspoolLevels';
import type { ChapterDef, LevelDef, OldStrandDef, Point2D, SectionDef, TargetColor } from './Types';
export const RELEASE_CHAPTERS: ChapterDef[] = [
{ id: 'unspool-scarf', index: 0, startIndex: 0, count: 10, motif: 'custom', name: '第一章 · 初拆旧围巾', subtitle: '认识线头与三格线碗' },
{ id: 'unspool-box', index: 1, startIndex: 10, count: 10, motif: 'custom', name: '第二章 · 两格针线盒', subtitle: '先送一团,再给下层留位' },
{ id: 'unspool-bridge', index: 2, startIndex: 20, count: 10, motif: 'custom', name: '第三章 · 叶桥与花锁', subtitle: '用落针改变下一条路' },
];
export const RELEASE_CHAPTER_LABELS = {
zh: ['初拆', '两格', '叶桥'],
en: ['Scarf', 'Bowls', 'Bridge'],
};
type Key = 'a' | 'b' | 'c' | 'd' | 'e' | 'f';
type Needle = [key: Key, color: TargetColor, x: number, y: number, shape: NonNullable<SectionDef['patch']>];
type Pond = [x: number, y: number, rx: number, ry: number, bridge?: Key];
interface Pattern {
name: string;
rank: 1 | 2 | 3 | 4;
goal: string;
needles: Needle[];
piles: Key[][];
locks?: Partial<Record<Key, Key>>;
ponds?: Pond[];
}
const patterns: Pattern[] = [
{ name: '第一根线', rank: 1, goal: '点亮金线头,再拖蚂蚁把线送到花心。', needles: [['a','gold',300,228,'flower']], piles: [['a']] },
{ name: '围巾的一层边', rank: 1, goal: '浅杏线压着金线,先从露出的线头拆起。', needles: [['a','coral',214,292,'leaf'],['b','gold',348,212,'flower']], piles: [['a','b']] },
{ name: '双瓣初开', rank: 1, goal: '两根金线可分开送,也可以让一只蚂蚁串两团。', needles: [['a','gold',219,214,'flower'],['b','gold',376,219,'flower']], piles: [['a'],['b']] },
{ name: '一金一绿', rank: 1, goal: '金线织花,绿线补上叶尖。', needles: [['a','gold',273,188,'flower'],['b','green',353,316,'leaf']], piles: [['a'],['b']] },
{ name: '露出线头', rank: 2, goal: '看清哪根旧线压住下一层,顺势拆出花与叶。', needles: [['a','green',230,315,'leaf'],['b','gold',322,185,'flower'],['c','rose',375,298,'flower']], piles: [['a','b'],['c']] },
{ name: '左右花瓣', rank: 2, goal: '从两组旧线拆出材料,补齐两侧花瓣。', needles: [['a','rose',179,246,'flower'],['b','green',239,345,'leaf'],['c','rose',426,231,'flower'],['d','gold',355,297,'flower']], piles: [['a','b'],['c','d']] },
{ name: '午后茶花', rank: 1, goal: '两个粉线头都露着,织一朵左右相合的茶花。', needles: [['a','rose',252,240,'flower'],['b','rose',346,205,'flower']], piles: [['a'],['b']] },
{ name: '水边的小芽', rank: 2, goal: '拖线时从水洼边绕过去。', needles: [['a','green',223,289,'leaf'],['b','gold',385,219,'flower']], piles: [['a'],['b']], ponds: [[327,391,72,28]] },
{ name: '针线盒归位', rank: 2, goal: '用三个线碗安排双金和一片绿叶。', needles: [['a','gold',197,212,'flower'],['b','gold',405,199,'flower'],['c','green',300,313,'leaf']], piles: [['a'],['b'],['c']] },
{ name: '围巾里的向日葵', rank: 3, goal: '绿叶先绣会开花锁,记得留下可用线碗。', needles: [['a','gold',205,207,'flower'],['b','green',240,315,'leaf'],['c','gold',378,204,'flower'],['d','rose',408,322,'flower']], piles: [['a','b'],['c','d']], locks: {a:'b'} },
{ name: '两只浅槽', rank: 1, goal: '落针后腾出的空碗,可以立刻装下一团。', needles: [['a','sky',208,239,'bell'],['b','gold',378,220,'bell']], piles: [['a'],['b']] },
{ name: '先送眼前的一团', rank: 2, goal: '三个线头只有两个碗,先送已经能落针的一团。', needles: [['a','rose',195,221,'bell'],['b','gold',302,184,'bell'],['c','sky',401,267,'bell']], piles: [['a'],['b'],['c']] },
{ name: '细边两卷', rank: 2, goal: '同一组旧线有三层,拆到一半就要先织。', needles: [['a','green',202,315,'leaf'],['b','rose',314,240,'bell'],['c','gold',392,183,'bell']], piles: [['a','b','c']] },
{ name: '空格留给同色', rank: 2, goal: '先让双金各占一格,可以一笔送到两个针位。', needles: [['a','green',249,341,'leaf'],['b','gold',184,207,'bell'],['c','gold',393,206,'bell']], piles: [['a'],['b'],['c']] },
{ name: '星星露一角', rank: 3, goal: '金针还锁着,先保留能取绿线的空位。', needles: [['a','gold',197,193,'bell'],['b','green',258,329,'leaf'],['c','rose',406,260,'bell']], piles: [['a','b'],['c']], locks: {a:'b'} },
{ name: '锁上挂绳', rank: 3, goal: '绿叶开粉锁,粉铃再打开金铃。', needles: [['a','rose',223,206,'bell'],['b','green',300,322,'leaf'],['c','gold',410,220,'bell']], piles: [['a','b'],['c']], locks: {a:'b',c:'a'} },
{ name: '两瓣余香', rank: 2, goal: '并排两根线,顺手织完两枚小风铃。', needles: [['a','rose',236,230,'bell'],['b','rose',358,274,'bell']], piles: [['a'],['b']] },
{ name: '两种铃声', rank: 3, goal: '先拆左、先拆右都可行,先取到的绿线会打开不同落点。', needles: [['a','rose',188,219,'bell'],['b','green',218,328,'leaf'],['c','gold',411,219,'bell'],['d','green',381,327,'leaf']], piles: [['a','b'],['c','d']], locks: {a:'b',c:'d'} },
{ name: '三卷一花', rank: 3, goal: '先送走一团好用的线,再取到要搭档的第二团金线。', needles: [['a','sky',240,288,'bell'],['b','gold',203,199,'bell'],['c','rose',383,304,'bell'],['d','gold',396,189,'bell']], piles: [['a','b'],['c','d']], locks: {d:'a'} },
{ name: '风铃穿针盒', rank: 4, goal: '蓝纹能搭桥,绿结能开锁。先看准备走哪边。', needles: [['a','rose',190,195,'bell'],['b','green',211,315,'leaf'],['c','gold',416,203,'bell'],['d','sky',381,289,'ripple'],['e','coral',308,155,'flower']], piles: [['a','b'],['c','d'],['e']], locks: {a:'b',c:'d',e:'a'}, ponds: [[321,391,76,20,'d']] },
{ name: '露珠与小荷', rank: 2, goal: '先送一团绿线补叶,粉荷才会打开。', needles: [['a','green',195,300,'leaf'],['b','rose',365,209,'flower']], piles: [['a'],['b']], locks: {b:'a'} },
{ name: '金蕊睡莲', rank: 2, goal: '金线先抽出来,给下层的绿线留一格。', needles: [['a','gold',361,208,'flower'],['b','green',234,318,'leaf']], piles: [['a','b']], locks: {a:'b'} },
{ name: '荷叶渡', rank: 3, goal: '可以先织叶搭桥,也可以让金舟先沿岸绕行。', needles: [['a','green',212,317,'leaf'],['b','gold',378,221,'boat'],['c','sky',307,276,'ripple']], piles: [['a'],['b','c']], ponds: [[298,392,91,25,'a']] },
{ name: '晨露叶桥', rank: 3, goal: '两根金线里,有一根压住绿线。留一格给绿线搭桥。', needles: [['a','gold',219,199,'flower'],['b','green',357,315,'leaf'],['c','gold',381,199,'flower']], piles: [['a','b'],['c']], locks: {a:'b',c:'b'}, ponds: [[298,392,82,24,'b']] },
{ name: '双叶金盏', rank: 3, goal: '两片绿叶各开一侧花锁,先决定哪一格留给底层。', needles: [['a','gold',190,199,'flower'],['b','green',223,322,'leaf'],['c','gold',407,195,'flower'],['d','green',375,322,'leaf']], piles: [['a','d'],['c','b']], locks: {a:'d',c:'b'} },
{ name: '水田双桥', rank: 4, goal: '左右都能先搭桥。先开哪座桥会决定手里的线先去哪里。', needles: [['a','rose',182,181,'flower'],['b','green',205,304,'leaf'],['c','gold',418,179,'flower'],['d','sky',397,306,'ripple'],['e','coral',302,227,'flower']], piles: [['a','b'],['c','d'],['e']], locks: {a:'d',c:'b',e:'b'}, ponds: [[222,380,65,20,'b'],[381,381,65,20,'d']] },
{ name: '扁舟靠岸', rank: 2, goal: '两团露线,补齐近岸舟身和水纹。', needles: [['a','gold',244,247,'boat'],['b','sky',367,302,'ripple']], piles: [['a'],['b']] },
{ name: '荷茎上的两瓣', rank: 4, goal: '先织能开路的叶子,留意同色两瓣谁先解锁。', needles: [['a','rose',200,212,'flower'],['b','green',234,325,'leaf'],['c','rose',405,196,'flower'],['d','green',387,309,'leaf'],['e','sky',298,253,'ripple']], piles: [['a','b'],['c','d'],['e']], locks: {a:'b',c:'e',e:'d'}, ponds: [[278,383,72,23,'b']] },
{ name: '并蒂荷与叶桥', rank: 4, goal: '一处绿叶开桥,另一处开花锁。两团线占槽前,想好先开哪边。', needles: [['a','gold',202,182,'flower'],['b','green',226,305,'leaf'],['c','rose',397,192,'flower'],['d','sky',373,302,'ripple'],['e','coral',302,149,'flower']], piles: [['a','b'],['c','d'],['e']], locks: {a:'d',c:'b',e:'c'}, ponds: [[266,389,88,22,'b']] },
{ name: '荷塘夜灯', rank: 4, goal: '两座桥各放开一条路。选一侧起手,留出碗位给压层里的灯线。', needles: [['a','gold',182,191,'bell'],['b','green',195,306,'leaf'],['c','rose',421,190,'flower'],['d','sky',400,304,'ripple'],['e','coral',294,221,'flower'],['f','gold',300,141,'bell']], piles: [['a','b'],['c','d'],['e','f']], locks: {a:'d',c:'b',e:'b',f:'e'}, ponds: [[223,385,73,22,'b'],[380,386,73,22,'d']] },
];
function buildStage(pattern: Pattern, index: number): LevelDef {
const chapter = Math.floor(index / 10);
const id = `unspool-release-${index + 1}`;
const needleId = (key: Key) => `${id}-${key}`;
const targets = pattern.needles.map(([key, color, x, y, patch]) => ({
id: needleId(key), color, x, y, patch, rx: patch === 'ripple' ? 39 : 32, ry: patch === 'ripple' ? 23 : 31,
}));
const byKey = new Map(pattern.needles.map(needle => [needle[0], needle[1]]));
const strands: OldStrandDef[] = [];
pattern.piles.forEach((pile, column) => {
const width = 504 / pattern.piles.length;
const left = 28 + column * width;
const mirror = (index + column) % 2 === 0;
for (let depth = pile.length - 1; depth >= 0; depth--) {
const key = pile[depth];
const x = (fraction: number) => left + width * (mirror ? fraction : 1 - fraction);
const tip = 0.82 - depth * 0.25;
const points: [number, number][] = depth === 0
? [[x(.15), 24], [x(.39), 38], [x(.59), 72], [x(tip), 105]]
: [[x(.13), 82 + (depth - 1) * 20], [x(.34), 67 + (depth - 1) * 24], [x(.60), 62 + (depth - 1) * 22], [x(tip), 50 + (depth - 1) * 15]];
strands.push({ id: needleId(key), color: byKey.get(key)!, points, coveredBy: depth ? [needleId(pile[depth - 1])] : [] });
}
});
const userSlots = chapter === 0 ? [176, 300, 424] : [186, 414];
const slots: Point2D[] = userSlots.map((x, slot) => ({
x, y: chapter === 0 && slot === 1 ? 458 : 475,
}));
const locks: Record<string, string> = {};
const patternLocks = pattern.locks ?? {};
for (const key of Object.keys(patternLocks) as Key[]) {
const dependsOn = patternLocks[key];
if (dependsOn) locks[needleId(key)] = needleId(dependsOn);
}
const level: LevelDef = {
id, chapter, name: pattern.name, difficulty: `D${pattern.rank}`, lesson: pattern.goal, goal: pattern.goal,
ruleTag: ['抽线与落针', '两格取线', '叶桥与花锁'][chapter], motif: 'custom',
nests: [{ ...NEST }], balls: [], targets, locks,
ponds: (pattern.ponds ?? []).map(([x,y,rx,ry,bridge]) => ({ x, y, rx, ry, bridgeSectionId: bridge ? needleId(bridge) : undefined })),
spools: [], buttons: [], dyes: [], gates: [], roughZones: [],
threeStar: 420 * targets.length * (pattern.rank >= 3 ? 1.1 : 1.25),
twoStar: 510 * targets.length * (pattern.rank >= 3 ? 1.1 : 1.25),
demo: [],
unspool: { slots, strands, storyTitle: ['旧围巾', '旧针线袋', '旧荷包'][chapter], storyNote: pattern.goal },
};
if (index === 23) {
// This blueprint was already tested with the physical drag UI.
const preview = LEAF_BRIDGE_PREVIEW.level;
level.unspool = preview.unspool;
level.threeStar = preview.threeStar;
level.twoStar = preview.twoStar;
}
return level;
}
export const RELEASE_LEVELS: LevelDef[] = patterns.map(buildStage);
export function isReleaseStageOpen(index: number, hasCleared: (level: LevelDef) => boolean): boolean {
return index >= 0 && index < RELEASE_LEVELS.length && (index === 0 || hasCleared(RELEASE_LEVELS[index - 1]));
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "56e03130-f18b-4bfa-9d90-465f36b53019",
"files": [],
"subMetas": {},
"userData": {}
}
+37
View File
@@ -11,6 +11,8 @@ import {
GateEvent,
HintState,
LevelDef,
OldClothClipDef,
OldStrandDef,
PickEvent,
Point2D,
PondDef,
@@ -20,6 +22,7 @@ import {
SpoolDef,
SpoolEvent,
TargetColor,
UnspoolConfig,
YarnColor,
} from './Types';
@@ -183,6 +186,40 @@ export function isPondBridged(pond: PondDef, lines: RouteState[]): boolean {
return false;
}
export function isClipUnlocked(
clip: OldClothClipDef,
lines: RouteState[],
drawing?: RouteState | null,
): boolean {
for (const line of lines) {
if (line.deliveries.some(d => d.target.id === clip.unlockSectionId)) return true;
}
if (drawing && drawing.deliveries.some(d => d.target.id === clip.unlockSectionId)) return true;
return false;
}
export function isStrandClipLocked(
config: UnspoolConfig,
strand: OldStrandDef,
lines: RouteState[],
): OldClothClipDef | null {
if (!strand.clipId || !config.clips?.length) return null;
const clip = config.clips.find(c => c.id === strand.clipId);
if (!clip) return null;
return isClipUnlocked(clip, lines) ? null : clip;
}
export function isStrandExposed(
config: UnspoolConfig,
strand: OldStrandDef,
removedIds: Set<string>,
lines: RouteState[],
): boolean {
if (removedIds.has(strand.id)) return false;
if (isStrandClipLocked(config, strand, lines)) return false;
return strand.coveredBy.every(cid => removedIds.has(cid));
}
export function isTargetLocked(
level: LevelDef,
targetId: string,
+7
View File
@@ -159,6 +159,13 @@ export class SoundService {
this.playTone(587, 0.08, 0, { type: 'sine', volume: 0.06, slideTo: 880 });
}
/** 「拆旧织新」抽线解压音效:轻快上升丝线抽拉 + 卷球落碗啵声 */
public unspool(): void {
this.playTone(392, 0.065, 0, { type: 'triangle', volume: 0.045, slideTo: 523 });
this.playTone(523, 0.075, 0.06, { type: 'triangle', volume: 0.048, slideTo: 659 });
this.playTone(784, 0.13, 0.13, { type: 'sine', volume: 0.06, slideTo: 988 });
}
public button(): void {
this.playTone(784, 0.055, 0, { volume: 0.05 });
}
+66
View File
@@ -24,6 +24,7 @@ export interface SectionDef {
ry: number;
color: TargetColor;
petals?: number[];
patch?: 'flower' | 'leaf' | 'bell' | 'ripple' | 'boat';
side?: number;
lotus?: 'bloom' | 'bud' | 'pad-left' | 'pad-right';
sakura?: 'left' | 'top' | 'right' | 'bird' | 'leaf';
@@ -97,6 +98,67 @@ export interface ChapterDef {
count: number;
}
/** 「拆旧织新」旧布木夹:绣完指定针位后松开夹子,解锁该区域内的旧线 */
export interface OldClothClipDef {
id: string;
/** 被夹住的旧布区域(旧绣片局部坐标 0..560 x 0..136) */
x: number;
y: number;
w: number;
h: number;
/** 必须先绣完的绣面针位 ID */
unlockSectionId: string;
/** 木夹与对应针位共用的辨识色与纹样 */
badgeColor: TargetColor;
badgeShape: 'leaf' | 'flower' | 'bell' | 'ripple';
/** 木夹上的简短标注 */
label?: string;
}
/** 「拆旧织新」旧绣片上的一根可分层抽取的旧毛线 */
export interface OldStrandDef {
id: string;
color: YarnColor;
/** 旧绣片画布局部坐标 (0..560 x 0..136) */
points: [number, number][];
/** 压在该线上方的线 ID(全部抽走后才露出可抽) */
coveredBy: string[];
/** 若属于某个被木夹夹住的旧布区,需对应旧夹松开后才可抽取 */
clipId?: string;
/** 可选指定落入的供线位索引(多巢空间供线时使用) */
slotIndex?: number;
}
export interface UnspoolConfig {
/** 绣绷内的固定线碗位置(紧挨蚁巢,抽出的球落入空碗成为标准毛线球) */
slots: Point2D[];
/** 同时最多可暂存的毛线球数(省略时等于 slots.length) */
capacity?: number;
/** 可选两片旧布拼接分界 X 坐标(0..560) */
patchDividerX?: number;
/** 可选旧布木夹列表(「新针开旧夹」) */
clips?: OldClothClipDef[];
/** 按从底层到顶层排列的旧线列表 */
strands: OldStrandDef[];
storyTitle: string;
storyNote: string;
}
export interface UnspoolRuntimeState {
/** 已经彻底抽完的线 ID */
removedIds: string[];
/** 正在播放逐段缩回动效的线 */
animating: { strandId: string; progress: number; slotIndex: number } | null;
/** 每个线碗里当前存放的 ballId(null 表示空碗) */
slotBallIds: (number | null)[];
/** 是否触发满槽死锁提示 */
deadlocked: boolean;
/** 点击被夹旧布时,高亮脉冲对应开夹针位 ID */
pulseTargetId?: string | null;
/** 高亮脉冲截止时间戳(ms) */
pulseUntil?: number;
}
export interface LevelDef {
id: string;
recordId?: string;
@@ -129,6 +191,8 @@ export interface LevelDef {
twoStar: number;
/** 每笔演示折线(首点必须是某个蚁巢坐标) */
demo: [number, number][][];
/** 若存在,则本关启用「拆旧织新」旧绣片分层抽线 + 绣绷线碗模式 */
unspool?: UnspoolConfig;
}
export interface PickEvent {
@@ -250,6 +314,8 @@ export interface GameState {
/** 本关是否看过演示(重来/重绣不清空,仅换关时重置) */
demoWatched: boolean;
hint: HintState | null;
/** 「拆旧织新」运行态(普通 60 关为 null) */
unspool?: UnspoolRuntimeState | null;
}
export interface RecordEntry {
+208
View File
@@ -0,0 +1,208 @@
import { MOTIFS, NEST } from './LevelData';
import { LevelDef, MotifId, SectionDef } from './Types';
function pickSections(motif: MotifId, ids: string[]): SectionDef[] {
return ids.map(id => {
const hit = MOTIFS[motif].find(s => s.id === id);
if (!hit) throw new Error(`Unknown section "${id}" in motif "${motif}"`);
return hit;
});
}
/**
* 「拆旧织新」特别番外原型(3 关渐进验证):
* - 番外 1:自由抽线体验(旧绣片无压层,感受抽线卷球滚入绣绷线碗 + 蚂蚁织画)
* - 番外 2:2 格线碗 + 压层 + 浮桥铜锁(验证“先抽压住绿线的左金线”核心顿悟)
* - 番外 3:双层压叠 + 不交叉 + 连锁锁桥(验证两步前瞻规划与双可行续法)
*/
export const UNSPOOL_LEVELS: LevelDef[] = [
{
id: 'unspool-1-scarf',
chapter: 0,
name: '旧围巾第一缕',
difficulty: '番外入门',
lesson: '点击或轻划上方旧绣片发光的线头,把旧毛线抽进绣绷线碗,再拖蚂蚁织成新花!',
goal: '拆下 3 缕旧毛线,补齐向日葵左右花瓣与绿叶。',
ruleTag: '拆旧织新 · 入门',
motif: 'sunflower',
budget: 1450,
nests: [{ ...NEST }],
targets: pickSections('sunflower', ['left', 'right', 'leaf']),
balls: [],
ponds: [],
spools: [],
buttons: [],
dyes: [],
gates: [],
roughZones: [],
threeStar: 1120,
twoStar: 1320,
demo: [],
unspool: {
storyTitle: '特别委托 · 旧围巾改织新画(1/3)',
storyNote: '林阿婆翻出一条褪边的小围巾,想拆下旧毛线给茶室织一朵新向日葵。',
slots: [
{ x: 186, y: 468 },
{ x: 414, y: 468 },
],
strands: [
{
id: 'u1-gold-l',
color: 'gold',
coveredBy: [],
points: [[54, 42], [110, 28], [156, 58], [122, 98], [72, 102]],
},
{
id: 'u1-green',
color: 'green',
coveredBy: [],
points: [[236, 98], [268, 42], [304, 34], [336, 76], [294, 106]],
},
{
id: 'u1-gold-r',
color: 'gold',
coveredBy: [],
points: [[414, 36], [472, 30], [506, 68], [468, 104], [418, 92]],
},
],
},
},
{
id: 'unspool-2-lock-bridge',
chapter: 0,
name: '压线解锁桥',
difficulty: '番外进阶',
lesson: '两格线碗有限!两片金花瓣都上了铜锁,必须先抽走压住绿线的那缕金线,拆出绿线搭桥解锁!',
goal: '先拆压层取绿线绣叶搭桥解锁,再双球绣齐金花瓣。',
ruleTag: '2 格线碗 · 压层解锁',
motif: 'sunflower',
budget: 1480,
locks: { left: 'leaf', right: 'leaf' },
nests: [{ ...NEST }],
targets: pickSections('sunflower', ['left', 'right', 'leaf']),
balls: [],
ponds: [{ x: 298, y: 392, rx: 82, ry: 24, bridgeSectionId: 'leaf' }],
spools: [],
buttons: [],
dyes: [],
gates: [],
roughZones: [],
threeStar: 1180,
twoStar: 1380,
demo: [],
unspool: {
storyTitle: '特别委托 · 旧围巾改织新画(2/3)',
storyNote: '旧绣片里绿线被左侧金线压在底下;线碗只有两格,先抽哪缕金线决定能不能过河!',
slots: [
{ x: 186, y: 474 },
{ x: 414, y: 474 },
],
strands: [
// 底层绿线(被左金线压住,清晰从下方透出绿色)
{
id: 'u2-green',
color: 'green',
coveredBy: ['u2-gold-l'],
points: [[96, 78], [134, 68], [182, 67], [238, 73], [296, 68]],
},
// 顶层左金线(斜跨压住绿线)
{
id: 'u2-gold-l',
color: 'gold',
coveredBy: [],
points: [[142, 24], [164, 39], [188, 65], [206, 91], [228, 110]],
},
// 顶层右金线(独立露在最上层,误先抽它会与左金线一起堵满 2 格线碗)
{
id: 'u2-gold-r',
color: 'gold',
coveredBy: [],
points: [[386, 32], [425, 27], [465, 42], [480, 69], [468, 91], [428, 108]],
},
],
},
},
{
id: 'unspool-3-double-lotus',
chapter: 1,
name: '双层织晨荷',
difficulty: '番外挑战',
lesson: '双层压线 + 不交叉 + 连锁锁桥!先解开左侧压层拿到绿叶搭桥,再灵活安排后续两缕旧线。',
goal: '不交叉避水,逐层拆出两绿两粉,绣成晨荷四区。',
ruleTag: '双层压叠 · 连锁锁桥',
motif: 'lotus',
noCross: true,
budget: 2150,
locks: { 'lotus-flower': 'lotus-pad-left', 'lotus-bud': 'lotus-pad-right' },
nests: [{ ...NEST }],
targets: pickSections('lotus', ['lotus-pad-left', 'lotus-pad-right', 'lotus-flower', 'lotus-bud']),
balls: [],
ponds: [{ x: 296, y: 382, rx: 74, ry: 22, bridgeSectionId: 'lotus-pad-left' }],
spools: [],
buttons: [],
dyes: [],
gates: [],
roughZones: [],
threeStar: 1760,
twoStar: 2020,
demo: [],
unspool: {
storyTitle: '特别委托 · 旧围巾改织新画(3/3)',
storyNote: '两缕翠绿丝线层层叠在旧荷帕底下;留好空碗与过桥顺序,让旧线重新开出双荷。',
slots: [
{ x: 186, y: 478 },
{ x: 414, y: 478 },
],
strands: [
// 最底层:第二缕绿线(被中层绿线压住)
{
id: 'u3-green-2',
color: 'green',
coveredBy: ['u3-green-1'],
points: [[204, 104], [268, 86], [334, 86], [386, 104]],
},
// 中层:第一缕绿线(压住 u3-green-2,同时被左粉线压住)
{
id: 'u3-green-1',
color: 'green',
coveredBy: ['u3-rose-l'],
points: [[96, 62], [178, 66], [254, 84], [312, 54]],
},
// 顶层左粉线(压住 u3-green-1)
{
id: 'u3-rose-l',
color: 'rose',
coveredBy: [],
points: [[130, 24], [174, 66], [198, 112]],
},
// 顶层右粉线(露在最上层的诱饵,先抽双粉会堵碗)
{
id: 'u3-rose-r',
color: 'rose',
coveredBy: [],
points: [[416, 28], [472, 46], [496, 92], [438, 106]],
},
],
},
},
];
const lockBridgePrototype = UNSPOOL_LEVELS[1];
export const LEAF_BRIDGE_PREVIEW: { number: number; level: LevelDef } = {
number: 24,
level: {
...lockBridgePrototype,
id: 'unspool-024-leaf-bridge',
chapter: 2,
name: '晨露叶桥',
difficulty: '样板关',
goal: '取旧线绣绿叶搭桥,再补齐两侧金瓣。',
ruleTag: '压线 · 搭桥',
unspool: {
...lockBridgePrototype.unspool!,
storyTitle: '旧荷包',
storyNote: '拆出荷包里的三缕旧线,织成晨露叶桥。',
},
},
};
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "000e926c-6884-45a9-b384-345f6ae6578b",
"files": [],
"subMetas": {},
"userData": {}
}
+364
View File
@@ -0,0 +1,364 @@
import { NEST } from './LevelData';
import { RELEASE_LEVELS } from './ReleaseLevels';
import type { LevelDef } from './Types';
export interface ValidationSampleEntry {
key: '026a' | '026b' | '038a' | '039' | '051';
shortLabel: string;
headerTitle: string;
hypothesis: string;
level: LevelDef;
}
const base026 = RELEASE_LEVELS[25];
/** 样板 026A:对照基准(现行 026 水田双桥,2 格线碗 + 三列竖栈) */
const sample026A: LevelDef = {
...base026,
id: 'sample-026a',
name: '水田双桥 · 2碗对照',
difficulty: 'A对照',
goal: 'A对照组:2 格碗 + 三列单栈。感受开局腾格压力与双桥顺序。',
ruleTag: '2碗 · 竖栈对照',
unspool: {
...base026.unspool!,
storyTitle: '026A · 2碗竖栈',
storyNote: '对照组:两格线碗、三列互不交叉的竖向压层。',
},
};
/**
* 样板 026B:实验组(同盘面目标/双桥/交叉锁,改为 3 格线碗 + 真交叉压层)
* - 底层绿 b 被「左粉 a + 中拱浅杏 e」双压(2 压 1)
* - 底层蓝 d 被「右金 c + 中拱浅杏 e」双压(2 压 1)
* - 中拱浅杏 e 同时压住绿 b 与蓝 d(1 压 2)
* - 验证重点:小屏能否一眼读出「先拆中拱 e 配任意一侧」,且 3 碗下仍保留误拆 a+c 满碗的真实张力
*/
const sample026B: LevelDef = {
...base026,
id: 'sample-026b',
name: '水田双桥 · 3碗交叉',
difficulty: 'B实验',
goal: 'B实验组:3 格碗 + 交叉压层。中拱浅杏线同时压着左右底层,读清压层再拆!',
ruleTag: '3碗 · 交叉压层',
unspool: {
storyTitle: '026B · 3碗交叉',
storyNote: '实验组:中拱浅杏同时压住绿、蓝两缕底层线,左粉与右金各压一侧。',
slots: [
{ x: 176, y: 474 },
{ x: 300, y: 458 },
{ x: 424, y: 474 },
],
strands: [
// 底层左:绿 b(被 a 与 e 双压;线头在最左,距其他线头 > 100px)
{
id: 'unspool-release-26-b',
color: 'green',
coveredBy: ['unspool-release-26-a', 'unspool-release-26-e'],
points: [[246, 84], [190, 76], [124, 78], [58, 86]],
},
// 底层右:蓝 d(被 c 与 e 双压;线头在最右)
{
id: 'unspool-release-26-d',
color: 'sky',
coveredBy: ['unspool-release-26-c', 'unspool-release-26-e'],
points: [[314, 84], [370, 76], [436, 78], [502, 86]],
},
// 上层左斜:粉 a(压住绿 b,线头在左上)
{
id: 'unspool-release-26-a',
color: 'rose',
coveredBy: [],
points: [[96, 114], [114, 82], [134, 50], [152, 22]],
},
// 上层右斜:金 c(压住蓝 d,线头在右上)
{
id: 'unspool-release-26-c',
color: 'gold',
coveredBy: [],
points: [[464, 114], [446, 82], [426, 50], [408, 22]],
},
// 上层中拱:浅杏 e(同时压住绿 b 与蓝 d,1 压 2 关键线,线头在右下拱脚)
{
id: 'unspool-release-26-e',
color: 'coral',
coveredBy: [],
points: [[212, 112], [234, 72], [280, 32], [326, 72], [348, 112]],
},
],
},
};
/**
* 样板 038A:039 前置极简教学(双巢 + 不交叉,10 秒读懂「留一条外路」)
* - 两个全露头线(金左、绿右)落入对应左右碗,但目标交叉在右上/左上
* - 直觉斜穿正中会挡住另一色,需一笔走顺路、另一笔顺外侧弧线绕开
*/
const sample038A: LevelDef = {
id: 'sample-038a',
chapter: 3,
name: '双巢让路 · 教学',
difficulty: '前置教',
lesson: '本关毛线不可交叉!先画的一笔会占路,试着给另一只蚂蚁留出绕行通道。',
goal: '两巢不交叉:给另一色留一条外侧走廊,两笔成画。',
ruleTag: '不交叉 · 前置教学',
motif: 'custom',
noCross: true,
maxDispatches: 2,
nests: [
{ x: 148, y: 472 },
{ x: 452, y: 472 },
],
balls: [],
targets: [
{ id: 's38a-gold', color: 'gold', x: 396, y: 234, rx: 32, ry: 31, patch: 'flower' },
{ id: 's38a-green', color: 'green', x: 204, y: 234, rx: 32, ry: 31, patch: 'leaf' },
],
ponds: [],
spools: [],
buttons: [],
dyes: [],
gates: [],
roughZones: [],
threeStar: 1120,
twoStar: 1320,
demo: [],
unspool: {
storyTitle: '038A · 让路教学',
storyNote: '拆下金、绿两缕线,体验不交叉条件下的双巢避让。',
slots: [
{ x: 184, y: 400 },
{ x: 416, y: 400 },
],
strands: [
{
id: 's38a-gold',
color: 'gold',
coveredBy: [],
slotIndex: 0,
points: [[72, 92], [134, 52], [218, 74]],
},
{
id: 's38a-green',
color: 'green',
coveredBy: [],
slotIndex: 1,
points: [[488, 92], [426, 52], [342, 74]],
},
],
},
};
/**
* 样板 039:三巢让路(调近双解耗线差版本)
* - 三巢、两格容量(三处空间供线位、同时最多占 2 格)、不交叉、最多 3 笔
* - 方案 A(3 笔直达):左右巢分送双金,中巢直达绿叶(省线)
* - 方案 B(2 笔串双金 + 绕外路):两格装双金后左巢一笔串送两金,再取绿球由中巢绕外侧避让(省笔)
*/
const sample039: LevelDef = {
id: 'sample-039',
chapter: 3,
name: '三巢让路 · 双解',
difficulty: 'D4样板',
lesson: '同时最多暂存 2 团线,且毛线不可交叉!比较「三笔直达」与「两笔串双金 + 外圈让路」。',
goal: '不交叉三巢:可用 3 笔分送省线,或 2 笔串双金留外路。',
ruleTag: '三巢 · 不交叉双解',
motif: 'custom',
noCross: true,
maxDispatches: 3,
nests: [
{ x: 152, y: 462 },
{ x: 300, y: 504 },
{ x: 448, y: 462 },
],
balls: [],
targets: [
{ id: 's39-gold-l', color: 'gold', x: 204, y: 244, rx: 30, ry: 30, patch: 'flower' },
{ id: 's39-green', color: 'green', x: 300, y: 176, rx: 30, ry: 30, patch: 'leaf' },
{ id: 's39-gold-r', color: 'gold', x: 396, y: 244, rx: 30, ry: 30, patch: 'flower' },
],
ponds: [],
spools: [],
buttons: [],
dyes: [],
gates: [],
roughZones: [],
threeStar: 1180,
twoStar: 1460,
demo: [],
unspool: {
storyTitle: '039 · 三巢让路',
storyNote: '三缕全露头线按左/中/右落入近巢供线碗,同时最多暂存 2 团。',
capacity: 2,
slots: [
{ x: 176, y: 386 },
{ x: 300, y: 446 },
{ x: 424, y: 386 },
],
strands: [
{
id: 's39-gold-l',
color: 'gold',
coveredBy: [],
slotIndex: 0,
points: [[44, 88], [94, 48], [154, 78]],
},
{
id: 's39-green',
color: 'green',
coveredBy: [],
slotIndex: 1,
points: [[224, 96], [280, 44], [336, 92]],
},
{
id: 's39-gold-r',
color: 'gold',
coveredBy: [],
slotIndex: 2,
points: [[516, 88], [466, 48], [406, 78]],
},
],
},
};
/**
* 样板 051:新针开旧夹(验证「织一针松开右片旧布,是否让玩家主动改变取线顺序」)
* - 左片(开放):露头「金甲」(压着「粉甲」) 与露头「绿叶」(对应右片绿叶木夹)
* - 右片(被绿叶木夹夹住):「金乙」与「粉乙」
* - 策略对照:
* 1) 朴素起手(先拆左片金甲→粉甲,后开夹):5 笔全分送,也能顺畅过关(1–2★)
* 2) 读夹变序(先抽绿叶开夹 → 双金串送 → 双粉串送):仅需 3 笔,狂省线拿 3★!
*/
const sample051: LevelDef = {
id: 'sample-051',
chapter: 5,
name: '拼布开旧夹 · 样板',
difficulty: 'D4样板',
lesson: '右片旧布被绿叶木夹夹住了!先绣左片金花也能过,但先绣绿叶开夹能凑齐同色串双球省大线!',
goal: '观察右片木夹:先绣带绿叶夹标的针位开夹,再巧用同色串双球!',
ruleTag: '新针开旧夹 · 2碗',
motif: 'custom',
nests: [{ ...NEST }],
balls: [],
targets: [
{ id: 's51-green', color: 'green', x: 296, y: 332, rx: 32, ry: 29, patch: 'leaf' },
{ id: 's51-gold-a', color: 'gold', x: 214, y: 214, rx: 31, ry: 31, patch: 'flower' },
{ id: 's51-gold-b', color: 'gold', x: 280, y: 186, rx: 31, ry: 31, patch: 'flower' },
{ id: 's51-rose-a', color: 'rose', x: 356, y: 236, rx: 31, ry: 31, patch: 'flower' },
{ id: 's51-rose-b', color: 'rose', x: 416, y: 192, rx: 31, ry: 31, patch: 'flower' },
],
ponds: [],
spools: [],
buttons: [],
dyes: [],
gates: [],
roughZones: [],
threeStar: 1740,
twoStar: 2120,
demo: [],
unspool: {
storyTitle: '051 · 新针开旧夹',
storyNote: '两片拼布:左片开放,右片被绿叶木夹夹住。先开夹就能和左片凑双金、双粉!',
patchDividerX: 278,
clips: [
{
id: 'clip-right',
x: 286,
y: 10,
w: 264,
h: 116,
unlockSectionId: 's51-green',
badgeColor: 'green',
badgeShape: 'leaf',
label: '绿叶开',
},
],
slots: [
{ x: 186, y: 472 },
{ x: 414, y: 472 },
],
strands: [
// 左片底层:粉甲(被金甲压住)
{
id: 's51-rose-a',
color: 'rose',
coveredBy: ['s51-gold-a'],
points: [[36, 94], [88, 76], [148, 86]],
},
// 左片上层左:金甲(露头,直接可绣,但先拆会失去和右片金乙串双球机会)
{
id: 's51-gold-a',
color: 'gold',
coveredBy: [],
points: [[68, 22], [90, 68], [108, 114]],
},
// 左片上层右:绿叶(露头,绣完即咔哒松开右片木夹)
{
id: 's51-green',
color: 'green',
coveredBy: [],
points: [[182, 108], [210, 64], [244, 30]],
},
// 右片(木夹内):金乙(开夹即露头)
{
id: 's51-gold-b',
color: 'gold',
coveredBy: [],
clipId: 'clip-right',
points: [[342, 92], [380, 48], [418, 34]],
},
// 右片(木夹内):粉乙(开夹即露头)
{
id: 's51-rose-b',
color: 'rose',
coveredBy: [],
clipId: 'clip-right',
points: [[442, 106], [486, 84], [520, 44]],
},
],
},
};
export const VALIDATION_SAMPLES: ValidationSampleEntry[] = [
{
key: '026a',
shortLabel: '026A 2碗',
headerTitle: '样板 026A · 2碗竖栈',
hypothesis: '对照组:2 格碗 + 三列单栈(8 种两抽开局 6 种卡住)',
level: sample026A,
},
{
key: '026b',
shortLabel: '026B 3碗交叉',
headerTitle: '样板 026B · 3碗交叉',
hypothesis: '实验组:3 格碗 + 中拱 1 压 2 交叉压层,测小屏可读性与取舍感',
level: sample026B,
},
{
key: '038a',
shortLabel: '038A 让路教',
headerTitle: '样板 038A · 让路教学',
hypothesis: '039 前置极简教学:2 巢 2 色不交叉,先建立“留外路”直觉',
level: sample038A,
},
{
key: '039',
shortLabel: '039 三巢让路',
headerTitle: '样板 039 · 三巢让路',
hypothesis: '拉近 3 笔分送与 2 笔串双金让路的耗线差,测走线是否多出一套策略',
level: sample039,
},
{
key: '051',
shortLabel: '051 开旧夹',
headerTitle: '样板 051 · 新针开旧夹',
hypothesis: '测“绣绿叶松开右片木夹”是否让玩家主动改变取线顺序(5 笔→3 笔)',
level: sample051,
},
];
export function findValidationSample(rawKey: string | null): ValidationSampleEntry | null {
if (!rawKey) return null;
const norm = rawKey.trim().toLowerCase();
return VALIDATION_SAMPLES.find(item => item.key === norm) ?? null;
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "1a0513c2-a6b1-4ca8-87a2-a3391a79f94b",
"files": [],
"subMetas": {},
"userData": {}
}
+467 -2
View File
@@ -1,7 +1,7 @@
import { ImageAsset, resources, SpriteFrame, Texture2D } from 'cc';
import { POSTER_FRAMES, PosterFrameDef } from '../core/AtelierService';
import { HOOP_CENTER, HOOP_HEIGHT, HOOP_RADIUS, HOOP_WIDTH, MOTIFS, NEST } from '../core/LevelData';
import { dyeRemainingUses, isPondBridged, isTargetLocked } from '../core/RouteEngine';
import { dyeRemainingUses, isClipUnlocked, isPondBridged, isStrandClipLocked, isStrandExposed, isTargetLocked } from '../core/RouteEngine';
import {
AntState,
ButtonAnchorDef,
@@ -10,16 +10,24 @@ import {
GateDef,
HintState,
LevelDef,
OldClothClipDef,
Point2D,
PondDef,
RoughZoneDef,
RouteState,
SectionDef,
SpoolDef,
TargetColor,
UnspoolConfig,
UnspoolRuntimeState,
YarnColor,
} from '../core/Types';
declare const wx: any;
export const UNSPOOL_CLOTH_WIDTH = 560;
export const UNSPOOL_CLOTH_HEIGHT = 136;
const GOLD = ['#9f501b', '#d59328', '#f6bb4f', '#ffe698'];
const HONEY = ['#9a4b1d', '#cb7724', '#ed9b39', '#ffd283'];
const LEAF = ['#394a31', '#7d8b50', '#a8aa68', '#d0cd8a'];
@@ -1120,7 +1128,80 @@ function drawStartDragGuide(c: CanvasRenderingContext2D, level: LevelDef, time:
c.restore();
}
function drawPatch(c: CanvasRenderingContext2D, section: SectionDef, stitched: boolean): void {
const palette = YARN_PALETTES[section.color];
const w = section.rx;
const h = section.ry;
c.save();
c.translate(section.x, section.y);
c.beginPath();
if (section.patch === 'flower') {
for (let i = 0; i <= 120; i++) {
const a = TAU * i / 120;
const radius = 0.75 + 0.23 * Math.cos(6 * a);
const x = Math.cos(a) * w * radius;
const y = Math.sin(a) * h * radius;
if (i === 0) c.moveTo(x, y);
else c.lineTo(x, y);
}
} else if (section.patch === 'leaf') {
c.moveTo(-w, h * 0.28);
c.quadraticCurveTo(-w * 0.57, -h, w, -h * 0.38);
c.quadraticCurveTo(w * 0.3, h, -w, h * 0.28);
} else if (section.patch === 'bell') {
c.moveTo(-w, h * 0.5);
c.quadraticCurveTo(-w * 0.5, h * 0.16, -w * 0.54, -h * 0.27);
c.bezierCurveTo(-w * 0.37, -h, w * 0.37, -h, w * 0.54, -h * 0.27);
c.quadraticCurveTo(w * 0.5, h * 0.16, w, h * 0.5);
c.quadraticCurveTo(0, h, -w, h * 0.5);
} else if (section.patch === 'boat') {
c.moveTo(-w, h * 0.1);
c.quadraticCurveTo(0, h * 1.5, w, h * 0.1);
c.lineTo(w * 0.18, h * 0.1);
c.lineTo(w * 0.18, -h);
c.quadraticCurveTo(-w * 0.49, -h * 0.63, -w * 0.48, h * 0.1);
c.lineTo(-w, h * 0.1);
} else {
c.moveTo(-w, 0);
c.bezierCurveTo(-w * 0.5, -h * 1.22, w * 0.54, h * 0.17, w, -h * 0.55);
c.bezierCurveTo(w * 0.55, h * 1.25, -w * 0.43, h * 0.13, -w, 0);
}
c.closePath();
c.fillStyle = stitched ? palette[1] : `${ROUTE_COLORS[section.color]}20`;
c.fill();
c.lineWidth = stitched ? 1.6 : 1.9;
c.strokeStyle = RINGS[section.color];
if (!stitched) c.setLineDash([4, 5]);
c.stroke();
if (stitched) {
c.save();
c.clip();
c.lineWidth = 1.2;
for (let y = -h - w; y < h + w; y += 2.8) {
c.strokeStyle = y % 4 < 1 ? palette[1] : palette[2];
line(c, -w - 2, y, w + 2, y - w * 0.72);
}
c.restore();
const detail = section.patch;
if (detail === 'flower' || detail === 'bell') {
ellipse(c, 0, detail === 'bell' ? h * 0.75 : 0, w * 0.19, h * 0.17);
c.fillStyle = palette[0];
c.fill();
}
if (detail === 'leaf') {
c.strokeStyle = palette[3];
c.lineWidth = 1.4;
line(c, -w * 0.72, h * 0.18, w * 0.74, -h * 0.32);
}
}
c.restore();
}
function drawSection(c: CanvasRenderingContext2D, section: SectionDef, stitched: boolean): void {
if (section.patch) {
drawPatch(c, section, stitched);
return;
}
if (section.garden) {
drawGardenSection(c, section, stitched);
return;
@@ -1143,6 +1224,9 @@ function drawSection(c: CanvasRenderingContext2D, section: SectionDef, stitched:
}
function sectionBounds(section: SectionDef): { x: number; y: number; w: number; h: number } {
if (section.patch) {
return { x: section.x - section.rx - 5, y: section.y - section.ry - 5, w: 2 * section.rx + 10, h: 2 * section.ry + 10 };
}
if (section.garden) {
return { x: Math.max(0, section.x - 52), y: Math.max(0, section.y - 52), w: 104, h: 104 };
}
@@ -1442,6 +1526,9 @@ export class EmbroideryRenderer {
private workshopLayer: OffscreenLayer | null = null;
private workshopTexture: Texture2D | null = null;
private workshopSpriteFrame: SpriteFrame | null = null;
private unspoolLayer: OffscreenLayer | null = null;
private unspoolTexture: Texture2D | null = null;
private unspoolSpriteFrame: SpriteFrame | null = null;
private activeLevel: LevelDef | null = null;
constructor(renderScale = 1.5) {
@@ -1853,7 +1940,10 @@ export class EmbroideryRenderer {
else this.drawOverlay(c, section);
}
if (level.motif === 'custom') {
for (const target of level.targets) this.drawArtworkGuideRing(c, target);
for (const target of level.targets) {
if (target.patch) drawSection(c, target, false);
else this.drawArtworkGuideRing(c, target);
}
}
}
@@ -2001,6 +2091,33 @@ export class EmbroideryRenderer {
const locked = isTargetLocked(level, target.id, lines, drawing);
const needsStop = !locked && Boolean(drawing && drawing.color === target.color && drawing.picks.length > drawing.deliveries.length);
drawTargetPin(c, target, Boolean(planned || needsStop), time, planned?.step, locked);
// 「新针开旧夹」:在对应开夹针位旁绘制与旧布木夹完全一致的微型徽标
const linkedClip = level.unspool?.clips?.find(clip => clip.unlockSectionId === target.id && !isClipUnlocked(clip, lines, drawing));
if (linkedClip) {
const pulsing = state.unspool?.pulseTargetId === target.id && time < (state.unspool.pulseUntil ?? 0);
if (pulsing) {
const wave = (time % 650) / 650;
c.save();
ellipse(c, target.x, target.y, target.rx + 8 + wave * 18, target.ry + 8 + wave * 18);
c.strokeStyle = ROUTE_COLORS[linkedClip.badgeColor];
c.globalAlpha = Math.max(0.15, 0.9 - wave * 0.75);
c.lineWidth = 3.5;
c.stroke();
c.restore();
}
const bx = target.x + Math.max(22, target.rx * 0.72);
const by = target.y - Math.max(20, target.ry * 0.68);
c.save();
roundRectPath(c, bx - 14, by - 11, 28, 22, 6);
c.fillStyle = '#8b5e36';
c.fill();
c.strokeStyle = pulsing ? '#fff1a8' : '#573619';
c.lineWidth = pulsing ? 2.4 : 1.5;
c.stroke();
this.drawClipEmblem(c, bx, by, 7.5, linkedClip.badgeColor, linkedClip.badgeShape);
c.restore();
}
}
drawUnlockLinks(c, level, lines, drawing, time);
@@ -2009,6 +2126,42 @@ export class EmbroideryRenderer {
drawNest(c, nestPos, time, lines.length === 0 && !drawing, idx === activeNestIndex, multiNest);
});
if (level.unspool) {
const deadlocked = Boolean(state.unspool?.deadlocked);
const animSlot = state.unspool?.animating?.slotIndex ?? -1;
const capacity = level.unspool.capacity ?? level.unspool.slots.length;
const occupiedCount = state.unspool?.slotBallIds.filter(id => id != null).length ?? 0;
const capFull = occupiedCount >= capacity;
level.unspool.slots.forEach((slot, idx) => {
const occupied = state.unspool?.slotBallIds[idx] != null;
const receiving = animSlot === idx;
const capBlocked = !occupied && capFull;
c.save();
c.translate(slot.x, slot.y);
c.globalAlpha = capBlocked ? 0.56 : 1;
ellipse(c, 2, 12, 30, 15);
c.fillStyle = '#63503d28';
c.fill();
ellipse(c, 0, 2, 28, 25);
c.fillStyle = deadlocked ? '#e7b9aa' : '#ddd0b9';
c.fill();
c.strokeStyle = deadlocked ? '#975449' : receiving ? '#826146' : '#a08e73';
c.lineWidth = receiving || deadlocked ? 2.8 : 1.6;
c.stroke();
ellipse(c, 0, 2, 21, 18);
c.fillStyle = occupied ? '#c2b091' : '#f2e7d4';
c.fill();
if (!occupied) {
c.fillStyle = '#6d5e4e';
c.font = `700 12px ${SERIF_FONT}`;
c.textAlign = 'center';
c.textBaseline = 'middle';
c.fillText(capBlocked ? '满格' : `线碗${idx + 1}`, 0, 2);
}
c.restore();
});
}
for (const ball of level.balls) {
let pickedAt: number | undefined;
for (const l of lines) {
@@ -2503,6 +2656,318 @@ export class EmbroideryRenderer {
this.workshopTexture.uploadData(this.workshopLayer.canvas);
}
public getUnspoolClothSpriteFrame(): SpriteFrame {
if (!this.unspoolSpriteFrame) {
this.unspoolLayer = createLayer(UNSPOOL_CLOTH_WIDTH, UNSPOOL_CLOTH_HEIGHT, 1.5);
const imageAsset = new ImageAsset(this.unspoolLayer.canvas);
this.unspoolTexture = new Texture2D();
this.unspoolTexture.image = imageAsset;
this.unspoolSpriteFrame = new SpriteFrame();
this.unspoolSpriteFrame.texture = this.unspoolTexture;
}
return this.unspoolSpriteFrame;
}
private drawClipEmblem(
c: CanvasRenderingContext2D,
x: number,
y: number,
r: number,
color: TargetColor,
shape: OldClothClipDef['badgeShape'],
): void {
c.save();
c.translate(x, y);
ellipse(c, 0, 0, r + 1.5, r + 1.5);
c.fillStyle = '#fbf4e4';
c.fill();
c.fillStyle = ROUTE_COLORS[color];
c.strokeStyle = RINGS[color];
c.lineWidth = 1.2;
c.beginPath();
if (shape === 'leaf') {
c.moveTo(-r * 0.72, r * 0.45);
c.quadraticCurveTo(-r * 0.35, -r * 0.78, r * 0.76, -r * 0.52);
c.quadraticCurveTo(r * 0.42, r * 0.76, -r * 0.72, r * 0.45);
c.closePath();
c.fill();
c.stroke();
} else if (shape === 'flower') {
for (let i = 0; i < 5; i++) {
const a = (i * Math.PI * 2) / 5 - Math.PI / 2;
c.moveTo(Math.cos(a) * r * 0.42 + r * 0.32, Math.sin(a) * r * 0.42);
c.arc(Math.cos(a) * r * 0.42, Math.sin(a) * r * 0.42, r * 0.32, 0, Math.PI * 2);
}
c.fill();
} else if (shape === 'bell') {
c.arc(0, -r * 0.1, r * 0.56, Math.PI, 0);
c.lineTo(r * 0.68, r * 0.52);
c.lineTo(-r * 0.68, r * 0.52);
c.closePath();
c.fill();
c.stroke();
} else {
c.arc(0, 0, r * 0.58, 0, Math.PI * 2);
c.fill();
c.stroke();
}
c.restore();
}
/** 「拆旧织新」上方旧绣片 2D 实时渲染:底层→顶层压叠投影、交叉阴影断口、旧布木夹与可抽亮色线头脉冲 */
public renderUnspoolClothFrame(
config: UnspoolConfig,
runtime: UnspoolRuntimeState,
timeMs: number,
lines: RouteState[] = [],
): void {
if (!this.unspoolLayer || !this.unspoolTexture) return;
const W = UNSPOOL_CLOTH_WIDTH;
const H = UNSPOOL_CLOTH_HEIGHT;
const c = this.unspoolLayer.ctx;
c.clearRect(0, 0, W, H);
const fabric = c.createLinearGradient(0, 0, W, H);
fabric.addColorStop(0, '#f5eddb');
fabric.addColorStop(1, '#e9dfcc');
roundRectPath(c, 1, 1, W - 2, H - 2, 15);
c.fillStyle = fabric;
c.fill();
c.strokeStyle = '#cfc0a7';
c.lineWidth = 1.5;
c.stroke();
c.save();
roundRectPath(c, 3, 3, W - 6, H - 6, 14);
c.clip();
if (config.patchDividerX) {
const dx = config.patchDividerX;
c.fillStyle = '#e7eef1';
c.fillRect(dx, 0, W - dx, H);
c.fillStyle = '#6f8ea11c';
for (let x = dx + 6; x < W; x += 12) c.fillRect(x, 0, 1.2, H);
for (let y = 6; y < H; y += 12) c.fillRect(dx, y, W - dx, 1.2);
c.fillStyle = '#8069490f';
for (let x = 3; x < dx; x += 5) c.fillRect(x, 0, 0.8, H);
c.beginPath();
c.moveTo(dx, 6);
c.lineTo(dx, H - 6);
c.strokeStyle = '#8f775d99';
c.lineWidth = 1.5;
c.setLineDash([4, 4]);
c.stroke();
c.setLineDash([]);
} else {
c.fillStyle = '#8069490d';
for (let x = 3; x < W; x += 5) c.fillRect(x, 0, 0.7, H);
c.fillStyle = '#ffffff66';
for (let y = 3; y < H; y += 5) c.fillRect(0, y, W, 0.8);
}
roundRectPath(c, 9, 9, W - 18, H - 18, 9);
c.strokeStyle = '#9c836d66';
c.lineWidth = 1;
c.setLineDash([3, 4]);
c.stroke();
c.restore();
const removed = new Set(runtime.removedIds);
const remaining = config.strands.filter(s => !removed.has(s.id));
if (remaining.length === 0) {
c.fillStyle = '#5f4627';
c.font = `700 18px ${SERIF_FONT}`;
c.textAlign = 'center';
c.textBaseline = 'middle';
c.fillText('旧线已拆完,拖蚂蚁开始落针', W / 2, H / 2);
this.unspoolTexture.uploadData(this.unspoolLayer.canvas);
return;
}
const coversSomeone = new Set<string>();
for (const s of remaining) {
for (const cid of s.coveredBy) {
if (!removed.has(cid)) coversSomeone.add(cid);
}
}
for (const strand of remaining) {
const lockedClip = isStrandClipLocked(config, strand, lines);
const exposed = isStrandExposed(config, strand, removed, lines);
const isUpper = exposed || coversSomeone.has(strand.id);
const isAnim = runtime.animating?.strandId === strand.id;
const progress = isAnim ? Math.min(1, Math.max(0, runtime.animating!.progress)) : 0;
const rawPts = strand.points.map(([x, y]) => ({ x, y }));
const segLens: number[] = [];
let totalLen = 0;
for (let i = 1; i < rawPts.length; i++) {
const d = Math.hypot(rawPts[i].x - rawPts[i - 1].x, rawPts[i].y - rawPts[i - 1].y);
segLens.push(d);
totalLen += d;
}
const keepLen = totalLen * (1 - progress);
const drawPts: Point2D[] = [rawPts[0]];
let acc = 0;
for (let i = 1; i < rawPts.length; i++) {
const seg = segLens[i - 1];
if (acc + seg >= keepLen) {
const t = seg > 0 ? Math.max(0, Math.min(1, (keepLen - acc) / seg)) : 0;
drawPts.push({
x: rawPts[i - 1].x + (rawPts[i].x - rawPts[i - 1].x) * t,
y: rawPts[i - 1].y + (rawPts[i].y - rawPts[i - 1].y) * t,
});
break;
}
drawPts.push(rawPts[i]);
acc += seg;
}
const palette = YARN_PALETTES[strand.color];
const mainColor = ROUTE_COLORS[strand.color];
const darkColor = RINGS[strand.color];
const lightColor = palette[3];
const width = exposed ? 13.5 : 10.5;
c.save();
c.lineCap = 'round';
c.lineJoin = 'round';
c.globalAlpha = exposed ? 1 : lockedClip ? 0.56 : 0.72;
if (drawPts.length >= 2) {
const traceSmoothPath = () => {
c.beginPath();
c.moveTo(drawPts[0].x, drawPts[0].y);
for (let i = 1; i < drawPts.length - 1; i++) {
const prev = drawPts[i - 1];
const joint = drawPts[i];
const next = drawPts[i + 1];
const inScale = Math.min(0.25, 9 / Math.hypot(joint.x - prev.x, joint.y - prev.y));
const outScale = Math.min(0.25, 9 / Math.hypot(next.x - joint.x, next.y - joint.y));
c.lineTo(joint.x + (prev.x - joint.x) * inScale, joint.y + (prev.y - joint.y) * inScale);
c.quadraticCurveTo(
joint.x, joint.y,
joint.x + (next.x - joint.x) * outScale, joint.y + (next.y - joint.y) * outScale,
);
}
const last = drawPts[drawPts.length - 1];
c.lineTo(last.x, last.y);
};
if (isUpper && coversSomeone.has(strand.id)) {
traceSmoothPath();
c.strokeStyle = '#efe5d2ee';
c.lineWidth = width + 6;
c.stroke();
}
traceSmoothPath();
c.shadowColor = exposed ? '#3b281496' : '#543f2526';
c.shadowBlur = exposed ? 6 : 1.5;
c.shadowOffsetY = exposed ? 3.5 : 1;
c.strokeStyle = darkColor;
c.lineWidth = width;
c.stroke();
c.shadowColor = 'transparent';
c.strokeStyle = mainColor;
c.lineWidth = width - 1.4;
c.stroke();
c.beginPath();
for (let i = 1; i < drawPts.length; i++) {
const start = drawPts[i - 1];
const end = drawPts[i];
const len = Math.hypot(end.x - start.x, end.y - start.y);
if (len < 10) continue;
const dx = (end.x - start.x) / len;
const dy = (end.y - start.y) / len;
for (let along = 5; along <= len - 5; along += 4.3) {
const x = start.x + dx * along;
const y = start.y + dy * along;
const radius = width * 0.37;
c.moveTo(x + dy * radius - dx * 1.9, y - dx * radius - dy * 1.9);
c.quadraticCurveTo(x + dx * 0.5, y + dy * 0.5, x - dy * radius + dx * 1.9, y + dx * radius + dy * 1.9);
}
}
c.strokeStyle = lightColor + '9c';
c.lineWidth = 1.1;
c.stroke();
}
const tip = drawPts[drawPts.length - 1];
if (isAnim) {
this.drawBall(c, tip.x, tip.y, strand.color, 0.45 + progress * 0.58, progress * 11, true);
} else if (exposed) {
const halo = 12.5 + Math.sin(timeMs / 280 + tip.x * 0.03) * 1.5;
ellipse(c, tip.x, tip.y, halo, halo);
c.fillStyle = '#fff9e4c8';
c.fill();
c.strokeStyle = darkColor;
c.lineWidth = 1.6;
c.stroke();
ellipse(c, tip.x, tip.y, 5.5, 5.5);
c.fillStyle = mainColor;
c.fill();
}
c.restore();
}
if (config.clips?.length) {
for (const clip of config.clips) {
const unlocked = isClipUnlocked(clip, lines);
c.save();
if (!unlocked) {
roundRectPath(c, clip.x, clip.y, clip.w, clip.h, 10);
c.fillStyle = '#dce4e888';
c.fill();
c.strokeStyle = '#7b6345aa';
c.lineWidth = 1.6;
c.setLineDash([5, 4]);
c.stroke();
c.setLineDash([]);
const cx = clip.x + 18;
const cy = clip.y + clip.h / 2;
c.shadowColor = '#2e1d0f55';
c.shadowBlur = 6;
c.shadowOffsetY = 2;
roundRectPath(c, cx - 22, cy - 30, 44, 60, 10);
const wood = c.createLinearGradient(cx - 22, cy - 30, cx + 22, cy + 30);
wood.addColorStop(0, '#ab7846');
wood.addColorStop(1, '#784c27');
c.fillStyle = wood;
c.fill();
c.shadowColor = 'transparent';
c.strokeStyle = '#4e2f15';
c.lineWidth = 1.8;
c.stroke();
c.fillStyle = '#e7c985';
c.fillRect(cx - 18, cy - 3, 36, 5);
this.drawClipEmblem(c, cx, cy - 11, 11, clip.badgeColor, clip.badgeShape);
c.fillStyle = '#fff5df';
c.font = `700 11px ${SERIF_FONT}`;
c.textAlign = 'center';
c.textBaseline = 'middle';
c.fillText(clip.label ?? '旧夹', cx, cy + 16);
} else {
const cx = clip.x + clip.w - 34;
const cy = clip.y + 13;
roundRectPath(c, cx - 24, cy - 9, 48, 18, 9);
c.fillStyle = '#6b8555d8';
c.fill();
c.fillStyle = '#fffaf0';
c.font = `700 11px ${SERIF_FONT}`;
c.textAlign = 'center';
c.textBaseline = 'middle';
c.fillText('已开夹', cx, cy + 0.5);
}
c.restore();
}
}
this.unspoolTexture.uploadData(this.unspoolLayer.canvas);
}
public exportArtwork(
state: GameState,
meta: {
+371 -33
View File
@@ -3,6 +3,7 @@ import { AtelierService } from '../core/AtelierService';
import { CHAPTERS, CHAPTER_UNLOCK_STARS, formatLength, formatShort, HOOP_HEIGHT, HOOP_WIDTH, LEVELS, NEST, YARN_COLORS } from '../core/LevelData';
import {
ANT_SPEED,
availableTargets,
checkSegmentBlock,
createEmptyRoute,
dispatchWarning,
@@ -11,11 +12,15 @@ import {
findNextHint,
interpolate,
isButtonEvent,
isClipUnlocked,
isDeliveryEvent,
isDyeEvent,
isGateEvent,
isPickEvent,
isSpoolEvent,
isStrandClipLocked,
isStrandExposed,
isTargetLocked,
passedGateIds,
planStops,
prepareRouteForRun,
@@ -28,8 +33,8 @@ import {
} from '../core/RouteEngine';
import { SoundService } from '../core/SoundService';
import { StorageService } from '../core/StorageService';
import { BlockReason, GameState, LevelDef, Point2D, RouteState, TargetColor } from '../core/Types';
import { EmbroideryRenderer } from '../render/EmbroideryRenderer';
import { BallDef, BlockReason, GameState, LevelDef, Point2D, RouteState, TargetColor } from '../core/Types';
import { EmbroideryRenderer, UNSPOOL_CLOTH_HEIGHT, UNSPOOL_CLOTH_WIDTH } from '../render/EmbroideryRenderer';
import { AtelierTab } from './AtelierModal';
import { applyCoverBackground, applySafeContentTransform, ScreenMetrics } from './ScreenAdapter';
import {
@@ -54,6 +59,8 @@ const { ccclass } = _decorator;
const HOOP_DISPLAY_W = 708;
const HOOP_DISPLAY_H = Math.round((HOOP_DISPLAY_W * HOOP_HEIGHT) / HOOP_WIDTH);
const RELATIVE_GAIN = 1.42;
const UNSPOOL_DISPLAY_WIDTH = 492;
const UNSPOOL_DISPLAY_HEIGHT = Math.round((UNSPOOL_DISPLAY_WIDTH * UNSPOOL_CLOTH_HEIGHT) / UNSPOOL_CLOTH_WIDTH);
const CHIP_STYLES: Record<TargetColor, { icon: string; dot: string; fill: string; stroke: string; text: string }> = {
gold: { icon: '✿', dot: '#d89a2c', fill: '#fbf0d4', stroke: '#d9b574', text: '#6a410b' },
@@ -86,8 +93,19 @@ export class PlayView extends Component {
private onOpenAtelier?: (tab: AtelierTab, chapterIndex: number, focusLevelIndex?: number) => void;
private currentIndex = 0;
private customMode = false;
private level: LevelDef = LEVELS[0];
private activeNestIndex = 0;
private get unspoolMode(): boolean {
return Boolean(this.level.unspool);
}
private unspoolNextBallId = 100;
private unspoolHistory: (
| { kind: 'unspool'; strandId: string; slotIndex: number; ballId: number }
| { kind: 'stitch'; restoredBalls: { slotIndex: number; ball: BallDef }[] }
)[] = [];
private targetCounts: Record<TargetColor, number> = {
gold: 0,
green: 0,
@@ -150,9 +168,14 @@ export class PlayView extends Component {
private topBarNode!: Node;
private missionRowNode!: Node;
private whisperRibbonNode!: Node;
private unspoolPanelNode!: Node;
private unspoolClothNode!: Node;
private unspoolClothTransform!: UITransform;
private unspoolHeaderLabel!: Label;
private resultFrameNode!: Node;
private relativeAnchorNode!: Node;
private relativeThumbNode!: Node;
private lastMetrics: ScreenMetrics | null = null;
private hintBtn!: ArtButton;
private hintHalo!: Node;
@@ -229,6 +252,38 @@ export class PlayView extends Component {
hoopSprite.sizeMode = Sprite.SizeMode.CUSTOM;
hoopSprite.spriteFrame = this.renderer.getSpriteFrame();
// 「拆旧织新」胡桃木铜钉旧布抽线板(仅在带 unspool 配置的关卡显示)
const unspoolFrame = createPanel('UnspoolClothPanel', 698, 132, {
fill: '#3c2514ee',
stroke: '#d8b068',
strokeWidth: 2,
radius: 20,
depth: 4,
depthColor: '#221308',
shadow: 5,
rivets: true,
rivetColor: '#e2ba6d',
}, this.safeRoot);
this.unspoolPanelNode = unspoolFrame.node;
this.unspoolHeaderLabel = createLabel('UnspoolHeader', '旧荷包\n点线头抽线', 166, 92, {
size: 21,
lineHeight: 30,
color: '#fff4d8',
bold: true,
align: Label.HorizontalAlign.LEFT,
overflow: Label.Overflow.SHRINK,
}, unspoolFrame.node);
this.unspoolHeaderLabel.node.setPosition(-242, 0, 0);
this.unspoolClothNode = createUINode('UnspoolClothCanvas', UNSPOOL_DISPLAY_WIDTH, UNSPOOL_DISPLAY_HEIGHT, unspoolFrame.node);
this.unspoolClothNode.setPosition(88, 0, 0);
this.unspoolClothTransform = this.unspoolClothNode.getComponent(UITransform)!;
const unspoolSprite = this.unspoolClothNode.addComponent(Sprite);
unspoolSprite.sizeMode = Sprite.SizeMode.CUSTOM;
unspoolSprite.spriteFrame = this.renderer.getUnspoolClothSpriteFrame();
this.unspoolClothNode.on(Node.EventType.TOUCH_START, this.onUnspoolClothTouch, this);
this.unspoolPanelNode.active = false;
// 隐形相对滑动轻提示环(松手即隐)
const relAnchor = createPanel('RelativeAnchor', 58, 58, {
fill: '#f7e7c426', stroke: '#fff7e082', strokeWidth: 2, radius: 29,
@@ -509,7 +564,7 @@ export class PlayView extends Component {
onClick: () => {
this.sound.unlock();
const gate = this.getNextChapterGate();
if (this.currentIndex + 1 < LEVELS.length && !gate.locked) {
if (!this.customMode && this.currentIndex + 1 < LEVELS.length && !gate.locked) {
this.loadLevel(this.currentIndex + 1);
} else {
this.onBackLobby();
@@ -670,10 +725,16 @@ export class PlayView extends Component {
}
public applyScreenMetrics(m: ScreenMetrics): void {
this.lastMetrics = m;
this.safeContentScale = Math.max(0.5, m.contentScale);
if (this.bgArtNode) applyCoverBackground(this.bgArtNode, m);
if (this.safeRoot) applySafeContentTransform(this.safeRoot, m);
if (!this.topBarNode) return;
this.layoutPlayArea();
}
private layoutPlayArea(): void {
if (!this.topBarNode || !this.lastMetrics) return;
const m = this.lastMetrics;
// 全面屏动态贴顶/贴底锚定并拉宽 HUD 与绣绷上下呼吸感,消除大块死空白
const h = m.safeHalfH;
@@ -681,20 +742,44 @@ export class PlayView extends Component {
const topBarY = h - 56;
const missionY = topBarY - 88 - e * 0.08;
const ribbonY = missionY - 68 - e * 0.08;
const dockY = -h + 84;
const hoopY = ((ribbonY - 20) + (dockY + 76)) / 2 + 8;
const dockY = -h + (this.customMode ? 128 : 84);
this.topBarNode.setPosition(0, topBarY, 0);
this.missionRowNode.setPosition(0, missionY, 0);
this.whisperRibbonNode.setPosition(0, ribbonY, 0);
this.dockTrayNode.setPosition(0, dockY, 0);
this.hoopNode.setPosition(0, hoopY, 0);
this.hoopShadowNode.setPosition(4, hoopY - 22, 0);
this.dragSurfaceNode.setPosition(0, hoopY - 10, 0);
this.resultFrameNode.setPosition(0, -h + 286, 0);
this.tutorialOverlay.setPosition(0, ribbonY - 94, 0);
this.resultFrameNode.setPosition(0, -h + (this.customMode ? 310 : 286), 0);
if (this.unspoolMode) {
const unspoolY = missionY - 96 - e * 0.04;
const ribbonY = dockY + 94;
const availTop = unspoolY - 70;
const availBottom = ribbonY + 24;
const availH = Math.max(480, availTop - availBottom);
const hoopScale = Math.min(0.95, availH / HOOP_DISPLAY_H);
const hoopY = (availTop + availBottom) / 2;
this.unspoolPanelNode.setPosition(0, unspoolY, 0);
this.whisperRibbonNode.setPosition(0, ribbonY, 0);
this.hoopNode.setPosition(0, hoopY, 0);
this.hoopNode.setScale(hoopScale, hoopScale, 1);
this.hoopShadowNode.setPosition(4 * hoopScale, hoopY - 22 * hoopScale, 0);
this.hoopShadowNode.setScale(hoopScale, hoopScale, 1);
this.dragSurfaceNode.setPosition(0, hoopY, 0);
this.dragSurfaceNode.getComponent(UITransform)!.setContentSize(740, availH + 20);
this.tutorialOverlay.setPosition(0, unspoolY, 0);
} else {
const ribbonY = missionY - 68 - e * 0.08;
const hoopY = ((ribbonY - 20) + (dockY + 76)) / 2 + 8;
this.whisperRibbonNode.setPosition(0, ribbonY, 0);
this.hoopNode.setPosition(0, hoopY, 0);
this.hoopNode.setScale(1, 1, 1);
this.hoopShadowNode.setPosition(4, hoopY - 22, 0);
this.hoopShadowNode.setScale(1, 1, 1);
this.dragSurfaceNode.setPosition(0, hoopY - 10, 0);
this.dragSurfaceNode.getComponent(UITransform)!.setContentSize(740, 940);
this.tutorialOverlay.setPosition(0, ribbonY - 94, 0);
}
}
private syncLoupeButton(): void {
@@ -736,7 +821,8 @@ export class PlayView extends Component {
if (this.pointer.relative) {
const uiLoc = event.getUILocation();
this.updateRelativeIndicator(uiLoc, false);
const scaleInv = 1 / this.safeContentScale;
const hoopScale = Math.max(0.5, this.hoopNode.scale.x);
const scaleInv = 1 / (this.safeContentScale * hoopScale);
const dx = (uiLoc.x - this.pointer.startUI.x) * scaleInv * (HOOP_WIDTH / HOOP_DISPLAY_W) * RELATIVE_GAIN;
const dy = -(uiLoc.y - this.pointer.startUI.y) * scaleInv * (HOOP_HEIGHT / HOOP_DISPLAY_H) * RELATIVE_GAIN;
if (this.state.drawing) this.state.drawing.fingerTip = null;
@@ -831,8 +917,27 @@ export class PlayView extends Component {
}
public loadLevel(index: number): void {
this.customMode = false;
this.currentIndex = index;
this.level = LEVELS[index];
const blueprint = LEVELS[index];
if (!blueprint) return;
this.level = blueprint.unspool ? { ...blueprint, balls: [] } : blueprint;
const numStr = index + 1 < 10 ? '0' + (index + 1) : String(index + 1);
this.setupLoadedLevel(`${numStr} ${this.level.name}`);
this.tutorialOverlay.active = !this.unspoolMode && index === 0 && !this.storage.hasSeenTutorial();
}
public loadCustomLevel(blueprint: LevelDef, headerTitle?: string): void {
this.customMode = true;
this.currentIndex = 0;
this.level = blueprint.unspool
? { ...blueprint, balls: [] }
: { ...blueprint, balls: blueprint.balls.map(b => ({ ...b })) };
this.setupLoadedLevel(headerTitle ?? blueprint.name);
this.tutorialOverlay.active = false;
}
private setupLoadedLevel(headerTitle: string): void {
this.targetCounts = {
gold: 0,
green: 0,
@@ -848,19 +953,16 @@ export class PlayView extends Component {
}
this.renderer.selectLevel(this.level);
const numStr = index + 1 < 10 ? '0' + (index + 1) : String(index + 1);
this.titleLabel.string = `${numStr} ${this.level.name}`;
if (this.nextBtn.label) this.nextBtn.label.string = index + 1 < LEVELS.length ? '下一关' : '返回大厅';
this.titleLabel.string = headerTitle;
if (this.nextBtn.label) {
this.nextBtn.label.string = !this.customMode && this.currentIndex + 1 < LEVELS.length ? '下一关' : '返回大厅';
}
this.layoutTopChips();
this.syncSoundButton();
this.syncLanguageChrome();
this.state.demoWatched = false;
this.resetLevel();
if (index === 0 && !this.storage.hasSeenTutorial()) {
this.tutorialOverlay.active = true;
} else {
this.tutorialOverlay.active = false;
}
this.layoutPlayArea();
}
private dismissTutorial(): void {
@@ -919,6 +1021,23 @@ export class PlayView extends Component {
this.pointer = null;
this.activeNestIndex = 0;
this.hideRelativeIndicator();
if (this.unspoolMode && this.level.unspool) {
this.level.balls = [];
this.unspoolHistory = [];
this.unspoolNextBallId = 100;
this.state.unspool = {
removedIds: [],
animating: null,
slotBallIds: this.level.unspool.slots.map(() => null),
deadlocked: false,
pulseTargetId: null,
pulseUntil: 0,
};
this.unspoolHeaderLabel.string = `${this.level.unspool.storyTitle}\n点线头抽线`;
this.renderer.renderUnspoolClothFrame(this.level.unspool, this.state.unspool, this.state.time, this.state.lines);
} else {
this.state.unspool = null;
}
this.setStatus(
this.state.demoWatched
? '已看过本关演示(本局最高 2 ★,换关后可重新挑战三星)。'
@@ -928,6 +1047,160 @@ export class PlayView extends Component {
this.renderer.renderFrame(this.state, this.activeNestIndex);
}
private pointToSegDist(px: number, py: number, ax: number, ay: number, bx: number, by: number): number {
const dx = bx - ax;
const dy = by - ay;
const lenSq = dx * dx + dy * dy;
const t = lenSq > 0 ? Math.max(0, Math.min(1, ((px - ax) * dx + (py - ay) * dy) / lenSq)) : 0;
return Math.hypot(px - (ax + dx * t), py - (ay + dy * t));
}
private onUnspoolClothTouch(event: EventTouch): void {
if (!this.unspoolMode || !this.level.unspool || !this.state.unspool) return;
if (this.state.complete || this.state.drawing || this.state.unspool.animating) return;
this.sound.unlock();
event.propagationStopped = true;
const uiLoc = event.getUILocation();
const local = this.unspoolClothTransform.convertToNodeSpaceAR(new Vec3(uiLoc.x, uiLoc.y, 0));
const { width, height } = this.unspoolClothTransform.contentSize;
const cx = (local.x / width + 0.5) * UNSPOOL_CLOTH_WIDTH;
const cy = (0.5 - local.y / height) * UNSPOOL_CLOTH_HEIGHT;
if (this.level.unspool.clips?.length) {
const hitLockedClip = this.level.unspool.clips.find(
clip => !isClipUnlocked(clip, this.state.lines) &&
cx >= clip.x && cx <= clip.x + clip.w && cy >= clip.y && cy <= clip.y + clip.h,
);
if (hitLockedClip) {
this.sound.block();
this.state.unspool.pulseTargetId = hitLockedClip.unlockSectionId;
this.state.unspool.pulseUntil = this.state.time + 2200;
this.setStatus('这块旧布被木夹夹住了!先绣出绣面上带同纹样木夹标示的针位即可松开。');
return;
}
}
const removed = new Set(this.state.unspool.removedIds);
const strands = this.level.unspool.strands;
const remaining = strands.filter(strand => !removed.has(strand.id));
let pickedStrand: typeof strands[number] | undefined;
let nearestTip = 33;
for (const strand of remaining) {
const [x, y] = strand.points[strand.points.length - 1];
const dist = Math.hypot(cx - x, cy - y);
if (dist < nearestTip) {
nearestTip = dist;
pickedStrand = strand;
}
}
if (!pickedStrand) {
pickedStrand = remaining.reverse().find(strand => strand.points.some(([x, y], index) => {
if (index === 0) return false;
const [px, py] = strand.points[index - 1];
return this.pointToSegDist(cx, cy, px, py, x, y) <= 14;
}));
}
if (!pickedStrand) return;
const lockedClip = isStrandClipLocked(this.level.unspool, pickedStrand, this.state.lines);
if (lockedClip) {
this.sound.block();
this.state.unspool.pulseTargetId = lockedClip.unlockSectionId;
this.state.unspool.pulseUntil = this.state.time + 2200;
this.setStatus('这缕线在被木夹锁住的旧布里,先绣出带同纹样木夹标示的针位即可松开!');
return;
}
const exposed = isStrandExposed(this.level.unspool, pickedStrand, removed, this.state.lines);
if (!exposed) {
const blockers = pickedStrand.coveredBy.filter(cid => !removed.has(cid)).length;
this.sound.block();
this.setStatus(
blockers > 1
? `这缕旧线被 ${blockers} 缕上层线压住,需先抽走压着它的上层发光线头!`
: '这缕旧线还压在底下,先抽走压着它的上层发光线头!',
);
return;
}
const capacity = this.level.unspool.capacity ?? this.level.unspool.slots.length;
const occupiedCount = this.state.unspool.slotBallIds.filter(id => id !== null).length;
if (occupiedCount >= capacity) {
this.sound.block();
this.setStatus(`线碗已装满(${occupiedCount}/${capacity})。先落针腾一格,或点「撤销」。`);
return;
}
const freeSlot = pickedStrand.slotIndex !== undefined && this.state.unspool.slotBallIds[pickedStrand.slotIndex] === null
? pickedStrand.slotIndex
: this.state.unspool.slotBallIds.indexOf(null);
if (freeSlot === -1) {
this.sound.block();
this.setStatus('线碗已经装满。先落针腾一格,或点「撤销」。');
return;
}
this.sound.unspool();
this.state.unspool.animating = { strandId: pickedStrand.id, progress: 0, slotIndex: freeSlot };
this.setStatus('滋溜抽线中,毛线正卷球滚入线碗…');
}
private finishUnspoolAnimation(): void {
if (!this.level.unspool || !this.state.unspool || !this.state.unspool.animating) return;
const { strandId, slotIndex } = this.state.unspool.animating;
const strand = this.level.unspool.strands.find(s => s.id === strandId);
const slotPos = this.level.unspool.slots[slotIndex];
this.state.unspool.animating = null;
if (!strand || !slotPos) return;
this.state.unspool.removedIds.push(strandId);
const ballId = this.unspoolNextBallId++;
const newBall: BallDef = { id: ballId, x: slotPos.x, y: slotPos.y, color: strand.color };
this.level.balls.push(newBall);
this.state.unspool.slotBallIds[slotIndex] = ballId;
this.unspoolHistory.push({ kind: 'unspool', strandId, slotIndex, ballId });
this.sound.pick(this.state.unspool.slotBallIds.filter(id => id !== null).length);
if (!this.checkUnspoolDeadlock()) {
const rem = this.level.unspool.strands.length - this.state.unspool.removedIds.length;
this.setStatus(
rem > 0
? `线球落入线碗 ${slotIndex + 1}!可继续抽线,或直接拖蚂蚁开始绣花。`
: '旧线已全部拆完,拖蚂蚁把线碗里的毛线织成新画吧!',
);
}
this.updateHud();
}
private checkUnspoolDeadlock(): boolean {
if (!this.unspoolMode || !this.level.unspool || !this.state.unspool) return false;
const capacity = this.level.unspool.capacity ?? this.level.unspool.slots.length;
const occupiedCount = this.state.unspool.slotBallIds.filter(id => id !== null).length;
if (occupiedCount < capacity) {
this.state.unspool.deadlocked = false;
return false;
}
const unlockedTargets = availableTargets(this.level, this.state.lines).filter(
t => !isTargetLocked(this.level, t.id, this.state.lines),
);
if (unlockedTargets.length === 0) {
this.state.unspool.deadlocked = false;
return false;
}
const unlockedColors = new Set(unlockedTargets.map(t => t.color));
const bowlColors = this.state.unspool.slotBallIds
.map(id => this.level.balls.find(b => b.id === id)?.color)
.filter((c): c is TargetColor => Boolean(c));
const canDeliver = bowlColors.some(c => unlockedColors.has(c));
this.state.unspool.deadlocked = !canDeliver;
if (!canDeliver) {
this.sound.block();
this.setStatus('线碗装满且对应针位还上着锁!点「撤销」换条拆线顺序试试~');
}
return !canDeliver;
}
private toggleHint(): void {
if (this.state.demo || this.state.complete) return;
const curTier = this.state.hint?.tier ?? 0;
@@ -969,7 +1242,28 @@ export class PlayView extends Component {
}
private undoLastLine(): void {
if (!this.state.lines.length || this.state.complete || this.state.demo) return;
if (this.state.complete || this.state.demo) return;
if (this.unspoolMode && this.state.unspool) {
if (this.state.unspool.animating || !this.unspoolHistory.length) return;
const last = this.unspoolHistory.pop()!;
if (last.kind === 'stitch') {
this.state.lines.pop();
for (const item of last.restoredBalls) {
this.state.unspool.slotBallIds[item.slotIndex] = item.ball.id;
}
this.setStatus('已收回上一笔刺绣,毛线球放回线碗。');
} else {
this.state.unspool.removedIds = this.state.unspool.removedIds.filter(id => id !== last.strandId);
this.state.unspool.slotBallIds[last.slotIndex] = null;
this.level.balls = this.level.balls.filter(b => b.id !== last.ballId);
this.setStatus('已把这缕旧线放回旧绣片,可以改抽其他线头。');
}
this.sound.undo();
this.checkUnspoolDeadlock();
this.updateHud();
return;
}
if (!this.state.lines.length) return;
this.state.lines.pop();
if (!this.state.lines.length) this.state.assisted = false;
this.sound.undo();
@@ -1116,7 +1410,26 @@ export class PlayView extends Component {
prepareRouteForRun(route, this.state.time);
this.state.lines.push(route);
this.state.hint = null;
this.setStatus(dispatchWarning(this.level, this.state.lines) || (route.picks.length > 1 ? '两颗球一起出发。' : '蚂蚁出发了,也可继续画下一笔。'));
if (this.unspoolMode && this.state.unspool) {
const restoredBalls: { slotIndex: number; ball: BallDef }[] = [];
for (const p of route.picks) {
const sIdx = this.state.unspool.slotBallIds.indexOf(p.ball.id);
if (sIdx >= 0) {
restoredBalls.push({ slotIndex: sIdx, ball: p.ball });
this.state.unspool.slotBallIds[sIdx] = null;
}
}
this.unspoolHistory.push({ kind: 'stitch', restoredBalls });
this.state.unspool.deadlocked = false;
}
this.setStatus(
dispatchWarning(this.level, this.state.lines) ||
(this.unspoolMode
? '蚂蚁出发啦!线碗已腾空,可以继续抽旧线~'
: route.picks.length > 1
? '两颗球一起出发。'
: '蚂蚁出发了,也可继续画下一笔。'),
);
this.updateHud();
return true;
}
@@ -1154,6 +1467,7 @@ export class PlayView extends Component {
const elapsed = now - route.startedAt;
let pause = 0;
let delivered = false;
let unlockedAnyClip = false;
for (let i = 0; i < route.events.length; i++) {
const ev = route.events[i];
const ms = ev.ms ?? 0;
@@ -1170,7 +1484,17 @@ export class PlayView extends Component {
route.carry.shift();
ev.arrivedAt = now;
delivered = true;
this.sound.deliver();
const openedClip = this.level.unspool?.clips?.find(c => c.unlockSectionId === ev.target.id);
if (openedClip) {
unlockedAnyClip = true;
this.sound.bonus();
if (this.state.unspool?.pulseTargetId === ev.target.id) {
this.state.unspool.pulseTargetId = null;
}
if (!this.state.drawing) this.setStatus('咔哒!旧布木夹松开了,右侧旧料已解锁可抽!');
} else {
this.sound.deliver();
}
} else if (isSpoolEvent(ev)) {
ev.collectedAt = now;
this.sound.bonus();
@@ -1205,7 +1529,9 @@ export class PlayView extends Component {
route.ant.walk = walking;
if (delivered) {
if (!this.state.drawing) this.setStatus(dispatchWarning(this.level, this.state.lines) || '送达落针!');
if (!this.state.drawing && !unlockedAnyClip) {
this.setStatus(dispatchWarning(this.level, this.state.lines) || '送达落针!');
}
this.updateHud();
}
if (elapsed >= route.duration) {
@@ -1378,9 +1704,10 @@ export class PlayView extends Component {
}
}
this.undoBtn.setEnabled(!this.state.demo && !this.state.complete && this.state.lines.length > 0);
this.demoBtn.setEnabled(!this.state.demo);
this.hintBtn.setEnabled(!this.state.demo && !this.state.complete);
const canUndo = this.unspoolMode ? this.unspoolHistory.length > 0 : this.state.lines.length > 0;
this.undoBtn.setEnabled(!this.state.demo && !this.state.complete && canUndo);
this.demoBtn.setEnabled(!this.state.demo && !this.unspoolMode);
this.hintBtn.setEnabled(!this.state.demo && !this.state.complete && !this.unspoolMode);
this.hintHalo.active = Boolean(this.state.hint);
if (this.hintBtn.label) {
this.hintBtn.label.string = this.state.hint ? `提示 ${this.state.hint.tier}/3` : '提示';
@@ -1391,6 +1718,7 @@ export class PlayView extends Component {
this.syncLoupeButton();
this.dockTrayNode.active = !this.state.complete;
this.unspoolPanelNode.active = this.unspoolMode && !this.state.complete;
this.resultOverlay.active = this.state.complete;
if (this.state.complete) {
const rawStars = scoreForLength(this.level, totalLength(this.state.lines));
@@ -1411,7 +1739,7 @@ export class PlayView extends Component {
this.resultLengthLabel.string = '用线 ' + formatLength(totalLength(this.state.lines)) + suffix;
if (this.nextBtn.label) {
const gate = this.getNextChapterGate();
if (this.currentIndex + 1 >= LEVELS.length) {
if (this.customMode || this.currentIndex + 1 >= LEVELS.length) {
this.nextBtn.label.string = en ? 'Lobby' : '返回大厅';
} else if (gate.locked) {
this.nextBtn.label.string = en ? `Need ${gate.req}★` : `集满${gate.req}★解锁下章`;
@@ -1442,6 +1770,16 @@ export class PlayView extends Component {
const clampedMs = Math.min(50, Math.max(0, dt * 1000));
this.state.time += clampedMs;
if (this.unspoolMode && this.level.unspool && this.state.unspool) {
if (this.state.unspool.animating) {
this.state.unspool.animating.progress += clampedMs / 340;
if (this.state.unspool.animating.progress >= 1) {
this.finishUnspoolAnimation();
}
}
this.renderer.renderUnspoolClothFrame(this.level.unspool, this.state.unspool, this.state.time, this.state.lines);
}
if (this.state.demo) this.runDemo(this.state.time);
for (const line of this.state.lines) {
if (!line.finished) this.animateRoute(line, this.state.time);
@@ -1472,7 +1810,7 @@ export class PlayView extends Component {
this.state.complete = true;
this.state.demo = false;
this.setStatus(this.state.assisted ? '演示完成,点「重绣本关」自己试一试。' : '这一幅绣好啦,可以保存绣画留念!');
if (!this.state.assisted) {
if (!this.state.assisted && !this.customMode) {
const len = totalLength(this.state.lines);
const rawStars = scoreForLength(this.level, len);
const earnedStars = this.state.hintCapped ? Math.min(2, rawStars) : rawStars;