Files
mayi_coco/assets/scripts/core/ReleaseLevels.ts
T

124 lines
12 KiB
TypeScript

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]));
}