mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +08:00
150 lines
5.5 KiB
JavaScript
Executable File
150 lines
5.5 KiB
JavaScript
Executable File
import { html, nothing } from "lit"
|
|
import ElementFactory from "../../element/ElementFactory.js"
|
|
import ISelectableDraggableTemplate from "../ISelectableDraggableTemplate.js"
|
|
import SVGIcon from "../../SVGIcon.js"
|
|
import Utility from "../../Utility.js"
|
|
|
|
/**
|
|
* @typedef {import("../../element/NodeElement.js").default} NodeElement
|
|
* @typedef {import("../../element/PinElement.js").default} PinElement
|
|
* @typedef {import("../../element/PinElement.js").PinElementConstructor} PinElementConstructor
|
|
* @typedef {import("lit").PropertyValues} PropertyValues
|
|
*/
|
|
|
|
/** @extends {ISelectableDraggableTemplate<NodeElement>} */
|
|
export default class NodeTemplate extends ISelectableDraggableTemplate {
|
|
|
|
/** @typedef {typeof NodeTemplate} NodeTemplateConstructor */
|
|
|
|
#hasSubtitle = false
|
|
|
|
static nodeStyleClasses = ["ueb-node-style-default"]
|
|
|
|
toggleAdvancedDisplayHandler = () => {
|
|
this.element.toggleShowAdvancedPinDisplay()
|
|
this.element.requestUpdate()
|
|
this.element.updateComplete.then(() => this.element.acknowledgeReflow())
|
|
}
|
|
|
|
/** @param {NodeElement} element */
|
|
initialize(element) {
|
|
super.initialize(element)
|
|
this.element.classList.add(.../** @type {NodeTemplateConstructor} */(this.constructor).nodeStyleClasses)
|
|
this.element.style.setProperty("--ueb-node-color", this.getColor().cssText)
|
|
}
|
|
|
|
getColor() {
|
|
return this.element.entity.nodeColor()
|
|
}
|
|
|
|
render() {
|
|
return html`
|
|
<div class="ueb-node-border">
|
|
<div class="ueb-node-wrapper">
|
|
<div class="ueb-node-top">${this.renderTop()}</div>
|
|
<div class="ueb-node-content">
|
|
<div class="ueb-node-inputs"></div>
|
|
<div class="ueb-node-outputs"></div>
|
|
</div>
|
|
${this.element.entity.isDevelopmentOnly() ? html`
|
|
<div class="ueb-node-developmentonly">
|
|
<span class="ueb-node-developmentonly-text">Development Only</span>
|
|
</div>
|
|
` : nothing}
|
|
${this.element.advancedPinDisplay ? html`
|
|
<div class="ueb-node-expansion" @click="${this.toggleAdvancedDisplayHandler}">
|
|
${SVGIcon.expandIcon}
|
|
</div>
|
|
` : nothing}
|
|
</div>
|
|
</div>
|
|
`
|
|
}
|
|
|
|
renderNodeIcon() {
|
|
return this.element.entity.nodeIcon()
|
|
}
|
|
|
|
renderNodeName() {
|
|
return this.element.getNodeDisplayName()
|
|
}
|
|
|
|
renderTop() {
|
|
const icon = this.renderNodeIcon()
|
|
const name = this.renderNodeName()
|
|
return html`
|
|
<div class="ueb-node-name">
|
|
${icon ? html`
|
|
<div class="ueb-node-name-symbol">${icon}</div>
|
|
` : nothing}
|
|
${name ? html`
|
|
<div class="ueb-node-name-text ueb-ellipsis-nowrap-text">
|
|
${name}
|
|
${this.#hasSubtitle && this.getTargetType().length > 0 ? html`
|
|
<div class="ueb-node-subtitle-text ueb-ellipsis-nowrap-text">
|
|
Target is ${Utility.formatStringName(this.getTargetType())}
|
|
</div>
|
|
`: nothing}
|
|
</div>
|
|
` : nothing}
|
|
</div>
|
|
`
|
|
}
|
|
|
|
/** @param {PropertyValues} changedProperties */
|
|
firstUpdated(changedProperties) {
|
|
super.firstUpdated(changedProperties)
|
|
this.setupPins()
|
|
this.element.updateComplete.then(() => this.element.acknowledgeReflow())
|
|
}
|
|
|
|
setupPins() {
|
|
const inputContainer = /** @type {HTMLElement} */(this.element.querySelector(".ueb-node-inputs"))
|
|
const outputContainer = /** @type {HTMLElement} */(this.element.querySelector(".ueb-node-outputs"))
|
|
this.element.nodeNameElement = /** @type {HTMLElement} */(this.element.querySelector(".ueb-node-name-text"))
|
|
let hasInput = false
|
|
let hasOutput = false
|
|
this.element.getPinElements().forEach(p => {
|
|
if (p.isInput()) {
|
|
inputContainer.appendChild(p)
|
|
hasInput = true
|
|
} else if (p.isOutput()) {
|
|
outputContainer.appendChild(p)
|
|
hasOutput = true
|
|
}
|
|
})
|
|
if (hasInput) {
|
|
this.element.classList.add("ueb-node-has-inputs")
|
|
}
|
|
if (hasOutput) {
|
|
this.element.classList.add("ueb-node-has-outputs")
|
|
}
|
|
}
|
|
|
|
createPinElements() {
|
|
return this.element.getPinEntities()
|
|
.filter(v => !v.isHidden())
|
|
.map(pinEntity => {
|
|
this.#hasSubtitle = this.#hasSubtitle
|
|
|| pinEntity.PinName === "self" && pinEntity.pinDisplayName() === "Target"
|
|
let pinElement = /** @type {PinElementConstructor} */(ElementFactory.getConstructor("ueb-pin"))
|
|
.newObject(pinEntity, undefined, this.element)
|
|
return pinElement
|
|
})
|
|
}
|
|
|
|
getTargetType() {
|
|
return this.element.entity.FunctionReference?.MemberParent?.getName() ?? "Untitled"
|
|
}
|
|
|
|
/**
|
|
* @param {NodeElement} node
|
|
* @returns {NodeListOf<PinElement>}
|
|
*/
|
|
getPinElements(node) {
|
|
return node.querySelectorAll("ueb-pin")
|
|
}
|
|
|
|
linksChanged() { }
|
|
}
|