Several serialization and deserialization fixes

This commit is contained in:
barsdeveloper
2023-04-15 12:20:53 +02:00
parent d10589f0bd
commit baf40a9094
17 changed files with 366 additions and 149 deletions

View File

@@ -49,10 +49,19 @@ export default class IEntity {
const Self = /** @type {EntityConstructor} */(this.constructor)
let attributes = Self.attributes
if (values.attributes) {
let attributes = { ...Self.attributes }
Utility.mergeArrays(Object.keys(attributes), Object.keys(values.attributes))
.forEach(k => attributes[k] = {
...attributes[k],
...values.attributes[k]
.forEach(k => {
attributes[k] = {
...IEntity.defaultAttribute,
...attributes[k],
...values.attributes[k]
}
if (!attributes[k].type) {
attributes[k].type = values[k] instanceof Array
? [Utility.getType(values[k][0])]
: Utility.getType(values[k])
}
})
IEntity.defineAttributes(this, attributes)
}

View File

@@ -11,7 +11,7 @@ import PinEntity from "./PinEntity.js"
import SVGIcon from "../SVGIcon.js"
import SymbolEntity from "./SymbolEntity.js"
import UnionType from "./UnionType.js"
import UserDefinedPinEntity from "./UserDefinedPinEntity.js"
import UnknownPinEntity from "./UnknownPinEntity.js"
import Utility from "../Utility.js"
import VariableReferenceEntity from "./VariableReferenceEntity.js"
@@ -187,6 +187,7 @@ export default class ObjectEntity extends IEntity {
},
NodeGuid: {
type: GuidEntity,
showDefault: false,
},
ErrorType: {
type: IntegerEntity,
@@ -198,7 +199,7 @@ export default class ObjectEntity extends IEntity {
showDefault: false,
},
CustomProperties: {
type: [new UnionType(PinEntity, UserDefinedPinEntity)]
type: [new UnionType(PinEntity, UnknownPinEntity)]
},
}
@@ -299,7 +300,7 @@ export default class ObjectEntity extends IEntity {
/** @type {GuidEntity} */ this.NodeGuid
/** @type {IntegerEntity?} */ this.ErrorType
/** @type {String?} */ this.ErrorMsg
/** @type {PinEntity[]} */ this.CustomProperties
/** @type {(PinEntity | UnknownPinEntity)[]} */ this.CustomProperties
}
getClass() {

6
js/entity/UnknownPinEntity.js Executable file
View File

@@ -0,0 +1,6 @@
import PinEntity from "./PinEntity.js"
export default class UnknownPinEntity extends PinEntity {
static lookbehind = ""
}

View File

@@ -1,9 +0,0 @@
import IEntity from "./IEntity.js"
import PinEntity from "./PinEntity.js"
/** @typedef {import("./IEntity.js").AnyValue} AnyValue */
export default class UserDefinedPinEntity extends IEntity {
static lookbehind = "UserDefinedPin"
}