Fixing linked knot

This commit is contained in:
barsdeveloper
2022-11-14 20:46:27 +01:00
parent 92e4735d47
commit decef44d02
14 changed files with 142 additions and 68 deletions

View File

@@ -32,5 +32,4 @@ export default class IFromToPositionedTemplate extends ITemplate {
this.element.style.height = `${height}px`
}
}
}

View File

@@ -47,8 +47,8 @@ export default class KnotNodeTemplate extends ISelectableDraggableTemplate {
const inputEntity = entities[entities[0].isInput() ? 0 : 1]
const outputEntity = entities[entities[0].isOutput() ? 0 : 1]
return [
this.#inputPin = new PinElement(inputEntity, new KnotPinTemplate()),
this.#outputPin = new PinElement(outputEntity, new KnotPinTemplate()),
this.#inputPin = new PinElement(inputEntity, new KnotPinTemplate(), this.element),
this.#outputPin = new PinElement(outputEntity, new KnotPinTemplate(), this.element),
]
}
}

View File

@@ -14,12 +14,13 @@ export default class KnotPinTemplate extends PinTemplate {
const rect = (
this.element.isInput()
// @ts-expect-error
? /** @type {KnotNodeTemplate} */ (this.element.nodeElement.template).outputPin.template.iconElement
: this.iconElement
).getBoundingClientRect()
? /** @type {KnotNodeTemplate} */ (this.element.nodeElement.template).outputPin.template
: this
)
.iconElement.getBoundingClientRect()
const location = Utility.convertLocation(
[
this.element.isInput() ? (rect.left + rect.right) / 2 : rect.right + 2,
this.element.isInput() ? rect.left + 1 : rect.right + 2,
(rect.top + rect.bottom) / 2,
],
this.element.blueprint.gridElement

View File

@@ -64,19 +64,28 @@ export default class LinkTemplate extends IFromToPositionedTemplate {
*/
willUpdate(changedProperties) {
super.willUpdate(changedProperties)
const sourcePint = this.element.sourcePin
if (
changedProperties.has("toX")
&& !this.element.destinationPin
&& sourcePint?.nodeElement.getType() == "/Script/BlueprintGraph.K2Node_Knot"
) {
if (sourcePint.isInput() && this.element.toX > this.element.fromX + 5) {
// @ts-expect-error
this.element.sourcePin = /** @type {KnotNodeTemplate} */(sourcePint.nodeElement.template).outputPin
const sourcePin = this.element.sourcePin
const destinationPin = this.element.destinationPin
if (changedProperties.has("fromX") || changedProperties.has("toX")) {
const isSourceAKnot = sourcePin?.nodeElement.getType() == Configuration.knotNodeTypeName
const isDestinationAKnot = destinationPin?.nodeElement.getType() == Configuration.knotNodeTypeName
if (isSourceAKnot && (!destinationPin || isDestinationAKnot)) {
if (sourcePin?.isInput() && this.element.toX > this.element.fromX + Configuration.distanceThreshold) {
// @ts-expect-error
this.element.sourcePin = /** @type {KnotNodeTemplate} */(sourcePin.nodeElement.template).outputPin
} else if (sourcePin?.isOutput() && this.element.toX < this.element.fromX - Configuration.distanceThreshold) {
// @ts-expect-error
this.element.sourcePin = /** @type {KnotNodeTemplate} */(sourcePin.nodeElement.template).inputPin
}
}
if (sourcePint.isOutput() && this.element.toX < this.element.fromX - 5) {
// @ts-expect-error
this.element.sourcePin = /** @type {KnotNodeTemplate} */(sourcePint.nodeElement.template).inputPin
if (isDestinationAKnot && (!isSourceAKnot || isSourceAKnot)) {
if (destinationPin?.isInput() && this.element.toX < this.element.fromX + Configuration.distanceThreshold) {
// @ts-expect-error
this.element.destinationPin = /** @type {KnotNodeTemplate} */(destinationPin.nodeElement.template).outputPin
} else if (destinationPin?.isOutput() && this.element.toX > this.element.fromX - Configuration.distanceThreshold) {
// @ts-expect-error
this.element.destinationPin = /** @type {KnotNodeTemplate} */(destinationPin.nodeElement.template).inputPin
}
}
}
const dx = Math.max(Math.abs(this.element.fromX - this.element.toX), 1)

View File

@@ -80,10 +80,6 @@ export default class NodeTemplate extends ISelectableDraggableTemplate {
createPinElements() {
return this.element.getPinEntities()
.filter(v => !v.isHidden())
.map(v => {
const pin = new PinElement(v)
pin.nodeElement = this.element
return pin
})
.map(v => new PinElement(v, undefined, this.element))
}
}

View File

@@ -26,7 +26,6 @@ export default class PinTemplate extends ITemplate {
constructed(element) {
super.constructed(element)
this.element.dataset.id = this.element.GetPinIdValue()
this.element.style.setProperty("--ueb-pin-color-rgb", Configuration.pinColor[this.element.pinType])
}
connectedCallback() {
@@ -91,6 +90,7 @@ export default class PinTemplate extends ITemplate {
/** @param {Map} changedProperties */
firstUpdated(changedProperties) {
super.firstUpdated(changedProperties)
this.element.style.setProperty("--ueb-pin-color-rgb", Configuration.pinColor[this.element.pinType])
this.#iconElement = this.element.querySelector(".ueb-pin-icon") ?? this.element
}