Some minor fixes and refactoring

This commit is contained in:
barsdeveloper
2025-01-31 00:22:11 +02:00
parent 1073691794
commit 0e2ecdf93e
26 changed files with 290 additions and 87 deletions

View File

@@ -151,6 +151,7 @@ export default class Configuration {
isValid: "/Engine/EditorBlueprintResources/StandardMacros.StandardMacros:IsValid",
kismetArrayLibrary: "/Script/Engine.KismetArrayLibrary",
kismetMathLibrary: "/Script/Engine.KismetMathLibrary",
kismetStringLibrary: "/Script/Engine.KismetStringLibrary",
knot: "/Script/BlueprintGraph.K2Node_Knot",
linearColor: "/Script/CoreUObject.LinearColor",
literal: "/Script/BlueprintGraph.K2Node_Literal",

View File

@@ -31,10 +31,6 @@ export default function nodeColor(entity) {
}
}
switch (entity.getClass()) {
case Configuration.paths.callFunction:
return entity.bIsPureFunc?.valueOf()
? Configuration.nodeColors.green
: Configuration.nodeColors.blue
case Configuration.paths.niagaraNodeFunctionCall:
return Configuration.nodeColors.darkerBlue
case Configuration.paths.dynamicCast:
@@ -82,7 +78,7 @@ export default function nodeColor(entity) {
return Configuration.nodeColors.intenseGreen
}
}
if (entity.bIsPureFunc?.valueOf()) {
if (entity.bIsPureFunc?.valueOf() || entity.bDefaultsToPureFunc?.valueOf()) {
return Configuration.nodeColors.green
}
if (entity["Input"]?.["Name"]) {

View File

@@ -78,10 +78,11 @@ const paths = Configuration.paths
* @return {new () => NodeTemplate}
*/
export default function nodeTemplateClass(nodeEntity) {
const className = nodeEntity.getClass()
if (
nodeEntity.getClass() === paths.callFunction
|| nodeEntity.getClass() === paths.commutativeAssociativeBinaryOperator
|| nodeEntity.getClass() === paths.callArrayFunction
className === paths.callFunction
|| className === paths.commutativeAssociativeBinaryOperator
|| className === paths.callArrayFunction
) {
const memberParent = nodeEntity.FunctionReference?.MemberParent?.path ?? ""
const memberName = nodeEntity.FunctionReference?.MemberName?.toString()
@@ -89,6 +90,7 @@ export default function nodeTemplateClass(nodeEntity) {
memberName && (
memberParent === paths.kismetMathLibrary
|| memberParent === paths.kismetArrayLibrary
|| memberParent === paths.kismetStringLibrary
)) {
if (memberName.startsWith("Conv_")) {
return VariableConversionNodeTemplate
@@ -148,7 +150,7 @@ export default function nodeTemplateClass(nodeEntity) {
return VariableOperationNodeTemplate
}
}
switch (nodeEntity.getClass()) {
switch (className) {
case paths.comment:
case paths.materialGraphNodeComment:
return CommentNodeTemplate

View File

@@ -372,6 +372,7 @@ export default function nodeTitle(entity) {
switch (memberParent) {
case paths.blueprintGameplayTagLibrary:
case paths.kismetMathLibrary:
case paths.kismetStringLibrary:
case paths.slateBlueprintLibrary:
case paths.timeManagementBlueprintLibrary:
const leadingLetter = memberName.match(/[BF]([A-Z]\w+)/)

View File

@@ -7,6 +7,7 @@ import IntPinTemplate from "../template/pin/IntPinTemplate.js"
import LinearColorPinTemplate from "../template/pin/LinearColorPinTemplate.js"
import NamePinTemplate from "../template/pin/NamePinTemplate.js"
import PinTemplate from "../template/pin/PinTemplate.js"
import ReadonlyNamePinTemplate from "../template/pin/ReadonlyInputPinTemplate.js"
import RealPinTemplate from "../template/pin/RealPinTemplate.js"
import ReferencePinTemplate from "../template/pin/ReferencePinTemplate.js"
import RotatorPinTemplate from "../template/pin/RotatorPinTemplate.js"
@@ -14,6 +15,7 @@ import StringPinTemplate from "../template/pin/StringPinTemplate.js"
import Vector2DPinTemplate from "../template/pin/Vector2DPinTemplate.js"
import Vector4DPinTemplate from "../template/pin/Vector4DPinTemplate.js"
import VectorPinTemplate from "../template/pin/VectorPinTemplate.js"
import pinTitle from "./pinTitle.js"
const inputPinTemplates = {
"bool": BoolPinTemplate,
@@ -51,6 +53,9 @@ export default function pinTemplate(entity) {
if (entity.isExecution()) {
return ExecPinTemplate
}
if (entity.PinName?.toString() === "self" && pinTitle(entity) === "Target") {
return ReadonlyNamePinTemplate
}
const type = entity.getType()
return (entity.isInput() ? inputPinTemplates[type] : PinTemplate) ?? PinTemplate
}

View File

@@ -98,8 +98,8 @@ export default class PinElement extends IElement {
this.pinId = this.entity.PinId
this.pinType = this.entity.getType()
this.defaultValue = this.entity.getDefaultValue()
this.color = PinElement.properties.color.converter.fromAttribute(this.getColor().toString())
this.pinDirection = entity.isInput() ? "input" : entity.isOutput() ? "output" : "hidden"
this.updateColor()
}
setup() {
@@ -107,6 +107,10 @@ export default class PinElement extends IElement {
this.nodeElement = this.closest("ueb-node")
}
updateColor() {
this.color = PinElement.properties.color.converter.fromAttribute(this.entity.pinColor().toString())
}
createPinReference() {
return new PinReferenceEntity(new SymbolEntity(this.nodeElement.getNodeName()), this.getPinId())
}
@@ -123,11 +127,6 @@ export default class PinElement extends IElement {
return this.entity.pinTitle()
}
/** @return {CSSResult} */
getColor() {
return this.entity.pinColor()
}
/** @param {PinElement} pin */
#traverseKnots(pin) {
while (pin?.isKnot()) {
@@ -271,8 +270,8 @@ export default class PinElement extends IElement {
}
unlinkFromAll() {
const isLinked = this.getLinks().length
this.getLinks().map(ref => this.blueprint.getPin(ref)).forEach(pin => this.unlinkFrom(pin))
const isLinked = false
}
/**

View File

@@ -63,6 +63,7 @@ export default class ObjectEntity extends IEntity {
bIsPureFunc: BooleanEntity,
bIsConstFunc: BooleanEntity,
bIsCaseSensitive: BooleanEntity,
bDefaultsToPureFunc: BooleanEntity,
VariableReference: VariableReferenceEntity,
SelfContextInfo: SymbolEntity,
DelegatePropertyName: StringEntity,
@@ -213,6 +214,7 @@ export default class ObjectEntity extends IEntity {
/** @type {InstanceType<typeof ObjectEntity.attributes.Archetype>} */ this.Archetype
/** @type {InstanceType<typeof ObjectEntity.attributes.AxisKey>} */ this.AxisKey
/** @type {InstanceType<typeof ObjectEntity.attributes.bIsPureFunc>} */ this.bIsPureFunc
/** @type {InstanceType<typeof ObjectEntity.attributes.bDefaultsToPureFunc>} */ this.bDefaultsToPureFunc
/** @type {InstanceType<typeof ObjectEntity.attributes.BlueprintElementInstance>} */ this.BlueprintElementInstance
/** @type {InstanceType<typeof ObjectEntity.attributes.BlueprintElementType>} */ this.BlueprintElementType
/** @type {InstanceType<typeof ObjectEntity.attributes.Class>} */ this.Class

View File

@@ -14,9 +14,6 @@ export default class MouseCreateLink extends IMouseClickDrag {
/** @type {NodeListOf<PinElement>} */
#listenedPins
/** @type {PinElement} */
#knotPin = null
/** @param {MouseEvent} e */
#mouseenterHandler = e => {
if (!this.enteredPin) {
@@ -80,9 +77,6 @@ export default class MouseCreateLink extends IMouseClickDrag {
}
startDrag(location) {
if (this.target.isKnot()) {
this.#knotPin = this.target
}
/** @type {LinkElement} */
this.link = /** @type {LinkElementConstructor} */(ElementFactory.getConstructor("ueb-link"))
.newObject(this.target, null)
@@ -110,20 +104,22 @@ export default class MouseCreateLink extends IMouseClickDrag {
})
this.#listenedPins = null
if (this.enteredPin && this.linkValid) {
const knot = this.enteredPin.isKnot()
? this.enteredPin
: this.link.origin.isKnot() ? this.link.origin : null
// Knot can use wither the input or output (by default) part indifferently, check if a switch is needed
if (this.#knotPin) {
const otherPin = this.#knotPin !== this.link.origin ? this.link.origin : this.enteredPin
if (knot) {
const otherPin = knot !== this.link.origin ? this.link.origin : this.enteredPin
// Knot pin direction correction
if (this.#knotPin.isInput() && otherPin.isInput() || this.#knotPin.isOutput() && otherPin.isOutput()) {
const oppositePin = /** @type {KnotPinTemplate} */(this.#knotPin.template).getoppositePin()
if (this.#knotPin === this.link.origin) {
if (knot.isInput() && otherPin.isInput() || knot.isOutput() && otherPin.isOutput()) {
const oppositePin = /** @type {KnotPinTemplate} */(knot.template).getoppositePin()
if (knot === this.link.origin) {
this.link.origin = oppositePin
} else {
this.enteredPin = oppositePin
}
}
} else if (this.enteredPin.isKnot()) {
this.#knotPin = this.enteredPin
if (this.link.origin.isOutput()) {
// Knot uses by default the output pin, let's switch to keep it coherent with the origin node we have
this.enteredPin = /** @type {KnotPinTemplate} */(this.enteredPin.template).getoppositePin()
@@ -142,6 +138,5 @@ export default class MouseCreateLink extends IMouseClickDrag {
this.link.removeMessage()
this.link.finishDragging()
this.link = null
this.#knotPin = null
}
}

View File

@@ -13,7 +13,7 @@ export default class CommentNodeTemplate extends IResizeableTemplate {
element.classList.add("ueb-node-style-comment", "ueb-node-resizeable")
element.sizeX = 25 * Configuration.gridSize
element.sizeY = 6 * Configuration.gridSize
super.initialize(element) // Keep it at the end because it calls this.getColor() where this.#color must be initialized
super.initialize(element) // Keep it at the end because it needs the color. this.#color must be initialized
}
/** @returns {HTMLElement} */

View File

@@ -35,6 +35,17 @@ export default class KnotNodeTemplate extends NodeTemplate {
this.element.classList.add("ueb-node-style-minimal")
}
/** @param {PropertyValues} changedProperties */
update(changedProperties) {
super.update(changedProperties)
if (!this.#inputPin.isLinked && !this.#outputPin.isLinked) {
this.#inputPin.entity.PinType.PinCategory.value = "wildcard"
this.#inputPin.updateColor()
this.#outputPin.entity.PinType.PinCategory.value = "wildcard"
this.#inputPin.updateColor()
}
}
render() {
return html`
<div class="ueb-node-border"></div>

View File

@@ -57,17 +57,13 @@ export default class NodeTemplate extends ISelectableDraggableTemplate {
super.initialize(element)
this.#subtitle = nodeSubtitle(element.entity)
this.element.classList.add(.../** @type {typeof NodeTemplate} */(this.constructor).nodeStyleClasses)
this.element.style.setProperty("--ueb-node-color", this.getColor().cssText)
this.element.style.setProperty("--ueb-node-color", this.element.entity.nodeColor().cssText)
this.pinInserter = this.element.entity.additionalPinInserter()
if (this.pinInserter) {
this.element.classList.add("ueb-node-is-variadic")
}
}
getColor() {
return this.element.entity.nodeColor()
}
render() {
return html`
<div class="ueb-node-border">

View File

@@ -21,6 +21,6 @@ export default class VariableAccessNodeTemplate extends VariableManagementNodeTe
setupPins() {
super.setupPins()
let outputPin = this.element.getPinElements().find(p => !p.entity.isHidden() && !p.entity.isExecution())
this.element.style.setProperty("--ueb-node-color", outputPin.getColor().cssText)
this.element.style.setProperty("--ueb-node-color", outputPin.entity.pinColor().cssText)
}
}

View File

@@ -32,7 +32,9 @@ export default class InputTemplate extends ITemplate {
super.initialize(element)
this.element.classList.add("ueb-pin-input-content")
this.element.setAttribute("role", "textbox")
this.element.contentEditable = "true"
if (this.element.contentEditable !== "false") {
this.element.contentEditable = "true"
}
}
/** @param {PropertyValues} changedProperties */

View File

@@ -1,5 +0,0 @@
import MinimalPinTemplate from "./MinimalPinTemplate.js"
export default class InternalPinTemplate extends MinimalPinTemplate {
}

View File

@@ -0,0 +1,19 @@
import { html } from "lit"
import PinTemplate from "./PinTemplate.js"
/** @extends PinTemplate<StringEntity> */
export default class ReadonlyNamePinTemplate extends PinTemplate {
setDefaultValue(values = [], rawValues = values) {
}
renderInput() {
return html`
<div class="ueb-pin-input-wrapper ueb-pin-input">
<ueb-input contenteditable="false" .singleLine="${true}" .selectOnFocus="${false}"
.innerText="${this.element.entity.PinName.toString()}">
</ueb-input>
</div>
`
}
}