Simple entities serialization fixed

This commit is contained in:
barsdeveloper
2024-06-04 14:40:47 +02:00
parent c05e6d3cc9
commit e16822760f
11 changed files with 266 additions and 128 deletions

View File

@@ -243,12 +243,20 @@ export default class IEntity {
}
const thisKeys = Object.keys(this)
const otherKeys = Object.keys(other)
if (thisKeys.length != otherKeys.length || !(this instanceof other.constructor) && !(other instanceof this.constructor)) {
if (
thisKeys.length !== otherKeys.length
|| this.lookbehind != other.lookbehind
|| !(this instanceof other.constructor) && !(other instanceof this.constructor)
) {
return false
}
for (let i = 0; i < thisKeys.length; ++i) {
const a = this[thisKeys[i]]
const b = other[otherKeys[i]]
const k = thisKeys[i]
if (!otherKeys.includes(k)) {
return false
}
const a = this[k]
const b = other[k]
if (a instanceof IEntity) {
if (!a.equals(b)) {
return false
@@ -298,7 +306,7 @@ export default class IEntity {
}
result += serialization
}
if (Self.trailing && result.length) {
if (this.trailing && result.length) {
result += Self.attributeSeparator
}
return Self.wrap(this, result)

View File

@@ -10,7 +10,7 @@ export default class RotatorEntity extends IEntity {
P: NumberEntity.withDefault(),
Y: NumberEntity.withDefault(),
}
static grammar = Grammar.createEntityGrammar(this).label("RotatorEntity")
static grammar = Grammar.createEntityGrammar(this, Grammar.commaSeparation, true).label("RotatorEntity")
constructor(values) {
super(values)

View File

@@ -4,6 +4,7 @@ import IEntity from "./IEntity.js"
export default class UnknownKeysEntity extends IEntity {
/** @type {P<UnknownKeysEntity>} */
static grammar = P.seq(
// Lookbehind
P.reg(new RegExp(`(${Grammar.Regex.Path.source}|${Grammar.Regex.Symbol.source}\\s*)?\\(\\s*`), 1),

View File

@@ -1,3 +1,4 @@
import P from "parsernostrum"
import Grammar from "../serialization/Grammar.js"
import IEntity from "./IEntity.js"
import NumberEntity from "./NumberEntity.js"
@@ -9,7 +10,8 @@ export default class Vector2DEntity extends IEntity {
X: NumberEntity.withDefault(),
Y: NumberEntity.withDefault(),
}
static grammar = Grammar.createEntityGrammar(this).label("Vector2DEntity")
/** @type {P<Vector2DEntity>} */
static grammar = Grammar.createEntityGrammar(this, Grammar.commaSeparation, true).label("Vector2DEntity")
constructor(values) {
super(values)

View File

@@ -11,7 +11,7 @@ export default class Vector4DEntity extends IEntity {
Z: NumberEntity.withDefault(),
W: NumberEntity.withDefault(),
}
static grammar = Grammar.createEntityGrammar(this).label("Vector4DEntity")
static grammar = Grammar.createEntityGrammar(this, Grammar.commaSeparation, true).label("Vector4DEntity")
constructor(values) {
super(values)

View File

@@ -1,3 +1,4 @@
import P from "parsernostrum"
import Grammar from "../serialization/Grammar.js"
import IEntity from "./IEntity.js"
import NumberEntity from "./NumberEntity.js"
@@ -10,7 +11,8 @@ export default class VectorEntity extends IEntity {
Y: NumberEntity.withDefault(),
Z: NumberEntity.withDefault(),
}
static grammar = Grammar.createEntityGrammar(this).label("VectorEntity")
/** @type {P<VectorEntity>} */
static grammar = Grammar.createEntityGrammar(this, Grammar.commaSeparation, true).label("VectorEntity")
constructor(values) {
super(values)