Serialization refactoring to drop suboject logic

This commit is contained in:
barsdeveloper
2023-04-01 15:26:44 +02:00
parent 8c30118a13
commit 82bb9917fb
13 changed files with 316 additions and 292 deletions

16
js/entity/ComputedType.js Normal file
View File

@@ -0,0 +1,16 @@
/** @typedef {import("./IEntity").default} IEntity */
export default class ComputedType {
#f
/** @param {Function} f */
constructor(f) {
this.#f = f
}
/** @param {IEntity} entity */
compute(entity) {
return this.#f(entity)
}
}

View File

@@ -1,3 +1,4 @@
import ComputedType from "./ComputedType.js"
import SerializerFactory from "../serialization/SerializerFactory.js"
import UnionType from "./UnionType.js"
import Utility from "../Utility.js"
@@ -78,15 +79,15 @@ export default class IEntity {
if (!attribute) {
// Remember attributeName can come from the values and be not defined in the attributes
// In that case just assign it and skip the rest
target[attributeName] = value
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 ComputedType) {
defaultType = defaultType.compute(this)
}
if (defaultType instanceof Array) {
defaultType = Array
@@ -190,11 +191,14 @@ export default class IEntity {
...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 === undefined) {
if (attribute.type === undefined) {
throw new Error(
`UEBlueprint: Expected either "type" or "value" property in ${this.name} attribute ${prefix}`
+ attributeName
)
}
attribute[attributeName] = Utility.sanitize(undefined, attribute.type)
}
if (attribute.value === null) {
attributes[attributeName].nullable = true

View File

@@ -88,6 +88,7 @@ export default class ObjectEntity extends IEntity {
},
InputKey: {
type: SymbolEntity,
value: null,
showDefault: false,
},
bOverrideFunction: {

View File

@@ -21,6 +21,7 @@ import UnionType from "./UnionType.js"
import Utility from "../Utility.js"
import Vector2DEntity from "./Vector2DEntity.js"
import VectorEntity from "./VectorEntity.js"
import ComputedType from "./ComputedType.js"
/**
* @typedef {import("./IEntity").AnyValue} AnyValue
@@ -52,71 +53,71 @@ export default class PinEntity extends IEntity {
}
static lookbehind = "Pin"
static attributes = {
"PinId": {
PinId: {
type: GuidEntity,
},
"PinName": "",
"PinFriendlyName": {
PinName: "",
PinFriendlyName: {
type: new UnionType(LocalizedTextEntity, FormatTextEntity, String),
showDefault: false,
},
"PinToolTip": {
PinToolTip: {
type: String,
showDefault: false,
},
"Direction": {
Direction: {
type: String,
showDefault: false,
},
"PinType.PinCategory": "",
"PinType.PinSubCategory": "",
"PinType.PinSubCategoryObject": {
PinType$PinCategory: "",
PinType$PinSubCategory: "",
PinType$PinSubCategoryObject: {
type: ObjectReferenceEntity,
},
"PinType.PinSubCategoryMemberReference": {
PinType$PinSubCategoryMemberReference: {
type: FunctionReferenceEntity,
value: null,
},
"PinType.PinValueType": {
PinType$PinValueType: {
type: PinTypeEntity,
value: null,
},
"PinType.ContainerType": {
PinType$ContainerType: {
type: PathSymbolEntity,
},
"PinType.bIsReference": false,
"PinType.bIsConst": false,
"PinType.bIsWeakPointer": false,
"PinType.bIsUObjectWrapper": false,
"PinType.bSerializeAsSinglePrecisionFloat": false,
"LinkedTo": {
PinType$bIsReference: false,
PinType$bIsConst: false,
PinType$bIsWeakPointer: false,
PinType$bIsUObjectWrapper: false,
PinType$bSerializeAsSinglePrecisionFloat: false,
LinkedTo: {
type: [PinReferenceEntity],
showDefault: false,
},
"DefaultValue": {
DefaultValue: {
/** @param {PinEntity} pinEntity */
type: pinEntity => pinEntity.getEntityType(true) ?? String,
type: new ComputedType(pinEntity => pinEntity.getEntityType(true) ?? String),
serialized: true,
showDefault: false,
},
"AutogeneratedDefaultValue": {
AutogeneratedDefaultValue: {
type: String,
showDefault: false,
},
"DefaultObject": {
DefaultObject: {
type: ObjectReferenceEntity,
showDefault: false,
value: null,
},
"PersistentGuid": {
PersistentGuid: {
type: GuidEntity,
},
"bHidden": false,
"bNotConnectable": false,
"bDefaultValueIsReadOnly": false,
"bDefaultValueIsIgnored": false,
"bAdvancedView": false,
"bOrphanedPin": false,
bHidden: false,
bNotConnectable: false,
bDefaultValueIsReadOnly: false,
bDefaultValueIsIgnored: false,
bAdvancedView: false,
bOrphanedPin: false,
}
static {
@@ -130,17 +131,17 @@ export default class PinEntity extends IEntity {
/** @type {LocalizedTextEntity | String} */ this.PinFriendlyName
/** @type {String} */ this.PinToolTip
/** @type {String} */ this.Direction
this.PinType$PinCategory ??= /** @type {String} */(undefined)
this.PinType$PinSubCategory ??= /** @type {String} */(undefined)
this.PinType$PinSubCategoryObject ??= /** @type {ObjectReferenceEntity} */(undefined)
this.PinType$PinSubCategoryMemberReference ??= /** @type {FunctionReferenceEntity} */(undefined)
this.PinType$PinValueType ??= /** @type {PinTypeEntity} */(undefined)
this.PinType$ContainerType ??= /** @type {PathSymbolEntity} */(undefined)
this.PinType$bIsReference ??= /** @type {Boolean} */(undefined)
this.PinType$bIsConst ??= /** @type {Boolean} */(undefined)
this.PinType$bIsWeakPointer ??= /** @type {Boolean} */(undefined)
this.PinType$bIsUObjectWrapper ??= /** @type {Boolean} */(undefined)
this.PinType$bIsUObjectWrapper ??= /** @type {Boolean} */(undefined)
/** @type {String} */ this.PinType$PinCategory
/** @type {String} */ this.PinType$PinSubCategory
/** @type {ObjectReferenceEntity} */ this.PinType$PinSubCategoryObject
/** @type {FunctionReferenceEntity} */ this.PinType$PinSubCategoryMemberReference
/** @type {PinTypeEntity} */ this.PinType$PinValueType
/** @type {PathSymbolEntity} */ this.PinType$ContainerType
/** @type {Boolean} */ this.PinType$bIsReference
/** @type {Boolean} */ this.PinType$bIsConst
/** @type {Boolean} */ this.PinType$bIsWeakPointer
/** @type {Boolean} */ this.PinType$bIsUObjectWrapper
/** @type {Boolean} */ this.PinType$bIsUObjectWrapper
/** @type {PinReferenceEntity[]} */ this.LinkedTo
/** @type {T} */ this.DefaultValue
/** @type {String} */ this.AutogeneratedDefaultValue