mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-05-19 20:37:36 +08:00
Fix links on pasted nodes
This commit is contained in:
@@ -7,7 +7,15 @@ export default class IEntity {
|
||||
|
||||
static attributes = {}
|
||||
|
||||
constructor(options = {}) {
|
||||
constructor(options) {
|
||||
// @ts-expect-error
|
||||
const attributes = this.constructor.attributes
|
||||
if (options.constructor !== Object && Object.getOwnPropertyNames(attributes).length == 1) {
|
||||
// Where there is just one attribute, option can be the value of that attribute
|
||||
options = {
|
||||
[Object.getOwnPropertyNames(attributes)[0]]: options
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param {String[]} prefix
|
||||
* @param {Object} target
|
||||
@@ -18,8 +26,10 @@ export default class IEntity {
|
||||
const last = fullKey.length - 1
|
||||
for (let property of Object.getOwnPropertyNames(properties)) {
|
||||
fullKey[last] = property
|
||||
let defaultValue = properties[property]
|
||||
const defaultType = (defaultValue instanceof Function) ? defaultValue : defaultValue?.constructor
|
||||
// Not instanceof because all objects are instenceof Object, exact match needed
|
||||
if (properties[property]?.constructor === Object) {
|
||||
if (defaultType === Object) {
|
||||
target[property] = {}
|
||||
defineAllAttributes(fullKey, target[property], properties[property])
|
||||
continue
|
||||
@@ -33,10 +43,9 @@ export default class IEntity {
|
||||
*/
|
||||
const value = Utility.objectGet(options, fullKey)
|
||||
if (value !== undefined) {
|
||||
target[property] = value
|
||||
target[property] = TypeInitialization.sanitize(value, defaultType)
|
||||
continue
|
||||
}
|
||||
let defaultValue = properties[property]
|
||||
if (defaultValue instanceof TypeInitialization) {
|
||||
if (!defaultValue.showDefault) {
|
||||
target[property] = undefined // to preserve the order
|
||||
@@ -49,13 +58,12 @@ export default class IEntity {
|
||||
continue
|
||||
}
|
||||
if (defaultValue instanceof Function) {
|
||||
defaultValue = TypeInitialization.sanitize(new defaultValue())
|
||||
defaultValue = TypeInitialization.sanitize(new defaultValue(), defaultType)
|
||||
}
|
||||
target[property] = TypeInitialization.sanitize(defaultValue)
|
||||
target[property] = TypeInitialization.sanitize(defaultValue, defaultType)
|
||||
}
|
||||
}
|
||||
// @ts-expect-error
|
||||
defineAllAttributes([], this, this.constructor.attributes)
|
||||
defineAllAttributes([], this, attributes)
|
||||
}
|
||||
|
||||
empty() {
|
||||
|
||||
@@ -76,11 +76,11 @@ export default class PinEntity extends IEntity {
|
||||
}
|
||||
|
||||
isInput() {
|
||||
return !this.bHidden && this.Direction !== "EGPD_Output"
|
||||
return !this.bHidden && this.Direction != "EGPD_Output"
|
||||
}
|
||||
|
||||
isOutput() {
|
||||
return !this.bHidden && this.Direction === "EGPD_Output"
|
||||
return !this.bHidden && this.Direction == "EGPD_Output"
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,12 +5,19 @@
|
||||
*/
|
||||
export default class TypeInitialization {
|
||||
|
||||
static sanitize(value) {
|
||||
if (!(value instanceof Object)) {
|
||||
return value // Is already primitive
|
||||
static sanitize(value, targetType) {
|
||||
if (targetType === undefined) {
|
||||
targetType = value?.constructor
|
||||
}
|
||||
let wrongType = false
|
||||
if (targetType && value?.constructor !== targetType && !(value instanceof targetType)) {
|
||||
wrongType = true
|
||||
}
|
||||
if (value instanceof Boolean || value instanceof Number || value instanceof String) {
|
||||
return value.valueOf()
|
||||
value = value.valueOf() // Get the relative primitive value
|
||||
}
|
||||
if (wrongType) {
|
||||
return new targetType(value)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user