mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-03-17 05:47:34 +08:00
Type initialization using objects
This commit is contained in:
@@ -6,10 +6,13 @@ export default class ByteEntity extends IntegerEntity {
|
||||
value: 0,
|
||||
}
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes)
|
||||
}
|
||||
|
||||
/** @param {Object | Number | String} values */
|
||||
constructor(values = 0) {
|
||||
super(values)
|
||||
/** @type {Number} */
|
||||
const value = Math.round(this.value)
|
||||
this.value = value >= 0 && value < 1 << 8 ? value : 0
|
||||
}
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
import IEntity from "./IEntity"
|
||||
import ObjectReferenceEntity from "./ObjectReferenceEntity"
|
||||
import TypeInitialization from "./TypeInitialization"
|
||||
|
||||
export default class FunctionReferenceEntity extends IEntity {
|
||||
|
||||
static attributes = {
|
||||
MemberParent: new TypeInitialization(ObjectReferenceEntity, false),
|
||||
MemberParent: {
|
||||
type: ObjectReferenceEntity,
|
||||
showDefault: false
|
||||
},
|
||||
MemberName: "",
|
||||
}
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes)
|
||||
}
|
||||
|
||||
constructor(values) {
|
||||
super(values)
|
||||
/** @type {ObjectReferenceEntity} */ this.MemberParent
|
||||
|
||||
@@ -3,7 +3,11 @@ import IEntity from "./IEntity"
|
||||
export default class GuidEntity extends IEntity {
|
||||
|
||||
static attributes = {
|
||||
value: String,
|
||||
value: "",
|
||||
}
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes)
|
||||
}
|
||||
|
||||
static generateGuid(random = true) {
|
||||
|
||||
@@ -1,19 +1,43 @@
|
||||
import CalculatedType from "./CalculatedType"
|
||||
import Observable from "../Observable"
|
||||
import SerializerFactory from "../serialization/SerializerFactory"
|
||||
import TypeInitialization from "./TypeInitialization"
|
||||
import Utility from "../Utility"
|
||||
import SubAttributesDeclaration from "./SubObject"
|
||||
import UnionType from "./UnionType"
|
||||
import Utility from "../Utility"
|
||||
|
||||
/** @typedef {typeof IEntity} EntityConstructor */
|
||||
/**
|
||||
* @template {IEntity} T
|
||||
* @typedef {new (Object) => T} IEntityConstructor
|
||||
* @typedef {(entity: IEntity) => AnyValue} ValueSupplier
|
||||
* @typedef {(entity: IEntity) => AnyValueConstructor<AnyValue>} TypeSupplier
|
||||
* @typedef {IEntity | String | Number | Boolean} AnySimpleValue
|
||||
* @typedef {AnySimpleValue | AnySimpleValue[]} AnyValue
|
||||
* @typedef {{
|
||||
* [key: String]: AttributeInformation | AnyValue | SubAttributesDeclaration
|
||||
* }} AttributeDeclarations
|
||||
* @typedef {typeof IEntity} EntityConstructor
|
||||
* @typedef {{
|
||||
* type?: AnyValueConstructor<AnyValue> | AnyValueConstructor<AnyValue>[] | UnionType | TypeSupplier,
|
||||
* value?: AnyValue | ValueSupplier,
|
||||
* showDefault?: Boolean,
|
||||
* nullable?: Boolean,
|
||||
* ignored?: Boolean,
|
||||
* serialized?: Boolean,
|
||||
* }} AttributeInformation
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template {AnyValue} T
|
||||
* @typedef {(new () => T) | EntityConstructor | StringConstructor | NumberConstructor | BooleanConstructor | ArrayConstructor} AnyValueConstructor
|
||||
*/
|
||||
|
||||
export default class IEntity extends Observable {
|
||||
|
||||
/** @type {AttributeDeclarations} */
|
||||
static attributes = {}
|
||||
static defaultAttribute = {
|
||||
showDefault: true,
|
||||
nullable: false,
|
||||
ignored: false,
|
||||
serialized: false,
|
||||
}
|
||||
|
||||
constructor(values = {}, suppressWarns = false) {
|
||||
super()
|
||||
@@ -24,82 +48,94 @@ export default class IEntity extends Observable {
|
||||
* @param {String} prefix
|
||||
*/
|
||||
const defineAllAttributes = (target, attributes, values = {}, prefix = "") => {
|
||||
const valuesPropertyNames = Object.getOwnPropertyNames(values)
|
||||
for (let attribute of Utility.mergeArrays(Object.getOwnPropertyNames(attributes), valuesPropertyNames)) {
|
||||
let value = Utility.objectGet(values, [attribute])
|
||||
let defaultValue = attributes[attribute]
|
||||
let defaultType = Utility.getType(defaultValue)
|
||||
if (defaultValue instanceof CalculatedType) {
|
||||
defaultValue = defaultValue.calculate(this)
|
||||
defaultType = Utility.getType(defaultValue)
|
||||
}
|
||||
if (defaultValue != null && defaultValue === defaultType) {
|
||||
defaultValue = new defaultType()
|
||||
const valuesNames = Object.getOwnPropertyNames(values)
|
||||
for (let attributeName of Utility.mergeArrays(Object.getOwnPropertyNames(attributes), valuesNames)) {
|
||||
let value = Utility.objectGet(values, [attributeName])
|
||||
/** @type {AttributeInformation} */
|
||||
let attribute = attributes[attributeName]
|
||||
|
||||
if (attribute instanceof SubAttributesDeclaration) {
|
||||
target[attributeName] = {}
|
||||
defineAllAttributes(
|
||||
target[attributeName],
|
||||
attribute.attributes,
|
||||
values[attributeName],
|
||||
attributeName + "."
|
||||
)
|
||||
continue
|
||||
}
|
||||
|
||||
if (!suppressWarns) {
|
||||
if (!(attribute in attributes)) {
|
||||
console.warn(
|
||||
`Attribute ${prefix}${attribute} in the serialized data is not defined in ${this.constructor.name}.attributes`
|
||||
if (!(attributeName in attributes)) {
|
||||
Utility.warn(
|
||||
`Attribute ${prefix}${attributeName} in the serialized data is not defined in `
|
||||
+ `${this.constructor.name}.attributes`
|
||||
)
|
||||
} else if (
|
||||
valuesPropertyNames.length > 0
|
||||
&& !(attribute in values)
|
||||
&& defaultValue !== undefined
|
||||
&& !(defaultValue instanceof TypeInitialization && (!defaultValue.showDefault || defaultValue.ignored))
|
||||
valuesNames.length > 0
|
||||
&& !(attributeName in values)
|
||||
&& !(!attribute.showDefault || attribute.ignored)
|
||||
) {
|
||||
console.warn(
|
||||
`${this.constructor.name} will add attribute ${prefix}${attribute} not defined in the serialized data`
|
||||
Utility.warn(
|
||||
`${this.constructor.name} will add attribute ${prefix}${attributeName} not defined in the `
|
||||
+ "serialized data"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Not instanceof because all objects are instenceof Object, exact match needed
|
||||
// @ts-expect-error
|
||||
if (defaultType === Object) {
|
||||
target[attribute] = {}
|
||||
defineAllAttributes(target[attribute], attributes[attribute], values[attribute], attribute + ".")
|
||||
continue
|
||||
let defaultValue = attribute.value
|
||||
let defaultType = attribute.type
|
||||
if (attribute.serialized && defaultType instanceof Function) {
|
||||
// If the attribute is serialized, the type must contain a function providing the type
|
||||
defaultType = /** @type {TypeSupplier} */(defaultType)(this)
|
||||
}
|
||||
if (defaultType instanceof Array) {
|
||||
defaultType = Array
|
||||
}
|
||||
if (defaultValue instanceof Function) {
|
||||
defaultValue = defaultValue(this)
|
||||
}
|
||||
if (defaultType instanceof UnionType) {
|
||||
if (defaultValue != undefined) {
|
||||
defaultType = defaultType.types.find(
|
||||
type => defaultValue instanceof type || defaultValue.constructor == type
|
||||
) ?? defaultType.getFirstType()
|
||||
} else {
|
||||
defaultType = defaultType.getFirstType()
|
||||
}
|
||||
}
|
||||
if (defaultType === undefined) {
|
||||
defaultType = Utility.getType(defaultValue)
|
||||
}
|
||||
|
||||
if (value !== undefined) {
|
||||
// Remember value can still be null
|
||||
if (
|
||||
value?.constructor === String
|
||||
&& defaultValue instanceof TypeInitialization
|
||||
&& defaultValue.serialized
|
||||
&& defaultValue.type !== String
|
||||
) {
|
||||
// @ts-expect-error
|
||||
value = SerializerFactory.getSerializer(defaultValue.type).deserialize(value)
|
||||
if (value?.constructor === String && attribute.serialized && defaultType !== String) {
|
||||
value = SerializerFactory
|
||||
.getSerializer(/** @type {AnyValueConstructor<*>} */(defaultType))
|
||||
.deserialize(/** @type {String} */(value))
|
||||
}
|
||||
target[attribute] = TypeInitialization.sanitize(value, Utility.getType(defaultValue))
|
||||
target[attributeName] = Utility.sanitize(value, /** @type {AnyValueConstructor<*>} */(defaultType))
|
||||
continue // We have a value, need nothing more
|
||||
}
|
||||
|
||||
if (defaultValue instanceof TypeInitialization) {
|
||||
if (!defaultValue.showDefault) {
|
||||
target[attribute] = undefined // Declare undefined to preserve the order of attributes
|
||||
continue
|
||||
}
|
||||
if (defaultValue.serialized) {
|
||||
defaultValue = ""
|
||||
} else {
|
||||
defaultType = defaultValue.type
|
||||
defaultValue = defaultValue.value
|
||||
if (defaultValue instanceof Function) {
|
||||
defaultValue = defaultValue()
|
||||
}
|
||||
if (defaultValue === undefined) {
|
||||
defaultValue = Utility.sanitize(new /** @type {AnyValueConstructor<*>} */(defaultType)())
|
||||
}
|
||||
if (!attribute.showDefault) {
|
||||
target[attributeName] = undefined // Declare undefined to preserve the order of attributes
|
||||
continue
|
||||
}
|
||||
if (attribute.serialized) {
|
||||
if (defaultType !== String && defaultValue.constructor === String) {
|
||||
defaultValue = SerializerFactory
|
||||
.getSerializer(/** @type {AnyValueConstructor<*>} */(defaultType))
|
||||
.deserialize(defaultValue)
|
||||
}
|
||||
}
|
||||
if (defaultValue instanceof UnionType) {
|
||||
defaultType = defaultValue.getFirstType()
|
||||
defaultValue = TypeInitialization.sanitize(null, defaultType)
|
||||
}
|
||||
if (defaultValue instanceof Array) {
|
||||
defaultValue = []
|
||||
}
|
||||
target[attribute] = TypeInitialization.sanitize(defaultValue, defaultType)
|
||||
target[attributeName] = Utility.sanitize(
|
||||
/** @type {AnyValue} */(defaultValue),
|
||||
/** @type {AnyValueConstructor<AnyValue>} */(defaultType)
|
||||
)
|
||||
}
|
||||
}
|
||||
const attributes = /** @type {typeof IEntity} */(this.constructor).attributes
|
||||
@@ -112,6 +148,45 @@ export default class IEntity extends Observable {
|
||||
defineAllAttributes(this, attributes, values)
|
||||
}
|
||||
|
||||
/** @param {AttributeDeclarations} attributes */
|
||||
static cleanupAttributes(attributes, prefix = "") {
|
||||
for (const attributeName in attributes) {
|
||||
if (attributes[attributeName] instanceof SubAttributesDeclaration) {
|
||||
this.cleanupAttributes(
|
||||
/** @type {SubAttributesDeclaration} */(attributes[attributeName]).attributes,
|
||||
prefix + "." + attributeName
|
||||
)
|
||||
continue
|
||||
}
|
||||
if (attributes[attributeName].constructor !== Object) {
|
||||
attributes[attributeName] = {
|
||||
value: attributes[attributeName],
|
||||
}
|
||||
}
|
||||
const attribute = /** @type {AttributeInformation} */(attributes[attributeName])
|
||||
if (attribute.type === undefined && !(attribute.value instanceof Function)) {
|
||||
attribute.type = Utility.getType(attribute.value)
|
||||
}
|
||||
attributes[attributeName] = {
|
||||
...IEntity.defaultAttribute,
|
||||
...attribute,
|
||||
}
|
||||
if (attribute.value === undefined && attribute.type === undefined) {
|
||||
throw new Error(
|
||||
`UEBlueprint: Expected either "type" or "value" property in ${this.name} attribute ${prefix}`
|
||||
+ attributeName
|
||||
)
|
||||
}
|
||||
if (attribute.value === null) {
|
||||
attributes[attributeName].nullable = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static isValueOfType(value, type) {
|
||||
return value != null && (value instanceof type || value.constructor === type)
|
||||
}
|
||||
|
||||
unexpectedKeys() {
|
||||
// @ts-expect-error
|
||||
return Object.getOwnPropertyNames(this).length - Object.getOwnPropertyNames(this.constructor.attributes).length
|
||||
|
||||
@@ -3,7 +3,11 @@ import IEntity from "./IEntity"
|
||||
export default class IdentifierEntity extends IEntity {
|
||||
|
||||
static attributes = {
|
||||
value: String,
|
||||
value: "",
|
||||
}
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes)
|
||||
}
|
||||
|
||||
static attributeConverter = {
|
||||
|
||||
@@ -6,10 +6,13 @@ export default class IntegerEntity extends IEntity {
|
||||
value: 0,
|
||||
}
|
||||
|
||||
/** @param {Object | Number | String} values */
|
||||
constructor(values = 0) {
|
||||
super(values)
|
||||
/** @type {Number} */
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes)
|
||||
}
|
||||
|
||||
/** @param {Object | Number | String} value */
|
||||
constructor(value = 0) {
|
||||
super(value)
|
||||
this.value = Math.round(this.value)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,11 @@ export default class InvariantTextEntity extends IEntity {
|
||||
|
||||
static lookbehind = "INVTEXT"
|
||||
static attributes = {
|
||||
value: String,
|
||||
value: "",
|
||||
}
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes)
|
||||
}
|
||||
|
||||
constructor(values) {
|
||||
|
||||
@@ -9,7 +9,13 @@ export default class KeyBindingEntity extends IEntity {
|
||||
bCtrl: false,
|
||||
bAlt: false,
|
||||
bCmd: false,
|
||||
Key: IdentifierEntity,
|
||||
Key: {
|
||||
type: IdentifierEntity
|
||||
},
|
||||
}
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes)
|
||||
}
|
||||
|
||||
constructor(values = {}) {
|
||||
|
||||
@@ -1,18 +1,43 @@
|
||||
import IEntity from "./IEntity"
|
||||
import RealUnitEntity from "./UnitRealEntity"
|
||||
import TypeInitialization from "./TypeInitialization"
|
||||
import Utility from "../Utility"
|
||||
|
||||
export default class LinearColorEntity extends IEntity {
|
||||
|
||||
static attributes = {
|
||||
R: RealUnitEntity,
|
||||
G: RealUnitEntity,
|
||||
B: RealUnitEntity,
|
||||
A: new TypeInitialization(RealUnitEntity, true, () => new RealUnitEntity(1), false, false),
|
||||
H: new TypeInitialization(RealUnitEntity, true, undefined, false, true),
|
||||
S: new TypeInitialization(RealUnitEntity, true, undefined, false, true),
|
||||
V: new TypeInitialization(RealUnitEntity, true, undefined, false, true),
|
||||
R: {
|
||||
type: RealUnitEntity,
|
||||
},
|
||||
G: {
|
||||
type: RealUnitEntity,
|
||||
},
|
||||
B: {
|
||||
type: RealUnitEntity,
|
||||
},
|
||||
A: {
|
||||
type: RealUnitEntity,
|
||||
value: () => new RealUnitEntity(1),
|
||||
showDefault: true,
|
||||
},
|
||||
H: {
|
||||
type: RealUnitEntity,
|
||||
showDefault: true,
|
||||
ignored: true,
|
||||
},
|
||||
S: {
|
||||
type: RealUnitEntity,
|
||||
showDefault: true,
|
||||
ignored: true,
|
||||
},
|
||||
V: {
|
||||
type: RealUnitEntity,
|
||||
showDefault: true,
|
||||
ignored: true,
|
||||
},
|
||||
}
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes)
|
||||
}
|
||||
|
||||
/** @param {Number} x */
|
||||
|
||||
@@ -5,9 +5,13 @@ export default class LocalizedTextEntity extends IEntity {
|
||||
|
||||
static lookbehind = "NSLOCTEXT"
|
||||
static attributes = {
|
||||
namespace: String,
|
||||
key: String,
|
||||
value: String,
|
||||
namespace: "",
|
||||
key: "",
|
||||
value: "",
|
||||
}
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes)
|
||||
}
|
||||
|
||||
constructor(values) {
|
||||
|
||||
@@ -5,9 +5,19 @@ import ObjectReferenceEntity from "./ObjectReferenceEntity"
|
||||
export default class MacroGraphReferenceEntity extends IEntity {
|
||||
|
||||
static attributes = {
|
||||
MacroGraph: ObjectReferenceEntity,
|
||||
GraphBlueprint: ObjectReferenceEntity,
|
||||
GraphGuid: GuidEntity,
|
||||
MacroGraph: {
|
||||
type: ObjectReferenceEntity,
|
||||
},
|
||||
GraphBlueprint: {
|
||||
type: ObjectReferenceEntity,
|
||||
},
|
||||
GraphGuid: {
|
||||
type: GuidEntity,
|
||||
},
|
||||
}
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes)
|
||||
}
|
||||
|
||||
constructor(values) {
|
||||
|
||||
@@ -9,45 +9,130 @@ import MacroGraphReferenceEntity from "./MacroGraphReferenceEntity"
|
||||
import ObjectReferenceEntity from "./ObjectReferenceEntity"
|
||||
import PinEntity from "./PinEntity"
|
||||
import SymbolEntity from "./SymbolEntity"
|
||||
import TypeInitialization from "./TypeInitialization"
|
||||
import Utility from "../Utility"
|
||||
import VariableReferenceEntity from "./VariableReferenceEntity"
|
||||
|
||||
export default class ObjectEntity extends IEntity {
|
||||
|
||||
static attributes = {
|
||||
Class: ObjectReferenceEntity,
|
||||
Class: {
|
||||
type: ObjectReferenceEntity,
|
||||
},
|
||||
Name: "",
|
||||
bIsPureFunc: new TypeInitialization(Boolean, false, false),
|
||||
VariableReference: new TypeInitialization(VariableReferenceEntity, false, null),
|
||||
SelfContextInfo: new TypeInitialization(SymbolEntity, false, null),
|
||||
FunctionReference: new TypeInitialization(FunctionReferenceEntity, false, null,),
|
||||
EventReference: new TypeInitialization(FunctionReferenceEntity, false, null,),
|
||||
TargetType: new TypeInitialization(ObjectReferenceEntity, false, null),
|
||||
MacroGraphReference: new TypeInitialization(MacroGraphReferenceEntity, false, null),
|
||||
Enum: new TypeInitialization(ObjectReferenceEntity, false),
|
||||
CommentColor: new TypeInitialization(LinearColorEntity, false),
|
||||
bCommentBubbleVisible_InDetailsPanel: new TypeInitialization(Boolean, false),
|
||||
bColorCommentBubble: new TypeInitialization(Boolean, false, false),
|
||||
MoveMode: new TypeInitialization(SymbolEntity, false),
|
||||
NodePosX: IntegerEntity,
|
||||
NodePosY: IntegerEntity,
|
||||
NodeWidth: new TypeInitialization(IntegerEntity, false),
|
||||
NodeHeight: new TypeInitialization(IntegerEntity, false),
|
||||
bCommentBubblePinned: new TypeInitialization(Boolean, false),
|
||||
bCommentBubbleVisible: new TypeInitialization(Boolean, false),
|
||||
NodeComment: new TypeInitialization(String, false),
|
||||
AdvancedPinDisplay: new TypeInitialization(IdentifierEntity, false, null),
|
||||
EnabledState: new TypeInitialization(IdentifierEntity, false, null),
|
||||
NodeGuid: GuidEntity,
|
||||
ErrorType: new TypeInitialization(IntegerEntity, false),
|
||||
ErrorMsg: new TypeInitialization(String, false, ""),
|
||||
CustomProperties: [PinEntity],
|
||||
bIsPureFunc: {
|
||||
value: false,
|
||||
showDefault: false,
|
||||
},
|
||||
VariableReference: {
|
||||
type: VariableReferenceEntity,
|
||||
value: null,
|
||||
showDefault: false,
|
||||
},
|
||||
SelfContextInfo: {
|
||||
type: SymbolEntity,
|
||||
value: null,
|
||||
showDefault: false,
|
||||
},
|
||||
FunctionReference: {
|
||||
type: FunctionReferenceEntity,
|
||||
value: null,
|
||||
showDefault: false,
|
||||
},
|
||||
EventReference: {
|
||||
type: FunctionReferenceEntity,
|
||||
value: null,
|
||||
showDefault: false,
|
||||
},
|
||||
TargetType: {
|
||||
type: ObjectReferenceEntity,
|
||||
value: null,
|
||||
showDefault: false,
|
||||
},
|
||||
MacroGraphReference: {
|
||||
type: MacroGraphReferenceEntity,
|
||||
value: null,
|
||||
showDefault: false,
|
||||
},
|
||||
Enum: {
|
||||
type: ObjectReferenceEntity,
|
||||
showDefault: false,
|
||||
},
|
||||
CommentColor: {
|
||||
type: LinearColorEntity,
|
||||
showDefault: false,
|
||||
},
|
||||
bCommentBubbleVisible_InDetailsPanel: {
|
||||
type: Boolean,
|
||||
showDefault: false,
|
||||
},
|
||||
bColorCommentBubble: {
|
||||
type: Boolean,
|
||||
value: false,
|
||||
showDefault: false,
|
||||
},
|
||||
MoveMode: {
|
||||
type: SymbolEntity,
|
||||
showDefault: false,
|
||||
},
|
||||
NodePosX: {
|
||||
type: IntegerEntity,
|
||||
},
|
||||
NodePosY: {
|
||||
type: IntegerEntity,
|
||||
},
|
||||
NodeWidth: {
|
||||
type: IntegerEntity,
|
||||
showDefault: false,
|
||||
},
|
||||
NodeHeight: {
|
||||
type: IntegerEntity,
|
||||
showDefault: false,
|
||||
},
|
||||
bCommentBubblePinned: {
|
||||
type: Boolean,
|
||||
showDefault: false,
|
||||
},
|
||||
bCommentBubbleVisible: {
|
||||
type: Boolean,
|
||||
showDefault: false,
|
||||
},
|
||||
NodeComment: {
|
||||
type: String,
|
||||
showDefault: false,
|
||||
},
|
||||
AdvancedPinDisplay: {
|
||||
type: IdentifierEntity,
|
||||
value: null,
|
||||
showDefault: false,
|
||||
},
|
||||
EnabledState: {
|
||||
type: IdentifierEntity,
|
||||
value: null,
|
||||
showDefault: false,
|
||||
},
|
||||
NodeGuid: {
|
||||
type: GuidEntity,
|
||||
},
|
||||
ErrorType: {
|
||||
type: IntegerEntity,
|
||||
showDefault: false,
|
||||
},
|
||||
ErrorMsg: {
|
||||
type: String,
|
||||
value: "",
|
||||
showDefault: false,
|
||||
},
|
||||
CustomProperties: {
|
||||
type: [PinEntity]
|
||||
},
|
||||
}
|
||||
|
||||
static nameRegex = /^(\w+?)(?:_(\d+))?$/
|
||||
static sequencerScriptingNameRegex = /\/Script\/SequencerScripting\.MovieSceneScripting(.+)Channel/
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes)
|
||||
}
|
||||
|
||||
constructor(values, suppressWarns = false) {
|
||||
super(values, suppressWarns)
|
||||
/** @type {ObjectReferenceEntity} */ this.Class
|
||||
|
||||
@@ -3,12 +3,16 @@ import IEntity from "./IEntity"
|
||||
export default class ObjectReferenceEntity extends IEntity {
|
||||
|
||||
static attributes = {
|
||||
type: String,
|
||||
path: String,
|
||||
type: "",
|
||||
path: "",
|
||||
}
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes)
|
||||
}
|
||||
|
||||
constructor(values = {}) {
|
||||
if (values.constructor !== Object) {
|
||||
if (values.constructor === String) {
|
||||
values = {
|
||||
path: values
|
||||
}
|
||||
|
||||
@@ -3,7 +3,11 @@ import IEntity from "./IEntity"
|
||||
export default class PathSymbolEntity extends IEntity {
|
||||
|
||||
static attributes = {
|
||||
value: String,
|
||||
value: "",
|
||||
}
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes)
|
||||
}
|
||||
|
||||
constructor(values) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import CalculatedType from "./CalculatedType"
|
||||
import GuidEntity from "./GuidEntity"
|
||||
import IEntity from "./IEntity"
|
||||
import IntegerEntity from "./IntegerEntity"
|
||||
@@ -10,13 +9,13 @@ import RotatorEntity from "./RotatorEntity"
|
||||
import SimpleSerializationRotatorEntity from "./SimpleSerializationRotatorEntity"
|
||||
import SimpleSerializationVector2DEntity from "./SimpleSerializationVector2DEntity"
|
||||
import SimpleSerializationVectorEntity from "./SimpleSerializationVectorEntity"
|
||||
import TypeInitialization from "./TypeInitialization"
|
||||
import SubAttributesDeclaration from "./SubObject"
|
||||
import UnionType from "./UnionType"
|
||||
import Utility from "../Utility"
|
||||
import Vector2DEntity from "./Vector2DEntity"
|
||||
import VectorEntity from "./VectorEntity"
|
||||
|
||||
/** @typedef {import("./TypeInitialization").AnyValue} AnyValue */
|
||||
/** @typedef {import("./IEntity").AnyValue} AnyValue */
|
||||
|
||||
/** @template {AnyValue} T */
|
||||
export default class PinEntity extends IEntity {
|
||||
@@ -40,38 +39,67 @@ export default class PinEntity extends IEntity {
|
||||
}
|
||||
static lookbehind = "Pin"
|
||||
static attributes = {
|
||||
PinId: GuidEntity,
|
||||
PinId: {
|
||||
type: GuidEntity,
|
||||
},
|
||||
PinName: "",
|
||||
PinFriendlyName: new TypeInitialization(new UnionType(LocalizedTextEntity, String), false, null),
|
||||
PinToolTip: new TypeInitialization(String, false, ""),
|
||||
Direction: new TypeInitialization(String, false, ""),
|
||||
PinType: {
|
||||
PinFriendlyName: {
|
||||
type: new UnionType(LocalizedTextEntity, String),
|
||||
showDefault: false,
|
||||
},
|
||||
PinToolTip: {
|
||||
type: String,
|
||||
showDefault: false,
|
||||
},
|
||||
Direction: {
|
||||
type: String,
|
||||
showDefault: false,
|
||||
},
|
||||
PinType: new SubAttributesDeclaration({
|
||||
PinCategory: "",
|
||||
PinSubCategory: "",
|
||||
PinSubCategoryObject: ObjectReferenceEntity,
|
||||
PinSubCategoryMemberReference: null,
|
||||
PinValueType: null,
|
||||
ContainerType: ObjectReferenceEntity,
|
||||
PinSubCategoryObject: {
|
||||
type: ObjectReferenceEntity,
|
||||
},
|
||||
PinSubCategoryMemberReference: {
|
||||
type: ObjectReferenceEntity,
|
||||
value: null,
|
||||
},
|
||||
PinValueType: {
|
||||
type: String,
|
||||
value: null,
|
||||
},
|
||||
ContainerType: {
|
||||
type: ObjectReferenceEntity,
|
||||
},
|
||||
bIsReference: false,
|
||||
bIsConst: false,
|
||||
bIsWeakPointer: false,
|
||||
bIsUObjectWrapper: false,
|
||||
bSerializeAsSinglePrecisionFloat: false,
|
||||
}),
|
||||
LinkedTo: {
|
||||
type: [PinReferenceEntity],
|
||||
showDefault: false,
|
||||
},
|
||||
DefaultValue: {
|
||||
/** @param {PinEntity} pinEntity */
|
||||
type: pinEntity => pinEntity.getEntityType(true) ?? String,
|
||||
serialized: true,
|
||||
showDefault: false,
|
||||
},
|
||||
AutogeneratedDefaultValue: {
|
||||
type: String,
|
||||
showDefault: false,
|
||||
},
|
||||
DefaultObject: {
|
||||
type: ObjectReferenceEntity,
|
||||
showDefault: false,
|
||||
value: null,
|
||||
},
|
||||
PersistentGuid: {
|
||||
type: GuidEntity,
|
||||
},
|
||||
LinkedTo: new TypeInitialization([PinReferenceEntity], false),
|
||||
DefaultValue:
|
||||
new CalculatedType(
|
||||
/** @param {PinEntity} pinEntity */
|
||||
pinEntity => new TypeInitialization(
|
||||
pinEntity.getEntityType(true) ?? String,
|
||||
false,
|
||||
undefined,
|
||||
true
|
||||
)
|
||||
),
|
||||
AutogeneratedDefaultValue: new TypeInitialization(String, false),
|
||||
DefaultObject: new TypeInitialization(ObjectReferenceEntity, false, null),
|
||||
PersistentGuid: GuidEntity,
|
||||
bHidden: false,
|
||||
bNotConnectable: false,
|
||||
bDefaultValueIsReadOnly: false,
|
||||
@@ -80,6 +108,10 @@ export default class PinEntity extends IEntity {
|
||||
bOrphanedPin: false,
|
||||
}
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes)
|
||||
}
|
||||
|
||||
constructor(values = {}, suppressWarns = false) {
|
||||
super(values, suppressWarns)
|
||||
/** @type {GuidEntity} */ this.PinId
|
||||
|
||||
@@ -5,8 +5,16 @@ import PathSymbolEntity from "./PathSymbolEntity"
|
||||
export default class PinReferenceEntity extends IEntity {
|
||||
|
||||
static attributes = {
|
||||
objectName: PathSymbolEntity,
|
||||
pinGuid: GuidEntity,
|
||||
objectName: {
|
||||
type: PathSymbolEntity,
|
||||
},
|
||||
pinGuid: {
|
||||
type: GuidEntity,
|
||||
},
|
||||
}
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes)
|
||||
}
|
||||
|
||||
constructor(values) {
|
||||
|
||||
@@ -3,9 +3,19 @@ import IEntity from "./IEntity"
|
||||
export default class RotatorEntity extends IEntity {
|
||||
|
||||
static attributes = {
|
||||
R: Number,
|
||||
P: Number,
|
||||
Y: Number,
|
||||
R: {
|
||||
value: 0,
|
||||
},
|
||||
P: {
|
||||
value: 0,
|
||||
},
|
||||
Y: {
|
||||
value: 0,
|
||||
},
|
||||
}
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes)
|
||||
}
|
||||
|
||||
constructor(values) {
|
||||
@@ -14,4 +24,16 @@ export default class RotatorEntity extends IEntity {
|
||||
/** @type {Number} */ this.P
|
||||
/** @type {Number} */ this.Y
|
||||
}
|
||||
|
||||
getRoll() {
|
||||
return this.R
|
||||
}
|
||||
|
||||
getPitch() {
|
||||
return this.P
|
||||
}
|
||||
|
||||
getYaw() {
|
||||
return this.Y
|
||||
}
|
||||
}
|
||||
|
||||
9
js/entity/SubObject.js
Normal file
9
js/entity/SubObject.js
Normal file
@@ -0,0 +1,9 @@
|
||||
/** @typedef {import("./IEntity").AttributeDeclarations} AttributeDeclarations */
|
||||
|
||||
export default class SubAttributesDeclaration {
|
||||
|
||||
/** @param {AttributeDeclarations} attributes */
|
||||
constructor(attributes) {
|
||||
this.attributes = attributes
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,11 @@ import IEntity from "./IEntity"
|
||||
export default class SymbolEntity extends IEntity {
|
||||
|
||||
static attributes = {
|
||||
value: String
|
||||
value: "",
|
||||
}
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes)
|
||||
}
|
||||
|
||||
constructor(values) {
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
import UnionType from "./UnionType"
|
||||
|
||||
/**
|
||||
* @typedef {IEntity | String | Number | Boolean | Array} AnyValue
|
||||
* @typedef {import("./IEntity").default} IEntity
|
||||
*/
|
||||
/**
|
||||
* @template {AnyValue} T
|
||||
* @typedef {import("./IEntity").IEntityConstructor<T>} IEntityConstructor
|
||||
*/
|
||||
/**
|
||||
* @template {AnyValue} T
|
||||
* @typedef {IEntityConstructor<T> | StringConstructor | NumberConstructor | BooleanConstructor | ArrayConstructor | UnionType} AnyValueConstructor
|
||||
*/
|
||||
|
||||
/** @template {AnyValue} T */
|
||||
export default class TypeInitialization {
|
||||
|
||||
/** @type {AnyValueConstructor<T>|AnyValueConstructor<T>[]} */
|
||||
#type
|
||||
get type() {
|
||||
return this.#type
|
||||
}
|
||||
set type(v) {
|
||||
this.#type = v
|
||||
}
|
||||
|
||||
#showDefault = true
|
||||
get showDefault() {
|
||||
return this.#showDefault
|
||||
}
|
||||
set showDefault(v) {
|
||||
this.#showDefault = v
|
||||
}
|
||||
|
||||
/** @type {T | T[] | String | (() => T) | (() => T[])} */
|
||||
#value
|
||||
get value() {
|
||||
return this.#value
|
||||
}
|
||||
set value(v) {
|
||||
this.#value = v
|
||||
}
|
||||
|
||||
/** @type {Boolean} */
|
||||
#serialized
|
||||
get serialized() {
|
||||
return this.#serialized
|
||||
}
|
||||
set serialized(v) {
|
||||
this.#serialized = v
|
||||
}
|
||||
|
||||
#ignored
|
||||
get ignored() {
|
||||
return this.#ignored
|
||||
}
|
||||
set ignored(v) {
|
||||
this.#ignored = v
|
||||
}
|
||||
|
||||
static isValueOfType(value, type) {
|
||||
return value != null && (value instanceof type || value.constructor === type)
|
||||
}
|
||||
|
||||
static sanitize(value, targetType) {
|
||||
if (targetType === undefined) {
|
||||
targetType = value?.constructor
|
||||
}
|
||||
if (targetType instanceof Array) {
|
||||
let type = targetType.find(t => TypeInitialization.isValueOfType(value, t))
|
||||
if (!type) {
|
||||
type = targetType[0]
|
||||
}
|
||||
targetType = type
|
||||
}
|
||||
if (targetType && !TypeInitialization.isValueOfType(value, targetType)) {
|
||||
value = new targetType(value)
|
||||
}
|
||||
if (value instanceof Boolean || value instanceof Number || value instanceof String) {
|
||||
value = value.valueOf() // Get the relative primitive value
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {AnyValueConstructor<T>|AnyValueConstructor<T>[]} type
|
||||
* @param {Boolean} showDefault
|
||||
* @param {T | T[] | String | (() => T) | (() => T[])} value
|
||||
* @param {Boolean} serialized
|
||||
*/
|
||||
constructor(type, showDefault = true, value = undefined, serialized = false, ignored = false) {
|
||||
if (value === undefined) {
|
||||
if (type instanceof Array) {
|
||||
value = []
|
||||
} else {
|
||||
value = () => TypeInitialization.sanitize(new type())
|
||||
}
|
||||
}
|
||||
this.#type = type
|
||||
this.#showDefault = showDefault
|
||||
this.#value = value
|
||||
this.#serialized = serialized
|
||||
this.#ignored = ignored
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
/**
|
||||
* @template T
|
||||
* @typedef {import("./TypeInitialization").AnyValueConstructor<T>} AnyValueConstructor
|
||||
*/
|
||||
/** @typedef {import("./IEntity").AnyValueConstructor<*>} AnyValueConstructor */
|
||||
|
||||
export default class UnionType {
|
||||
|
||||
@@ -10,7 +7,7 @@ export default class UnionType {
|
||||
return this.#types
|
||||
}
|
||||
|
||||
/** @param {...AnyValueConstructor<any>} types */
|
||||
/** @param {...AnyValueConstructor} types */
|
||||
constructor(...types) {
|
||||
this.#types = types
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@ export default class RealUnitEntity extends IEntity {
|
||||
value: 0,
|
||||
}
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes)
|
||||
}
|
||||
|
||||
/** @param {Object | Number | String} values */
|
||||
constructor(values = 0) {
|
||||
super(values)
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import IEntity from "./IEntity"
|
||||
import TypeInitialization from "./TypeInitialization"
|
||||
|
||||
export default class UnknownKeysEntity extends IEntity {
|
||||
|
||||
static attributes = {
|
||||
lookbehind: new TypeInitialization(String, false, "", false, true)
|
||||
lookbehind:
|
||||
{
|
||||
value: "",
|
||||
showDefault: false,
|
||||
ignore: true,
|
||||
},
|
||||
}
|
||||
|
||||
constructor(values) {
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
import IEntity from "./IEntity"
|
||||
import GuidEntity from "./GuidEntity"
|
||||
import TypeInitialization from "./TypeInitialization"
|
||||
|
||||
export default class VariableReferenceEntity extends IEntity {
|
||||
|
||||
static attributes = {
|
||||
MemberScope: new TypeInitialization(String, false),
|
||||
MemberName: String,
|
||||
MemberGuid: GuidEntity,
|
||||
bSelfContext: new TypeInitialization(Boolean, false, false)
|
||||
MemberScope: {
|
||||
value: "",
|
||||
showDefault: false,
|
||||
},
|
||||
MemberName: "",
|
||||
MemberGuid: {
|
||||
type: GuidEntity,
|
||||
},
|
||||
bSelfContext: {
|
||||
value: false,
|
||||
showDefault: false,
|
||||
},
|
||||
}
|
||||
|
||||
constructor(values) {
|
||||
|
||||
@@ -3,8 +3,8 @@ import IEntity from "./IEntity"
|
||||
export default class Vector2DEntity extends IEntity {
|
||||
|
||||
static attributes = {
|
||||
X: Number,
|
||||
Y: Number,
|
||||
X: 0,
|
||||
Y: 0,
|
||||
}
|
||||
|
||||
constructor(values) {
|
||||
|
||||
@@ -3,9 +3,9 @@ import IEntity from "./IEntity"
|
||||
export default class VectorEntity extends IEntity {
|
||||
|
||||
static attributes = {
|
||||
X: Number,
|
||||
Y: Number,
|
||||
Z: Number,
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Z: 0,
|
||||
}
|
||||
|
||||
constructor(values) {
|
||||
|
||||
Reference in New Issue
Block a user