Deduce quoted object reference

This commit is contained in:
barsdeveloper
2024-09-09 15:16:48 +02:00
parent 4601c9dc48
commit 4885a988f9
6 changed files with 41 additions and 17 deletions

24
dist/ueblueprint.js vendored
View File

@@ -4473,8 +4473,8 @@ 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
@@ -5122,12 +5122,11 @@ class ObjectReferenceEntity extends IEntity {
super();
this.#type = type;
this.#path = path;
this.#full = full
?? (
this.type.includes("/") || this.path
? `"${this.type + (this.path ? (`'${this.path}'`) : "")}"`
: this.type
);
this.#full = full ?? (
this.type.includes("/") || this.path
? `"${this.type + (this.path ? (`'${this.path}'`) : "")}"`
: this.type
);
}
/** @returns {P<ObjectReferenceEntity>} */
@@ -6038,6 +6037,7 @@ class NullEntity extends IEntity {
// @ts-expect-error
return Parsernostrum.reg(new RegExp(String.raw`\(${Parsernostrum.whitespaceInlineOpt.getParser().regexp.source}\)`))
.map(v => new this())
.label("NullEntity")
}
serialize(
@@ -13423,7 +13423,13 @@ function initializeSerializerFactory() {
Parsernostrum.str("None").map(() => ObjectReferenceEntity.createNoneInstance()),
NullEntity.grammar,
NumberEntity.grammar,
ObjectReferenceEntity.fullReferenceGrammar,
Parsernostrum.alt(
ObjectReferenceEntity.fullReferenceGrammar,
Parsernostrum.regArray(
// @ts-expect-error
new RegExp(`"(${Grammar.Regex.Path.source})'(${Grammar.symbol.getParser().regexp.source})'"`)
).map(([full, type, path]) => new ObjectReferenceEntity(type, path, full))
),
StringEntity.grammar,
LocalizedTextEntity.grammar,
InvariantTextEntity.grammar,

File diff suppressed because one or more lines are too long

View File

@@ -10,6 +10,7 @@ export default class NullEntity extends IEntity {
// @ts-expect-error
return P.reg(new RegExp(String.raw`\(${P.whitespaceInlineOpt.getParser().regexp.source}\)`))
.map(v => new this())
.label("NullEntity")
}
serialize(

View File

@@ -19,6 +19,7 @@ import UnknownKeysEntity from "../entity/UnknownKeysEntity.js"
import Vector2DEntity from "../entity/Vector2DEntity.js"
import Vector4DEntity from "../entity/Vector4DEntity.js"
import VectorEntity from "../entity/VectorEntity.js"
import Grammar from "./Grammar.js"
export default function initializeSerializerFactory() {
IEntity.unknownEntityGrammar =
@@ -29,7 +30,13 @@ export default function initializeSerializerFactory() {
Parsernostrum.str("None").map(() => ObjectReferenceEntity.createNoneInstance()),
NullEntity.grammar,
NumberEntity.grammar,
ObjectReferenceEntity.fullReferenceGrammar,
Parsernostrum.alt(
ObjectReferenceEntity.fullReferenceGrammar,
Parsernostrum.regArray(
// @ts-expect-error
new RegExp(`"(${Grammar.Regex.Path.source})'(${Grammar.symbol.getParser().regexp.source})'"`)
).map(([full, type, path]) => new ObjectReferenceEntity(type, path, full))
),
StringEntity.grammar,
LocalizedTextEntity.grammar,
InvariantTextEntity.grammar,

View File

@@ -1,13 +1,12 @@
{
"name": "ueblueprint",
"description": "UE's Blueprint visualisation library",
"version": "1.0.0",
"description": "Unreal Engine's Blueprint visualization web library",
"version": "2.0.0",
"type": "module",
"main": "dist/ueblueprint.js",
"types": "types.js",
"scripts": {
"build": "rollup --config && sass scss/export.scss:dist/css/ueb-style.css && sass scss/export.scss:dist/css/ueb-style.min.css --style=compressed",
"test": "npm run build && export UEBLUEPRINT_TEST_SERVER_PORT=8181 && npx concurrently -k \"http-server -s -p $UEBLUEPRINT_TEST_SERVER_PORT\" \"npx cypress run --env UEBLUEPRINT_TEST_SERVER_PORT=8181\"",
"start": "npx http-server"
},
"repository": {
@@ -26,7 +25,7 @@
},
"homepage": "https://github.com/barsdeveloper/ueblueprint#readme",
"devDependencies": {
"@playwright/test": "^1",
"@playwright/test": "1.46",
"@rollup/plugin-commonjs": "^25",
"@rollup/plugin-node-resolve": "^15",
"@rollup/plugin-terser": "^0",

View File

@@ -830,7 +830,7 @@ test("ObjectReferenceEntity", () => {
"/Game/Mods/CrazyDinos/ElementalDragon/CDElementalDragon_Character_BP.SKEL_CDElementalDragon_Character_BP_C:ROS Change Element",
))
expect(value.serialize()).toEqual(
String.raw`Function'"/Game/Mods/CrazyDinos/ElementalDragon/CDElementalDragon_Character_BP.SKEL_CDElementalDragon_Character_BP_C:ROS Change Element"'`
`Function'"/Game/Mods/CrazyDinos/ElementalDragon/CDElementalDragon_Character_BP.SKEL_CDElementalDragon_Character_BP_C:ROS Change Element"'`
)
expect(value.serialize(true)).toEqual(
String.raw`Function'\"/Game/Mods/CrazyDinos/ElementalDragon/CDElementalDragon_Character_BP.SKEL_CDElementalDragon_Character_BP_C:ROS Change Element\"'`
@@ -899,6 +899,14 @@ test("ObjectReferenceEntity", () => {
value = grammar.parse(`"/Game/_YukiritoLib/Textures/T_紫色渐变01.T_紫色渐变01"`)
expect(value).toBeInstanceOf(ObjectReferenceEntity)
expect(value).toEqual(new ObjectReferenceEntity("/Game/_YukiritoLib/Textures/T_紫色渐变01.T_紫色渐变01"))
value = grammar.parse(`"/Script/MetasoundEditor.MetasoundEditorGraphVariable'MetasoundEditorGraphVariable_1'"`)
expect(value).toBeInstanceOf(ObjectReferenceEntity)
expect(value).toEqual(new ObjectReferenceEntity(
"/Script/MetasoundEditor.MetasoundEditorGraphVariable",
"MetasoundEditorGraphVariable_1"
))
expect(value.serialize()).toEqual(`"/Script/MetasoundEditor.MetasoundEditorGraphVariable'MetasoundEditorGraphVariable_1'"`)
})
test("PinEntity", () => {
@@ -1190,6 +1198,9 @@ test("Unknown", () => {
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(`"/Script/MetasoundEditor.MetasoundEditorGraphVariable'MetasoundEditorGraphVariable_1'"`)).toBeInstanceOf(ObjectReferenceEntity)
expect(parser.parse(`"/Script/MetasoundEditor.MetasoundEditorGraphVariable'MetasoundEditorGraphVariable_1'"`).serialize())
.toEqual(`"/Script/MetasoundEditor.MetasoundEditorGraphVariable'MetasoundEditorGraphVariable_1'"`)
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)