Skip to content

Commit a55eb0d

Browse files
committed
make it work
1 parent 9106156 commit a55eb0d

25 files changed

+154
-111
lines changed

.vscode/launch.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Launch Program",
11+
"skipFiles": [
12+
"<node_internals>/**"
13+
],
14+
"program": "${workspaceFolder}/build/index.js",
15+
"outFiles": [
16+
"${workspaceFolder}/**/*.js"
17+
]
18+
}
19+
]
20+
}

package-lock.json

+40-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
"version": "1.0.0",
44
"description": "",
55
"main": "index.js",
6+
"type": "module",
67
"scripts": {
78
"compile": "npx tsc",
8-
"start": "npm run compile && node -r esm build/index.js "
9+
"start": "npm run compile && node build/index.js "
910
},
1011
"author": "[email protected]",
1112
"license": "ISC",
12-
"dependencies": {
13-
"esm": "^3.2.25"
14-
},
1513
"devDependencies": {
16-
"typescript": "^4.0.2",
17-
"@types/node": "^14.0.13"
14+
"@types/node": "^22.9.1",
15+
"typescript": "^5.0.0"
1816
}
1917
}

src/main/app.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {clearScreen, hideCursor, showCursor} from "./util/ansi";
2-
import {draw, Drawable} from "./draw";
1+
import {clearScreen, hideCursor, showCursor} from "./util/ansi.js";
2+
import {draw, Drawable} from "./draw.js";
33

44
export enum KeyCode {
55
Backspace = 127,
@@ -63,7 +63,7 @@ export abstract class Screen<State, TApp extends App>{
6363
private dirty = false;
6464

6565
setState(newState: Partial<State>) {
66-
this.state = Object.assign(this.state, newState);
66+
this.state = Object.assign(this.state as any, newState);
6767
if (!this.dirty) {
6868
Promise.resolve().then(() => {
6969
this.dirty = false;
@@ -73,7 +73,6 @@ export abstract class Screen<State, TApp extends App>{
7373
}
7474

7575
onKeyPress(_key: KeyCode): void {
76-
7776
}
7877

7978
abstract render(): Drawable[];

src/main/draw.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {background, clearScreen, goHome} from "./util/ansi";
2-
import {Tile} from "./tile";
3-
import {Rectangle} from "./util/position";
1+
import {background, clearScreen, goHome} from "./util/ansi.js";
2+
import {Tile} from "./tile.js";
3+
import {Rectangle} from "./util/position.js";
44

55
let prevTerminalTile: Tile | null = null;
66
let prevTerminalHeight: number | null = null;

src/main/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {loadPuzzleCollection} from "./puzzle";
2-
import {SokobanApp} from "./sokobanApp";
1+
import {loadPuzzleCollection} from "./puzzle.js";
2+
import {SokobanApp} from "./sokobanApp.js";
33

44
new SokobanApp(loadPuzzleCollection("resources/original_and_extra.sok"));

src/main/level.ts

+25-24
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import {Position, Rectangle} from "./util/position";
2-
import {Puzzle} from "./puzzle";
3-
import {fail} from "./util/fail";
4-
import {hexToRgb} from "./util/color";
5-
import {Crate} from "./objects/crate";
6-
import {Player} from "./objects/player";
7-
import {Goal} from "./objects/goal";
8-
import {Wall} from "./objects/wall";
9-
import {Floor} from "./objects/floor";
10-
import {addLights, Light} from "./objects/lights";
11-
import {Tile} from "./tile";
12-
import {Track} from "./objects/track";
1+
import {Position, Rectangle} from "./util/position.js";
2+
import {fail} from "./util/fail.js";
3+
import {Puzzle} from "./puzzle.js";
4+
import {hexToRgb} from "./util/color.js";
5+
import {Crate} from "./objects/crate.js";
6+
import {Player} from "./objects/player.js";
7+
import {Goal} from "./objects/goal.js";
8+
import {Wall} from "./objects/wall.js";
9+
import {Floor} from "./objects/floor.js";
10+
import {addLights, Light} from "./objects/lights.js";
11+
import {Tile} from "./tile.js";
12+
import {Track} from "./objects/track.js";
1313

1414
const tileWidth = 7;
1515
const tileHeight = 3;
@@ -114,8 +114,8 @@ const visibilityCache = new Map<string, boolean>();
114114

115115
function createStaticLights(level: Level, crow: number, ccol: number): Light[] {
116116
const lights: Light[] = [];
117-
for (let row = 0; row < crow; row++) {
118-
for (let column = 0; column < ccol; column++) {
117+
for (let row = 0; row < crow; row+=3) {
118+
for (let column = 0; column < ccol; column+=3) {
119119
const p = new Position(column * tileWidth + tileWidth / 2, row * tileHeight + tileHeight / 2);
120120
const n = [
121121
level.getCell(p.move(-tileWidth, -tileHeight)),
@@ -129,15 +129,15 @@ function createStaticLights(level: Level, crow: number, ccol: number): Light[] {
129129
level.getCell(p.move(tileWidth, tileHeight)),
130130
];
131131

132-
if (Math.random() < 0.05 && n.filter(x => x !== Cell.Wall && x !== Cell.Void).length > 5) {
132+
// if (n.filter(x => x !== Cell.Wall && x !== Cell.Void).length > 5) {
133133
lights.push({
134-
color: hexToRgb(0x555555),
134+
color: hexToRgb(0x222222),
135135
x: p.x,
136136
y: p.y,
137-
z: 3 * tileWidth,
137+
z: 4 * tileWidth,
138138
direction: null,
139139
});
140-
}
140+
// }
141141
}
142142
}
143143
return lights;
@@ -146,16 +146,16 @@ function createStaticLights(level: Level, crow: number, ccol: number): Light[] {
146146
function createPlayerLight(level: Level): Light {
147147
return {
148148
x: level.player.rectangle.x + 4 +
149-
(level.player.dir === Dir.Right ? -3 : level.player.dir === Dir.Left ? 3 : 0),
149+
(level.player.dir === Dir.Right ? -2 : level.player.dir === Dir.Left ? 2 : 0),
150150
y: level.player.rectangle.y + 1.5 +
151-
(level.player.dir === Dir.Down ? -1 : level.player.dir === Dir.Up ? 1 : 0),
151+
(level.player.dir === Dir.Down ? -0 : level.player.dir === Dir.Up ? 0 : 0),
152152
z: 1,
153-
color: hexToRgb(0x440000),
153+
color: hexToRgb(0x888800),
154154
direction: {
155155
x: level.player.dir === Dir.Right ? -1 : level.player.dir === Dir.Left ? 1 : 0,
156156
y: level.player.dir === Dir.Down ? -1 : level.player.dir === Dir.Up ? 1 : 0,
157-
z: -0.2,
158-
cosTheta: Math.cos(Math.PI / 3)
157+
z: 1,
158+
cosTheta: Math.cos(Math.PI / 3),
159159
},
160160
};
161161
}
@@ -311,7 +311,6 @@ export class Level {
311311
let oldState = this.state;
312312
let newState: State = oldState;
313313
const newPlayerRect = this.player.rectangle.move(dx * tileWidth, dy * tileHeight)
314-
315314
newState = {
316315
...newState,
317316
player: newState.player.withDir(
@@ -356,11 +355,13 @@ export class Level {
356355
case Cell.Goal:
357356
case Cell.Empty:
358357
case Cell.Void:
358+
359359
newState = {
360360
...newState,
361361
player: newState.player.withCenter(newPlayerRect.center),
362362
steps: this.steps + 1,
363363
};
364+
364365
break;
365366
}
366367

src/main/objects/crate.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {Position, Rectangle} from "../util/position";
2-
import {darkenColor} from "../util/color";
3-
import {tile, Tile} from "../tile";
1+
import {Position, Rectangle} from "../util/position.js";
2+
import {darkenColor} from "../util/color.js";
3+
import {tile, Tile} from "../tile.js";
44

55
const colors = [
66
0x000000, // black

src/main/objects/floor.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {Position} from "../util/position";
2-
import {Random} from "../util/random";
3-
import {Tile} from "../tile";
4-
import {perturbedColor} from "../util/color";
1+
import {Position} from "../util/position.js";
2+
import {Random} from "../util/random.js";
3+
import {Tile} from "../tile.js";
4+
import {perturbedColor} from "../util/color.js";
55

66
export const baseFg = 0x424242;
77
export const baseBg = 0x505050;

src/main/objects/goal.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {Position, Rectangle} from "../util/position";
2-
import {Tile, tile} from "../tile";
1+
import {Position, Rectangle} from "../util/position.js";
2+
import {Tile, tile} from "../tile.js";
33

44
const colors = [
55
0x0000ff

src/main/objects/input.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {Position, Rectangle} from "../util/position";
2-
import {Random} from "../util/random";
3-
import {tile, Tile} from "../tile";
4-
import {darkenColor, perturbedColor} from "../util/color";
5-
import {Crate} from "./crate";
6-
import {Floor} from "./floor";
1+
import {Position, Rectangle} from "../util/position.js";
2+
import {Random} from "../util/random.js";
3+
import {tile, Tile} from "../tile.js";
4+
import {darkenColor, perturbedColor} from "../util/color.js";
5+
import {Crate} from "./crate.js";
6+
import {Floor} from "./floor.js";
77

88
export type InputProps = {
99
readonly question: string;

src/main/objects/lights.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {hexToRgb, Rgb, rgbToHex} from "../util/color";
2-
import {Cell, Level} from "../level";
3-
import {Position} from "../util/position";
4-
import {Tile} from "../tile";
1+
import {hexToRgb, Rgb, rgbToHex} from "../util/color.js";
2+
import {Cell, Level} from "../level.js";
3+
import {Position} from "../util/position.js";
4+
import {Tile} from "../tile.js";
55

66
type Cone = {
77
readonly x: number;

src/main/objects/logo.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {solidTile, Tile} from "../tile";
2-
import {Drawable} from "../draw";
1+
import {solidTile, Tile} from "../tile.js";
2+
import {Drawable} from "../draw.js";
33

44
export const logo = solidTile(0xffffff)`
55
| ▄████████ ▄██████▄ ▄█ ▄█▄ ▄██████▄ ▀█████████▄ ▄████████ ███▄▄▄▄

src/main/objects/player.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {Position, Rectangle} from "../util/position";
2-
import {Dir} from "../level";
3-
import {tile, Tile} from "../tile";
1+
import {Position, Rectangle} from "../util/position.js";
2+
import {Dir} from "../level.js";
3+
import {tile, Tile} from "../tile.js";
44

55
const colors = [
66
0x000000, // black

src/main/objects/track.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {Tile} from "../tile";
2-
import {Player} from "./player";
3-
import {darkenColor} from "../util/color";
1+
import {Tile} from "../tile.js";
2+
import {Player} from "./player.js";
3+
import {darkenColor} from "../util/color.js";
44

55
export class Track {
66
private prev: Track | null = null;

src/main/objects/wall.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {stripMargin} from "../util/stripMargin";
2-
import {Position, Rectangle} from "../util/position";
3-
import {Random} from "../util/random";
4-
import {darkenColor, perturbedColor} from "../util/color";
5-
import {Tile} from "../tile";
1+
import {stripMargin} from "../util/stripMargin.js";
2+
import {Position, Rectangle} from "../util/position.js";
3+
import {Random} from "../util/random.js";
4+
import {darkenColor, perturbedColor} from "../util/color.js";
5+
import {Tile} from "../tile.js";
66

77
const random = new Random(0);
88

src/main/puzzle.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as fs from "fs";
2-
import {SOKReader} from "./sokparser";
2+
import {SOKReader} from "./sokparser.js";
33

44
export class PuzzleCollection {
55
title: string | null = null;

src/main/screens/confirmExitScreen.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {Screen, KeyCode} from "../app";
2-
import {Drawable} from "../draw";
3-
import {SokobanApp} from "../sokobanApp";
4-
import {Level} from "../level";
1+
import {Screen, KeyCode} from "../app.js";
2+
import {Drawable} from "../draw.js";
3+
import {SokobanApp} from "../sokobanApp.js";
4+
import {Level} from "../level.js";
55

66
type State = {
77
level: Level

src/main/screens/levelScreen.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {Screen, KeyCode} from "../app";
2-
import {Drawable} from "../draw";
3-
import {SokobanApp} from "../sokobanApp";
4-
import {Level} from "../level";
1+
import {Screen, KeyCode} from "../app.js";
2+
import {Drawable} from "../draw.js";
3+
import {SokobanApp} from "../sokobanApp.js";
4+
import {Level} from "../level.js";
55

66
type State = {
77
previousLevel: Level | null,
@@ -39,6 +39,7 @@ export class LevelScreen extends Screen<State, SokobanApp> {
3939
}
4040

4141
onKeyPress(key: KeyCode) {
42+
4243
switch (key) {
4344
case KeyCode.Backspace:
4445
const previousLevel = this.state.previousLevel;

0 commit comments

Comments
 (0)