mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-28 03:24:43 +08:00
Entities cleanup, Primitive concept introduced
This commit is contained in:
@@ -9,14 +9,14 @@ export default class Entity {
|
||||
* @param {Object} target
|
||||
* @param {Object} properties
|
||||
*/
|
||||
const defineAllAttributes = (prefix, target, properties, propertySetter = (t, p, v) => t[p] = v) => {
|
||||
const defineAllAttributes = (prefix, target, properties) => {
|
||||
let fullKey = prefix.concat("")
|
||||
const last = fullKey.length - 1
|
||||
for (let property in properties) {
|
||||
fullKey[last] = property
|
||||
// Not instanceof because all objects are instenceof Object
|
||||
// Not instanceof because all objects are instenceof Object, exact match needed
|
||||
if (properties[property]?.constructor === Object) {
|
||||
propertySetter(target, property, {})
|
||||
target[property] = {}
|
||||
defineAllAttributes(fullKey, target[property], properties[property])
|
||||
continue
|
||||
}
|
||||
@@ -29,7 +29,7 @@ export default class Entity {
|
||||
*/
|
||||
const value = Utility.objectGet(options, fullKey)
|
||||
if (value !== null) {
|
||||
propertySetter(target, property, value)
|
||||
target[property] = value
|
||||
continue
|
||||
}
|
||||
let defaultValue = properties[property]
|
||||
@@ -40,18 +40,13 @@ export default class Entity {
|
||||
defaultValue = defaultValue.value
|
||||
}
|
||||
if (defaultValue instanceof Array) {
|
||||
propertySetter(target, property, [])
|
||||
defineAllAttributes(
|
||||
fullKey,
|
||||
target[property],
|
||||
defaultValue,
|
||||
(t, _, v) => t.push(v))
|
||||
target[property] = []
|
||||
continue
|
||||
}
|
||||
if (defaultValue instanceof Function) {
|
||||
defaultValue = Utility.sanitize(new defaultValue())
|
||||
}
|
||||
propertySetter(target, property, defaultValue)
|
||||
target[property] = defaultValue
|
||||
}
|
||||
}
|
||||
defineAllAttributes([], this, this.getAttributes())
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import Entity from "./Entity"
|
||||
import ObjectReferenceEntity from "./ObjectReferenceEntity"
|
||||
import ObjectReference from "./primitive/ObjectReference"
|
||||
|
||||
export default class FunctionReferenceEntity extends Entity {
|
||||
static attributes = {
|
||||
MemberParent: ObjectReferenceEntity,
|
||||
MemberParent: ObjectReference,
|
||||
MemberName: ""
|
||||
}
|
||||
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
import Entity from "./Entity";
|
||||
|
||||
export default class GuidEntity extends Entity {
|
||||
|
||||
static attributes = {
|
||||
value: String
|
||||
}
|
||||
|
||||
static generateGuid(random) {
|
||||
let values = new Uint32Array(4);
|
||||
if (random === true) {
|
||||
crypto.getRandomValues(values)
|
||||
}
|
||||
let result = ""
|
||||
values.forEach(n => {
|
||||
result += ('00000000' + n.toString(16).toUpperCase()).slice(-8)
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
constructor(guid) {
|
||||
if (guid?.constructor === String) {
|
||||
guid = {
|
||||
value: guid
|
||||
}
|
||||
} else if (guid?.constructor === Boolean) {
|
||||
guid = {
|
||||
value: GuidEntity.generateGuid(guid == true)
|
||||
}
|
||||
}
|
||||
super(guid)
|
||||
}
|
||||
|
||||
getAttributes() {
|
||||
return GuidEntity.attributes
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import Entity from "./Entity"
|
||||
|
||||
export default class Integer extends Entity {
|
||||
|
||||
static attributes = {
|
||||
value: 0
|
||||
}
|
||||
|
||||
constructor(value) {
|
||||
if (value?.constructor === String) {
|
||||
value = Number(value)
|
||||
}
|
||||
if (value?.constructor === Number) {
|
||||
value = {
|
||||
value: Math.round(value.valueOf())
|
||||
}
|
||||
}
|
||||
super(value)
|
||||
}
|
||||
|
||||
getAttributes() {
|
||||
return Integer.attributes
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import Entity from "./Entity"
|
||||
|
||||
export default class LocalizedTextEntity extends Entity {
|
||||
|
||||
static attributes = {
|
||||
namespace: "",
|
||||
key: "",
|
||||
value: ""
|
||||
}
|
||||
|
||||
getAttributes() {
|
||||
return LocalizedTextEntity.attributes
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
import Entity from "./Entity"
|
||||
import FunctionReferenceEntity from "./FunctionReferenceEntity"
|
||||
import GuidEntity from "./GuidEntity"
|
||||
import Integer from "./Integer"
|
||||
import ObjectReferenceEntity from "./ObjectReferenceEntity"
|
||||
import Guid from "./primitive/Guid"
|
||||
import ObjectReference from "./primitive/ObjectReference"
|
||||
import PinEntity from "./PinEntity"
|
||||
import TypeInitialization from "./TypeInitialization"
|
||||
import VariableReferenceEntity from "./VariableReferenceEntity"
|
||||
@@ -10,16 +9,16 @@ import VariableReferenceEntity from "./VariableReferenceEntity"
|
||||
export default class ObjectEntity extends Entity {
|
||||
|
||||
static attributes = {
|
||||
Class: ObjectReferenceEntity,
|
||||
Class: ObjectReference,
|
||||
Name: "",
|
||||
bIsPureFunc: new TypeInitialization(false, false),
|
||||
VariableReference: new TypeInitialization(null, false, VariableReferenceEntity),
|
||||
FunctionReference: new TypeInitialization(null, false, FunctionReferenceEntity),
|
||||
TargetType: new TypeInitialization(null, false, ObjectReferenceEntity),
|
||||
bIsPureFunc: new TypeInitialization(Boolean, false, false),
|
||||
VariableReference: new TypeInitialization(VariableReferenceEntity, false, null),
|
||||
FunctionReference: new TypeInitialization(FunctionReferenceEntity, false, null,),
|
||||
TargetType: new TypeInitialization(ObjectReference, false, null),
|
||||
NodePosX: 0,
|
||||
NodePosY: 0,
|
||||
NodeGuid: GuidEntity,
|
||||
CustomProperties: [new TypeInitialization(null, false, PinEntity)]
|
||||
NodeGuid: Guid,
|
||||
CustomProperties: [PinEntity]
|
||||
}
|
||||
|
||||
getAttributes() {
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
import Entity from "./Entity"
|
||||
|
||||
export default class ObjectReferenceEntity extends Entity {
|
||||
|
||||
static attributes = {
|
||||
type: "",
|
||||
path: ""
|
||||
}
|
||||
|
||||
getAttributes() {
|
||||
return ObjectReferenceEntity.attributes
|
||||
}
|
||||
|
||||
toString() {
|
||||
return (this.type ?? "") + (
|
||||
this.path
|
||||
? this.type ? `'"${this.path}"'` : this.path
|
||||
: ""
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export default class Path {
|
||||
|
||||
}
|
||||
@@ -1,34 +1,34 @@
|
||||
import Entity from "./Entity"
|
||||
import GuidEntity from "./GuidEntity"
|
||||
import LocalizedTextEntity from "./LocalizedTextEntity"
|
||||
import ObjectReferenceEntity from "./ObjectReferenceEntity"
|
||||
import TypeInitialization from "./TypeInitialization"
|
||||
import Guid from "./primitive/Guid"
|
||||
import LocalizedTextEntity from "./primitive/LocalizedTextEntity"
|
||||
import ObjectReference from "./primitive/ObjectReference"
|
||||
import PinReferenceEntity from "./PinReferenceEntity"
|
||||
import TypeInitialization from "./TypeInitialization"
|
||||
|
||||
export default class PinEntity extends Entity {
|
||||
|
||||
static attributes = {
|
||||
PinId: GuidEntity,
|
||||
PinId: Guid,
|
||||
PinName: "",
|
||||
PinFriendlyName: new TypeInitialization(new LocalizedTextEntity(), false),
|
||||
PinFriendlyName: new TypeInitialization(LocalizedTextEntity, false, null),
|
||||
PinToolTip: "",
|
||||
Direction: new TypeInitialization("", false),
|
||||
Direction: new TypeInitialization(String, false, ""),
|
||||
PinType: {
|
||||
PinCategory: "",
|
||||
PinSubCategory: "",
|
||||
PinSubCategoryObject: ObjectReferenceEntity,
|
||||
PinSubCategoryObject: ObjectReference,
|
||||
PinSubCategoryMemberReference: null,
|
||||
PinValueType: null,
|
||||
ContainerType: ObjectReferenceEntity,
|
||||
ContainerType: ObjectReference,
|
||||
bIsReference: false,
|
||||
bIsConst: false,
|
||||
bIsWeakPointer: false,
|
||||
bIsUObjectWrapper: false
|
||||
},
|
||||
LinkedTo: [new TypeInitialization(null, false, PinReferenceEntity)],
|
||||
LinkedTo: [new TypeInitialization(PinReferenceEntity, false, null)],
|
||||
DefaultValue: "",
|
||||
AutogeneratedDefaultValue: "",
|
||||
PersistentGuid: GuidEntity,
|
||||
PersistentGuid: Guid,
|
||||
bHidden: false,
|
||||
bNotConnectable: false,
|
||||
bDefaultValueIsReadOnly: false,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import Entity from "./Entity"
|
||||
import GuidEntity from "./GuidEntity"
|
||||
import Guid from "./primitive/Guid"
|
||||
|
||||
export default class PinReferenceEntity extends Entity {
|
||||
|
||||
static attributes = {
|
||||
objectName: String,
|
||||
pinGuid: GuidEntity
|
||||
pinGuid: Guid
|
||||
}
|
||||
|
||||
getAttributes() {
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
import Utility from "../Utility"
|
||||
|
||||
export default class TypeInitialization {
|
||||
constructor(value, showDefault = true, type = Utility.getType(value)) {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {typeof Object} type
|
||||
* @param {boolean} showDefault
|
||||
* @param {*} value
|
||||
*/
|
||||
constructor(type, showDefault = true, value = undefined) {
|
||||
if (value === undefined) {
|
||||
value = Utility.sanitize(new type())
|
||||
}
|
||||
this.value = value
|
||||
this.showDefault = showDefault
|
||||
this.type = type
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import GuidEntity from "./GuidEntity"
|
||||
import Entity from "./Entity"
|
||||
import Guid from "./primitive/Guid"
|
||||
|
||||
export default class VariableReferenceEntity extends Entity {
|
||||
|
||||
static attributes = {
|
||||
MemberName: String,
|
||||
MemberGuid: GuidEntity,
|
||||
bSelfContext: true
|
||||
MemberGuid: Guid,
|
||||
bSelfContext: false
|
||||
}
|
||||
|
||||
getAttributes() {
|
||||
|
||||
32
js/entity/primitive/Guid.js
Normal file
32
js/entity/primitive/Guid.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import Primitive from "./Primitive";
|
||||
|
||||
export default class Guid extends Primitive {
|
||||
|
||||
static generateGuid(random) {
|
||||
let values = new Uint32Array(4);
|
||||
if (random === true) {
|
||||
crypto.getRandomValues(values)
|
||||
}
|
||||
let result = ""
|
||||
values.forEach(n => {
|
||||
result += ('00000000' + n.toString(16).toUpperCase()).slice(-8)
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
constructor(guid) {
|
||||
super()
|
||||
// Using constructor equality and not instanceof in order to consider both primitives and objects
|
||||
if (guid?.constructor === Boolean) {
|
||||
guid = Guid.generateGuid(guid == true)
|
||||
}
|
||||
if (guid instanceof Guid) {
|
||||
guid = guid.value
|
||||
}
|
||||
this.value = guid
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.value.toString()
|
||||
}
|
||||
}
|
||||
25
js/entity/primitive/Integer.js
Normal file
25
js/entity/primitive/Integer.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import Primitive from "./Primitive"
|
||||
|
||||
export default class Integer extends Primitive {
|
||||
|
||||
constructor(value) {
|
||||
super()
|
||||
// Using constructor equality and not instanceof in order to consider both primitives and objects
|
||||
if (value?.constructor === String) {
|
||||
value = Number(value)
|
||||
}
|
||||
if (value?.constructor === Number) {
|
||||
value = Math.round(value)
|
||||
}
|
||||
/** @type {number} */
|
||||
this.value = value
|
||||
}
|
||||
|
||||
valueOf() {
|
||||
this.value
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.value.toString()
|
||||
}
|
||||
}
|
||||
22
js/entity/primitive/LocalizedTextEntity.js
Normal file
22
js/entity/primitive/LocalizedTextEntity.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import Primitive from "./Primitive"
|
||||
|
||||
export default class LocalizedTextEntity extends Primitive {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {String} namespace
|
||||
* @param {String} key
|
||||
* @param {String} value
|
||||
*/
|
||||
constructor(namespace, key, value) {
|
||||
super()
|
||||
this.namespace = namespace
|
||||
this.key = key
|
||||
this.value = value
|
||||
}
|
||||
|
||||
toString() {
|
||||
"NSLOCTEXT(" + `"${this.namespace}"` + ", " + `"${this.key}"` + ", " + `"${this.value}"` + ")"
|
||||
}
|
||||
|
||||
}
|
||||
23
js/entity/primitive/ObjectReference.js
Normal file
23
js/entity/primitive/ObjectReference.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import Primitive from "./Primitive"
|
||||
|
||||
export default class ObjectReference extends Primitive {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {String} type
|
||||
* @param {String} path
|
||||
*/
|
||||
constructor(type, path) {
|
||||
super()
|
||||
this.type = type
|
||||
this.path = path
|
||||
}
|
||||
|
||||
toString() {
|
||||
return (this.type ?? "") + (
|
||||
this.path
|
||||
? this.type ? `'"${this.path}"'` : this.path
|
||||
: ""
|
||||
)
|
||||
}
|
||||
}
|
||||
5
js/entity/primitive/Primitive.js
Normal file
5
js/entity/primitive/Primitive.js
Normal file
@@ -0,0 +1,5 @@
|
||||
export default class Primitive {
|
||||
toString() {
|
||||
return "Unimplemented for " + this.constructor.name
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user