LinkedTo not shown by default, node name fixed

This commit is contained in:
barsdeveloper
2022-04-23 19:34:37 +02:00
parent 7f1a1b13d4
commit 81276a86be
9 changed files with 142 additions and 34 deletions

87
dist/ueblueprint.js vendored
View File

@@ -219,6 +219,32 @@ class IInput {
*/
class TypeInitialization {
/** @type {T} */
#value
get value() {
return this.#value
}
set value(v) {
this.#value = v;
}
#showDefault = true
get showDefault() {
return this.#showDefault
}
set showDefault(v) {
this.#showDefault = v;
}
/** @type {Constructor|Array<Constructor>} */
#type
get type() {
return this.#type
}
set type(v) {
this.#type = v;
}
static sanitize(value, targetType) {
if (targetType === undefined) {
targetType = value?.constructor;
@@ -237,17 +263,22 @@ class TypeInitialization {
}
/**
* @param {new () => T} type
* @typedef {new () => T} Constructor
* @param {Constructor|Array<Constructor>} type
* @param {Boolean} showDefault
* @param {any} value
*/
constructor(type, showDefault = true, value = undefined) {
if (value === undefined) {
value = TypeInitialization.sanitize(new type());
if (type instanceof Array) {
value = [];
} else {
value = TypeInitialization.sanitize(new type());
}
}
this.value = value;
this.showDefault = showDefault;
this.type = type;
this.#value = value;
this.#showDefault = showDefault;
this.#type = type;
}
}
@@ -334,7 +365,12 @@ class Utility {
static equals(a, b) {
a = TypeInitialization.sanitize(a);
b = TypeInitialization.sanitize(b);
return a === b
if (a === b) {
return true
}
if (a instanceof Array && b instanceof Array) {
return a.length == b.length && !a.find((value, i) => !Utility.equals(value, b[i]))
}
}
/**
@@ -348,8 +384,9 @@ class Utility {
let constructor = value?.constructor;
switch (constructor) {
case TypeInitialization:
return value.type
return Utility.getType(value.type)
case Function:
// value is already a constructor
return value
default:
return constructor
@@ -398,7 +435,14 @@ class Utility {
return value
.replace(/\n$/, "") // Remove trailing newline
.replaceAll("\u00A0", " ") // Replace special space symbol
.replaceAll("\n", "\\r\\n") // Replace newline with \r\n
.replaceAll("\n", String.raw`\r\n`) // Replace newline with \r\n
}
/**
* @param {String} value
*/
static formatStringName(value) {
return value.replaceAll(/\s+/g, " ").replaceAll(/(?<=[a-z])(?=[A-Z])|_/g, " ").trim()
}
}
@@ -424,11 +468,7 @@ class IEntity {
console.warn(`Property ${prefix}${property} is not defined in ${this.constructor.name}`);
}
let defaultValue = properties[property];
const defaultType = (defaultValue instanceof TypeInitialization)
? defaultValue.type
: (defaultValue instanceof Function)
? defaultValue
: defaultValue?.constructor;
const defaultType = Utility.getType(defaultValue);
// Not instanceof because all objects are instenceof Object, exact match needed
if (defaultType === Object) {
target[property] = {};
@@ -708,8 +748,8 @@ class PinEntity extends IEntity {
bIsWeakPointer: false,
bIsUObjectWrapper: false,
},
LinkedTo: [PinReferenceEntity],
DefaultValue: "",
LinkedTo: new TypeInitialization([PinReferenceEntity], false),
DefaultValue: new TypeInitialization(String, false),
AutogeneratedDefaultValue: "",
DefaultObject: new TypeInitialization(ObjectReferenceEntity, false, null),
PersistentGuid: GuidEntity,
@@ -897,7 +937,13 @@ class ObjectEntity extends IEntity {
}
getDisplayName() {
return this.getNameAndCounter()[0]
let name = this.FunctionReference?.MemberName;
if (name) {
name = Utility.formatStringName(name);
return name
}
name = Utility.formatStringName(this.getNameAndCounter()[0]);
return name
}
getCounter() {
@@ -928,6 +974,9 @@ class Grammar {
/* --- Factory --- */
static getGrammarForType(r, attributeType, defaultGrammar) {
if (attributeType instanceof TypeInitialization) {
attributeType = attributeType.type;
}
switch (Utility.getType(attributeType)) {
case Boolean:
return r.Boolean
@@ -3213,7 +3262,7 @@ class NodeTemplate extends SelectableDraggableTemplate {
<div class="ueb-node-name">
<span class="ueb-node-name-symbol"></span>
<span class="ueb-node-name-text">
${sanitizeText(node.getNodeName())}
${sanitizeText(node.getNodeDisplayName())}
</span>
</div>
</div>
@@ -3309,6 +3358,10 @@ class NodeElement extends ISelectableDraggableElement {
return this.entity.getFullName()
}
getNodeDisplayName() {
return this.entity.getDisplayName()
}
sanitizeLinks() {
this.getPinElements().forEach(pin => pin.sanitizeLinks());
}

View File

@@ -83,7 +83,12 @@ export default class Utility {
static equals(a, b) {
a = TypeInitialization.sanitize(a)
b = TypeInitialization.sanitize(b)
return a === b
if (a === b) {
return true
}
if (a instanceof Array && b instanceof Array) {
return a.length == b.length && !a.find((value, i) => !Utility.equals(value, b[i]))
}
}
/**
@@ -97,8 +102,9 @@ export default class Utility {
let constructor = value?.constructor
switch (constructor) {
case TypeInitialization:
return value.type
return Utility.getType(value.type)
case Function:
// value is already a constructor
return value
default:
return constructor
@@ -147,6 +153,13 @@ export default class Utility {
return value
.replace(/\n$/, "") // Remove trailing newline
.replaceAll("\u00A0", " ") // Replace special space symbol
.replaceAll("\n", "\\r\\n") // Replace newline with \r\n
.replaceAll("\n", String.raw`\r\n`) // Replace newline with \r\n
}
/**
* @param {String} value
*/
static formatStringName(value) {
return value.replaceAll(/\s+/g, " ").replaceAll(/(?<=[a-z])(?=[A-Z])|_/g, " ").trim()
}
}

View File

@@ -41,6 +41,10 @@ export default class NodeElement extends ISelectableDraggableElement {
return this.entity.getFullName()
}
getNodeDisplayName() {
return this.entity.getDisplayName()
}
sanitizeLinks() {
this.getPinElements().forEach(pin => pin.sanitizeLinks())
}

View File

@@ -23,11 +23,7 @@ export default class IEntity {
console.warn(`Property ${prefix}${property} is not defined in ${this.constructor.name}`)
}
let defaultValue = properties[property]
const defaultType = (defaultValue instanceof TypeInitialization)
? defaultValue.type
: (defaultValue instanceof Function)
? defaultValue
: defaultValue?.constructor
const defaultType = Utility.getType(defaultValue)
// Not instanceof because all objects are instenceof Object, exact match needed
if (defaultType === Object) {
target[property] = {}

View File

@@ -1,5 +1,6 @@
// @ts-check
import Utility from "../Utility"
import FunctionReferenceEntity from "./FunctionReferenceEntity"
import GuidEntity from "./GuidEntity"
import IdentifierEntity from "./IdentifierEntity"
@@ -66,7 +67,13 @@ export default class ObjectEntity extends IEntity {
}
getDisplayName() {
return this.getNameAndCounter()[0]
let name = this.FunctionReference?.MemberName
if (name) {
name = Utility.formatStringName(name)
return name
}
name = Utility.formatStringName(this.getNameAndCounter()[0])
return name
}
getCounter() {

View File

@@ -28,8 +28,8 @@ export default class PinEntity extends IEntity {
bIsWeakPointer: false,
bIsUObjectWrapper: false,
},
LinkedTo: [PinReferenceEntity],
DefaultValue: "",
LinkedTo: new TypeInitialization([PinReferenceEntity], false),
DefaultValue: new TypeInitialization(String, false),
AutogeneratedDefaultValue: "",
DefaultObject: new TypeInitialization(ObjectReferenceEntity, false, null),
PersistentGuid: GuidEntity,

View File

@@ -5,6 +5,32 @@
*/
export default class TypeInitialization {
/** @type {T} */
#value
get value() {
return this.#value
}
set value(v) {
this.#value = v
}
#showDefault = true
get showDefault() {
return this.#showDefault
}
set showDefault(v) {
this.#showDefault = v
}
/** @type {Constructor|Array<Constructor>} */
#type
get type() {
return this.#type
}
set type(v) {
this.#type = v
}
static sanitize(value, targetType) {
if (targetType === undefined) {
targetType = value?.constructor
@@ -23,16 +49,21 @@ export default class TypeInitialization {
}
/**
* @param {new () => T} type
* @typedef {new () => T} Constructor
* @param {Constructor|Array<Constructor>} type
* @param {Boolean} showDefault
* @param {any} value
*/
constructor(type, showDefault = true, value = undefined) {
if (value === undefined) {
value = TypeInitialization.sanitize(new type())
if (type instanceof Array) {
value = []
} else {
value = TypeInitialization.sanitize(new type())
}
}
this.value = value
this.showDefault = showDefault
this.type = type
this.#value = value
this.#showDefault = showDefault
this.#type = type
}
}

View File

@@ -13,6 +13,7 @@ import Parsimmon from "parsimmon"
import PathSymbolEntity from "../entity/PathSymbolEntity"
import PinEntity from "../entity/PinEntity"
import PinReferenceEntity from "../entity/PinReferenceEntity"
import TypeInitialization from "../entity/TypeInitialization"
import Utility from "../Utility"
let P = Parsimmon
@@ -22,6 +23,9 @@ export default class Grammar {
/* --- Factory --- */
static getGrammarForType(r, attributeType, defaultGrammar) {
if (attributeType instanceof TypeInitialization) {
attributeType = attributeType.type
}
switch (Utility.getType(attributeType)) {
case Boolean:
return r.Boolean

View File

@@ -24,7 +24,7 @@ export default class NodeTemplate extends SelectableDraggableTemplate {
<div class="ueb-node-name">
<span class="ueb-node-name-symbol"></span>
<span class="ueb-node-name-text">
${sanitizeText(node.getNodeName())}
${sanitizeText(node.getNodeDisplayName())}
</span>
</div>
</div>