mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-05-19 04:07:33 +08:00
Arrays elements can now be inlined
This commit is contained in:
@@ -36,11 +36,13 @@ import Vector2DEntity from "../entity/Vector2DEntity.js"
|
||||
import VectorEntity from "../entity/VectorEntity.js"
|
||||
|
||||
/**
|
||||
* @typedef {import ("../entity/IEntity").AnyValue} AnyValue
|
||||
* @typedef {import ("../entity/IEntity").AttributeType} AttributeType
|
||||
* @typedef {import ("../entity/IEntity").AttributeInformation} AttributeInformation
|
||||
* @typedef {import ("../entity/IEntity").EntityConstructor} EntityConstructor
|
||||
*/
|
||||
/**
|
||||
* @template T
|
||||
* @template {AnyValue} T
|
||||
* @typedef {import ("../entity/IEntity").AnyValueConstructor<T>} AnyValueConstructor
|
||||
*/
|
||||
|
||||
@@ -133,7 +135,7 @@ export default class Grammar {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {AnyValueConstructor<any>} type
|
||||
* @param {AttributeType} type
|
||||
* @returns {Parsimmon.Parser<any>}
|
||||
*/
|
||||
static grammarFor(
|
||||
@@ -597,8 +599,8 @@ export default class Grammar {
|
||||
})
|
||||
)
|
||||
|
||||
static inlinedArrayEntry = P.lazy(() => {
|
||||
return P.seq(
|
||||
static inlinedArrayEntry = P.lazy(() =>
|
||||
P.seq(
|
||||
this.symbol,
|
||||
this.regexMap(
|
||||
new RegExp(`\\s*\\(\\s*(\\d+)\\s*\\)\\s*\\=\\s*`),
|
||||
@@ -611,8 +613,16 @@ export default class Grammar {
|
||||
values => (values[symbol] ??= []).push(currentValue)
|
||||
)
|
||||
)
|
||||
})
|
||||
)
|
||||
|
||||
static subObjectEntity = P.lazy(() =>
|
||||
this.objectEntity
|
||||
.map(object =>
|
||||
values => values["SubObject_" + object.Name] = object
|
||||
)
|
||||
)
|
||||
|
||||
/** @type {Parsimmon.Parser<ObjectEntity>} */
|
||||
static objectEntity = P.lazy(() =>
|
||||
P.seq(
|
||||
P.regex(/Begin\s+Object/),
|
||||
@@ -621,7 +631,9 @@ export default class Grammar {
|
||||
P.alt(
|
||||
this.customProperty,
|
||||
this.createAttributeGrammar(ObjectEntity),
|
||||
this.inlinedArrayEntry
|
||||
this.inlinedArrayEntry,
|
||||
// Legacy subobject
|
||||
this.subObjectEntity
|
||||
)
|
||||
)
|
||||
.map(([_0, entry]) => entry)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Grammar from "./Grammar.js"
|
||||
import IEntity from "../entity/IEntity.js"
|
||||
import SerializerFactory from "./SerializerFactory.js"
|
||||
import Utility from "../Utility.js"
|
||||
|
||||
@@ -60,7 +61,7 @@ export default class Serializer {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {T} entity
|
||||
* @param {T & IEntity} entity
|
||||
* @param {Boolean} insideString
|
||||
* @returns {String}
|
||||
*/
|
||||
@@ -74,7 +75,7 @@ export default class Serializer {
|
||||
attributeKeyPrinter = this.attributeKeyPrinter
|
||||
) {
|
||||
let result = ""
|
||||
const attributes = /** @type {EntityConstructor} */(entity.constructor).attributes ?? {}
|
||||
const attributes = IEntity.getAttributes(entity)
|
||||
const keys = Utility.mergeArrays(
|
||||
Object.keys(attributes),
|
||||
Object.keys(entity)
|
||||
@@ -83,6 +84,7 @@ export default class Serializer {
|
||||
for (const key of keys) {
|
||||
const value = entity[key]
|
||||
if (value !== undefined && this.showProperty(entity, key)) {
|
||||
const keyValue = entity instanceof Array ? `(${key})` : key
|
||||
const isSerialized = Utility.isSerialized(entity, key)
|
||||
if (first) {
|
||||
first = false
|
||||
@@ -98,13 +100,13 @@ export default class Serializer {
|
||||
false,
|
||||
attributeValueConjunctionSign,
|
||||
attributes[key].type instanceof Array
|
||||
? k => attributeKeyPrinter(`${key}(${k})`)
|
||||
: k => attributeKeyPrinter(`${key}.${k}`),
|
||||
? k => attributeKeyPrinter(`${keyValue}${k}`)
|
||||
: k => attributeKeyPrinter(`${keyValue}.${k}`)
|
||||
)
|
||||
continue
|
||||
}
|
||||
result +=
|
||||
attributeKeyPrinter(key)
|
||||
attributeKeyPrinter(keyValue)
|
||||
+ this.attributeValueConjunctionSign
|
||||
+ (
|
||||
isSerialized
|
||||
|
||||
Reference in New Issue
Block a user