Small serialization fixes

This commit is contained in:
barsdeveloper
2024-09-08 23:20:07 +02:00
parent 19ef3bd10e
commit 4601c9dc48
6 changed files with 38 additions and 8 deletions

10
dist/ueblueprint.js vendored
View File

@@ -5122,7 +5122,12 @@ class ObjectReferenceEntity extends IEntity {
super();
this.#type = type;
this.#path = path;
this.#full = full ?? `"${this.type + (this.path ? (`'${this.path}'`) : "")}"`;
this.#full = full
?? (
this.type.includes("/") || this.path
? `"${this.type + (this.path ? (`'${this.path}'`) : "")}"`
: this.type
);
}
/** @returns {P<ObjectReferenceEntity>} */
@@ -5162,7 +5167,7 @@ class ObjectReferenceEntity extends IEntity {
}
static createNoneInstance() {
return new ObjectReferenceEntity("None")
return new ObjectReferenceEntity("None", "", "None")
}
getName(dropCounter = false) {
@@ -6436,6 +6441,7 @@ class ObjectEntity extends IEntity {
obj.Node.getter = () => new ObjectReferenceEntity(
this.PCGNode.type,
`${this.Name}.${this.PCGNode.path}`,
nodeRef.full,
);
}
}

File diff suppressed because one or more lines are too long

View File

@@ -30,8 +30,8 @@ export default class ArrayEntity extends IEntity {
).map(([_0, values, trailing]) => {
values = values instanceof Array ? values : []
let Self = this
if (trailing !== undefined != Self.trailing) {
Self = Self.flagTrailing()
if ((trailing !== undefined) !== Self.trailing) {
Self = Self.flagTrailing(trailing !== undefined)
}
const result = new Self(values)
return result

View File

@@ -346,6 +346,7 @@ export default class ObjectEntity extends IEntity {
obj.Node.getter = () => new ObjectReferenceEntity(
this.PCGNode.type,
`${this.Name}.${this.PCGNode.path}`,
nodeRef.full,
)
}
}

View File

@@ -49,7 +49,11 @@ export default class ObjectReferenceEntity extends IEntity {
super()
this.#type = type
this.#path = path
this.#full = full ?? `"${this.type + (this.path ? (`'${this.path}'`) : "")}"`
this.#full = full ?? (
this.type.includes("/") || this.path
? `"${this.type + (this.path ? (`'${this.path}'`) : "")}"`
: this.type
)
}
/** @returns {P<ObjectReferenceEntity>} */
@@ -89,7 +93,7 @@ export default class ObjectReferenceEntity extends IEntity {
}
static createNoneInstance() {
return new ObjectReferenceEntity("None")
return new ObjectReferenceEntity("None", "", "None")
}
getName(dropCounter = false) {

View File

@@ -1158,25 +1158,44 @@ test("StringEntity", () => {
expect(() => grammar.parse("Hello")).toThrow()
})
test("UnknownKeysValue", () => {
test("Unknown", () => {
const parser = IEntity.unknownEntityGrammar
expect(parser.parse('"Hello"')).toBeInstanceOf(StringEntity)
expect(parser.parse('"Hello"').serialize()).toEqual(`"Hello"`)
expect(parser.parse("()")).toBeInstanceOf(NullEntity)
expect(parser.parse("()").serialize()).toEqual("()")
expect(parser.parse("8345")).toBeInstanceOf(NumberEntity)
expect(parser.parse("8345").serialize()).toEqual("8345")
expect(parser.parse("True")).toBeInstanceOf(BooleanEntity)
expect(parser.parse("True").serialize()).toEqual("True")
expect(parser.parse("False")).toBeInstanceOf(BooleanEntity)
expect(parser.parse("False").serialize()).toEqual("False")
expect(parser.parse("F0223D3742E67C0D9FEFB2A64946B7F0")).toBeInstanceOf(GuidEntity)
expect(parser.parse("F0223D3742E67C0D9FEFB2A64946B7F0").serialize()).toEqual("F0223D3742E67C0D9FEFB2A64946B7F0")
expect(parser.parse("None")).toBeInstanceOf(ObjectReferenceEntity)
expect(parser.parse("None").serialize()).toEqual("None")
expect(parser.parse("SYMBOL1")).toBeInstanceOf(SymbolEntity)
expect(parser.parse("SYMBOL1").serialize()).toEqual("SYMBOL1")
expect(parser.parse("Symbol_2_3_4")).toBeInstanceOf(SymbolEntity)
expect(parser.parse("Symbol_2_3_4").serialize()).toEqual("Symbol_2_3_4")
expect(parser.parse("(X=-0.495,Y=+765.0,Z=7,W=56)")).toBeInstanceOf(Vector4DEntity)
expect(parser.parse("(X=-0.495,Y=+765.0,Z=7,W=56)").serialize()).toEqual("(X=-0.495,Y=765.0,Z=7,W=56)")
expect(parser.parse("(X=-0.495, Y=0, )")).toBeInstanceOf(Vector2DEntity)
expect(parser.parse("(X=-0.495, Y=0, )").serialize()).toEqual("(X=-0.495,Y=0,)")
expect(parser.parse("(X=-0.495,Y=+765.0,Z=7)")).toBeInstanceOf(VectorEntity)
expect(parser.parse("(X=-0.495,Y=+765.0,Z=7)").serialize()).toEqual("(X=-0.495,Y=765.0,Z=7)")
expect(parser.parse("(R=1.000000,P=7.6,Y=+88.99)")).toBeInstanceOf(RotatorEntity)
expect(parser.parse("(R=1.000000,P=7.6,Y=+88.99)").serialize()).toEqual("(R=1.000000,P=7.6,Y=88.99)")
expect(parser.parse("(R=0.000000,G=0.660000,B=1.000000,A=1.000000)")).toBeInstanceOf(LinearColorEntity)
expect(parser.parse("(R=0.000000,G=0.660000,B=1.000000,A=1.000000)").serialize()).toEqual("(R=0.000000,G=0.660000,B=1.000000,A=1.000000)")
expect(parser.parse(`Class'"/Script/Engine.KismetSystemLibrary"'`)).toBeInstanceOf(ObjectReferenceEntity)
expect(parser.parse(`Class'"/Script/Engine.KismetSystemLibrary"'`).serialize()).toEqual(`Class'"/Script/Engine.KismetSystemLibrary"'`)
expect(parser.parse("(1,2,3,4,5,6,7,8,9)")).toBeInstanceOf(ArrayEntity)
expect(parser.parse("(1,2,3,4,5,6,7,8,9)").serialize()).toEqual("(1,2,3,4,5,6,7,8,9)")
expect(parser.parse(`("Hello", "World",)`)).toBeInstanceOf(ArrayEntity)
expect(parser.parse(`("Hello", "World",)`).serialize()).toEqual(`("Hello","World",)`)
expect(parser.parse(`("Alpha", 123, Beta, "Gamma", "Delta", 99)`)).toBeInstanceOf(ArrayEntity)
expect(parser.parse(`("Alpha", 123, Beta, "Gamma", "Delta", 99)`).serialize()).toEqual(`("Alpha",123,Beta,"Gamma","Delta",99)`)
})
test("UnknownKeysEntity", () => {