mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +08:00
Indexed array entity, user defined pins
This commit is contained in:
@@ -4,6 +4,7 @@ import FormatTextEntity from "../entity/FormatTextEntity.js"
|
||||
import FunctionReferenceEntity from "../entity/FunctionReferenceEntity.js"
|
||||
import GuidEntity from "../entity/GuidEntity.js"
|
||||
import IdentifierEntity from "../entity/IdentifierEntity.js"
|
||||
import IndexedArray from "../entity/IndexedArray.js"
|
||||
import Integer64Entity from "../entity/Integer64Entity.js"
|
||||
import IntegerEntity from "../entity/IntegerEntity.js"
|
||||
import InvariantTextEntity from "../entity/InvariantTextEntity.js"
|
||||
@@ -27,6 +28,7 @@ import SimpleSerializationVectorEntity from "../entity/SimpleSerializationVector
|
||||
import SymbolEntity from "../entity/SymbolEntity.js"
|
||||
import UnionType from "../entity/UnionType.js"
|
||||
import UnknownKeysEntity from "../entity/UnknownKeysEntity.js"
|
||||
import UserDefinedPinEntity from "../entity/UserDefinedPinEntity.js"
|
||||
import Utility from "../Utility.js"
|
||||
import VariableReferenceEntity from "../entity/VariableReferenceEntity.js"
|
||||
import Vector2DEntity from "../entity/Vector2DEntity.js"
|
||||
@@ -242,6 +244,9 @@ export default class Grammar {
|
||||
case SymbolEntity:
|
||||
result = this.symbolEntity
|
||||
break
|
||||
case UserDefinedPinEntity:
|
||||
result = this.userDefinedPinEntity
|
||||
break
|
||||
case VariableReferenceEntity:
|
||||
result = this.variableReferenceEntity
|
||||
break
|
||||
@@ -342,10 +347,16 @@ export default class Grammar {
|
||||
static integerEntity = P.lazy(() => this.integer.map(v => new IntegerEntity(v)))
|
||||
|
||||
static invariantTextEntity = P.lazy(() =>
|
||||
P.seq(
|
||||
P.regex(new RegExp(`${InvariantTextEntity.lookbehind}\\s*`)),
|
||||
this.grammarFor(InvariantTextEntity.attributes.value)
|
||||
)
|
||||
P.alt(
|
||||
P.seq(
|
||||
P.regex(new RegExp(`${InvariantTextEntity.lookbehind}\\s*\\(`)),
|
||||
this.grammarFor(InvariantTextEntity.attributes.value),
|
||||
P.regex(/\s*\)/)
|
||||
)
|
||||
.map(([_0, value, _2]) => value),
|
||||
P.regex(new RegExp(InvariantTextEntity.lookbehind)) // InvariantTextEntity can not have arguments
|
||||
.map(() => "")
|
||||
).map(value => new InvariantTextEntity(value))
|
||||
)
|
||||
|
||||
static keyBindingEntity = P.lazy(() =>
|
||||
@@ -482,6 +493,8 @@ export default class Grammar {
|
||||
|
||||
static symbolEntity = P.lazy(() => this.symbol.map(v => new SymbolEntity(v)))
|
||||
|
||||
static userDefinedPinEntity = P.lazy(() => this.createEntityGrammar(UserDefinedPinEntity))
|
||||
|
||||
static variableReferenceEntity = P.lazy(() => this.createEntityGrammar(VariableReferenceEntity))
|
||||
|
||||
static vector2DEntity = P.lazy(() => this.createEntityGrammar(Vector2DEntity, false))
|
||||
@@ -526,6 +539,7 @@ export default class Grammar {
|
||||
this.string,
|
||||
this.localizedTextEntity,
|
||||
this.invariantTextEntity,
|
||||
this.formatTextEntity,
|
||||
this.pinReferenceEntity,
|
||||
this.vectorEntity,
|
||||
this.linearColorEntity,
|
||||
@@ -540,7 +554,7 @@ export default class Grammar {
|
||||
static customProperty = P.lazy(() =>
|
||||
P.seq(
|
||||
P.regex(/CustomProperties\s+/),
|
||||
this.pinEntity,
|
||||
this.grammarFor(undefined, ObjectEntity.attributes.CustomProperties.type[0]),
|
||||
).map(([_0, pin]) => values => {
|
||||
if (!values.CustomProperties) {
|
||||
values.CustomProperties = []
|
||||
@@ -560,12 +574,9 @@ export default class Grammar {
|
||||
.chain(([symbol, _1]) =>
|
||||
this.grammarFor(ObjectEntity.attributes[symbol])
|
||||
.map(currentValue =>
|
||||
values => {
|
||||
if (!values[symbol]) {
|
||||
values[symbol] = []
|
||||
}
|
||||
values[symbol].push(currentValue)
|
||||
})
|
||||
values => (values[symbol] ??= new IndexedArray(currentValue.constructor))
|
||||
.value.push(currentValue)
|
||||
)
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import IndexedArray from "../entity/IndexedArray.js"
|
||||
import SerializerFactory from "./SerializerFactory.js"
|
||||
import Utility from "../Utility.js"
|
||||
|
||||
@@ -66,14 +67,29 @@ export default class ISerializer {
|
||||
const value = entity[key]
|
||||
if (value !== undefined && this.showProperty(entity, key)) {
|
||||
const isSerialized = Utility.isSerialized(entity, key)
|
||||
if (value instanceof IndexedArray) {
|
||||
value.value.forEach((value, i) =>
|
||||
result += (result.length ? this.attributeSeparator : "")
|
||||
+ this.attributePrefix
|
||||
+ Utility.decodeKeyName(this.attributeKeyPrinter(key))
|
||||
+ `(${i})`
|
||||
+ this.attributeValueConjunctionSign
|
||||
+ (
|
||||
isSerialized
|
||||
? `"${this.writeValue(value, true)}"`
|
||||
: this.writeValue(value, insideString)
|
||||
)
|
||||
)
|
||||
continue
|
||||
}
|
||||
result += (result.length ? this.attributeSeparator : "")
|
||||
+ this.attributePrefix
|
||||
+ Utility.decodeKeyName(this.attributeKeyPrinter(key))
|
||||
+ this.attributeValueConjunctionSign
|
||||
+ (
|
||||
isSerialized
|
||||
? `"${this.writeValue(entity, key, true)}"`
|
||||
: this.writeValue(entity, key, insideString)
|
||||
? `"${this.writeValue(value, true)}"`
|
||||
: this.writeValue(value, insideString)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -86,19 +102,20 @@ export default class ISerializer {
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @param {String} key
|
||||
* @param {Boolean} insideString
|
||||
*/
|
||||
writeValue(entity, key, insideString) {
|
||||
const value = entity[key]
|
||||
writeValue(value, insideString) {
|
||||
const type = Utility.getType(value)
|
||||
// @ts-expect-error
|
||||
const serializer = SerializerFactory.getSerializer(type)
|
||||
if (!serializer) {
|
||||
throw new Error(`Unknown value type "${type.name}", a serializer must be registered in the SerializerFactory class, check initializeSerializerFactory.js`)
|
||||
throw new Error(
|
||||
`Unknown value type "${type.name}", a serializer must be registered in the SerializerFactory class, `
|
||||
+ "check initializeSerializerFactory.js"
|
||||
)
|
||||
}
|
||||
return serializer.write(
|
||||
entity[key],
|
||||
value,
|
||||
insideString
|
||||
)
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ export default class ObjectSerializer extends ISerializer {
|
||||
* @param {Boolean} insideString
|
||||
*/
|
||||
write(entity, insideString) {
|
||||
let result = `Begin Object Class=${entity.Class.path} Name=${this.writeValue(entity, "Name", insideString)}\n`
|
||||
let result = `Begin Object Class=${entity.Class.path} Name=${this.writeValue(entity.Name, insideString)}\n`
|
||||
+ super.write(entity, insideString)
|
||||
+ entity.CustomProperties.map(pin =>
|
||||
this.attributeSeparator
|
||||
|
||||
Reference in New Issue
Block a user