mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-16 10:54:42 +08:00
Color picker refactoring
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
// @ts-nocheck
|
||||
import ColorChannelValueEntity from "../entity/ColorChannelValueEntity"
|
||||
import FunctionReferenceEntity from "../entity/FunctionReferenceEntity"
|
||||
import GuidEntity from "../entity/GuidEntity"
|
||||
import IdentifierEntity from "../entity/IdentifierEntity"
|
||||
@@ -14,6 +13,7 @@ import Parsimmon from "parsimmon"
|
||||
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 SimpleSerializationRotatorEntity from "../entity/SimpleSerializationRotatorEntity"
|
||||
import SimpleSerializationVectorEntity from "../entity/SimpleSerializationVectorEntity"
|
||||
@@ -37,44 +37,6 @@ export default class Grammar {
|
||||
return result
|
||||
}
|
||||
switch (Utility.getType(attributeType)) {
|
||||
case Boolean:
|
||||
return r.Boolean
|
||||
case Number:
|
||||
return r.Number
|
||||
case IntegerEntity:
|
||||
return r.Integer
|
||||
case String:
|
||||
return r.String
|
||||
case GuidEntity:
|
||||
return r.Guid
|
||||
case IdentifierEntity:
|
||||
return r.Identifier
|
||||
case ObjectReferenceEntity:
|
||||
return r.Reference
|
||||
case LocalizedTextEntity:
|
||||
return r.LocalizedText
|
||||
case InvariantTextEntity:
|
||||
return r.InvariantText
|
||||
case PinReferenceEntity:
|
||||
return r.PinReference
|
||||
case VectorEntity:
|
||||
return r.Vector
|
||||
case RotatorEntity:
|
||||
return r.Rotator
|
||||
case SimpleSerializationRotatorEntity:
|
||||
return r.SimpleSerializationRotator
|
||||
case SimpleSerializationVectorEntity:
|
||||
return r.SimpleSerializationVector
|
||||
case ColorChannelValueEntity:
|
||||
return r.ColorChannelValue
|
||||
case ColorChannelRealValue:
|
||||
return r.ColorChannelRealValue
|
||||
case LinearColorEntity:
|
||||
return r.LinearColor
|
||||
case FunctionReferenceEntity:
|
||||
return r.FunctionReference
|
||||
case PinEntity:
|
||||
return r.Pin
|
||||
case Array:
|
||||
return P.seqMap(
|
||||
P.string("("),
|
||||
@@ -91,6 +53,42 @@ export default class Grammar {
|
||||
P.string(")"),
|
||||
(_, grammar, __) => grammar
|
||||
)
|
||||
case Boolean:
|
||||
return r.Boolean
|
||||
case FunctionReferenceEntity:
|
||||
return r.FunctionReference
|
||||
case GuidEntity:
|
||||
return r.Guid
|
||||
case IdentifierEntity:
|
||||
return r.Identifier
|
||||
case IntegerEntity:
|
||||
return r.Integer
|
||||
case InvariantTextEntity:
|
||||
return r.InvariantText
|
||||
case LinearColorEntity:
|
||||
return r.LinearColor
|
||||
case LocalizedTextEntity:
|
||||
return r.LocalizedText
|
||||
case Number:
|
||||
return r.Number
|
||||
case ObjectReferenceEntity:
|
||||
return r.Reference
|
||||
case PinEntity:
|
||||
return r.Pin
|
||||
case PinReferenceEntity:
|
||||
return r.PinReference
|
||||
case RealUnitEntity:
|
||||
return r.RealUnit
|
||||
case RotatorEntity:
|
||||
return r.Rotator
|
||||
case SimpleSerializationRotatorEntity:
|
||||
return r.SimpleSerializationRotator
|
||||
case SimpleSerializationVectorEntity:
|
||||
return r.SimpleSerializationVector
|
||||
case String:
|
||||
return r.String
|
||||
case VectorEntity:
|
||||
return r.Vector
|
||||
default:
|
||||
return defaultGrammar
|
||||
}
|
||||
@@ -160,6 +158,9 @@ export default class Grammar {
|
||||
/** @param {Grammar} r */
|
||||
RealNumber = r => P.regex(/[-\+]?[0-9]+\.[0-9]+/).map(Number).desc("a number written as real")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
RealUnit = r => P.regex(/\+?[0-9]+(?:\.[0-9]+)?/).map(Number).assert(v => v >= 0 && v <= 1).desc("a number between 0 and 1")
|
||||
|
||||
/** @param {Grammar} r */
|
||||
NaturalNumber = r => P.regex(/0|[1-9]\d*/).map(Number).desc("a natural number")
|
||||
|
||||
@@ -310,17 +311,6 @@ export default class Grammar {
|
||||
})
|
||||
)
|
||||
|
||||
/** @param {Grammar} r */
|
||||
ColorChannelValue = r => P.alt(
|
||||
r.RealNumber.map(v => new ColorChannelValueEntity(v * 255)),
|
||||
r.ColorNumber.map(v => new ColorChannelValueEntity(v)),
|
||||
)
|
||||
|
||||
/** @param {Grammar} r */
|
||||
ColorChannelRealValue = r => P.alt(
|
||||
r.RealNumber.map(v => new ColorChannelValueEntity(v * 255))
|
||||
)
|
||||
|
||||
/** @param {Grammar} r */
|
||||
LinearColor = r => Grammar.createEntityGrammar(r, LinearColorEntity)
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import ColorChannelRealValueEntity from "../entity/ColorChannelRealValueEntity"
|
||||
import ColorChannelValueEntity from "../entity/ColorChannelValueEntity"
|
||||
import CustomSerializer from "./CustomSerializer"
|
||||
import FunctionReferenceEntity from "../entity/FunctionReferenceEntity"
|
||||
import GeneralSerializer from "./GeneralSerializer"
|
||||
@@ -16,6 +14,7 @@ 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"
|
||||
@@ -66,16 +65,6 @@ export default function initializeSerializerFactory() {
|
||||
)
|
||||
)
|
||||
|
||||
SerializerFactory.registerSerializer(
|
||||
ColorChannelRealValueEntity,
|
||||
new ToStringSerializer(ColorChannelValueEntity)
|
||||
)
|
||||
|
||||
SerializerFactory.registerSerializer(
|
||||
ColorChannelValueEntity,
|
||||
new ToStringSerializer(ColorChannelValueEntity)
|
||||
)
|
||||
|
||||
SerializerFactory.registerSerializer(
|
||||
FunctionReferenceEntity,
|
||||
new GeneralSerializer(bracketsWrapped, FunctionReferenceEntity)
|
||||
@@ -157,6 +146,11 @@ export default function initializeSerializerFactory() {
|
||||
new GeneralSerializer(v => v, PinReferenceEntity, "", " ", false, "", _ => "")
|
||||
)
|
||||
|
||||
SerializerFactory.registerSerializer(
|
||||
RealUnitEntity,
|
||||
new ToStringSerializer(RealUnitEntity)
|
||||
)
|
||||
|
||||
SerializerFactory.registerSerializer(
|
||||
RotatorEntity,
|
||||
new GeneralSerializer(bracketsWrapped, RotatorEntity)
|
||||
|
||||
Reference in New Issue
Block a user