add puzzle center/fit
This commit is contained in:
parent
a406d8abe8
commit
d009f84156
8 changed files with 50 additions and 7 deletions
1
build/public/assets/index.855f4dd3.js
Normal file
1
build/public/assets/index.855f4dd3.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -4,7 +4,7 @@
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
|
||||||
<title>🧩 jigsaw.hyottoko.club</title>
|
<title>🧩 jigsaw.hyottoko.club</title>
|
||||||
<script type="module" crossorigin src="/assets/index.c8fb176c.js"></script>
|
<script type="module" crossorigin src="/assets/index.855f4dd3.js"></script>
|
||||||
<link rel="modulepreload" href="/assets/vendor.684f7bc8.js">
|
<link rel="modulepreload" href="/assets/vendor.684f7bc8.js">
|
||||||
<link rel="stylesheet" href="/assets/index.22dc307c.css">
|
<link rel="stylesheet" href="/assets/index.22dc307c.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
|
||||||
|
|
@ -362,6 +362,7 @@ const INPUT_EV_REPLAY_TOGGLE_PAUSE = 12;
|
||||||
const INPUT_EV_REPLAY_SPEED_UP = 13;
|
const INPUT_EV_REPLAY_SPEED_UP = 13;
|
||||||
const INPUT_EV_REPLAY_SPEED_DOWN = 14;
|
const INPUT_EV_REPLAY_SPEED_DOWN = 14;
|
||||||
const INPUT_EV_TOGGLE_PLAYER_NAMES = 15;
|
const INPUT_EV_TOGGLE_PLAYER_NAMES = 15;
|
||||||
|
const INPUT_EV_CENTER_FIT_PUZZLE = 16;
|
||||||
const CHANGE_DATA = 1;
|
const CHANGE_DATA = 1;
|
||||||
const CHANGE_TILE = 2;
|
const CHANGE_TILE = 2;
|
||||||
const CHANGE_PLAYER = 3;
|
const CHANGE_PLAYER = 3;
|
||||||
|
|
@ -389,6 +390,7 @@ var Protocol = {
|
||||||
INPUT_EV_REPLAY_SPEED_UP,
|
INPUT_EV_REPLAY_SPEED_UP,
|
||||||
INPUT_EV_REPLAY_SPEED_DOWN,
|
INPUT_EV_REPLAY_SPEED_DOWN,
|
||||||
INPUT_EV_TOGGLE_PLAYER_NAMES,
|
INPUT_EV_TOGGLE_PLAYER_NAMES,
|
||||||
|
INPUT_EV_CENTER_FIT_PUZZLE,
|
||||||
CHANGE_DATA,
|
CHANGE_DATA,
|
||||||
CHANGE_TILE,
|
CHANGE_TILE,
|
||||||
CHANGE_PLAYER,
|
CHANGE_PLAYER,
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,7 @@ const INPUT_EV_REPLAY_SPEED_UP = 13
|
||||||
const INPUT_EV_REPLAY_SPEED_DOWN = 14
|
const INPUT_EV_REPLAY_SPEED_DOWN = 14
|
||||||
|
|
||||||
const INPUT_EV_TOGGLE_PLAYER_NAMES = 15
|
const INPUT_EV_TOGGLE_PLAYER_NAMES = 15
|
||||||
|
const INPUT_EV_CENTER_FIT_PUZZLE = 16
|
||||||
|
|
||||||
const CHANGE_DATA = 1
|
const CHANGE_DATA = 1
|
||||||
const CHANGE_TILE = 2
|
const CHANGE_TILE = 2
|
||||||
|
|
@ -101,6 +102,7 @@ export default {
|
||||||
INPUT_EV_REPLAY_SPEED_DOWN,
|
INPUT_EV_REPLAY_SPEED_DOWN,
|
||||||
|
|
||||||
INPUT_EV_TOGGLE_PLAYER_NAMES,
|
INPUT_EV_TOGGLE_PLAYER_NAMES,
|
||||||
|
INPUT_EV_CENTER_FIT_PUZZLE,
|
||||||
|
|
||||||
CHANGE_DATA,
|
CHANGE_DATA,
|
||||||
CHANGE_TILE,
|
CHANGE_TILE,
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,12 @@ export default function Camera () {
|
||||||
let y = 0
|
let y = 0
|
||||||
let curZoom = 1
|
let curZoom = 1
|
||||||
|
|
||||||
|
const reset = () => {
|
||||||
|
x = 0
|
||||||
|
y = 0
|
||||||
|
curZoom = 1
|
||||||
|
}
|
||||||
|
|
||||||
const move = (byX: number, byY: number) => {
|
const move = (byX: number, byY: number) => {
|
||||||
x += byX / curZoom
|
x += byX / curZoom
|
||||||
y += byY / curZoom
|
y += byY / curZoom
|
||||||
|
|
@ -130,9 +136,11 @@ export default function Camera () {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getCurrentZoom: () => curZoom,
|
getCurrentZoom: () => curZoom,
|
||||||
|
reset,
|
||||||
move,
|
move,
|
||||||
canZoom,
|
canZoom,
|
||||||
zoom,
|
zoom,
|
||||||
|
setZoom,
|
||||||
worldToViewport,
|
worldToViewport,
|
||||||
worldToViewportRaw,
|
worldToViewportRaw,
|
||||||
worldDimToViewport, // not used outside
|
worldDimToViewport, // not used outside
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@
|
||||||
<tr><td>🔍+ Zoom in:</td><td><div><kbd>E</kbd>/🖱️-Wheel</div></td></tr>
|
<tr><td>🔍+ Zoom in:</td><td><div><kbd>E</kbd>/🖱️-Wheel</div></td></tr>
|
||||||
<tr><td>🔍- Zoom out:</td><td><div><kbd>Q</kbd>/🖱️-Wheel</div></td></tr>
|
<tr><td>🔍- Zoom out:</td><td><div><kbd>Q</kbd>/🖱️-Wheel</div></td></tr>
|
||||||
<tr><td>🖼️ Toggle preview:</td><td><div><kbd>Space</kbd></div></td></tr>
|
<tr><td>🖼️ Toggle preview:</td><td><div><kbd>Space</kbd></div></td></tr>
|
||||||
|
<tr><td>🎯 Center puzzle in screen:</td><td><div><kbd>C</kbd></div></td></tr>
|
||||||
|
|
||||||
<tr><td>🧩✔️ Toggle fixed pieces:</td><td><div><kbd>F</kbd></div></td></tr>
|
<tr><td>🧩✔️ Toggle fixed pieces:</td><td><div><kbd>F</kbd></div></td></tr>
|
||||||
<tr><td>🧩❓ Toggle loose pieces:</td><td><div><kbd>G</kbd></div></td></tr>
|
<tr><td>🧩❓ Toggle loose pieces:</td><td><div><kbd>G</kbd></div></td></tr>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -211,6 +211,9 @@ function EventAdapter (
|
||||||
if (ev.code === 'KeyN') {
|
if (ev.code === 'KeyN') {
|
||||||
addEvent([Protocol.INPUT_EV_TOGGLE_PLAYER_NAMES])
|
addEvent([Protocol.INPUT_EV_TOGGLE_PLAYER_NAMES])
|
||||||
}
|
}
|
||||||
|
if (ev.code === 'KeyC') {
|
||||||
|
addEvent([Protocol.INPUT_EV_CENTER_FIT_PUZZLE])
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const addEvent = (event: GameEvent) => {
|
const addEvent = (event: GameEvent) => {
|
||||||
|
|
@ -416,12 +419,34 @@ export async function main(
|
||||||
// initialize some view data
|
// initialize some view data
|
||||||
// this global data will change according to input events
|
// this global data will change according to input events
|
||||||
const viewport = Camera()
|
const viewport = Camera()
|
||||||
// center viewport
|
|
||||||
|
const centerPuzzle = () => {
|
||||||
|
// center on the puzzle
|
||||||
|
viewport.reset()
|
||||||
viewport.move(
|
viewport.move(
|
||||||
-(TABLE_WIDTH - canvas.width) /2,
|
-(TABLE_WIDTH - canvas.width) /2,
|
||||||
-(TABLE_HEIGHT - canvas.height) /2
|
-(TABLE_HEIGHT - canvas.height) /2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// zoom viewport to fit whole puzzle in
|
||||||
|
const x = viewport.worldDimToViewport(BOARD_DIM)
|
||||||
|
const border = 20
|
||||||
|
const targetW = canvas.width - (border * 2)
|
||||||
|
const targetH = canvas.height - (border * 2)
|
||||||
|
if (
|
||||||
|
(x.w > targetW || x.h > targetH)
|
||||||
|
|| (x.w < targetW && x.h < targetH)
|
||||||
|
) {
|
||||||
|
const zoom = Math.min(targetW / x.w, targetH / x.h)
|
||||||
|
viewport.setZoom(zoom, {
|
||||||
|
x: canvas.width / 2,
|
||||||
|
y: canvas.height / 2,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
centerPuzzle()
|
||||||
|
|
||||||
const evts = EventAdapter(canvas, window, viewport, MODE)
|
const evts = EventAdapter(canvas, window, viewport, MODE)
|
||||||
|
|
||||||
const previewImageUrl = Game.getImageUrl(gameId)
|
const previewImageUrl = Game.getImageUrl(gameId)
|
||||||
|
|
@ -717,6 +742,8 @@ export async function main(
|
||||||
HUD.toggleSoundsEnabled()
|
HUD.toggleSoundsEnabled()
|
||||||
} else if (type === Protocol.INPUT_EV_TOGGLE_PLAYER_NAMES) {
|
} else if (type === Protocol.INPUT_EV_TOGGLE_PLAYER_NAMES) {
|
||||||
HUD.togglePlayerNames()
|
HUD.togglePlayerNames()
|
||||||
|
} else if (type === Protocol.INPUT_EV_CENTER_FIT_PUZZLE) {
|
||||||
|
centerPuzzle()
|
||||||
}
|
}
|
||||||
|
|
||||||
// LOCAL + SERVER CHANGES
|
// LOCAL + SERVER CHANGES
|
||||||
|
|
@ -787,6 +814,8 @@ export async function main(
|
||||||
HUD.toggleSoundsEnabled()
|
HUD.toggleSoundsEnabled()
|
||||||
} else if (type === Protocol.INPUT_EV_TOGGLE_PLAYER_NAMES) {
|
} else if (type === Protocol.INPUT_EV_TOGGLE_PLAYER_NAMES) {
|
||||||
HUD.togglePlayerNames()
|
HUD.togglePlayerNames()
|
||||||
|
} else if (type === Protocol.INPUT_EV_CENTER_FIT_PUZZLE) {
|
||||||
|
centerPuzzle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue