Link icon fixing, name refactoring

This commit is contained in:
barsdeveloper
2022-11-21 11:45:43 +01:00
parent 401ce75fdc
commit a7468f4cf0
37 changed files with 239 additions and 151 deletions

View File

@@ -20,9 +20,9 @@ export default class GeneralSerializer extends ISerializer {
* @param {(value: String, entity: T) => String} wrap
* @param {AnyValueConstructor<T>} entityType
*/
constructor(wrap, entityType, prefix, separator, trailingSeparator, attributeValueConjunctionSign, attributeKeyPrinter) {
constructor(wrap, entityType, attributePrefix, attributeSeparator, trailingSeparator, attributeValueConjunctionSign, attributeKeyPrinter) {
wrap = wrap ?? (v => `(${v})`)
super(entityType, prefix, separator, trailingSeparator, attributeValueConjunctionSign, attributeKeyPrinter)
super(entityType, attributePrefix, attributeSeparator, trailingSeparator, attributeValueConjunctionSign, attributeKeyPrinter)
this.wrap = wrap
}
@@ -35,6 +35,7 @@ export default class GeneralSerializer extends ISerializer {
let grammar = Grammar.getGrammarForType(ISerializer.grammar, this.entityType)
const parseResult = grammar.parse(value)
if (!parseResult.status) {
// @ts-expect-error
throw new Error(`Error when trying to parse the entity ${this.entityType.prototype.constructor.name}.`)
}
return parseResult.value

View File

@@ -18,6 +18,7 @@ import RealUnitEntity from "../entity/UnitRealEntity"
import RotatorEntity from "../entity/RotatorEntity"
import SimpleSerializationRotatorEntity from "../entity/SimpleSerializationRotatorEntity"
import SimpleSerializationVectorEntity from "../entity/SimpleSerializationVectorEntity"
import SymbolEntity from "../entity/SymbolEntity"
import TypeInitialization from "../entity/TypeInitialization"
import UnionType from "../entity/UnionType"
import UnknownKeysEntity from "../entity/UnknownKeysEntity"
@@ -92,6 +93,8 @@ export default class Grammar {
return r.SimpleSerializationVector
case String:
return r.String
case SymbolEntity:
return r.Symbol
case UnionType:
return attributeType.types
.map(v => Grammar.getGrammarForType(r, Utility.getType(v)))
@@ -242,6 +245,9 @@ export default class Grammar {
/** @param {Grammar} r */
PathSymbolOptSpaces = r => P.regex(/[0-9\w]+(?: [0-9\w]+)+|[0-9\w]+/).map(v => new PathSymbolEntity({ value: v }))
/** @param {Grammar} r */
Symbol = r => P.regex(/\w+/).map(v => new SymbolEntity({ value: v }))
/** @param {Grammar} r */
ObjectReference = r => P.alt(
r.None,
@@ -304,6 +310,7 @@ export default class Grammar {
r.LinearColor,
r.UnknownKeys,
r.ObjectReference,
r.Symbol,
)
/** @param {Grammar} r */

View File

@@ -21,15 +21,15 @@ export default class ISerializer {
/** @param {AnyValueConstructor<T>} entityType */
constructor(
entityType,
prefix = "",
separator = ",",
attributePrefix = "",
attributeSeparator = ",",
trailingSeparator = false,
attributeValueConjunctionSign = "=",
attributeKeyPrinter = k => k.join(".")
) {
this.entityType = entityType
this.prefix = prefix
this.separator = separator
this.attributePrefix = attributePrefix
this.attributeSeparator = attributeSeparator
this.trailingSeparator = trailingSeparator
this.attributeValueConjunctionSign = attributeValueConjunctionSign
this.attributeKeyPrinter = attributeKeyPrinter
@@ -94,12 +94,12 @@ export default class ISerializer {
const value = object[property]
if (value?.constructor === Object) {
// Recursive call when finding an object
result += (result.length ? this.separator : "")
result += (result.length ? this.attributeSeparator : "")
+ this.subWrite(entity, fullKey, value, insideString)
} else if (value !== undefined && this.showProperty(entity, object, fullKey, value)) {
const isSerialized = Utility.isSerialized(entity, fullKey)
result += (result.length ? this.separator : "")
+ this.prefix
result += (result.length ? this.attributeSeparator : "")
+ this.attributePrefix
+ this.attributeKeyPrinter(fullKey)
+ this.attributeValueConjunctionSign
+ (
@@ -111,7 +111,7 @@ export default class ISerializer {
}
if (this.trailingSeparator && result.length && fullKey.length === 1) {
// append separator at the end if asked and there was printed content
result += this.separator
result += this.attributeSeparator
}
return result
}

View File

@@ -47,8 +47,8 @@ export default class ObjectSerializer extends ISerializer {
${this.subWrite(entity, [], object, insideString)
+ object
.CustomProperties.map(pin =>
this.separator
+ this.prefix
this.attributeSeparator
+ this.attributePrefix
+ "CustomProperties "
+ SerializerFactory.getSerializer(PinEntity).serialize(pin)
)

View File

@@ -20,6 +20,7 @@ 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"
@@ -193,6 +194,11 @@ export default function initializeSerializerFactory() {
)
)
SerializerFactory.registerSerializer(
SymbolEntity,
new ToStringSerializer(SymbolEntity)
)
SerializerFactory.registerSerializer(
UnknownKeysEntity,
new GeneralSerializer((string, entity) => `${entity.lookbehind ?? ""}(${string})`, UnknownKeysEntity)