mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-03-06 23:57:30 +08:00
Various fixes, tests and refactoring
This commit is contained in:
@@ -7,6 +7,7 @@ import IMouseClickDrag from "./IMouseClickDrag"
|
||||
* @typedef {import("../../element/LinkElement").LinkElementConstructor} LinkElementConstructor
|
||||
* @typedef {import("../../element/PinElement").default} PinElement
|
||||
* @typedef {import("../../template/node/KnotNodeTemplate").default} KnotNodeTemplate
|
||||
* @typedef {import("../../template/pin/KnotPinTemplate").default} KnotPinTemplate
|
||||
*/
|
||||
|
||||
/** @extends IMouseClickDrag<PinElement> */
|
||||
@@ -18,46 +19,46 @@ export default class MouseCreateLink extends IMouseClickDrag {
|
||||
/** @type {PinElement} */
|
||||
#knotPin = null
|
||||
|
||||
#mouseenterHandler =
|
||||
/** @param {MouseEvent} e */
|
||||
e => {
|
||||
if (!this.enteredPin) {
|
||||
this.linkValid = false
|
||||
this.enteredPin = /** @type {PinElement} */(e.target)
|
||||
const a = this.link.sourcePin ?? this.target // Remember target might have change
|
||||
const b = this.enteredPin
|
||||
if (
|
||||
a.nodeElement.getType() == Configuration.nodeType.knot
|
||||
|| b.nodeElement.getType() == Configuration.nodeType.knot
|
||||
) {
|
||||
// A knot can be linked to any pin, it doesn't matter the type or input/output direction
|
||||
this.link.setMessageCorrect()
|
||||
this.linkValid = true
|
||||
} else if (a.getNodeElement() == b.getNodeElement()) {
|
||||
this.link.setMessageSameNode()
|
||||
} else if (a.isOutput() == b.isOutput()) {
|
||||
this.link.setMessageDirectionsIncompatible()
|
||||
} else if (a.isOutput() == b.isOutput()) {
|
||||
this.link.setMessageDirectionsIncompatible()
|
||||
} else if (this.blueprint.getLinks(a, b).length) {
|
||||
this.link.setMessageReplaceLink()
|
||||
this.linkValid = true
|
||||
} else {
|
||||
this.link.setMessageCorrect()
|
||||
this.linkValid = true
|
||||
}
|
||||
/** @param {MouseEvent} e */
|
||||
#mouseenterHandler = e => {
|
||||
if (!this.enteredPin) {
|
||||
this.linkValid = false
|
||||
this.enteredPin = /** @type {PinElement} */(e.target)
|
||||
const a = this.link.sourcePin ?? this.target // Remember target might have change
|
||||
const b = this.enteredPin
|
||||
const outputPin = a.isOutput() ? a : b
|
||||
if (
|
||||
a.nodeElement.getType() === Configuration.nodeType.knot
|
||||
|| b.nodeElement.getType() === Configuration.nodeType.knot
|
||||
) {
|
||||
// A knot can be linked to any pin, it doesn't matter the type or input/output direction
|
||||
this.link.setMessageCorrect()
|
||||
this.linkValid = true
|
||||
} else if (a.getNodeElement() === b.getNodeElement()) {
|
||||
this.link.setMessageSameNode()
|
||||
} else if (a.isOutput() === b.isOutput()) {
|
||||
this.link.setMessageDirectionsIncompatible()
|
||||
} else if (this.blueprint.getLinks(a, b).length) {
|
||||
this.link.setMessageReplaceLink()
|
||||
this.linkValid = true
|
||||
} else if (outputPin.entity.getType() === "exec" && outputPin.isLinked) {
|
||||
this.link.setMessageReplaceOutputLink()
|
||||
this.linkValid = true
|
||||
} else {
|
||||
this.link.setMessageCorrect()
|
||||
this.linkValid = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#mouseleaveHandler =
|
||||
/** @param {MouseEvent} e */
|
||||
e => {
|
||||
if (this.enteredPin == e.target) {
|
||||
this.enteredPin = null
|
||||
this.linkValid = false
|
||||
this.link?.setMessagePlaceNode()
|
||||
}
|
||||
/** @param {MouseEvent} e */
|
||||
#mouseleaveHandler = e => {
|
||||
if (this.enteredPin == e.target) {
|
||||
this.enteredPin = null
|
||||
this.linkValid = false
|
||||
this.link?.setMessagePlaceNode()
|
||||
}
|
||||
}
|
||||
|
||||
/** @type {LinkElement?} */
|
||||
link
|
||||
@@ -102,15 +103,15 @@ export default class MouseCreateLink extends IMouseClickDrag {
|
||||
const otherPin = this.#knotPin !== this.link.sourcePin ? this.link.sourcePin : this.enteredPin
|
||||
// Knot pin direction correction
|
||||
if (this.#knotPin.isInput() && otherPin.isInput() || this.#knotPin.isOutput() && otherPin.isOutput()) {
|
||||
const oppositePin = this.#knotPin.isInput()
|
||||
? /** @type {KnotNodeTemplate} */(this.#knotPin.nodeElement.template).outputPin
|
||||
: /** @type {KnotNodeTemplate} */(this.#knotPin.nodeElement.template).inputPin
|
||||
const oppositePin = /** @type {KnotPinTemplate} */(this.#knotPin.template).getOppositePin()
|
||||
if (this.#knotPin === this.link.sourcePin) {
|
||||
this.link.sourcePin = oppositePin
|
||||
} else {
|
||||
this.enteredPin = oppositePin
|
||||
}
|
||||
}
|
||||
} else if (this.enteredPin.nodeElement.getType() === Configuration.nodeType.knot) {
|
||||
this.enteredPin = /** @type {KnotPinTemplate} */(this.enteredPin.template).getOppositePin()
|
||||
}
|
||||
this.blueprint.addGraphElement(this.link)
|
||||
this.link.destinationPin = this.enteredPin
|
||||
|
||||
Reference in New Issue
Block a user