Files
ueblueprint/js/template/node/KnotNodeTemplate.js
BarsDev 6ba2705386 Large refactoring and new nodes
* Fix node reference when changing elements

* Fix ScriptVariables parsing

* Fix invariant text and niagara types

* Niagara convert nodes

* Move node tests to own files

* More Niagara tests

* Niagara float and smaller fixes

* More Decoding

* More decoding

* WIP

* Float is real

* WIP

* More types and colors

* Test case and small polish

* WIP

* WIP

* Fix niagara script variables merging

* Fix Niagara variables

* Fixing mirrored ExportPath

* Fix Export paths name adjustments

* Simplify arc calculation

* Simplify a bit arc calculation

* source / destionation => origin / target

* Minor refactoring

* Fix switched link position

* Rename some properties for uniformity

* Fix input escape

* Simplify test

* About window

* Dialog backdrop style

* About dialog touches

* Remove dependency and minot improvement

* Light mode

* Fix link location and css small improvement

* Link direction and minor fixes

* Some minor fixes and refactoring

* Refactoring WIP

* Shorting repetitive bits

* More tests

* Simplify linking tests
2025-02-07 00:36:03 +02:00

87 lines
2.8 KiB
JavaScript
Executable File

import { html } from "lit"
import ElementFactory from "../../element/ElementFactory.js"
import KnotPinTemplate from "../pin/KnotPinTemplate.js"
import NodeTemplate from "./NodeTemplate.js"
export default class KnotNodeTemplate extends NodeTemplate {
#switchDirectionsVisually = false
get switchDirectionsVisually() {
return this.#switchDirectionsVisually
}
set switchDirectionsVisually(value) {
if (this.#switchDirectionsVisually == value) {
return
}
this.#switchDirectionsVisually = value
this.element.acknowledgeUpdate()
}
/** @type {PinElement} */
#inputPin
get inputPin() {
return this.#inputPin
}
/** @type {PinElement} */
#outputPin
get outputPin() {
return this.#outputPin
}
/** @param {NodeElement} element */
initialize(element) {
super.initialize(element)
this.element.classList.add("ueb-node-style-minimal")
}
render() {
return html`
<div class="ueb-node-border"></div>
`
}
setupPins() {
for (const p of this.getPinElements()) {
/** @type {HTMLElement} */(this.element.querySelector(".ueb-node-border")).appendChild(p)
}
}
createPinElements() {
const entities = this.element.getPinEntities().filter(v => !v.isHidden())
const inputEntity = entities[entities[0].isInput() ? 0 : 1]
const outputEntity = entities[entities[0].isOutput() ? 0 : 1]
const pinElementConstructor = /** @type {PinElementConstructor} */(ElementFactory.getConstructor("ueb-pin"))
let result = [
this.#inputPin = pinElementConstructor.newObject(inputEntity, new KnotPinTemplate(), this.element),
this.#outputPin = pinElementConstructor.newObject(outputEntity, new KnotPinTemplate(), this.element),
]
return result
}
checkSwtichDirectionsVisually() {
let leftPinsDelta = 0
let leftPinsCount = 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()) {
rightPinsDelta += delta
++rightPinsCount
} else if (pin?.isOutput()) {
leftPinsDelta += delta
++leftPinsCount
}
}
leftPinsDelta /= leftPinsCount
rightPinsDelta /= rightPinsCount
if ((rightPinsDelta < leftPinsDelta) != this.switchDirectionsVisually) {
this.switchDirectionsVisually = rightPinsDelta < leftPinsDelta
}
}
}