Skip to content

Commit 13bc0d9

Browse files
committed
feat: add roads, improve editor
1 parent b87ea8e commit 13bc0d9

16 files changed

Lines changed: 17516 additions & 16882 deletions

editor/deno.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"extension": "deno -A jsr:@kt3k/pack@0.1.14 extension.tsx -o out/extension.js --external vscode --format cjs",
1414
"webview": "deno -A jsr:@kt3k/pack@0.1.14 webview.ts -o out/webview.js",
1515
"webview-style": "deno -A npm:tailwindcss@3 -o out/style.css",
16-
"package": "deno -A --unstable-unsafe-proto npm:@vscode/vsce package"
16+
"package": "deno task compile && deno -A --unstable-unsafe-proto npm:@vscode/vsce package",
17+
"update-package": "deno task package && code --install-extension vscode-bw-block-editor-0.4.0.vsix",
1718
},
1819
"lint": {
1920
"rules": {

editor/extension.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,17 @@ function resolveCustomTextEditor(
3939
<div class="toolbox fixed left-0 top-0 flex items-center gap-2 bg-neutral-900/50 w-full">
4040
<div class="cell-switch flex items-center relative">
4141
</div>
42-
<div class="mode-switch" title="Press 's' to toggle">
43-
dot
42+
<div class="group relative">
43+
<span class="mode-switch">dot</span>
44+
<span class="
45+
absolute top-full left-1/2 -translate-x-1/2 mt-2
46+
hidden group-hover:block
47+
bg-neutral-800 text-white text-sm px-2 py-1 rounded-lg
48+
border border-neutral-600
49+
whitespace-nowrap pointer-events-none
50+
">
51+
Press "s" to toggle
52+
</span>
4453
</div>
4554
</div>
4655
<script src={u("out/webview.js")} type="module"></script>
402 Bytes
Binary file not shown.

editor/webview.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,8 @@ function CellSwitch({ on, el, subscribe }: Context) {
167167
})
168168
}
169169

170-
function ModeSwitch({ on, subscribe, el }: Context<HTMLElement>) {
170+
function ModeSwitch({ subscribe, el }: Context<HTMLElement>) {
171171
subscribe(mode, (mode) => el.textContent = mode)
172-
173-
on("click", () => {
174-
if (mode.get() === "dot") {
175-
mode.update("stroke")
176-
} else {
177-
mode.update("dot")
178-
}
179-
})
180172
}
181173

182174
function FieldBlockCanvas({ on, el }: Context<HTMLCanvasElement>) {
@@ -206,7 +198,7 @@ function FieldBlockCanvas({ on, el }: Context<HTMLCanvasElement>) {
206198
}
207199

208200
on("click", (e) => {
209-
if (mode.get() === "dot") paint(e)
201+
paint(e)
210202
})
211203

212204
on("mousemove", (e) => {
@@ -247,6 +239,8 @@ function KeyHandler({ on }: Context) {
247239
} else {
248240
mode.update("dot")
249241
}
242+
} else if (e.key === "Escape") {
243+
mode.update("dot")
250244
}
251245
})
252246
}

model/field-block.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,24 @@ export class ItemSpawnInfo implements IBox {
3333
readonly j: number
3434
readonly type: ItemType
3535
readonly src: string
36+
readonly srcBase: string
3637
readonly x: number
3738
readonly y: number
3839
readonly w = CELL_SIZE
3940
readonly h = CELL_SIZE
40-
constructor(i: number, j: number, type: ItemType, src: string) {
41+
constructor(
42+
i: number,
43+
j: number,
44+
type: ItemType,
45+
src: string,
46+
srcBase: string,
47+
) {
4148
this.id = `${i}.${j}.${type}` // Unique ID for the spawn
4249
this.i = i
4350
this.j = j
4451
this.type = type
4552
this.src = src
53+
this.srcBase = srcBase
4654
this.x = i * CELL_SIZE
4755
this.y = j * CELL_SIZE
4856
}
@@ -65,6 +73,7 @@ export class CharacterSpawnInfo implements IBox {
6573
readonly j: number
6674
readonly type: NPCType
6775
readonly src: string
76+
readonly srcBase: string
6877
readonly dir?: Dir
6978
readonly speed?: CharacterSpeed
7079
readonly x: number
@@ -76,6 +85,7 @@ export class CharacterSpawnInfo implements IBox {
7685
j: number,
7786
type: NPCType,
7887
src: string,
88+
srcBase: string,
7989
{ dir, speed }: {
8090
dir?: Dir
8191
speed?: CharacterSpeed
@@ -88,6 +98,7 @@ export class CharacterSpawnInfo implements IBox {
8898
this.speed = speed
8999
this.type = type
90100
this.src = src
101+
this.srcBase = srcBase
91102
this.x = i * CELL_SIZE
92103
this.y = j * CELL_SIZE
93104
}
@@ -185,7 +196,8 @@ export class BlockMap {
185196
spawn.i,
186197
spawn.j,
187198
spawn.type,
188-
new URL(spawn.src, this.url).href,
199+
spawn.src,
200+
this.url,
189201
{
190202
dir: spawn.dir,
191203
speed: spawn.speed,
@@ -199,7 +211,8 @@ export class BlockMap {
199211
item.i,
200212
item.j,
201213
item.type,
202-
new URL(item.src, this.url).href,
214+
item.src,
215+
this.url,
203216
)
204217
)
205218
this.field = obj.field

player/game-screen.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ class Field implements IFieldTester {
449449
spawn.type,
450450
spawn.i,
451451
spawn.j,
452-
spawn.src,
452+
new URL(spawn.src, spawn.srcBase).href,
453453
{
454454
dir: spawn.dir,
455455
speed: spawn.speed,
@@ -470,7 +470,7 @@ class Field implements IFieldTester {
470470
spawn.i,
471471
spawn.j,
472472
spawn.type,
473-
spawn.src,
473+
new URL(spawn.src, spawn.srcBase).href,
474474
),
475475
)
476476
}
@@ -519,7 +519,7 @@ export function GameScreen({ el, query }: Context) {
519519
el.style.width = screenSize + "px"
520520
el.style.height = screenSize + "px"
521521

522-
const me = new MainCharacter(2, 2, "char/kimi/", "kimi", "down", 1)
522+
const me = new MainCharacter(22, 22, "char/kimi/", "kimi", "down", 1)
523523
signal.centerPixel.update({ x: me.centerX, y: me.centerY })
524524

525525
const viewScope = new ViewScope(screenSize, screenSize)

static/cell/floor0.png

2 Bytes
Loading

static/cell/floor1.png

0 Bytes
Loading

static/cell/floor2.png

158 Bytes
Loading

0 commit comments

Comments
 (0)