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 { 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) { static sanitize(value, targetType) {
if (targetType === undefined) { if (targetType === undefined) {
targetType = value?.constructor; 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 {Boolean} showDefault
* @param {any} value * @param {any} value
*/ */
constructor(type, showDefault = true, value = undefined) { constructor(type, showDefault = true, value = undefined) {
if (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.#value = value;
this.showDefault = showDefault; this.#showDefault = showDefault;
this.type = type; this.#type = type;
} }
} }
@@ -334,7 +365,12 @@ class Utility {
static equals(a, b) { static equals(a, b) {
a = TypeInitialization.sanitize(a); a = TypeInitialization.sanitize(a);
b = TypeInitialization.sanitize(b); 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; let constructor = value?.constructor;
switch (constructor) { switch (constructor) {
case TypeInitialization: case TypeInitialization:
return value.type return Utility.getType(value.type)
case Function: case Function:
// value is already a constructor
return value return value
default: default:
return constructor return constructor
@@ -398,7 +435,14 @@ class Utility {
return value return value
.replace(/\n$/, "") // Remove trailing newline .replace(/\n$/, "") // Remove trailing newline
.replaceAll("\u00A0", " ") // Replace special space symbol .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}`); console.warn(`Property ${prefix}${property} is not defined in ${this.constructor.name}`);
} }
let defaultValue = properties[property]; let defaultValue = properties[property];
const defaultType = (defaultValue instanceof TypeInitialization) const defaultType = Utility.getType(defaultValue);
? defaultValue.type
: (defaultValue instanceof Function)
? defaultValue
: defaultValue?.constructor;
// Not instanceof because all objects are instenceof Object, exact match needed // Not instanceof because all objects are instenceof Object, exact match needed
if (defaultType === Object) { if (defaultType === Object) {
target[property] = {}; target[property] = {};
@@ -708,8 +748,8 @@ class PinEntity extends IEntity {
bIsWeakPointer: false, bIsWeakPointer: false,
bIsUObjectWrapper: false, bIsUObjectWrapper: false,
}, },
LinkedTo: [PinReferenceEntity], LinkedTo: new TypeInitialization([PinReferenceEntity], false),
DefaultValue: "", DefaultValue: new TypeInitialization(String, false),
AutogeneratedDefaultValue: "", AutogeneratedDefaultValue: "",
DefaultObject: new TypeInitialization(ObjectReferenceEntity, false, null), DefaultObject: new TypeInitialization(ObjectReferenceEntity, false, null),
PersistentGuid: GuidEntity, PersistentGuid: GuidEntity,
@@ -897,7 +937,13 @@ class ObjectEntity extends IEntity {
} }
getDisplayName() { 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() { getCounter() {
@@ -928,6 +974,9 @@ class Grammar {
/* --- Factory --- */ /* --- Factory --- */
static getGrammarForType(r, attributeType, defaultGrammar) { static getGrammarForType(r, attributeType, defaultGrammar) {
if (attributeType instanceof TypeInitialization) {
attributeType = attributeType.type;
}
switch (Utility.getType(attributeType)) { switch (Utility.getType(attributeType)) {
case Boolean: case Boolean:
return r.Boolean return r.Boolean
@@ -3213,7 +3262,7 @@ class NodeTemplate extends SelectableDraggableTemplate {
<div class="ueb-node-name"> <div class="ueb-node-name">
<span class="ueb-node-name-symbol"></span> <span class="ueb-node-name-symbol"></span>
<span class="ueb-node-name-text"> <span class="ueb-node-name-text">
${sanitizeText(node.getNodeName())} ${sanitizeText(node.getNodeDisplayName())}
</span> </span>
</div> </div>
</div> </div>
@@ -3309,6 +3358,10 @@ class NodeElement extends ISelectableDraggableElement {
return this.entity.getFullName() return this.entity.getFullName()
} }
getNodeDisplayName() {
return this.entity.getDisplayName()
}
sanitizeLinks() { sanitizeLinks() {
this.getPinElements().forEach(pin => pin.sanitizeLinks()); this.getPinElements().forEach(pin => pin.sanitizeLinks());
} }

View File

@@ -83,7 +83,12 @@ export default class Utility {
static equals(a, b) { static equals(a, b) {
a = TypeInitialization.sanitize(a) a = TypeInitialization.sanitize(a)
b = TypeInitialization.sanitize(b) 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 let constructor = value?.constructor
switch (constructor) { switch (constructor) {
case TypeInitialization: case TypeInitialization:
return value.type return Utility.getType(value.type)
case Function: case Function:
// value is already a constructor
return value return value
default: default:
return constructor return constructor
@@ -147,6 +153,13 @@ export default class Utility {
return value return value
.replace(/\n$/, "") // Remove trailing newline .replace(/\n$/, "") // Remove trailing newline
.replaceAll("\u00A0", " ") // Replace special space symbol .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() return this.entity.getFullName()
} }
getNodeDisplayName() {
return this.entity.getDisplayName()
}
sanitizeLinks() { sanitizeLinks() {
this.getPinElements().forEach(pin => pin.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}`) console.warn(`Property ${prefix}${property} is not defined in ${this.constructor.name}`)
} }
let defaultValue = properties[property] let defaultValue = properties[property]
const defaultType = (defaultValue instanceof TypeInitialization) const defaultType = Utility.getType(defaultValue)
? defaultValue.type
: (defaultValue instanceof Function)
? defaultValue
: defaultValue?.constructor
// Not instanceof because all objects are instenceof Object, exact match needed // Not instanceof because all objects are instenceof Object, exact match needed
if (defaultType === Object) { if (defaultType === Object) {
target[property] = {} target[property] = {}

View File

@@ -1,5 +1,6 @@
// @ts-check // @ts-check
import Utility from "../Utility"
import FunctionReferenceEntity from "./FunctionReferenceEntity" import FunctionReferenceEntity from "./FunctionReferenceEntity"
import GuidEntity from "./GuidEntity" import GuidEntity from "./GuidEntity"
import IdentifierEntity from "./IdentifierEntity" import IdentifierEntity from "./IdentifierEntity"
@@ -66,7 +67,13 @@ export default class ObjectEntity extends IEntity {
} }
getDisplayName() { 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() { getCounter() {

View File

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

View File

@@ -5,6 +5,32 @@
*/ */
export default class TypeInitialization { 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) { static sanitize(value, targetType) {
if (targetType === undefined) { if (targetType === undefined) {
targetType = value?.constructor 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 {Boolean} showDefault
* @param {any} value * @param {any} value
*/ */
constructor(type, showDefault = true, value = undefined) { constructor(type, showDefault = true, value = undefined) {
if (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.#value = value
this.showDefault = showDefault this.#showDefault = showDefault
this.type = type this.#type = type
} }
} }

View File

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

View File

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