Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions src/core/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Meteor, number>): 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;
Expand Down Expand Up @@ -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);
}

/** 画面上端(大気圏)を越えた隕石から順に消える */
Expand Down Expand Up @@ -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 に揃える */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1056,8 +1081,8 @@ export class Game {
rest.delete(cell.lump!);
}

// 持ち上げる隕石を掴んでいた指と、巻き込むカタマリを掴んでいた指を離す。
// 地面の列は点火位置から上をまとめて取るので、持ち上げない隕石の添字は変わらない。
// 持ち上げる隕石を掴んでいた指は離す。
// 巻き込んだカタマリの残りを掴んでいた指は、最後に今いる場所へ付け直す。
// 片方の手で点火しても、関係のない列を運んでいるもう片方の手は離さない
const held = this.heldMeteors();
const dropped = new Set<number>();
Expand Down Expand Up @@ -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);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/render/news.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
101 changes: 101 additions & 0 deletions tests/core/drag.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Loading