mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-03-06 15:47:30 +08:00
Minor refactoring
This commit is contained in:
@@ -74,60 +74,34 @@ export default class LinkTemplate extends IFromToPositionedTemplate {
|
||||
// Switch actual input/output pins if allowed and makes sense
|
||||
if (isOriginAKnot && (!targetPin || isTargetAKnot)) {
|
||||
if (originPin?.isInputLoosely() && to > from + Configuration.distanceThreshold) {
|
||||
this.element.origin = /** @type {KnotPinTemplate} */(originPin.template).oppositePin()
|
||||
this.element.origin = /** @type {KnotPinTemplate} */(originPin.template).getoppositePin()
|
||||
} else if (originPin?.isOutputLoosely() && to < from - Configuration.distanceThreshold) {
|
||||
this.element.origin = /** @type {KnotPinTemplate} */(originPin.template).oppositePin()
|
||||
this.element.origin = /** @type {KnotPinTemplate} */(originPin.template).getoppositePin()
|
||||
}
|
||||
}
|
||||
if (isTargetAKnot && (!originPin || isOriginAKnot)) {
|
||||
if (targetPin?.isInputLoosely() && to < from - Configuration.distanceThreshold) {
|
||||
this.element.target = /** @type {KnotPinTemplate} */(targetPin.template).oppositePin()
|
||||
this.element.target = /** @type {KnotPinTemplate} */(targetPin.template).getoppositePin()
|
||||
} else if (targetPin?.isOutputLoosely() && to > from + Configuration.distanceThreshold) {
|
||||
this.element.target = /** @type {KnotPinTemplate} */(targetPin.template).oppositePin()
|
||||
this.element.target = /** @type {KnotPinTemplate} */(targetPin.template).getoppositePin()
|
||||
}
|
||||
}
|
||||
|
||||
// Switch visual input/output pins if allowed and makes sense
|
||||
let directionsCheckedKnot
|
||||
if (
|
||||
originPin?.isKnot()
|
||||
&& !changedProperties.has("fromX")
|
||||
&& changedProperties.has("toX")
|
||||
) {
|
||||
// The target end has moved and origin end is a knot
|
||||
directionsCheckedKnot = originPin.nodeElement
|
||||
} else if (
|
||||
targetPin?.isKnot()
|
||||
&& changedProperties.has("toX")
|
||||
&& !changedProperties.has("fromX")
|
||||
) {
|
||||
// The origin end has moved and target end is a knot
|
||||
directionsCheckedKnot = targetPin.nodeElement
|
||||
}
|
||||
if (directionsCheckedKnot) {
|
||||
let leftPinsLocation = 0
|
||||
let leftPinsCount = 0
|
||||
let rightPinsLocation = 0
|
||||
let rightPinsCount = 0
|
||||
const pins = directionsCheckedKnot.template
|
||||
.getAllConnectedLinks()
|
||||
.map(l => l.getOtherPin(directionsCheckedKnot))
|
||||
for (const pin of pins) {
|
||||
if (pin.isInput()) {
|
||||
rightPinsLocation += pin.getLinkLocation()[0]
|
||||
++rightPinsCount
|
||||
} else if (pin.isOutput()) {
|
||||
leftPinsLocation += pin.getLinkLocation()[0]
|
||||
++leftPinsCount
|
||||
}
|
||||
if (originPin && targetPin) {
|
||||
let directionsCheckedKnot
|
||||
if (originPin?.isKnot()) {
|
||||
// The target end has moved and origin end is a knot
|
||||
directionsCheckedKnot = originPin.nodeElement
|
||||
} else if (targetPin?.isKnot()) {
|
||||
// The origin end has moved and target end is a knot
|
||||
directionsCheckedKnot = targetPin.nodeElement
|
||||
}
|
||||
leftPinsLocation /= leftPinsCount
|
||||
rightPinsLocation /= rightPinsCount
|
||||
const knotTemplate = /** @type {KnotNodeTemplate} */(directionsCheckedKnot.template)
|
||||
if ((rightPinsLocation < leftPinsLocation) != knotTemplate.switchDirectionsVisually) {
|
||||
knotTemplate.switchDirectionsVisually = rightPinsLocation < leftPinsLocation
|
||||
if (directionsCheckedKnot && directionsCheckedKnot.hasUpdated) {
|
||||
/** @type {KnotNodeTemplate} */(directionsCheckedKnot.template).checkSwtichDirectionsVisually()
|
||||
}
|
||||
}
|
||||
|
||||
let sameDirection = originPin?.isOutputVisually() == targetPin?.isOutputVisually()
|
||||
|
||||
// Actual computation
|
||||
|
||||
@@ -60,6 +60,28 @@ export default class KnotNodeTemplate extends NodeTemplate {
|
||||
}
|
||||
|
||||
linksChanged() {
|
||||
}
|
||||
|
||||
checkSwtichDirectionsVisually() {
|
||||
let leftPinsLocation = 0
|
||||
let leftPinsCount = 0
|
||||
let rightPinsLocation = 0
|
||||
let rightPinsCount = 0
|
||||
const links = this.getAllConnectedLinks()
|
||||
for (const link of links) {
|
||||
const pin = link.getOtherPin(this.element)
|
||||
if (pin?.isInput()) {
|
||||
rightPinsLocation += pin.getLinkLocation()[0]
|
||||
++rightPinsCount
|
||||
} else if (pin?.isOutput()) {
|
||||
leftPinsLocation += pin.getLinkLocation()[0]
|
||||
++leftPinsCount
|
||||
}
|
||||
}
|
||||
leftPinsLocation /= leftPinsCount
|
||||
rightPinsLocation /= rightPinsCount
|
||||
if ((rightPinsLocation < leftPinsLocation) != this.switchDirectionsVisually) {
|
||||
this.switchDirectionsVisually = rightPinsLocation < leftPinsLocation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,15 @@ export default class KnotPinTemplate extends MinimalPinTemplate {
|
||||
return this.element.isOutput() ? super.render() : html``
|
||||
}
|
||||
|
||||
oppositePin() {
|
||||
getoppositePin() {
|
||||
const nodeTemplate = /** @type {KnotNodeTemplate} */(this.element.nodeElement.template)
|
||||
return this.element.isOutput() ? nodeTemplate.inputPin : nodeTemplate.outputPin
|
||||
}
|
||||
|
||||
/** Location on the grid of a link connecting to this pin */
|
||||
getLinkLocation() {
|
||||
if (this.element.isInput()) {
|
||||
return this.oppositePin().getLinkLocation()
|
||||
return this.getoppositePin().getLinkLocation()
|
||||
}
|
||||
return super.getLinkLocation()
|
||||
}
|
||||
|
||||
@@ -172,9 +172,12 @@ export default class PinTemplate extends ITemplate {
|
||||
}
|
||||
|
||||
getLinkLocation() {
|
||||
const rect = this.iconElement.getBoundingClientRect()
|
||||
const rect = (this.#iconElement ?? this.element).getBoundingClientRect()
|
||||
/** @type {[Number, Number]} */
|
||||
const boundingLocation = [this.element.isInputVisually() ? rect.left : rect.right + 1, (rect.top + rect.bottom) / 2]
|
||||
const boundingLocation = [
|
||||
this.element.isInputVisually() ? rect.left : rect.right + 1,
|
||||
(rect.top + rect.bottom) / 2
|
||||
]
|
||||
const location = Utility.convertLocation(boundingLocation, this.blueprint.template.gridElement)
|
||||
return this.blueprint.compensateTranslation(location[0], location[1])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user