Add some freewheelin' palette entry action

main
kts of kettek 2024-02-17 00:13:55 -08:00
parent 094fae0302
commit 3547c2b7d4
4 changed files with 54 additions and 1 deletions

View File

@ -27,6 +27,19 @@
let palette: Palette = defaultPalette()
let primaryColorIndex: number = 1
let secondaryColorIndex: number = 0
// Oh no, what are you doing, step palette~
function stepPalette(step: number, primary: boolean) {
if (primary) {
primaryColorIndex += step
if (primaryColorIndex < 0) primaryColorIndex = focusedFile?.canvas.palette.length-1
if (primaryColorIndex >= focusedFile?.canvas.palette.length) primaryColorIndex = 0
} else {
secondaryColorIndex += step
if (secondaryColorIndex < 0) secondaryColorIndex = focusedFile?.canvas.palette.length-1
if (secondaryColorIndex >= focusedFile?.canvas.palette.length) secondaryColorIndex = 0
}
}
let showImport: boolean = false
let importValid: boolean = false
@ -127,6 +140,10 @@
<Shortcut global cmd='move down' keys={['arrowdown']} on:trigger={()=>toolMove.shift({file: focusedFile}, {x: 0, y: 1, id: 0})} />
<Shortcut global cmd='brush' keys={['b']} on:trigger={()=>swapTool(toolBrush)} />
<Shortcut global cmd='brushToPicker' keys={['alt']} on:trigger={()=>currentTool===toolBrush?swapTool(toolPicker):null} on:release={()=>previousTool===toolBrush&&currentTool===toolPicker?swapTool(toolBrush):null} />
<Shortcut global cmd='previousPrimaryPaletteEntry' keys={['alt+wheelup']} on:trigger={()=>stepPalette(-1, true)}/>
<Shortcut global cmd='nextPrimaryPaletteEntry' keys={['alt+wheeldown']} on:trigger={()=>stepPalette(1, true)}/>
<Shortcut global cmd='previousSecondaryPaletteEntry' keys={['alt+shift+wheelup']} on:trigger={()=>stepPalette(-1, false)}/>
<Shortcut global cmd='nextSecondaryPaletteEntry' keys={['alt+shift+wheeldown']} on:trigger={()=>stepPalette(1, false)}/>
<Shortcut global cmd='fill' keys={['f']} on:trigger={()=>swapTool(toolFill)} />
<Shortcut global cmd='picker' keys={['i']} on:trigger={()=>swapTool(toolPicker)} />
<Shortcut global cmd='erase' keys={['e']} on:trigger={()=>swapTool(toolErase)} />

View File

@ -71,6 +71,29 @@
keys.delete(key.toLowerCase())
keystring = keysToString([...keys])
})
window.addEventListener('wheel', (event: WheelEvent) => {
if (event.deltaY < 0 || event.deltaX < 0) {
keys.add('wheelup')
} else if (event.deltaY > 0 || event.deltaX > 0) {
keys.add('wheeldown')
}
keystring = keysToString([...keys])
let cur = get(currentShortcuts)
for (let shortcut of get(shortcuts)) {
if (shortcut.group !== cur.group) continue
if (!shortcut.global && shortcut.id !== cur.id) continue
if (shortcut.keys.includes(keystring)) {
shortcut.trigger()
}
}
keys.delete('wheelup')
keys.delete('wheeldown')
})
window.addEventListener('blur', () => {
keys.clear()
keystring = ''

View File

@ -274,6 +274,7 @@
}
return
}
if (e.altKey) return
if (e.deltaY < 0) {
if (e.shiftKey) {
offsetX--

View File

@ -15,9 +15,21 @@
primaryColorIndex = index
}
}
function handleWheel(event: WheelEvent) {
if (event.deltaX < 0) {
secondaryColorIndex = (secondaryColorIndex - 1 + file.canvas.palette.length) % file.canvas.palette.length
} else if (event.deltaX > 0) {
secondaryColorIndex = (secondaryColorIndex + 1) % file.canvas.palette.length
}
if (event.deltaY < 0) {
primaryColorIndex = (primaryColorIndex - 1 + file.canvas.palette.length) % file.canvas.palette.length
} else if (event.deltaY > 0) {
primaryColorIndex = (primaryColorIndex + 1) % file.canvas.palette.length
}
}
</script>
<main>
<main on:wheel={handleWheel}>
{#if file}
{#each file.canvas.palette as palette, paletteIndex}
<span on:click={paletteClick} x-index={paletteIndex} class='entry{paletteIndex===primaryColorIndex?' primary':''}{paletteIndex===secondaryColorIndex?' secondary':''}'>