Inline attributes semantics and tests

This commit is contained in:
barsdeveloper
2023-04-09 10:41:50 +02:00
parent 0a40f0b33c
commit 53d79a16f5
22 changed files with 508 additions and 382 deletions

View File

@@ -4,13 +4,9 @@ import UnionType from "./UnionType.js"
import Utility from "../Utility.js"
/**
* @typedef {(entity: IEntity) => AnyValue} ValueSupplier
* @typedef {IEntity | String | Number | BigInt | Boolean} AnySimpleValue
* @typedef {AnySimpleValue | AnySimpleValue[]} AnyValue
* @typedef {{
* [key: String]: AttributeInformation
* }} AttributeDeclarations
* @typedef {typeof IEntity} EntityConstructor
* @typedef {(entity: IEntity) => AnyValue} ValueSupplier
* @typedef {{
* type?: AnyValueConstructor<AnyValue> | AnyValueConstructor<AnyValue>[] | UnionType | ComputedType,
* default?: AnyValue | ValueSupplier,
@@ -22,6 +18,10 @@ import Utility from "../Utility.js"
* inlined?: Boolean,
* predicate?: (value: AnyValue) => Boolean,
* }} AttributeInformation
* @typedef {{
* [key: String]: AttributeInformation
* }} AttributeDeclarations
* @typedef {typeof IEntity} EntityConstructor
*/
/**
@@ -45,7 +45,8 @@ export default class IEntity {
}
constructor(values = {}, suppressWarns = false) {
const attributes = /** @type {typeof IEntity} */(this.constructor).attributes
const Self = /** @type {EntityConstructor} */(this.constructor)
const attributes = Self.attributes
if (values.constructor !== Object && Object.keys(attributes).length === 1) {
// Where there is just one attribute, option can be the value of that attribute
values = {
@@ -57,14 +58,14 @@ export default class IEntity {
const allAttributesNames = Utility.mergeArrays(attributesNames, valuesNames)
for (let attributeName of allAttributesNames) {
let value = values[attributeName]
let attribute = /** @type {AttributeInformation} */(attributes[attributeName])
let attribute = attributes[attributeName]
if (!suppressWarns) {
if (!(attributeName in attributes)) {
const typeName = value instanceof Array ? `[${value[0].constructor.name}]` : value.constructor.name
console.warn(
`UEBlueprint: Attribute ${attributeName} (of type ${typeName}) in the serialized data is not defined in `
+ `${this.constructor.name}.attributes`
`UEBlueprint: Attribute ${attributeName} (of type ${typeName}) in the serialized data is not `
+ `defined in ${Self.name}.attributes`
)
} else if (
valuesNames.length > 0
@@ -72,8 +73,7 @@ export default class IEntity {
&& !(!attribute.showDefault || attribute.ignored)
) {
console.warn(
`UEBlueprint: ${this.constructor.name} will add attribute ${attributeName} not `
+ "defined in the serialized data"
`UEBlueprint: ${Self.name} will add attribute ${attributeName} missing from the serialized data`
)
}
}
@@ -115,8 +115,8 @@ export default class IEntity {
set(v) {
if (!attribute.predicate?.(v)) {
console.warn(
`UEBlueprint: Tried to assign attribute ${attributeName} to `
+ `${this.constructor.name} not satisfying the predicate`
`UEBlueprint: Tried to assign attribute ${attributeName} to`
+ `${Self.name} not satisfying the predicate`
)
return
}
@@ -172,7 +172,9 @@ export default class IEntity {
for (const attributeName in attributes) {
const attribute = /** @type {AttributeInformation} */(attributes[attributeName])
if (attribute.type === undefined && !(attribute.default instanceof Function)) {
attribute.type = Utility.getType(attribute.default)
attribute.type = attribute.default instanceof Array
? [Utility.getType(attribute.default[0])]
: Utility.getType(attribute.default)
}
attributes[attributeName] = {
...IEntity.defaultAttribute,

View File

@@ -1,17 +0,0 @@
/** @typedef {import("./IEntity").AnyValueConstructor<*>} AnyValueConstructor */
export default class IndexedArray {
#type
get type() {
return this.#type
}
value = []
/** @param {AnyValueConstructor} type */
constructor(type, value = []) {
this.#type = type
this.value = value
}
}

View File

@@ -414,7 +414,7 @@ export default class ObjectEntity extends IEntity {
}
getDelegatePin() {
return this.CustomProperties?.find(pin => pin.PinType$PinCategory === "delegate")
return this.CustomProperties?.find(pin => pin.PinType.PinCategory === "delegate")
}
nodeDisplayName() {

View File

@@ -3,7 +3,6 @@ import ComputedType from "./ComputedType.js"
import Configuration from "../Configuration.js"
import EnumEntity from "./EnumEntity.js"
import FormatTextEntity from "./FormatTextEntity.js"
import FunctionReferenceEntity from "./FunctionReferenceEntity.js"
import GuidEntity from "./GuidEntity.js"
import IEntity from "./IEntity.js"
import Integer64Entity from "./Integer64Entity.js"
@@ -11,13 +10,12 @@ import IntegerEntity from "./IntegerEntity.js"
import LinearColorEntity from "./LinearColorEntity.js"
import LocalizedTextEntity from "./LocalizedTextEntity.js"
import ObjectReferenceEntity from "./ObjectReferenceEntity.js"
import PathSymbolEntity from "./PathSymbolEntity.js"
import PinReferenceEntity from "./PinReferenceEntity.js"
import PinTypeEntity from "./PinTypeEntity.js"
import RotatorEntity from "./RotatorEntity.js"
import SimpleSerializationRotatorEntity from "./SimpleSerializationRotatorEntity.js"
import SimpleSerializationVector2DEntity from "./SimpleSerializationVector2DEntity.js"
import SimpleSerializationVectorEntity from "./SimpleSerializationVectorEntity.js"
import TerminalTypeEntity from "./TerminalTypeEntity.js"
import UnionType from "./UnionType.js"
import Utility from "../Utility.js"
import Vector2DEntity from "./Vector2DEntity.js"
@@ -71,40 +69,9 @@ export default class PinEntity extends IEntity {
type: String,
showDefault: false,
},
PinType$PinCategory: {
default: "",
},
PinType$PinSubCategory: {
default: "",
},
PinType$PinSubCategoryObject: {
type: ObjectReferenceEntity,
},
PinType$PinSubCategoryMemberReference: {
type: FunctionReferenceEntity,
default: null,
},
PinType$PinValueType: {
type: TerminalTypeEntity,
default: null,
},
PinType$ContainerType: {
type: PathSymbolEntity,
},
PinType$bIsReference: {
default: false,
},
PinType$bIsConst: {
default: false,
},
PinType$bIsWeakPointer: {
default: false,
},
PinType$bIsUObjectWrapper: {
default: false,
},
PinType$bSerializeAsSinglePrecisionFloat: {
default: false,
PinType: {
type: PinTypeEntity,
inlined: true,
},
LinkedTo: {
type: [PinReferenceEntity],
@@ -167,17 +134,7 @@ export default class PinEntity extends IEntity {
/** @type {LocalizedTextEntity | String} */ this.PinFriendlyName
/** @type {String} */ this.PinToolTip
/** @type {String} */ this.Direction
/** @type {String} */ this.PinType$PinCategory
/** @type {String} */ this.PinType$PinSubCategory
/** @type {ObjectReferenceEntity} */ this.PinType$PinSubCategoryObject
/** @type {FunctionReferenceEntity} */ this.PinType$PinSubCategoryMemberReference
/** @type {TerminalTypeEntity} */ 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 {PinTypeEntity} */ this.PinType
/** @type {PinReferenceEntity[]} */ this.LinkedTo
/** @type {T} */ this.DefaultValue
/** @type {String} */ this.AutogeneratedDefaultValue
@@ -192,12 +149,12 @@ export default class PinEntity extends IEntity {
}
getType() {
const subCategory = this.PinType$PinSubCategoryObject
if (this.PinType$PinCategory === "struct" || this.PinType$PinCategory === "object") {
const subCategory = this.PinType.PinSubCategoryObject
if (this.PinType.PinCategory === "struct" || this.PinType.PinCategory === "object") {
return subCategory.path
}
if (
this.PinType$PinCategory === "byte"
this.PinType.PinCategory === "byte"
&& (
subCategory.type === Configuration.nodeType.enum
|| subCategory.type === Configuration.nodeType.userDefinedEnum
@@ -205,7 +162,7 @@ export default class PinEntity extends IEntity {
) {
return "enum"
}
return this.PinType$PinCategory
return this.PinType.PinCategory
}
getEntityType(alternative = false) {
@@ -234,16 +191,16 @@ export default class PinEntity extends IEntity {
/** @param {PinEntity} other */
copyTypeFrom(other) {
this.PinType$PinCategory = other.PinType$PinCategory
this.PinType$PinSubCategory = other.PinType$PinSubCategory
this.PinType$PinSubCategoryObject = other.PinType$PinSubCategoryObject
this.PinType$PinSubCategoryMemberReference = other.PinType$PinSubCategoryMemberReference
this.PinType$PinValueType = other.PinType$PinValueType
this.PinType$ContainerType = other.PinType$ContainerType
this.PinType$bIsReference = other.PinType$bIsReference
this.PinType$bIsConst = other.PinType$bIsConst
this.PinType$bIsWeakPointer = other.PinType$bIsWeakPointer
this.PinType$bIsUObjectWrapper = other.PinType$bIsUObjectWrapper
this.PinType.PinCategory = other.PinType.PinCategory
this.PinType.PinSubCategory = other.PinType.PinSubCategory
this.PinType.PinSubCategoryObject = other.PinType.PinSubCategoryObject
this.PinType.PinSubCategoryMemberReference = other.PinType.PinSubCategoryMemberReference
this.PinType.PinValueType = other.PinType.PinValueType
this.PinType.ContainerType = other.PinType.ContainerType
this.PinType.bIsReference = other.PinType.bIsReference
this.PinType.bIsConst = other.PinType.bIsConst
this.PinType.bIsWeakPointer = other.PinType.bIsWeakPointer
this.PinType.bIsUObjectWrapper = other.PinType.bIsUObjectWrapper
this.PinType$bSerializeAsSinglePrecisionFloat = other.PinType$bSerializeAsSinglePrecisionFloat
}
@@ -255,7 +212,7 @@ export default class PinEntity extends IEntity {
}
isExecution() {
return this.PinType$PinCategory === "exec"
return this.PinType.PinCategory === "exec"
}
isHidden() {
@@ -313,13 +270,13 @@ export default class PinEntity extends IEntity {
}
getSubCategory() {
return this.PinType$PinSubCategoryObject.path
return this.PinType.PinSubCategoryObject.path
}
/** @return {CSSResult} */
pinColor() {
return Configuration.pinColor[this.getType()]
?? Configuration.pinColor[this.PinType$PinCategory.toLowerCase()]
?? Configuration.pinColor[this.PinType.PinCategory.toLowerCase()]
?? Configuration.pinColor["default"]
}
}