More entities fixed

This commit is contained in:
barsdeveloper
2024-06-04 01:00:41 +02:00
parent 1a8636bb5d
commit c05e6d3cc9
15 changed files with 913 additions and 456 deletions

View File

@@ -1,22 +1,40 @@
import P from "parsernostrum"
import Grammar from "../serialization/Grammar.js"
import VectorEntity from "./VectorEntity.js"
import NumberEntity from "./NumberEntity.js"
export default class SimpleSerializationVectorEntity extends VectorEntity {
static attributeSeparator = ", "
/** @type {P<SimpleSerializationVectorEntity>} */
static grammar = P.alt(
P.regArray(new RegExp(
`(${Grammar.numberRegexSource})`
`(${NumberEntity.numberRegexSource})`
+ String.raw`\s*,\s*`
+ `(${Grammar.numberRegexSource})`
+ `(${NumberEntity.numberRegexSource})`
+ String.raw`\s*,\s*`
+ `(${Grammar.numberRegexSource})`
+ `(${NumberEntity.numberRegexSource})`
))
.map(([_0, x, y, z]) => new this({
X: Number(x),
Y: Number(y),
Z: Number(z),
.map(([_, x, xPrecision, y, yPrecision, z, zPrecision]) => new this({
X: new NumberEntity(x, xPrecision?.length),
Y: new NumberEntity(y, yPrecision?.length),
Z: new NumberEntity(z, zPrecision?.length),
})),
VectorEntity.grammar
VectorEntity.grammar.map(v => new this({
X: v.X,
Y: v.Y,
Z: v.Z,
}))
)
toString(
insideString = false,
indentation = "",
printKey = this.Self().printKey,
) {
const Self = this.Self()
return this.X.toString(insideString) + Self.attributeSeparator
+ this.Y.toString(insideString) + Self.attributeSeparator
+ this.Z.toString(insideString) + (this.trailing ? Self.attributeSeparator : "")
}
}