Fix attributes keys order

This commit is contained in:
barsdeveloper
2022-12-29 13:23:11 +01:00
parent 0e7b61d701
commit 8c4ef42d7c
5 changed files with 30 additions and 16 deletions

View File

@@ -211,10 +211,13 @@ export default class Utility {
*/
static mergeArrays(a = [], b = []) {
let result = []
a = [...a]
b = [...b]
restart:
for (let j = 0; j < b.length; ++j) {
for (let i = 0; i < a.length; ++i) {
if (a[i] == b[j]) {
// Found a corresponding element in the two arrays
// Found an element in common in the two arrays
result.push(
// Take and append all the elements skipped from a
...a.splice(0, i),
@@ -223,10 +226,8 @@ export default class Utility {
// Take and append the element in common
...a.splice(0, 1)
)
j = 0
i = 0
b.shift()
break
b.shift() // Remove the same element from b
break restart
}
}
}

View File

@@ -324,9 +324,9 @@ export default class Grammar {
r.LocalizedText,
r.InvariantText,
r.PinReference,
Grammar.createEntityGrammar(r, Vector2DEntity, true),
Grammar.createEntityGrammar(r, VectorEntity, true),
Grammar.createEntityGrammar(r, LinearColorEntity, true),
Grammar.createEntityGrammar(r, Vector2DEntity, true),
r.UnknownKeys,
r.ObjectReference,
r.Symbol,

View File

@@ -89,7 +89,15 @@ export default class ISerializer {
let result = ""
let fullKey = key.concat("")
const last = fullKey.length - 1
for (const property of Object.getOwnPropertyNames(object)) {
const attributes = /** @type {EntityConstructor} */(object.constructor).attributes
const keys =
attributes ?
Utility.mergeArrays(
Object.getOwnPropertyNames(attributes),
Object.getOwnPropertyNames(object)
)
: Object.getOwnPropertyNames(object)
for (const property of keys) {
fullKey[last] = property
const value = object[property]
if (value?.constructor === Object) {