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

29
dist/ueblueprint.js vendored
View File

@@ -3073,7 +3073,7 @@ class Grammar {
).chain(([attributeName, _1]) => {
const attributeKey = attributeName.split(Configuration.keysSeparator);
const attributeValue = this.getAttribute(entityType, attributeKey);
return attributeValue.grammar.map(attributeValue =>
return (attributeValue?.grammar ?? IEntity.unknownEntityGrammar).map(attributeValue =>
values => {
handleObjectSet(values, attributeKey, attributeValue);
Utility.objectSet(values, attributeKey, attributeValue);
@@ -3083,11 +3083,11 @@ class Grammar {
}
/**
* @template {IEntity} T
* @param {new (...args: any) => T} entityType
* @return {Parsernostrum<T>}
* @template {typeof IEntity} T
* @param {T} entityType
* @return {Parsernostrum<InstanceType<T>>}
*/
static createEntityGrammar(entityType, entriesSeparator = this.commaSeparation) {
static createEntityGrammar(entityType, entriesSeparator = this.commaSeparation, complete = false) {
const lookbehind = entityType.lookbehind instanceof Array ? entityType.lookbehind.join("|") : entityType.lookbehind;
return Parsernostrum.seq(
Parsernostrum.reg(new RegExp(String.raw`(${lookbehind})\s*\(\s*`), 1),
@@ -3108,7 +3108,12 @@ class Grammar {
if (entityType.lookbehind instanceof Array || entityType.lookbehind !== lookbehind) {
entityType = entityType.withLookbehind(lookbehind);
}
return Parsernostrum.success().map(() => new entityType(values))
const keys = Object.keys(values);
return complete
? Parsernostrum.success()
.assert(v => Object.keys(entityType.attributes).every(k => keys.includes(k)))
.map(() => new entityType(values))
: Parsernostrum.success().map(() => new entityType(values))
})
}
@@ -5191,7 +5196,7 @@ class Vector2DEntity extends IEntity {
X: NumberEntity.withDefault(),
Y: NumberEntity.withDefault(),
}
static grammar = Grammar.createEntityGrammar(this).label("Vector2DEntity")
static grammar = Grammar.createEntityGrammar(this, Grammar.commaSeparation, true).label("Vector2DEntity")
constructor(values) {
super(values);
@@ -5228,7 +5233,7 @@ 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);
@@ -5324,7 +5329,7 @@ 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);
@@ -5374,7 +5379,7 @@ class VectorEntity extends IEntity {
Y: NumberEntity.withDefault(),
Z: NumberEntity.withDefault(),
}
static grammar = Grammar.createEntityGrammar(this).label("VectorEntity")
static grammar = Grammar.createEntityGrammar(this, Grammar.commaSeparation, true).label("VectorEntity")
constructor(values) {
super(values);
@@ -13428,11 +13433,11 @@ function initializeSerializerFactory() {
InvariantTextEntity.grammar,
FormatTextEntity.grammar,
PinReferenceEntity.grammar,
Vector4DEntity.grammar,
Vector2DEntity.grammar,
VectorEntity.grammar,
Vector4DEntity.grammar,
RotatorEntity.grammar,
LinearColorEntity.grammar,
Vector2DEntity.grammar,
UnknownKeysEntity.grammar,
SymbolEntity.grammar,
ArrayEntity.of(PinReferenceEntity).grammar,

File diff suppressed because one or more lines are too long