New LinearColorEntity, string serialization fixed

This commit is contained in:
barsdeveloper
2022-05-11 21:01:54 +02:00
parent 3c643f0c6a
commit e416591784
20 changed files with 707 additions and 125 deletions

View File

@@ -1,13 +1,15 @@
// @ts-check
import ISerializable from "./ISerializable"
import TypeInitialization from "./TypeInitialization"
import Utility from "../Utility"
export default class IEntity {
export default class IEntity extends ISerializable {
static attributes = {}
constructor(values) {
super()
/**
* @param {Object} target
* @param {Object} properties
@@ -46,6 +48,7 @@ export default class IEntity {
const value = Utility.objectGet(values, [property])
if (value !== undefined) {
target[property] = TypeInitialization.sanitize(value, defaultType)
// We have a value, need nothing more
continue
}
if (defaultValue instanceof TypeInitialization) {

View File

@@ -0,0 +1,15 @@
export default class ISerializable {
#showAsString = false
isShownAsString() {
return this.#showAsString
}
/**
* @param {Boolean} v
*/
setShowAsString(v) {
this.#showAsString = v
}
}

View File

@@ -0,0 +1,21 @@
// @ts-check
import IEntity from "./IEntity"
export default class LinearColorEntity extends IEntity {
static attributes = {
R: Number,
G: Number,
B: Number,
A: Number,
}
constructor(options = {}) {
super(options)
/** @type {Number} */ this.R
/** @type {Number} */ this.G
/** @type {Number} */ this.B
/** @type {Number} */ this.A
}
}

View File

@@ -2,9 +2,11 @@
import GuidEntity from "./GuidEntity"
import IEntity from "./IEntity"
import LinearColorEntity from "./LinearColorEntity"
import LocalizedTextEntity from "./LocalizedTextEntity"
import ObjectReferenceEntity from "./ObjectReferenceEntity"
import PinReferenceEntity from "./PinReferenceEntity"
import SerializedType from "./SerializedType"
import TypeInitialization from "./TypeInitialization"
export default class PinEntity extends IEntity {
@@ -30,7 +32,7 @@ export default class PinEntity extends IEntity {
bSerializeAsSinglePrecisionFloat: false,
},
LinkedTo: new TypeInitialization([PinReferenceEntity], false),
DefaultValue: new TypeInitialization(String, false),
DefaultValue: new TypeInitialization(new SerializedType(LinearColorEntity, String), false),
AutogeneratedDefaultValue: new TypeInitialization(String, false),
DefaultObject: new TypeInitialization(ObjectReferenceEntity, false, null),
PersistentGuid: GuidEntity,
@@ -140,4 +142,14 @@ export default class PinEntity extends IEntity {
getType() {
return this.PinType.PinCategory
}
getSubCategory() {
return this.PinType.PinSubCategoryObject.path
}
getColorValue() {
if (this.PinType.PinSubCategoryObject.path == "/Script/CoreUObject.LinearColor") {
}
}
}

View File

@@ -0,0 +1,26 @@
// @ts-check
/**
* @typedef {import("../entity/IEntity").default} IEntity
* @typedef {(new (object?: Object) => IEntity) | StringConstructor | NumberConstructor | BooleanConstructor} Constructor
* @typedef {Constructor|Constructor[]} AcceptedType
*/
export default class SerializedType {
/** @type {(Constructor|Array<Constructor>)[]} */
#types
get types() {
return this.#types
}
set types(v) {
this.#types = v
}
/**
* @param {...AcceptedType} acceptedTypes
*/
constructor(...acceptedTypes) {
this.#types = acceptedTypes
}
}

View File

@@ -1,5 +1,7 @@
// @ts-check
import SerializedType from "./SerializedType"
/**
* @template T
*/
@@ -36,20 +38,21 @@ export default class TypeInitialization {
targetType = value?.constructor
}
let wrongType = false
if (targetType && value?.constructor !== targetType && !(value instanceof targetType)) {
wrongType = true
if (
targetType
&& targetType !== SerializedType
&& !(value?.constructor === targetType || value instanceof targetType)
) {
value = new targetType(value)
}
if (value instanceof Boolean || value instanceof Number || value instanceof String) {
value = value.valueOf() // Get the relative primitive value
}
if (wrongType) {
return new targetType(value)
}
return value
}
/**
* @typedef {(new () => T) | StringConstructor | NumberConstructor | BooleanConstructor} Constructor
* @typedef {(new () => T) | SerializedType | StringConstructor | NumberConstructor | BooleanConstructor} Constructor
* @param {Constructor|Array<Constructor>} type
* @param {Boolean} showDefault
* @param {any} value
@@ -58,6 +61,8 @@ export default class TypeInitialization {
if (value === undefined) {
if (type instanceof Array) {
value = []
} else if (type instanceof SerializedType) {
value = ""
} else {
value = TypeInitialization.sanitize(new type())
}