Reviewed-on: #87
This commit was merged in pull request #87.
This commit is contained in:
@@ -436,6 +436,14 @@ async function onTokenPointerUp(event) {
|
|||||||
await placeToken(token.actor, { x, y });
|
await placeToken(token.actor, { x, y });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Double clicking a token (or Enter on a focused one) opens the sheet of the actor it stands for.
|
||||||
|
// A single click cannot be the trigger: the click that ends a drag lands on the token too, so
|
||||||
|
// dragging a token over the map would open its sheet every time.
|
||||||
|
function openTokenSheet(token) {
|
||||||
|
const actor = tokenActor(token);
|
||||||
|
if (actor) openActorSheet(actor);
|
||||||
|
}
|
||||||
|
|
||||||
const CELL_STEPS = {
|
const CELL_STEPS = {
|
||||||
ArrowLeft: [-1, 0],
|
ArrowLeft: [-1, 0],
|
||||||
ArrowRight: [1, 0],
|
ArrowRight: [1, 0],
|
||||||
@@ -443,7 +451,8 @@ const CELL_STEPS = {
|
|||||||
ArrowDown: [0, 1]
|
ArrowDown: [0, 1]
|
||||||
};
|
};
|
||||||
|
|
||||||
// A focused token answers to the keyboard too: arrows walk it over the grid, Delete takes it off.
|
// A focused token answers to the keyboard too: arrows walk it over the grid, Delete takes it off
|
||||||
|
// and Enter opens its sheet, the way a double click does.
|
||||||
async function onTokenKeydown(event, token) {
|
async function onTokenKeydown(event, token) {
|
||||||
const step = CELL_STEPS[event.key];
|
const step = CELL_STEPS[event.key];
|
||||||
if (step) {
|
if (step) {
|
||||||
@@ -456,6 +465,7 @@ async function onTokenKeydown(event, token) {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
await removeToken(token);
|
await removeToken(token);
|
||||||
}
|
}
|
||||||
|
if (event.key === 'Enter') openTokenSheet(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onTokenContextMenu(token) {
|
function onTokenContextMenu(token) {
|
||||||
@@ -609,6 +619,7 @@ onBeforeUnmount(() => {
|
|||||||
@pointermove="onTokenPointerMove"
|
@pointermove="onTokenPointerMove"
|
||||||
@pointerup="onTokenPointerUp"
|
@pointerup="onTokenPointerUp"
|
||||||
@pointercancel="onTokenPointerUp"
|
@pointercancel="onTokenPointerUp"
|
||||||
|
@dblclick="openTokenSheet(token)"
|
||||||
@contextmenu.stop.prevent="onTokenContextMenu(token)"
|
@contextmenu.stop.prevent="onTokenContextMenu(token)"
|
||||||
@keydown="onTokenKeydown($event, token)"
|
@keydown="onTokenKeydown($event, token)"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ cell you dropped it on and is sized by that cell, so a huge creature can be give
|
|||||||
sizing it up on the map's settings.
|
sizing it up on the map's settings.
|
||||||
|
|
||||||
Once a token is on the map you can drag it to another cell, step it across the grid one cell at a time
|
Once a token is on the map you can drag it to another cell, step it across the grid one cell at a time
|
||||||
with the **arrow keys**, and take it off with **Delete**. Clicking a token opens the sheet of the actor
|
with the **arrow keys**, and take it off with **Delete**. Double-clicking a token opens the sheet of
|
||||||
it stands for.
|
the actor it stands for, and **Enter** does the same on a token focused with the keyboard.
|
||||||
|
|
||||||
Tokens belong to the map, not to the actor: the same character can stand on several maps, and taking a
|
Tokens belong to the map, not to the actor: the same character can stand on several maps, and taking a
|
||||||
token off does not remove the character from the campaign.
|
token off does not remove the character from the campaign.
|
||||||
|
|||||||
@@ -341,6 +341,17 @@ function mapViewerTokenWiringTests() {
|
|||||||
assert.match(pane, /@contextmenu\.stop\.prevent="onTokenContextMenu\(token\)"/);
|
assert.match(pane, /@contextmenu\.stop\.prevent="onTokenContextMenu\(token\)"/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("double clicking a token opens its actor's character sheet", () => {
|
||||||
|
assert.match(pane, /@dblclick="openTokenSheet\(token\)"/);
|
||||||
|
// The sheet is opened for the actor behind the token, and only when that actor is known.
|
||||||
|
assert.match(pane, /function openTokenSheet\(token\) \{[^}]*tokenActor\(token\)[^}]*openActorSheet\(/);
|
||||||
|
// A single click is not the trigger: it lands on the token at the end of every drag, so
|
||||||
|
// moving a token would open its sheet every time.
|
||||||
|
assert.doesNotMatch(pane, /@click="openTokenSheet\(/);
|
||||||
|
// The keyboard reaches the same sheet: Enter on a focused token, like its arrow keys.
|
||||||
|
assert.match(pane, /if \(event\.key === 'Enter'\) openTokenSheet\(token\);/);
|
||||||
|
});
|
||||||
|
|
||||||
test("tokens are saved and taken off through the map routes", () => {
|
test("tokens are saved and taken off through the map routes", () => {
|
||||||
assert.match(pane, /['"]\/map\/place-token['"]/);
|
assert.match(pane, /['"]\/map\/place-token['"]/);
|
||||||
assert.match(pane, /['"]\/map\/remove-token['"]/);
|
assert.match(pane, /['"]\/map\/remove-token['"]/);
|
||||||
|
|||||||
Reference in New Issue
Block a user