Skip to content

Commit

Permalink
qol: some shortcuts, canvas focus indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
mathis committed Oct 25, 2023
1 parent 22baf4e commit 8592c8f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 14 deletions.
8 changes: 4 additions & 4 deletions client/src/gl/viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ export class Viewport {
}

private onkeydown(e: KeyboardEvent) {
if (e.key === 'ArrowLeft') this.pos.x -= 1
else if (e.key === 'ArrowRight') this.pos.x += 1
else if (e.key === 'ArrowUp') this.pos.y -= 1
else if (e.key === 'ArrowDown') this.pos.y += 1
if (e.key === 'ArrowLeft' || e.key === 'a') this.pos.x -= 1
else if (e.key === 'ArrowRight' || e.key === 'd') this.pos.x += 1
else if (e.key === 'ArrowUp' || e.key === 'w') this.pos.y -= 1
else if (e.key === 'ArrowDown' || e.key === 's') this.pos.y += 1
}

// ------------ mobile events --------------------------------
Expand Down
4 changes: 2 additions & 2 deletions client/src/ui/lib/editBrush.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@
function onKeyPress(e: KeyboardEvent) {
if (e.ctrlKey || e.altKey) return
if (['r', 'v', 'h', 'n', 'm'].includes(e.key.toLowerCase())) e.preventDefault()
if (['r', 't', 'v', 'h', 'n', 'm'].includes(e.key.toLowerCase())) e.preventDefault()
if (e.key === 'r') onRotateCW()
else if (e.key === 'R') onRotateCCW()
else if (e.key === 'R' || e.key === 't') onRotateCCW()
else if (e.key === 'v' || e.key === 'm') onFlipV()
else if (e.key === 'h' || e.key === 'n') onFlipH()
}
Expand Down
10 changes: 3 additions & 7 deletions client/src/ui/lib/editor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,6 @@
}
}
function onToggleAnim() {
$anim = !$anim
}
function onUndo() {
if (!$server.undo()) {
console.warn('cannot undo')
Expand All @@ -182,13 +178,13 @@
Editor.fire('keydown', e)
if (e.ctrlKey && ['s', ' ', 'z', 'y'].includes(e.key)) {
if (e.ctrlKey && ['s', ' ', 'z', 'y', 'm'].includes(e.key)) {
e.preventDefault()
if (e.key === 's') {
Actions.saveMap()
} else if (e.key === ' ') {
onToggleAnim()
} else if (e.key === ' ' || e.key === 'm') {
$anim = !$anim
} else if (e.key === 'z') {
onUndo()
} else if (e.key === 'y') {
Expand Down
2 changes: 1 addition & 1 deletion client/src/ui/lib/mapView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
}
</script>

<div class="map-view" bind:this={cont}>
<div class="map-view" tabindex="-1" bind:this={cont}>
<canvas bind:this={canvas}></canvas>
<slot></slot>
</div>
17 changes: 17 additions & 0 deletions client/src/ui/lib/quadsView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import { coordToJson, resIndexToString, uvToJson } from '../../server/convert'
import { rmap } from '../global'
import type { Send } from '../../server/protocol'
import * as Editor from './editor'
export let layer: QuadsLayer
Expand All @@ -25,6 +26,22 @@
}
$: [g, l] = layerIndex($rmap.map, layer)
onMount(() => {
Editor.on('keypress', onKeyPress)
})
onDestroy(() => {
Editor.off('keypress', onKeyPress)
})
function onKeyPress(e: KeyboardEvent) {
if (e.ctrlKey && ['q'].includes(e.key)) {
e.preventDefault()
if (e.key === 'q') createQuad()
}
}
function quadPointsStr(points: Info.Coord[]) {
const toStr = (p: Info.Coord) => p.x / 1024 + ',' + p.y / 1024
const topLeft = points[0]
Expand Down
8 changes: 8 additions & 0 deletions client/styles/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ $header-h: 3rem;
width: 100%;
height: 100%;

// make the canvas darker when unfocused to show that other inputs have focus.
transition: background-color .2s, box-shadow .2s;

&:not(:focus) {
background-color: rgba(0, 0, 0, 0.10);
box-shadow: inset 0 0 20px -10px black;
}

>canvas {
height: 100%;
width: 100%;
Expand Down

0 comments on commit 8592c8f

Please sign in to comment.