mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-06-17 18:03:17 +08:00
Replace parsing and test libraries
* WIP * WIP * wip * WIP * Several fixes * Tests wip port to playwright * WIP * Fix more tests * Serialization tests fixed * Several fixes for tests * Input options types * Type adjustments * Fix object reference parser * Tests fixes * More tests fixes
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import ComputedType from "./ComputedType.js"
|
||||
import Configuration from "../Configuration.js"
|
||||
import MirroredEntity from "./MirroredEntity.js"
|
||||
import Serializable from "../serialization/Serializable.js"
|
||||
import SerializerFactory from "../serialization/SerializerFactory.js"
|
||||
import Union from "./Union.js"
|
||||
import Utility from "../Utility.js"
|
||||
|
||||
/** @abstract */
|
||||
export default class IEntity extends Serializable {
|
||||
|
||||
/** @type {String | Union<String[]>} */
|
||||
@@ -31,7 +33,7 @@ export default class IEntity extends Serializable {
|
||||
let attributes = Self.attributes
|
||||
if (values.attributes) {
|
||||
attributes = { ...Self.attributes }
|
||||
Utility.mergeArrays(Object.keys(attributes), Object.keys(values.attributes))
|
||||
Utility.mergeArrays(Object.keys(values.attributes), Object.keys(attributes))
|
||||
.forEach(k => {
|
||||
attributes[k] = {
|
||||
...IEntity.defaultAttribute,
|
||||
@@ -55,13 +57,17 @@ export default class IEntity extends Serializable {
|
||||
}
|
||||
for (const attributeName of allAttributesNames) {
|
||||
if (attributeName == "attributes") {
|
||||
// Ignore this special attribute describing all the attributes
|
||||
continue
|
||||
}
|
||||
let value = values[attributeName]
|
||||
let attribute = attributes[attributeName]
|
||||
|
||||
if (!suppressWarns && value !== undefined) {
|
||||
if (!(attributeName in attributes) && !attributeName.startsWith("#SubObject")) {
|
||||
if (
|
||||
!(attributeName in attributes)
|
||||
&& !attributeName.startsWith(Configuration.subObjectAttributeNamePrefix)
|
||||
) {
|
||||
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 `
|
||||
@@ -128,7 +134,7 @@ export default class IEntity extends Serializable {
|
||||
.getSerializer(defaultType)
|
||||
.read(/** @type {String} */(value))
|
||||
}
|
||||
assignAttribute(Utility.sanitize(value, /** @type {SimpleValueType<SimpleValue>} */(defaultType)))
|
||||
assignAttribute(Utility.sanitize(value, /** @type {AttributeConstructor<Attribute>} */(defaultType)))
|
||||
continue // We have a value, need nothing more
|
||||
}
|
||||
if (Object.hasOwn(attribute, "default")) { // Accept also explicit undefined
|
||||
@@ -137,7 +143,7 @@ export default class IEntity extends Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
/** @param {AttributeType} attributeType */
|
||||
/** @param {AttributeTypeDescription} attributeType */
|
||||
static defaultValueProviderFromType(attributeType) {
|
||||
if (attributeType === Boolean) {
|
||||
return false
|
||||
@@ -152,12 +158,11 @@ export default class IEntity extends Serializable {
|
||||
} else if (attributeType instanceof Union) {
|
||||
return this.defaultValueProviderFromType(attributeType.values[0])
|
||||
} else if (attributeType instanceof MirroredEntity) {
|
||||
return () => new MirroredEntity(attributeType.type, attributeType.key, attributeType.getter)
|
||||
return () => new MirroredEntity(attributeType.type, attributeType.getter)
|
||||
} else if (attributeType instanceof ComputedType) {
|
||||
return undefined
|
||||
} else {
|
||||
// @ts-expect-error
|
||||
return () => new attributeType()
|
||||
return () => new /** @type {AnyConstructor<Attribute>} */(attributeType)()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,6 +210,7 @@ export default class IEntity extends Serializable {
|
||||
return this.getAttributes(object)[attribute]
|
||||
}
|
||||
|
||||
/** @returns {AttributeDeclarations} */
|
||||
static getAttributes(object) {
|
||||
return object.attributes ?? object.constructor?.attributes ?? {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user