From df3856336b423c042872e3697b6846572a13074e Mon Sep 17 00:00:00 2001 From: uphy Date: Sun, 27 Sep 2026 14:54:37 +0900 Subject: [PATCH] =?UTF-8?q?=E7=A9=BA=E4=B8=AD=E3=81=AE=E3=82=AB=E3=82=BF?= =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=92=E9=81=8B=E3=82=93=E3=81=A7=E3=81=84?= =?UTF-8?q?=E3=82=8B=E9=80=94=E4=B8=AD=E3=81=A7=E6=8C=87=E3=81=8B=E3=82=89?= =?UTF-8?q?=E5=A4=96=E3=82=8C=E3=81=AA=E3=81=84=E3=82=88=E3=81=86=E3=80=81?= =?UTF-8?q?=E7=9D=80=E5=9C=B0=E3=83=BB=E3=83=89=E3=83=83=E3=82=AD=E3=83=B3?= =?UTF-8?q?=E3=82=B0=E3=83=BB=E5=90=8C=E3=81=98=E3=82=AB=E3=82=BF=E3=83=9E?= =?UTF-8?q?=E3=83=AA=E3=81=AE=E5=88=A5=E3=81=AE=E5=88=97=E3=81=AE=E7=82=B9?= =?UTF-8?q?=E7=81=AB=E3=81=A7=E5=BD=A2=E3=81=8C=E5=A4=89=E3=82=8F=E3=81=A3?= =?UTF-8?q?=E3=81=9F=E3=81=82=E3=81=A8=E3=81=AF=E3=80=81=E6=8E=B4=E3=81=BF?= =?UTF-8?q?=E3=82=92=E6=8D=A8=E3=81=A6=E3=81=9A=E3=81=AB=E9=9A=95=E7=9F=B3?= =?UTF-8?q?=E3=81=AE=E4=BB=8A=E3=81=84=E3=82=8B=E5=A0=B4=E6=89=80=EF=BC=88?= =?UTF-8?q?=E5=9C=B0=E9=9D=A2=E3=81=AE=E5=B1=B1=E3=81=8B=E3=80=81=E5=90=88?= =?UTF-8?q?=E3=82=8F=E3=81=95=E3=81=A3=E3=81=9F=E3=82=AB=E3=82=BF=E3=83=9E?= =?UTF-8?q?=E3=83=AA=EF=BC=89=E3=81=B8=E4=BB=98=E3=81=91=E7=9B=B4=E3=81=99?= =?UTF-8?q?=E3=80=82=E3=81=93=E3=82=8C=E3=81=BE=E3=81=A7=E3=81=AF=E6=8C=87?= =?UTF-8?q?=E3=82=92=E9=9B=A2=E3=81=97=E3=81=A6=E3=81=84=E3=81=AA=E3=81=84?= =?UTF-8?q?=E3=81=AE=E3=81=AB=E3=80=81=E3=81=9D=E3=81=AE=E7=9E=AC=E9=96=93?= =?UTF-8?q?=E3=81=AB=E9=9A=95=E7=9F=B3=E3=81=8C=E5=A4=96=E3=82=8C=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/game.ts | 39 +++++++++++++--- src/render/news.ts | 9 ++++ tests/core/drag.test.ts | 101 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+), 7 deletions(-) diff --git a/src/core/game.ts b/src/core/game.ts index fd24493..af07d1d 100644 --- a/src/core/game.ts +++ b/src/core/game.ts @@ -485,6 +485,32 @@ export class Game { for (const [finger, d] of [...this.drags]) if (hit(d, finger)) this.drags.delete(finger); } + /** + * カタマリの着地・合体・点火で盤面の形が変わったあと、掴みを隕石の今いる場所へ付け直す。 + * 掴みは添字で覚えているので、形が変わると別の隕石を指すか、列ごと無くなる。 + * `held` は形が変わる前の `heldMeteors()`。隕石が盤面から消えていたら離す。 + * 付け直さずに外していたころは、運んでいるカタマリが着地した瞬間に指から離れていた + */ + private rebindDrags(held: Map): void { + for (const [meteor, finger] of held) { + const d = this.drags.get(finger); + if (!d) continue; + const index = this.ground[d.col].indexOf(meteor); + if (index >= 0) { + if (d.kind !== 'ground') d.charge = 0; + Object.assign(d, { kind: 'ground', lumpId: 0, index }); + continue; + } + const lump = this.lumps.find((l) => l.cells.some((c) => c.meteor === meteor)); + if (lump) { + const i = this.columnOfLump(lump, d.col).findIndex((c) => c.meteor === meteor); + Object.assign(d, { kind: 'lump', lumpId: lump.id, index: i }); + continue; + } + this.drags.delete(finger); + } + } + /** 掴んでいる列の index 番の隕石 */ private meteorAt(d: Drag, index: number): Meteor | null { if (d.kind === 'ground') return this.ground[d.col][index] ?? null; @@ -771,8 +797,10 @@ export class Game { this.screenOut(lump); } this.lumps = this.lumps.filter((l) => l.cells.length > 0); + const held = this.heldMeteors(); this.dock(); this.landLumps(); + this.rebindDrags(held); } /** 画面上端(大気圏)を越えた隕石から順に消える */ @@ -907,7 +935,6 @@ export class Game { a.thrustAccel = Math.max(a.thrustAccel, b.thrustAccel); } this.normalize(a); - this.dropDrags((d) => d.kind === 'lump' && d.lumpId === b.id); } /** 列ごとに rel を詰め直し、最下段を 0 に揃える */ @@ -947,8 +974,6 @@ export class Game { if (lump.cells.length > 0) { this.normalize(lump); remain.push(lump); - } else { - this.dropDrags((d) => d.kind === 'lump' && d.lumpId === lump.id); } } this.lumps = remain; @@ -1056,8 +1081,8 @@ export class Game { rest.delete(cell.lump!); } - // 持ち上げる隕石を掴んでいた指と、巻き込むカタマリを掴んでいた指を離す。 - // 地面の列は点火位置から上をまとめて取るので、持ち上げない隕石の添字は変わらない。 + // 持ち上げる隕石を掴んでいた指は離す。 + // 巻き込んだカタマリの残りを掴んでいた指は、最後に今いる場所へ付け直す。 // 片方の手で点火しても、関係のない列を運んでいるもう片方の手は離さない const held = this.heldMeteors(); const dropped = new Set(); @@ -1108,8 +1133,8 @@ export class Game { this.applyThrust(lump, ignited.length, runs.vertical, bottom); this.lumps.push(lump); this.scoreIgnition(ignited, lump.combo, runs.vertical); - const involvedIds = new Set([...involved].map((l) => l.id)); - this.dropDrags((d, finger) => dropped.has(finger) || (d.kind === 'lump' && involvedIds.has(d.lumpId))); + this.dropDrags((_, finger) => dropped.has(finger)); + this.rebindDrags(held); } /** diff --git a/src/render/news.ts b/src/render/news.ts index 03d8e23..f38c81c 100644 --- a/src/render/news.ts +++ b/src/render/news.ts @@ -19,6 +19,15 @@ export interface NewsItem { } export const NEWS: readonly NewsItem[] = [ + { + id: '2026-09-27-4', + date: '2026.09.27', + title: '空中のカタマリを運んでいる途中で外れないようにした', + lines: [ + '掴んでいるカタマリが着地したとき、別のカタマリとドッキングしたとき、同じカタマリの別の列で点火したときに、指を離していないのに隕石が外れていた。', + 'いまは掴んだまま運び続けられる。', + ], + }, { id: '2026-09-27-3', date: '2026.09.27', diff --git a/tests/core/drag.test.ts b/tests/core/drag.test.ts index d58b47f..13ad2f3 100644 --- a/tests/core/drag.test.ts +++ b/tests/core/drag.test.ts @@ -221,3 +221,104 @@ describe('両手で運ぶ', () => { expect(g.ground[4][2]).toBe(held); }); }); + +describe('掴んでいるカタマリの形が変わっても指から離れない', () => { + let nextId = 7000; + const m = (kind: Kind) => meteor(kind, nextId++); + /** 空の盤面 */ + function empty(): Game { + const g = new Game({ seed: 4, rareMetal: false }); + g.ground = g.ground.map(() => []); + g.fallings = []; + return g; + } + /** 1 フレーム進める。降り始めた隕石は消して、組んだ盤面だけを動かす */ + function step(g: Game) { + const ev = g.tick(); + g.fallings = []; + return ev; + } + function lump(id: number, cells: [number, number, Kind][], y: number, vy: number) { + return { + id, + cells: cells.map(([col, rel, kind]) => ({ col, rel, meteor: m(kind) })), + y, + vy, + thrustFrames: 0, + thrustAccel: 0, + combo: 1, + }; + } + + it('運んでいるカタマリが着地したら、地面の山で掴んだまま', () => { + const g = empty(); + g.ground[0] = [m(Kind.Circle)]; + g.lumps = [lump(900, [[0, 0, Kind.Square], [0, 1, Kind.Drop], [1, 0, Kind.Hexagon]], 3, -0.05)]; + expect(g.grab(0, 4.5, 1)).toBe(true); + const held = g.dragPosition(1)!.meteor; + for (let i = 0; i < 200 && g.lumps.length > 0; i++) step(g); + expect(g.lumps.length).toBe(0); + + expect(g.dragPosition(1)?.meteor).toBe(held); + g.dragBy(-1, 1); + expect(g.ground[0][1]).toBe(held); + }); + + it('一部の列だけが着地しても、着地した列の隕石を掴んだまま', () => { + const g = empty(); + g.ground[0] = [m(Kind.Circle), m(Kind.Square)]; + g.lumps = [lump(900, [[0, 0, Kind.Drop], [0, 1, Kind.Hexagon], [1, 0, Kind.Pentagon]], 3, -0.05)]; + expect(g.grab(0, 4.5, 1)).toBe(true); + const held = g.dragPosition(1)!.meteor; + for (let i = 0; i < 200 && g.ground[0].length < 4; i++) step(g); + expect(g.lumps.length).toBe(1); + + expect(g.dragPosition(1)?.meteor).toBe(held); + g.dragBy(-1, 1); + expect(g.ground[0][2]).toBe(held); + }); + + it('掴んでいるカタマリがドッキングしても掴んだまま', () => { + const g = empty(); + g.lumps = [ + lump(900, [[0, 0, Kind.Square], [0, 1, Kind.Drop]], 5, 0), + lump(901, [[0, 0, Kind.Hexagon], [0, 1, Kind.Circle], [1, 0, Kind.Pentagon]], 3, 0.3), + ]; + expect(g.grab(0, 3.5, 1)).toBe(true); + const held = g.dragPosition(1)!.meteor; + let docked = 0; + for (let i = 0; i < 30; i++) docked += step(g).airDock; + expect(docked).toBe(1); + + expect(g.dragPosition(1)?.meteor).toBe(held); + }); + + it('掴んでいるカタマリの別の列で点火しても、掴んだまま', () => { + const g = empty(); + g.lumps = [ + lump( + 900, + [ + [0, 0, Kind.Square], + [0, 1, Kind.Drop], + [0, 2, Kind.Hexagon], + [2, 0, Kind.Triangle], + [2, 1, Kind.Triangle], + [2, 2, Kind.Circle], + [2, 3, Kind.Triangle], + ], + 6, + 0, + ), + ]; + expect(g.grab(0, 6.5, 1)).toBe(true); + const held = g.dragPosition(1)!.meteor; + // もう片方の手で列 2 の Circle と Triangle を入れ替えて、縦に 3 つ揃える + expect(g.grab(2, 8.5, 2)).toBe(true); + g.dragBy(1, 2); + for (let i = 0; i < IGNITION_GRACE_FRAMES + 1; i++) step(g); + expect(g.score).toBeGreaterThan(0); + + expect(g.dragPosition(1)?.meteor).toBe(held); + }); +});