mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:41:34 +08:00
RBSerialization 2D Vector
This commit is contained in:
@@ -59,12 +59,12 @@ export default class Configuration {
|
||||
// End of upper case work (upper case followed by either word or number)
|
||||
+ "|(?<=[A-Z])"
|
||||
+ /* Except "UVs" */ "(?<!U(?=Vs(?![a-z])))"
|
||||
+ /* Except V3 */ "(?<!V(?=3(?![0-9])))"
|
||||
+ /* Except V2, V3 */ "(?<!V(?=[23](?![0-9])))"
|
||||
+ /* Except T2d */ "(?<!T(?=2d(?![a-z])))"
|
||||
+ "(?=[A-Z][a-z]|[0-9])"
|
||||
// Number followed by a letter
|
||||
+ "|(?<=[0-9])"
|
||||
+ /* Except 2D 3D */ "(?<))"
|
||||
+ /* Except 2D, 3D */ "(?<))"
|
||||
+ "(?=[a-zA-Z])"
|
||||
// "Alpha__Bravo" => "Alpha Bravo"
|
||||
+ "|\\s*_+\\s*"
|
||||
|
||||
@@ -35,6 +35,7 @@ export default class PinElement extends IElement {
|
||||
"int64": Int64PinTemplate,
|
||||
"MUTABLE_REFERENCE": ReferencePinTemplate,
|
||||
"name": NamePinTemplate,
|
||||
"rg": Vector2DPinTemplate,
|
||||
"real": RealPinTemplate,
|
||||
"string": StringPinTemplate,
|
||||
[Configuration.paths.linearColor]: LinearColorPinTemplate,
|
||||
|
||||
@@ -14,6 +14,7 @@ import LocalizedTextEntity from "./LocalizedTextEntity.js"
|
||||
import ObjectReferenceEntity from "./ObjectReferenceEntity.js"
|
||||
import PinReferenceEntity from "./PinReferenceEntity.js"
|
||||
import PinTypeEntity from "./PinTypeEntity.js"
|
||||
import RBSerializationVector2DEntity from "./RBSerializationVector2DEntity.js"
|
||||
import RotatorEntity from "./RotatorEntity.js"
|
||||
import SimpleSerializationRotatorEntity from "./SimpleSerializationRotatorEntity.js"
|
||||
import SimpleSerializationVector2DEntity from "./SimpleSerializationVector2DEntity.js"
|
||||
@@ -43,6 +44,7 @@ export default class PinEntity extends IEntity {
|
||||
}
|
||||
static #alternativeTypeEntityMap = {
|
||||
"enum": EnumDisplayValueEntity,
|
||||
"rg": RBSerializationVector2DEntity,
|
||||
[Configuration.paths.rotator]: SimpleSerializationRotatorEntity,
|
||||
[Configuration.paths.vector]: SimpleSerializationVectorEntity,
|
||||
[Configuration.paths.vector2D]: SimpleSerializationVector2DEntity,
|
||||
@@ -165,12 +167,17 @@ export default class PinEntity extends IEntity {
|
||||
return this.PinType.PinSubCategoryObject.path
|
||||
}
|
||||
if (category === "optional") {
|
||||
if (this.PinType.PinSubCategory === "red") {
|
||||
return "real"
|
||||
} else if (this.PinType.PinSubCategory === "rgb") {
|
||||
return Configuration.paths.vector
|
||||
} else if (this.PinType.PinSubCategory === "rgba") {
|
||||
return Configuration.paths.linearColor
|
||||
switch (this.PinType.PinSubCategory) {
|
||||
case "int":
|
||||
return "int"
|
||||
case "red":
|
||||
return "real"
|
||||
case "rg":
|
||||
return "rg"
|
||||
case "rgb":
|
||||
return Configuration.paths.vector
|
||||
case "rgba":
|
||||
return Configuration.paths.linearColor
|
||||
}
|
||||
}
|
||||
if (this.isEnum()) {
|
||||
|
||||
22
js/entity/RBSerializationVector2DEntity.js
Normal file
22
js/entity/RBSerializationVector2DEntity.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import Grammar from "../serialization/Grammar.js"
|
||||
import Parsimmon from "parsimmon"
|
||||
import Vector2DEntity from "./Vector2DEntity.js"
|
||||
|
||||
export default class RBSerializationVector2DEntity extends Vector2DEntity {
|
||||
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
static createGrammar() {
|
||||
return Parsimmon.alt(
|
||||
Parsimmon.seq(
|
||||
Parsimmon.string("X").then(Grammar.equalSeparation).then(Grammar.number),
|
||||
Parsimmon.regex(Grammar.Regex.InlineWhitespace),
|
||||
Parsimmon.string("Y").then(Grammar.equalSeparation).then(Grammar.number),
|
||||
).map(([x, _1, y]) => new this({
|
||||
X: x,
|
||||
Y: y,
|
||||
})),
|
||||
Vector2DEntity.createGrammar()
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -98,6 +98,7 @@ export default class Grammar {
|
||||
)
|
||||
static guid = P.regex(new RegExp(`${Grammar.Regex.HexDigit.source}{32}`))
|
||||
static commaSeparation = P.regex(/\s*,\s*(?!\))/)
|
||||
static commaOrSpaceSeparation = P.regex(/\s*,\s*(?!\))|\s+/)
|
||||
static equalSeparation = P.regex(/\s*=\s*/)
|
||||
static typeReference = P.alt(P.regex(Grammar.Regex.Path), this.symbol)
|
||||
static hexColorChannel = P.regex(new RegExp(Grammar.Regex.HexDigit.source + "{2}"))
|
||||
@@ -249,7 +250,7 @@ export default class Grammar {
|
||||
* @param {Boolean | Number} acceptUnknownKeys Number to specify the limit or true, to let it be a reasonable value
|
||||
* @returns {Parsimmon.Parser<T>}
|
||||
*/
|
||||
static createEntityGrammar = (entityType, acceptUnknownKeys = true) =>
|
||||
static createEntityGrammar = (entityType, acceptUnknownKeys = true, entriesSeparator = this.commaSeparation) =>
|
||||
P.seq(
|
||||
this.regexMap(
|
||||
entityType.lookbehind instanceof Union
|
||||
@@ -259,7 +260,7 @@ export default class Grammar {
|
||||
: /()\(\s*/,
|
||||
result => result[1]
|
||||
),
|
||||
this.createAttributeGrammar(entityType).sepBy1(this.commaSeparation),
|
||||
this.createAttributeGrammar(entityType).sepBy1(entriesSeparator),
|
||||
P.regex(/\s*(?:,\s*)?\)/), // trailing comma
|
||||
)
|
||||
.map(([lookbehind, attributes, _2]) => {
|
||||
|
||||
@@ -23,6 +23,7 @@ import Parsimmon from "parsimmon"
|
||||
import PathSymbolEntity from "../entity/PathSymbolEntity.js"
|
||||
import PinEntity from "../entity/PinEntity.js"
|
||||
import PinReferenceEntity from "../entity/PinReferenceEntity.js"
|
||||
import RBSerializationVector2DEntity from "../entity/RBSerializationVector2DEntity.js"
|
||||
import RotatorEntity from "../entity/RotatorEntity.js"
|
||||
import Serializer from "./Serializer.js"
|
||||
import SerializerFactory from "./SerializerFactory.js"
|
||||
@@ -241,6 +242,14 @@ export default function initializeSerializerFactory() {
|
||||
new Serializer(TerminalTypeEntity, Serializer.bracketsWrapped)
|
||||
)
|
||||
|
||||
SerializerFactory.registerSerializer(
|
||||
RBSerializationVector2DEntity,
|
||||
new CustomSerializer(
|
||||
(value, insideString) => `X=${value.X} Y=${value.Y}`,
|
||||
RBSerializationVector2DEntity
|
||||
)
|
||||
)
|
||||
|
||||
SerializerFactory.registerSerializer(
|
||||
RotatorEntity,
|
||||
new Serializer(RotatorEntity, Serializer.bracketsWrapped)
|
||||
|
||||
Reference in New Issue
Block a user