Skip to content

Commit dcbc798

Browse files
committed
feat: rollback to start, rolldown to latest
1 parent 42684a0 commit dcbc798

File tree

6 files changed

+288
-162
lines changed

6 files changed

+288
-162
lines changed

src/ability.ts

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,7 @@ export function init(cx: Context, options?: AbilityInit) {
3737
e.preventDefault();
3838
if (get(cx.state).usage.paste > 0 && onGround) paste(cx);
3939
});
40-
41-
// there is no such thing as undo / redo event
42-
document.addEventListener("keydown", (e) => {
43-
if (!e.ctrlKey && !e.metaKey) return;
44-
switch (e.key) {
45-
case "z":
46-
e.preventDefault();
47-
History.undo(cx);
48-
break;
49-
case "y":
50-
e.preventDefault();
51-
History.redo(cx);
52-
break;
53-
}
54-
});
55-
History.record(cx);
40+
History.init(cx);
5641
}
5742

5843
export function focusCoord(playerAt: Coords, facing: Facing) {
@@ -79,9 +64,9 @@ export function copy(cx: Context) {
7964
if (!focus) return;
8065
const x = focus.x;
8166
const y = focus.y;
82-
const target = cx.grid.getBlock(x, y);
67+
const target = cx.grid.getBlock(cx, x, y);
8368
if (!target || target !== Block.movable) return;
84-
const movableObject = cx.grid.getMovableObject(x, y);
69+
const movableObject = cx.grid.getMovableObject(cx, x, y);
8570
if (!movableObject) return;
8671

8772
History.record(cx);
@@ -114,7 +99,7 @@ export function paste(cx: Context) {
11499
for (const i of inventory.relativePositions) {
115100
const positionX = x + i.x;
116101
const positionY = y + i.y;
117-
const target = cx.grid.getBlock(positionX, positionY);
102+
const target = cx.grid.getBlock(cx, positionX, positionY);
118103
if (target !== Block.air) {
119104
// すでに何かある場合は、ペーストできない
120105
return;
@@ -139,10 +124,10 @@ export function cut(cx: Context) {
139124

140125
const x = focus.x;
141126
const y = focus.y;
142-
const target = cx.grid.getBlock(x, y);
127+
const target = cx.grid.getBlock(cx, x, y);
143128
// removable 以外はカットできない
144129
if (!target || target !== Block.movable) return;
145-
const movableObject = cx.grid.getMovableObject(x, y);
130+
const movableObject = cx.grid.getMovableObject(cx, x, y);
146131
if (!movableObject) return;
147132

148133
History.record(cx);
@@ -170,7 +155,7 @@ export function placeMovableObject(
170155
for (const i of object.relativePositions) {
171156
const positionX = x + i.x;
172157
const positionY = y + i.y;
173-
const target = grid.getBlock(positionX, positionY);
158+
const target = grid.getBlock(cx, positionX, positionY);
174159
if (target !== Block.air) {
175160
// すでに何かある場合は、ペーストできない
176161
return;
@@ -192,7 +177,7 @@ export function removeMovableObject(
192177
y: number,
193178
): MovableObject | undefined {
194179
const grid = cx.grid;
195-
const obj = grid.getMovableObject(x, y);
180+
const obj = grid.getMovableObject(cx, x, y);
196181
if (!obj) return undefined;
197182

198183
for (const i of obj.relativePositions) {

0 commit comments

Comments
 (0)