mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +08:00
232 lines
7.6 KiB
JavaScript
Executable File
232 lines
7.6 KiB
JavaScript
Executable File
import CustomSerializer from "./CustomSerializer"
|
|
import FunctionReferenceEntity from "../entity/FunctionReferenceEntity"
|
|
import GeneralSerializer from "./GeneralSerializer"
|
|
import GuidEntity from "../entity/GuidEntity"
|
|
import IdentifierEntity from "../entity/IdentifierEntity"
|
|
import IntegerEntity from "../entity/IntegerEntity"
|
|
import InvariantTextEntity from "../entity/InvariantTextEntity"
|
|
import KeyBindingEntity from "../entity/KeyBindingEntity"
|
|
import LinearColorEntity from "../entity/LinearColorEntity"
|
|
import LocalizedTextEntity from "../entity/LocalizedTextEntity"
|
|
import MacroGraphReferenceEntity from "../entity/MacroGraphReferenceEntity"
|
|
import ObjectEntity from "../entity/ObjectEntity"
|
|
import ObjectReferenceEntity from "../entity/ObjectReferenceEntity"
|
|
import ObjectSerializer from "./ObjectSerializer"
|
|
import PathSymbolEntity from "../entity/PathSymbolEntity"
|
|
import PinEntity from "../entity/PinEntity"
|
|
import PinReferenceEntity from "../entity/PinReferenceEntity"
|
|
import RealUnitEntity from "../entity/UnitRealEntity"
|
|
import RotatorEntity from "../entity/RotatorEntity"
|
|
import SerializerFactory from "./SerializerFactory"
|
|
import SimpleSerializationRotatorEntity from "../entity/SimpleSerializationRotatorEntity"
|
|
import SimpleSerializationVectorEntity from "../entity/SimpleSerializationVectorEntity"
|
|
import SymbolEntity from "../entity/SymbolEntity"
|
|
import ToStringSerializer from "./ToStringSerializer"
|
|
import UnknownKeysEntity from "../entity/UnknownKeysEntity"
|
|
import Utility from "../Utility"
|
|
import VariableReferenceEntity from "../entity/VariableReferenceEntity"
|
|
import Vector2DEntity from "../entity/Vector2DEntity"
|
|
import VectorEntity from "../entity/VectorEntity"
|
|
import SimpleSerializationVector2DEntity from "../entity/SimpleSerializationVector2DEntity"
|
|
|
|
export default function initializeSerializerFactory() {
|
|
|
|
const bracketsWrapped = v => `(${v})`
|
|
|
|
SerializerFactory.registerSerializer(
|
|
null,
|
|
new CustomSerializer(
|
|
(nullValue, insideString) => "()",
|
|
null
|
|
)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
Array,
|
|
new CustomSerializer(
|
|
/** @param {Array} array */
|
|
(array, insideString) =>
|
|
`(${array
|
|
.map(v =>
|
|
// @ts-expect-error
|
|
SerializerFactory.getSerializer(Utility.getType(v)).serialize(v, insideString) + ","
|
|
)
|
|
.join("")
|
|
})`,
|
|
Array
|
|
)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
Boolean,
|
|
new CustomSerializer(
|
|
/** @param {Boolean} boolean */
|
|
(boolean, insideString) => boolean
|
|
? insideString
|
|
? "true"
|
|
: "True"
|
|
: insideString
|
|
? "false"
|
|
: "False",
|
|
Boolean
|
|
)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
FunctionReferenceEntity,
|
|
new GeneralSerializer(bracketsWrapped, FunctionReferenceEntity)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
GuidEntity,
|
|
new ToStringSerializer(GuidEntity)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
IdentifierEntity,
|
|
new ToStringSerializer(IdentifierEntity)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
IntegerEntity,
|
|
new ToStringSerializer(IntegerEntity)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
InvariantTextEntity,
|
|
new GeneralSerializer(v => `${InvariantTextEntity.lookbehind}(${v})`, InvariantTextEntity, "", ", ", false, "", _ => "")
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
KeyBindingEntity,
|
|
new GeneralSerializer(bracketsWrapped, KeyBindingEntity)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
LinearColorEntity,
|
|
new GeneralSerializer(bracketsWrapped, LinearColorEntity)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
LocalizedTextEntity,
|
|
new GeneralSerializer(v => `${LocalizedTextEntity.lookbehind}(${v})`, LocalizedTextEntity, "", ", ", false, "", _ => "")
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
MacroGraphReferenceEntity,
|
|
new GeneralSerializer(bracketsWrapped, MacroGraphReferenceEntity)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
Number,
|
|
new CustomSerializer(
|
|
/** @param {Number} value */
|
|
value => value.toString(),
|
|
Number
|
|
)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
ObjectEntity,
|
|
new ObjectSerializer()
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
ObjectReferenceEntity,
|
|
new CustomSerializer(
|
|
objectReference => (objectReference.type ?? "") + (
|
|
objectReference.path
|
|
? objectReference.type ? `'"${objectReference.path}"'` : `"${objectReference.path}"`
|
|
: ""
|
|
),
|
|
ObjectReferenceEntity
|
|
)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
PathSymbolEntity,
|
|
new ToStringSerializer(PathSymbolEntity)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
PinEntity,
|
|
new GeneralSerializer(v => `${PinEntity.lookbehind} (${v})`, PinEntity, "", ",", true)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
PinReferenceEntity,
|
|
new GeneralSerializer(v => v, PinReferenceEntity, "", " ", false, "", _ => "")
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
RealUnitEntity,
|
|
new ToStringSerializer(RealUnitEntity)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
RotatorEntity,
|
|
new GeneralSerializer(bracketsWrapped, RotatorEntity)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
String,
|
|
new CustomSerializer(
|
|
(value, insideString) => insideString
|
|
// @ts-expect-error
|
|
? Utility.escapeString(value)
|
|
// @ts-expect-error
|
|
: `"${Utility.escapeString(value)}"`,
|
|
String
|
|
)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
SimpleSerializationRotatorEntity,
|
|
new CustomSerializer(
|
|
(value, insideString) => `${value.P}, ${value.Y}, ${value.R}`,
|
|
SimpleSerializationRotatorEntity
|
|
)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
SimpleSerializationVector2DEntity,
|
|
new CustomSerializer(
|
|
(value, insideString) => `${value.X}, ${value.Y}`,
|
|
SimpleSerializationVector2DEntity
|
|
)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
SimpleSerializationVectorEntity,
|
|
new CustomSerializer(
|
|
(value, insideString) => `${value.X}, ${value.Y}, ${value.Z}`,
|
|
SimpleSerializationVectorEntity
|
|
)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
SymbolEntity,
|
|
new ToStringSerializer(SymbolEntity)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
UnknownKeysEntity,
|
|
new GeneralSerializer((string, entity) => `${entity.lookbehind ?? ""}(${string})`, UnknownKeysEntity)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
VariableReferenceEntity,
|
|
new GeneralSerializer(bracketsWrapped, VariableReferenceEntity)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
Vector2DEntity,
|
|
new GeneralSerializer(bracketsWrapped, Vector2DEntity)
|
|
)
|
|
|
|
SerializerFactory.registerSerializer(
|
|
VectorEntity,
|
|
new GeneralSerializer(bracketsWrapped, VectorEntity)
|
|
)
|
|
}
|