mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +08:00
* Fix node reference when changing elements * Fix ScriptVariables parsing * Fix invariant text and niagara types * Niagara convert nodes * Move node tests to own files * More Niagara tests * Niagara float and smaller fixes * More Decoding * More decoding * WIP * Float is real * WIP * More types and colors * Test case and small polish * WIP * WIP * Fix niagara script variables merging * Fix Niagara variables * Fixing mirrored ExportPath * Fix Export paths name adjustments * Simplify arc calculation * Simplify a bit arc calculation * source / destionation => origin / target * Minor refactoring * Fix switched link position * Rename some properties for uniformity * Fix input escape * Simplify test * About window * Dialog backdrop style * About dialog touches * Remove dependency and minot improvement * Light mode * Fix link location and css small improvement * Link direction and minor fixes * Some minor fixes and refactoring * Refactoring WIP * Shorting repetitive bits * More tests * Simplify linking tests
136 lines
4.0 KiB
JavaScript
Executable File
136 lines
4.0 KiB
JavaScript
Executable File
import P from "parsernostrum"
|
|
import Utility from "../Utility.js"
|
|
import Grammar from "../serialization/Grammar.js"
|
|
import IEntity from "./IEntity.js"
|
|
|
|
export default class ObjectReferenceEntity extends IEntity {
|
|
|
|
static typeReference = P.reg(
|
|
// @ts-expect-error
|
|
new RegExp(Grammar.Regex.Path.source + "|" + Grammar.symbol.getParser().regexp.source)
|
|
)
|
|
static fullReferenceGrammar = this.createFullReferenceGrammar()
|
|
static grammar = this.createGrammar()
|
|
|
|
#type
|
|
get type() {
|
|
return this.#type
|
|
}
|
|
set type(value) {
|
|
this.#type = value
|
|
}
|
|
|
|
#path
|
|
get path() {
|
|
return this.#path
|
|
}
|
|
set path(value) {
|
|
this.#name = ""
|
|
this.#path = value
|
|
}
|
|
|
|
#serializer
|
|
get full() {
|
|
return this.#serializer
|
|
}
|
|
set full(value) {
|
|
this.#serializer = value
|
|
}
|
|
|
|
#name = ""
|
|
|
|
/** @param {(t: String, p: String) => String} serializer */
|
|
constructor(
|
|
type = "None",
|
|
path = "",
|
|
serializer = type.includes("/") || path
|
|
? (t, p) => `"${t + (p ? (`'${p}'`) : "")}"`
|
|
: (t, p) => t) {
|
|
super()
|
|
this.#type = type
|
|
this.#path = path
|
|
this.#serializer = serializer
|
|
}
|
|
|
|
/** @returns {P<ObjectReferenceEntity>} */
|
|
static createGrammar() {
|
|
return P.alt(
|
|
this.createFullReferenceSerializedGrammar(),
|
|
this.createFullReferenceGrammar(),
|
|
this.createTypeReferenceGrammar(),
|
|
).label("ObjectReferenceEntity")
|
|
}
|
|
|
|
/** @returns {P<ObjectReferenceEntity>} */
|
|
static createFullReferenceGrammar() {
|
|
return P.regArray(
|
|
new RegExp(
|
|
// @ts-expect-error
|
|
"(" + this.typeReference.getParser().regexp.source + ")"
|
|
+ "(?:"
|
|
+ `'"(${Grammar.Regex.InsideString.source})"'`
|
|
+ "|"
|
|
+ `'(${Grammar.Regex.InsideSingleQuotedString.source})'`
|
|
+ ")"
|
|
)
|
|
).map(([full, type, fullQuotedPath, simpleQuotedPath]) => {
|
|
let fullQuoted = fullQuotedPath ? true : false
|
|
let quotes = fullQuoted ? [`'"`, `"'`] : ["'", "'"]
|
|
return new this(
|
|
type,
|
|
fullQuoted ? fullQuotedPath : simpleQuotedPath,
|
|
(t, p) => t + quotes[0] + p + quotes[1]
|
|
)
|
|
})
|
|
}
|
|
|
|
/** @returns {P<ObjectReferenceEntity>} */
|
|
static createFullReferenceSerializedGrammar() {
|
|
return P.regArray(
|
|
new RegExp(
|
|
'"(' + Grammar.Regex.InsideString.source + "?)"
|
|
+ "(?:'(" + Grammar.Regex.InsideSingleQuotedString.source + `?)')?"`
|
|
)
|
|
).map(([_0, type, path]) => new this(type, path, (t, p) => `"${t}${p ? `'${p}'` : ""}"`))
|
|
}
|
|
|
|
/** @returns {P<ObjectReferenceEntity>} */
|
|
static createTypeReferenceGrammar() {
|
|
return this.typeReference.map(v => new this(v, "", (t, p) => t))
|
|
}
|
|
|
|
static createNoneInstance() {
|
|
return new this("None")
|
|
}
|
|
|
|
getName(dropCounter = false) {
|
|
if (!this.#name) {
|
|
if (!dropCounter) {
|
|
return this.#name = Utility.getNameFromPath(this.path.replace(/_C$/, ""), dropCounter)
|
|
}
|
|
return Utility.getNameFromPath(this.path.replace(/_C$/, ""), dropCounter)
|
|
}
|
|
return this.#name
|
|
}
|
|
|
|
doSerialize(insideString = false) {
|
|
let result = this.full(this.type, this.path)
|
|
if (insideString) {
|
|
result = Utility.escapeString(result, false)
|
|
}
|
|
return result
|
|
}
|
|
|
|
/** @param {IEntity} other */
|
|
equals(other) {
|
|
if (!(other instanceof ObjectReferenceEntity)) {
|
|
return false
|
|
}
|
|
return this.type == other.type && this.path == other.path
|
|
}
|
|
|
|
toString() {
|
|
return this.full(this.type, this.path)
|
|
}
|
|
}
|