diff --git a/client/src/ui/lib/editBrush.svelte b/client/src/ui/lib/editBrush.svelte
index 2659505..f49d2a7 100644
--- a/client/src/ui/lib/editBrush.svelte
+++ b/client/src/ui/lib/editBrush.svelte
@@ -17,6 +17,7 @@
import FlipH from '../../../assets/flip-h.svg?component'
import RotateCW from '../../../assets/rotate-cw.svg?component'
import RotateCCW from '../../../assets/rotate-ccw.svg?component'
+ import { LayerKind } from '../../twmap/mapdir'
export let brush: Editor.Brush
@@ -32,6 +33,13 @@
Editor.off('keypress', onKeyPress)
})
+ function clamp(cur: number, min: number, max: number) {
+ if (isNaN(cur))
+ return min
+ else
+ return Math.min(Math.max(min, cur), max)
+ }
+
function brushRotateCW(sel: Info.AnyTile[][]) {
return Array.from({ length: sel[0].length }, (_, j) =>
Array.from({ length: sel.length }, (_, i) => sel[sel.length - 1 - i][j])
@@ -252,6 +260,34 @@
else if (e.key === 'h' || e.key === 'n') onFlipH()
}
+ function tilesProperty(tiles: Info.AnyTile[][], prop: string): number | undefined {
+ let res: number
+
+ for (const row of tiles) {
+ for (const tile of row) {
+ if (prop in tile) {
+ if (res === undefined) {
+ res = tile[prop]
+ }
+ else if (tile[prop] !== res) {
+ return undefined
+ }
+ }
+ }
+ }
+
+ return res
+ }
+
+ function onSetProperty(prop: string, val: number) {
+ brush.layers.forEach(l => l.tiles.forEach(r => r.forEach(t => {
+ if (prop in t) {
+ t[prop] = val
+ }
+ })))
+ dispatch('change', brush)
+ }
+
@@ -268,6 +304,48 @@
+ {#if brush.layers.length === 1}
+ {@const layer = brush.layers[0]}
+ {#if layer.kind === LayerKind.Tele}
+
+ Teleport target
+ onSetProperty('number', clamp(parseInt(e.currentTarget.value), 0, 255))} />
+
+ {:else if layer.kind === LayerKind.Speedup}
+
+ Speedup force
+ onSetProperty('force', clamp(parseInt(e.currentTarget.value), 0, 255))} />
+
+
+ Speedup max speed
+ onSetProperty('maxSpeed', clamp(parseInt(e.currentTarget.value), 0, 255))}
+ />
+
+
+ Speedup angle
+ onSetProperty('angle', clamp(parseInt(e.currentTarget.value), 0, 255))} />
+
+ {:else if layer.kind === LayerKind.Switch}
+
+ Switch number
+ onSetProperty('number', clamp(parseInt(e.currentTarget.value), 0, 255))} />
+
+
+ Switch delay
+ onSetProperty('delay', clamp(parseInt(e.currentTarget.value), 0, 255))} />
+
+ {:else if layer.kind === LayerKind.Tune}
+
+ Tune zone
+ onSetProperty('number', clamp(parseInt(e.currentTarget.value), 0, 255))} />
+
+ {/if}
+ {/if}
diff --git a/client/src/ui/lib/editor.ts b/client/src/ui/lib/editor.ts
index 7a4fc68..4a5b30f 100644
--- a/client/src/ui/lib/editor.ts
+++ b/client/src/ui/lib/editor.ts
@@ -13,6 +13,7 @@ export type Brush = {
group: number,
layers: {
layer: number,
+ kind: MapDir.LayerKind,
tiles: Info.AnyTile[][],
}[]
}
@@ -106,7 +107,11 @@ export function makeBoxSelection(map: Map, g: number, ll: number[], sel: Range):
tiles.push(row)
}
- res.layers.push({ layer: l, tiles })
+ res.layers.push({
+ layer: l,
+ kind: layerKind(layer),
+ tiles
+ })
}
return res
@@ -132,7 +137,11 @@ export function makeEmptySelection(map: Map, g: number, ll: number[], sel: Range
tiles.push(row)
}
- res.layers.push({ layer: l, tiles })
+ res.layers.push({
+ layer: l,
+ kind: layerKind(layer),
+ tiles
+ })
}
return res
@@ -196,10 +205,7 @@ function adaptTile(tile: Info.AnyTile, kind: MapDir.LayerKind): Info.AnyTile {
}
}
-export function adaptTilesToLayer(map: Map, g: number, l: number, tiles: Info.AnyTile[][]): Info.AnyTile[][] {
- const layer = map.groups[g].layers[l]
- const kind = layerKind(layer)
-
+export function adaptTiles(tiles: Info.AnyTile[][], kind: MapDir.LayerKind): Info.AnyTile[][] {
return tiles.map(row =>
row.map(tile => adaptTile(tile, kind))
)
@@ -214,9 +220,11 @@ export function adaptBrushToLayers(map: Map, brush: Brush, g: number, ll: number
return layer
}
else {
+ const kind = layerKind(map.groups[g].layers[l])
return {
layer: l,
- tiles: adaptTilesToLayer(map, g, l, brush.layers[0].tiles)
+ kind,
+ tiles: adaptTiles(brush.layers[0].tiles, kind)
}
}
})
@@ -307,6 +315,7 @@ export function fill(
group: brush.group,
layers: brush.layers.map(l => ({
layer: l.layer,
+ kind: l.kind,
tiles: repeat(l.tiles, size),
}))
}
diff --git a/client/src/ui/lib/mapEditor.svelte b/client/src/ui/lib/mapEditor.svelte
index 8bfe829..0bf2909 100644
--- a/client/src/ui/lib/mapEditor.svelte
+++ b/client/src/ui/lib/mapEditor.svelte
@@ -15,7 +15,7 @@
import Stats from './stats.svelte'
import { RenderAnyTilesLayer } from "../../gl/renderTilesLayer"
import { viewport, renderer } from '../../gl/global'
- import { externalImageUrl } from './util'
+ import { externalImageUrl, layerKind } from './util'
import MapView from './mapView.svelte'
import type { RenderGroup } from '../../gl/renderGroup'
import type { RenderLayer } from '../../gl/renderLayer'
@@ -499,6 +499,7 @@
group: g,
layers: [{
layer: l,
+ kind: layerKind($map.groups[g].layers[l]),
tiles: e.detail,
}]
}
diff --git a/client/src/ui/lib/tilePicker.svelte b/client/src/ui/lib/tilePicker.svelte
index 59b484e..f59409b 100644
--- a/client/src/ui/lib/tilePicker.svelte
+++ b/client/src/ui/lib/tilePicker.svelte
@@ -60,7 +60,7 @@
let currentSpeedup: { kind: MapDir.LayerKind.Speedup } & Speedup = { kind: MapDir.LayerKind.Speedup, ...SpeedupLayer.defaultTile() }
let currentTune: { kind: MapDir.LayerKind.Tune } & Tune = { kind: MapDir.LayerKind.Tune, ...TuneLayer.defaultTile() }
- function sanitizeInputs() {
+ function onInputChanged() {
currentTele.number = clamp(currentTele.number, 0, 255)
currentSwitch.delay = clamp(currentSwitch.delay, 0, 255)
currentSwitch.number = clamp(currentSwitch.number, 0, 255)
@@ -258,18 +258,11 @@