forked from profectus/Profectus
Fix canAccept not passing in otherNode
This commit is contained in:
parent
2999c971cf
commit
3808f299ec
3 changed files with 20 additions and 10 deletions
|
@ -122,7 +122,7 @@ watchEffect(() => {
|
||||||
return smallest;
|
return smallest;
|
||||||
}
|
}
|
||||||
const nodeType = props.types.value[curr.type];
|
const nodeType = props.types.value[curr.type];
|
||||||
const canAccept = getNodeProperty(nodeType.canAccept, curr);
|
const canAccept = getNodeProperty(nodeType.canAccept, curr, node);
|
||||||
if (!canAccept) {
|
if (!canAccept) {
|
||||||
return smallest;
|
return smallest;
|
||||||
}
|
}
|
||||||
|
@ -225,8 +225,10 @@ function drag(e: MouseEvent | TouchEvent) {
|
||||||
|
|
||||||
function endDragging(node: BoardNode | null) {
|
function endDragging(node: BoardNode | null) {
|
||||||
if (props.draggingNode.value != null && props.draggingNode.value === node) {
|
if (props.draggingNode.value != null && props.draggingNode.value === node) {
|
||||||
props.draggingNode.value.position.x += Math.round(dragged.value.x / 25) * 25;
|
if (props.receivingNode.value == null) {
|
||||||
props.draggingNode.value.position.y += Math.round(dragged.value.y / 25) * 25;
|
props.draggingNode.value.position.x += Math.round(dragged.value.x / 25) * 25;
|
||||||
|
props.draggingNode.value.position.y += Math.round(dragged.value.y / 25) * 25;
|
||||||
|
}
|
||||||
|
|
||||||
const nodes = props.nodes.value;
|
const nodes = props.nodes.value;
|
||||||
nodes.push(nodes.splice(nodes.indexOf(props.draggingNode.value), 1)[0]);
|
nodes.push(nodes.splice(nodes.indexOf(props.draggingNode.value), 1)[0]);
|
||||||
|
|
|
@ -253,9 +253,9 @@ const progressDisplay = computed(() =>
|
||||||
);
|
);
|
||||||
const canAccept = computed(
|
const canAccept = computed(
|
||||||
() =>
|
() =>
|
||||||
unref(props.dragging) != null &&
|
props.dragging.value != null &&
|
||||||
unref(props.hasDragged) &&
|
unref(props.hasDragged) &&
|
||||||
getNodeProperty(props.nodeType.value.canAccept, unref(props.node))
|
getNodeProperty(props.nodeType.value.canAccept, unref(props.node), props.dragging.value)
|
||||||
);
|
);
|
||||||
const style = computed(() => getNodeProperty(props.nodeType.value.style, unref(props.node)));
|
const style = computed(() => getNodeProperty(props.nodeType.value.style, unref(props.node)));
|
||||||
const classes = computed(() => getNodeProperty(props.nodeType.value.classes, unref(props.node)));
|
const classes = computed(() => getNodeProperty(props.nodeType.value.classes, unref(props.node)));
|
||||||
|
|
|
@ -33,7 +33,9 @@ export const BoardType = Symbol("Board");
|
||||||
/**
|
/**
|
||||||
* A type representing a computable value for a node on the board. Used for node types to return different values based on the given node and the state of the board.
|
* A type representing a computable value for a node on the board. Used for node types to return different values based on the given node and the state of the board.
|
||||||
*/
|
*/
|
||||||
export type NodeComputable<T> = Computable<T> | ((node: BoardNode) => T);
|
export type NodeComputable<T, S extends unknown[] = []> =
|
||||||
|
| Computable<T>
|
||||||
|
| ((node: BoardNode, ...args: S) => T);
|
||||||
|
|
||||||
/** Ways to display progress of an action with a duration. */
|
/** Ways to display progress of an action with a duration. */
|
||||||
export enum ProgressDisplay {
|
export enum ProgressDisplay {
|
||||||
|
@ -101,7 +103,7 @@ export interface NodeTypeOptions {
|
||||||
/** The shape of the node. */
|
/** The shape of the node. */
|
||||||
shape: NodeComputable<Shape>;
|
shape: NodeComputable<Shape>;
|
||||||
/** Whether the node can accept another node being dropped upon it. */
|
/** Whether the node can accept another node being dropped upon it. */
|
||||||
canAccept?: boolean | Ref<boolean> | ((node: BoardNode, otherNode: BoardNode) => boolean);
|
canAccept?: NodeComputable<boolean, [BoardNode]>;
|
||||||
/** The progress value of the node. */
|
/** The progress value of the node. */
|
||||||
progress?: NodeComputable<number>;
|
progress?: NodeComputable<number>;
|
||||||
/** How the progress should be displayed on the node. */
|
/** How the progress should be displayed on the node. */
|
||||||
|
@ -164,7 +166,7 @@ export type GenericNodeType = Replace<
|
||||||
size: NodeComputable<number>;
|
size: NodeComputable<number>;
|
||||||
draggable: NodeComputable<boolean>;
|
draggable: NodeComputable<boolean>;
|
||||||
shape: NodeComputable<Shape>;
|
shape: NodeComputable<Shape>;
|
||||||
canAccept: NodeComputable<boolean>;
|
canAccept: NodeComputable<boolean, [BoardNode]>;
|
||||||
progressDisplay: NodeComputable<ProgressDisplay>;
|
progressDisplay: NodeComputable<ProgressDisplay>;
|
||||||
progressColor: NodeComputable<string>;
|
progressColor: NodeComputable<string>;
|
||||||
actionDistance: NodeComputable<number>;
|
actionDistance: NodeComputable<number>;
|
||||||
|
@ -490,8 +492,14 @@ export function createBoard<T extends BoardOptions>(
|
||||||
* @param property The property to find the value of
|
* @param property The property to find the value of
|
||||||
* @param node The node to get the property of
|
* @param node The node to get the property of
|
||||||
*/
|
*/
|
||||||
export function getNodeProperty<T>(property: NodeComputable<T>, node: BoardNode): T {
|
export function getNodeProperty<T, S extends unknown[]>(
|
||||||
return isFunction<T, [BoardNode], Computable<T>>(property) ? property(node) : unref(property);
|
property: NodeComputable<T, S>,
|
||||||
|
node: BoardNode,
|
||||||
|
...args: S
|
||||||
|
): T {
|
||||||
|
return isFunction<T, [BoardNode, ...S], Computable<T>>(property)
|
||||||
|
? property(node, ...args)
|
||||||
|
: unref(property);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue