mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-03-06 23:57:30 +08:00
Entities tests fixed
This commit is contained in:
@@ -64,9 +64,14 @@ export default class ArrayEntity extends IEntity {
|
||||
toString(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
printKey = this.Self().printKey,
|
||||
Self = this.Self(),
|
||||
printKey = Self.printKey,
|
||||
wrap = Self.wrap,
|
||||
) {
|
||||
let result = this.values.map(v => v?.toString()).join(this.Self().attributeSeparator)
|
||||
if (this.Self().inlined) {
|
||||
return super.toString.bind(this.values, insideString, indentation, Self, printKey, wrap)()
|
||||
}
|
||||
let result = this.values.map(v => v?.toString(insideString)).join(this.Self().attributeSeparator)
|
||||
if (this.trailing) {
|
||||
result += this.Self().attributeSeparator
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import P from "parsernostrum"
|
||||
import Grammar from "../serialization/Grammar.js"
|
||||
import GuidEntity from "./GuidEntity.js"
|
||||
import IEntity from "./IEntity.js"
|
||||
@@ -12,6 +13,7 @@ export default class FunctionReferenceEntity extends IEntity {
|
||||
MemberName: StringEntity,
|
||||
MemberGuid: GuidEntity,
|
||||
}
|
||||
/** @type {P<FunctionReferenceEntity>} */
|
||||
static grammar = Grammar.createEntityGrammar(this)
|
||||
|
||||
constructor(values) {
|
||||
|
||||
@@ -135,7 +135,7 @@ export default class IEntity {
|
||||
* @template {typeof IEntity} T
|
||||
* @this {T}
|
||||
*/
|
||||
static withDefault(value = /** @type {(type: T) => InstanceType<T>} */(type => new type())) {
|
||||
static withDefault(value = /** @type {(type: T) => (InstanceType<T> | NullEntity)} */(type => new type())) {
|
||||
const result = this.asUniqueClass()
|
||||
result.default = value
|
||||
return result
|
||||
@@ -270,18 +270,22 @@ export default class IEntity {
|
||||
return true
|
||||
}
|
||||
|
||||
/** @this {IEntity | Array} */
|
||||
toString(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
printKey = this.Self().printKey,
|
||||
Self = this.Self(),
|
||||
printKey = Self.printKey,
|
||||
wrap = Self.wrap,
|
||||
) {
|
||||
const Self = this.Self()
|
||||
let result = ""
|
||||
let first = true
|
||||
for (const key of this.keys) {
|
||||
const keys = this instanceof IEntity ? this.keys : Object.keys(this)
|
||||
for (const key of keys) {
|
||||
/** @type {IEntity} */
|
||||
const value = this[key]
|
||||
if (value === undefined || !this.showProperty(key)) {
|
||||
let keyValue = this instanceof Array ? `(${key})` : key
|
||||
if (value === undefined || this instanceof IEntity && !this.showProperty(key)) {
|
||||
continue
|
||||
}
|
||||
if (first) {
|
||||
@@ -289,26 +293,29 @@ export default class IEntity {
|
||||
} else {
|
||||
result += Self.attributeSeparator
|
||||
}
|
||||
if (Self.inlined) {
|
||||
result += value.toString(insideString, indentation, k => printKey(`${key}.${k}`))
|
||||
if (value.Self?.().inlined) {
|
||||
const inlinedPrintKey = value.Self().className() === "ArrayEntity"
|
||||
? k => printKey(`${keyValue}${k}`)
|
||||
: k => printKey(`${keyValue}.${k}`)
|
||||
result += value.toString(insideString, indentation, Self, inlinedPrintKey, Self.notWrapped)
|
||||
continue
|
||||
}
|
||||
let keyValue = printKey(key)
|
||||
keyValue = printKey(keyValue)
|
||||
if (keyValue.length) {
|
||||
if (Self.quoted) {
|
||||
keyValue = `"${keyValue}"`
|
||||
}
|
||||
result += (Self.attributeSeparator.includes("\n") ? indentation : "") + keyValue + Self.keySeparator
|
||||
}
|
||||
let serialization = value?.toString(insideString, indentation, printKey)
|
||||
let serialization = value?.toString(insideString, indentation)
|
||||
if (Self.serialized) {
|
||||
serialization = `"${serialization.replaceAll(/(?<=(?:[^\\]|^)(?:\\\\)*?)"/, '\\"')}"`
|
||||
}
|
||||
result += serialization
|
||||
}
|
||||
if (this.trailing && result.length) {
|
||||
if (this instanceof IEntity && this.trailing && result.length) {
|
||||
result += Self.attributeSeparator
|
||||
}
|
||||
return Self.wrap(this, result)
|
||||
return wrap(this, result)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,11 +31,12 @@ import StringEntity from "./StringEntity.js"
|
||||
import Vector2DEntity from "./Vector2DEntity.js"
|
||||
import Vector4DEntity from "./Vector4DEntity.js"
|
||||
import VectorEntity from "./VectorEntity.js"
|
||||
import P from "parsernostrum"
|
||||
|
||||
/** @template {IEntity} T */
|
||||
export default class PinEntity extends IEntity {
|
||||
|
||||
static lookbehind = "INVTEXT"
|
||||
static lookbehind = "Pin"
|
||||
static #typeEntityMap = {
|
||||
[Configuration.paths.linearColor]: LinearColorEntity,
|
||||
[Configuration.paths.rotator]: RotatorEntity,
|
||||
@@ -92,6 +93,7 @@ export default class PinEntity extends IEntity {
|
||||
bAdvancedView: BooleanEntity.withDefault(),
|
||||
bOrphanedPin: BooleanEntity.withDefault(),
|
||||
}
|
||||
/** @type {P<PinEntity>} */
|
||||
static grammar = Grammar.createEntityGrammar(this)
|
||||
|
||||
#recomputesNodeTitleOnChange = false
|
||||
|
||||
@@ -13,7 +13,7 @@ export default class PinTypeEntity extends IEntity {
|
||||
PinCategory: StringEntity.withDefault(),
|
||||
PinSubCategory: StringEntity.withDefault(),
|
||||
PinSubCategoryObject: ObjectReferenceEntity.withDefault(),
|
||||
PinSubCategoryMemberReference: FunctionReferenceEntity.withDefault(type => null),
|
||||
PinSubCategoryMemberReference: FunctionReferenceEntity.withDefault(),
|
||||
PinValueType: PinTypeEntity.withDefault(),
|
||||
ContainerType: SymbolEntity,
|
||||
bIsReference: BooleanEntity.withDefault(),
|
||||
|
||||
Reference in New Issue
Block a user