Link direction and minor fixes

This commit is contained in:
barsdeveloper
2025-01-27 22:29:52 +02:00
parent dd81356d68
commit 1073691794
11 changed files with 94 additions and 131 deletions

View File

@@ -283,12 +283,12 @@ export default class LinkElement extends IFromToPositionedElement {
this.origin = pin
}
/** @param {NodeElement} pin */
getOtherPin(pin) {
if (this.origin?.nodeElement === pin) {
/** @param {NodeElement} node */
getOtherPin(node) {
if (this.origin?.nodeElement === node) {
return this.target
}
if (this.target?.nodeElement === pin) {
if (this.target?.nodeElement === node) {
return this.origin
}
}

View File

@@ -164,9 +164,7 @@ export default class PinElement extends IElement {
/** @type {PinElement} */
let result = this
if (ignoreKnots) {
if (ignoreKnots) {
return this.#traverseKnots(result)?.isOutput()
}
return this.#traverseKnots(result)?.isOutput()
}
return result.entity.isOutput()
}
@@ -242,12 +240,13 @@ export default class PinElement extends IElement {
const pinReference = this.createPinReference()
if (
this.isLinked
&& (
this.isInput(true)
|| this.isOutput(true) && (this.entity.isExecution() || targetPinElement.entity.isExecution())
)
&& !this.getLinks().some(ref => pinReference.equals(ref))
&& this.entity.isExecution()
&& this.isOutput(true)
&& this.getLinks().some(ref => !pinReference.equals(ref))
) {
if (this.isKnot()) {
}
this.unlinkFromAll()
}
if (this.entity.linkTo(targetPinElement.getNodeElement().getNodeName(), targetPinElement.entity)) {

View File

@@ -72,14 +72,14 @@ export default class LinkTemplate extends IFromToPositionedTemplate {
const to = this.element.targetX
// Switch actual input/output pins if allowed and makes sense
if (isOriginAKnot && (!targetPin || isTargetAKnot)) {
if (isOriginAKnot && !targetPin) {
if (originPin?.isInputLoosely() && to > from + Configuration.distanceThreshold) {
this.element.origin = /** @type {KnotPinTemplate} */(originPin.template).getoppositePin()
} else if (originPin?.isOutputLoosely() && to < from - Configuration.distanceThreshold) {
this.element.origin = /** @type {KnotPinTemplate} */(originPin.template).getoppositePin()
}
}
if (isTargetAKnot && (!originPin || isOriginAKnot)) {
if (isTargetAKnot && !originPin) {
if (targetPin?.isInputLoosely() && to < from - Configuration.distanceThreshold) {
this.element.target = /** @type {KnotPinTemplate} */(targetPin.template).getoppositePin()
} else if (targetPin?.isOutputLoosely() && to > from + Configuration.distanceThreshold) {
@@ -90,15 +90,11 @@ export default class LinkTemplate extends IFromToPositionedTemplate {
// Switch visual input/output pins if allowed and makes sense
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
if (originPin.isKnot() && originPin.hasUpdated) {
/** @type {KnotNodeTemplate} */(originPin.nodeElement.template).checkSwtichDirectionsVisually()
}
if (directionsCheckedKnot && directionsCheckedKnot.hasUpdated) {
/** @type {KnotNodeTemplate} */(directionsCheckedKnot.template).checkSwtichDirectionsVisually()
if (targetPin.isKnot() && targetPin.hasUpdated) {
/** @type {KnotNodeTemplate} */(targetPin.nodeElement.template).checkSwtichDirectionsVisually()
}
}

View File

@@ -60,25 +60,27 @@ export default class KnotNodeTemplate extends NodeTemplate {
}
checkSwtichDirectionsVisually() {
let leftPinsLocation = 0
let leftPinsDelta = 0
let leftPinsCount = 0
let rightPinsLocation = 0
let rightPinsDelta = 0
let rightPinsCount = 0
const location = this.outputPin.getLinkLocation()[0]
const links = this.getAllConnectedLinks()
for (const link of links) {
const pin = link.getOtherPin(this.element)
const delta = pin.getLinkLocation()[0] - location
if (pin?.isInput()) {
rightPinsLocation += pin.getLinkLocation()[0]
rightPinsDelta += delta
++rightPinsCount
} else if (pin?.isOutput()) {
leftPinsLocation += pin.getLinkLocation()[0]
leftPinsDelta += delta
++leftPinsCount
}
}
leftPinsLocation /= leftPinsCount
rightPinsLocation /= rightPinsCount
if ((rightPinsLocation < leftPinsLocation) != this.switchDirectionsVisually) {
this.switchDirectionsVisually = rightPinsLocation < leftPinsLocation
leftPinsDelta /= leftPinsCount
rightPinsDelta /= rightPinsCount
if ((rightPinsDelta < leftPinsDelta) != this.switchDirectionsVisually) {
this.switchDirectionsVisually = rightPinsDelta < leftPinsDelta
}
}
}

View File

@@ -40,7 +40,9 @@ export default class BoolPinTemplate extends PinTemplate {
renderInput() {
return html`
<input type="checkbox" class="ueb-pin-input-wrapper ueb-pin-input" ?checked="${this.element.defaultValue?.valueOf() === true}" />
<input type="checkbox" class="ueb-pin-input-wrapper ueb-pin-input"
?checked="${this.element.defaultValue?.valueOf() === true}"
/>
`
}
}

View File

@@ -42,7 +42,8 @@ export default class LinearColorPinTemplate extends PinTemplate {
renderInput() {
return html`
<span class="ueb-pin-input-wrapper ueb-pin-input" data-linear-color="${this.element.getDefaultValue()?.toString() ?? nothing}"
<span class="ueb-pin-input-wrapper ueb-pin-input"
data-linear-color="${this.element.getDefaultValue()?.toString() ?? nothing}"
@click="${this.#launchColorPickerWindow}"
style="--ueb-linear-color: rgba(${this.element.getDefaultValue()?.toString() ?? nothing})">
</span>