mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +08:00
Small refactoring, set variable node
This commit is contained in:
@@ -19,8 +19,10 @@ import RotatorEntity from "../entity/RotatorEntity"
|
||||
import SimpleSerializationRotatorEntity from "../entity/SimpleSerializationRotatorEntity"
|
||||
import SimpleSerializationVectorEntity from "../entity/SimpleSerializationVectorEntity"
|
||||
import TypeInitialization from "../entity/TypeInitialization"
|
||||
import UnionType from "../entity/UnionType"
|
||||
import Utility from "../Utility"
|
||||
import VectorEntity from "../entity/VectorEntity"
|
||||
import VariableReferenceEntity from "../entity/VariableReferenceEntity"
|
||||
|
||||
let P = Parsimmon
|
||||
|
||||
@@ -43,10 +45,9 @@ export default class Grammar {
|
||||
P.string("("),
|
||||
attributeType
|
||||
.map(v => Grammar.getGrammarForType(r, Utility.getType(v)))
|
||||
.reduce((accum, cur) =>
|
||||
!cur || accum === r.AttributeAnyValue
|
||||
? r.AttributeAnyValue
|
||||
: accum.or(cur)
|
||||
.reduce((accum, cur) => !cur || accum === r.AttributeAnyValue
|
||||
? r.AttributeAnyValue
|
||||
: accum.or(cur)
|
||||
)
|
||||
.trim(P.optWhitespace)
|
||||
.sepBy(P.string(","))
|
||||
@@ -90,6 +91,14 @@ export default class Grammar {
|
||||
return r.SimpleSerializationVector
|
||||
case String:
|
||||
return r.String
|
||||
case UnionType:
|
||||
return attributeType.types
|
||||
.map(v => Grammar.getGrammarForType(r, Utility.getType(v)))
|
||||
.reduce((accum, cur) => !cur || accum === r.AttributeAnyValue
|
||||
? r.AttributeAnyValue
|
||||
: accum.or(cur))
|
||||
case VariableReferenceEntity:
|
||||
return r.VariableReference
|
||||
case VectorEntity:
|
||||
return r.Vector
|
||||
default:
|
||||
@@ -139,7 +148,7 @@ export default class Grammar {
|
||||
.trim(P.optWhitespace) // Drop spaces around a attribute assignment
|
||||
.sepBy(P.string(",")) // Assignments are separated by comma
|
||||
.skip(P.regex(/,?/).then(P.optWhitespace)), // Optional trailing comma and maybe additional space
|
||||
P.string(')'),
|
||||
P.string(")"),
|
||||
(_0, attributes, _2) => {
|
||||
let values = {}
|
||||
attributes.forEach(attributeSetter => attributeSetter(values))
|
||||
@@ -196,7 +205,7 @@ export default class Grammar {
|
||||
.desc('string (with possibility to escape the quote using \")')
|
||||
|
||||
/** @param {Grammar} r */
|
||||
AttributeName = r => r.Word.sepBy1(P.string(".")).tieWith(".").desc('words separated by ""')
|
||||
AttributeName = r => r.Word.sepBy1(P.string(".")).tieWith(".").desc("dot-separated words")
|
||||
|
||||
/* --- Entity --- */
|
||||
|
||||
@@ -331,6 +340,9 @@ export default class Grammar {
|
||||
/** @param {Grammar} r */
|
||||
FunctionReference = r => Grammar.createEntityGrammar(r, FunctionReferenceEntity)
|
||||
|
||||
/** @param {Grammar} r */
|
||||
VariableReference = r => Grammar.createEntityGrammar(r, VariableReferenceEntity)
|
||||
|
||||
/** @param {Grammar} r */
|
||||
MacroGraphReference = r => Grammar.createEntityGrammar(r, MacroGraphReferenceEntity)
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import SimpleSerializationRotatorEntity from "../entity/SimpleSerializationRotat
|
||||
import SimpleSerializationVectorEntity from "../entity/SimpleSerializationVectorEntity"
|
||||
import ToStringSerializer from "./ToStringSerializer"
|
||||
import Utility from "../Utility"
|
||||
import VariableReferenceEntity from "../entity/VariableReferenceEntity"
|
||||
import VectorEntity from "../entity/VectorEntity"
|
||||
|
||||
export default function initializeSerializerFactory() {
|
||||
@@ -43,6 +44,7 @@ export default function initializeSerializerFactory() {
|
||||
(array, insideString) =>
|
||||
`(${array
|
||||
.map(v =>
|
||||
// @ts-expect-error
|
||||
SerializerFactory.getSerializer(Utility.getType(v)).serialize(v, insideString) + ","
|
||||
)
|
||||
.join("")
|
||||
@@ -190,6 +192,11 @@ export default function initializeSerializerFactory() {
|
||||
)
|
||||
)
|
||||
|
||||
SerializerFactory.registerSerializer(
|
||||
VariableReferenceEntity,
|
||||
new GeneralSerializer(bracketsWrapped, VariableReferenceEntity)
|
||||
)
|
||||
|
||||
SerializerFactory.registerSerializer(
|
||||
VectorEntity,
|
||||
new GeneralSerializer(bracketsWrapped, VectorEntity)
|
||||
|
||||
Reference in New Issue
Block a user