mirror of
https://github.com/thepaperpilot/Planar-Pioneers.git
synced 2024-11-24 09:21:45 +00:00
Move selecting action logic inside the board component
This commit is contained in:
parent
3b1ca588cf
commit
536db8bf9f
4 changed files with 20 additions and 7 deletions
|
@ -44,6 +44,7 @@
|
|||
:selectedAction="unref(selectedAction)"
|
||||
@mouseDown="mouseDown"
|
||||
@endDragging="endDragging"
|
||||
@clickAction="actionId => clickAction(node, actionId)"
|
||||
/>
|
||||
</g>
|
||||
</transition-group>
|
||||
|
@ -240,6 +241,15 @@ function endDragging(nodeID: number | null) {
|
|||
props.state.value.selectedAction = null;
|
||||
}
|
||||
}
|
||||
|
||||
function clickAction(node: BoardNode, actionId: string) {
|
||||
if (props.state.value.selectedAction === actionId) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
unref(props.selectedAction)!.onClick(unref(props.selectedNode)!);
|
||||
} else {
|
||||
props.state.value = { ...props.state.value, selectedAction: actionId };
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
:node="node"
|
||||
:node-type="nodeType"
|
||||
:selected-action="selectedAction"
|
||||
@click-action="actionId => emit('clickAction', actionId)"
|
||||
/>
|
||||
|
||||
<g
|
||||
|
@ -168,6 +169,7 @@ const props = toRefs(_props);
|
|||
const emit = defineEmits<{
|
||||
(e: "mouseDown", event: MouseEvent | TouchEvent, node: number, isDraggable: boolean): void;
|
||||
(e: "endDragging", node: number): void;
|
||||
(e: "clickAction", actionId: string): void;
|
||||
}>();
|
||||
|
||||
const isSelected = computed(() => unref(props.selectedNode) === unref(props.node));
|
||||
|
|
|
@ -52,6 +52,10 @@ const _props = defineProps<{
|
|||
}>();
|
||||
const props = toRefs(_props);
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: "clickAction", actionId: string): void;
|
||||
}>();
|
||||
|
||||
const size = computed(() => getNodeProperty(props.nodeType.value.size, unref(props.node)));
|
||||
const outlineColor = computed(
|
||||
() =>
|
||||
|
@ -68,13 +72,10 @@ const actionDistance = computed(() =>
|
|||
);
|
||||
|
||||
function performAction(e: MouseEvent | TouchEvent, action: GenericBoardNodeAction) {
|
||||
// If the onClick function made this action selected,
|
||||
// don't propagate the event (which will deselect everything)
|
||||
if (action.onClick(unref(props.node)) || unref(props.selectedAction)?.id === action.id) {
|
||||
emit("clickAction", action.id);
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}
|
||||
}
|
||||
|
||||
function actionMouseUp(e: MouseEvent | TouchEvent, action: GenericBoardNodeAction) {
|
||||
if (unref(props.selectedAction)?.id === action.id) {
|
||||
|
|
|
@ -191,7 +191,7 @@ export interface BoardNodeActionOptions {
|
|||
/** An array of board node links associated with the action. They appear when the action is focused. */
|
||||
links?: NodeComputable<BoardNodeLink[]>;
|
||||
/** A function that is called when the action is clicked. */
|
||||
onClick: (node: BoardNode) => boolean | undefined;
|
||||
onClick: (node: BoardNode) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue