mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-05-17 10:17:29 +08:00
Link direction and minor fixes
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}"
|
||||
/>
|
||||
`
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user