Decoding code fixes

This commit is contained in:
barsdeveloper
2024-07-16 21:36:13 +02:00
parent 98ebdd78b2
commit e0d8990e6a
18 changed files with 722 additions and 683 deletions

View File

@@ -1,10 +1,10 @@
import P from "parsernostrum"
import IPrintableEntity from "./IPrintableEntity.js"
import InvariantTextEntity from "./InvariantTextEntity.js"
import LocalizedTextEntity from "./LocalizedTextEntity.js"
import StringEntity from "./StringEntity.js"
import IEntity from "./IEntity.js"
export default class FormatTextEntity extends IPrintableEntity {
export default class FormatTextEntity extends IEntity {
static attributeSeparator = ", "
static lookbehind = ["LOCGEN_FORMAT_NAMED", "LOCGEN_FORMAT_ORDERED"]
@@ -31,13 +31,12 @@ export default class FormatTextEntity extends IPrintableEntity {
this.values = values
}
print() {
const pattern = this.values?.[0]?.print() // The pattern is always the first element of the array
valueOf() {
const pattern = this.values?.[0]?.valueOf() // The pattern is always the first element of the array
if (!pattern) {
return ""
}
const values = this.values.slice(1).map(v => v.print())
const values = this.values.slice(1).map(v => v?.valueOf())
let result = this.lookbehind == "LOCGEN_FORMAT_NAMED"
? pattern.replaceAll(/\{([a-zA-Z]\w*)\}/g, (substring, arg) => {
const argLocation = values.indexOf(arg) + 1
@@ -59,7 +58,9 @@ export default class FormatTextEntity extends IPrintableEntity {
toString(
insideString = false,
indentation = "",
printKey = this.Self().printKey,
Self = this.Self(),
printKey = Self.printKey,
wrap = Self.wrap,
) {
const separator = this.Self().attributeSeparator
return this.lookbehind + "("

View File

@@ -16,7 +16,7 @@ export default class IEntity {
/** @type {(k: String) => String} */
static printKey = k => k
/** @type {P<IEntity>} */
static grammar = /** @type {any} */(P.failure())
static grammar = P.lazy(() => this.unknownEntity)
/** @type {P<IEntity>} */
static unknownEntityGrammar
static unknownEntity

View File

@@ -1,8 +0,0 @@
import IEntity from "./IEntity.js"
export default class IPrintableEntity extends IEntity {
print() {
return this.toString()
}
}

View File

@@ -1,7 +1,7 @@
import P from "parsernostrum"
import IPrintableEntity from "./IPrintableEntity.js"
import IEntity from "./IEntity.js"
export default class InvariantTextEntity extends IPrintableEntity {
export default class InvariantTextEntity extends IEntity {
static lookbehind = "INVTEXT"
@@ -23,15 +23,7 @@ export default class InvariantTextEntity extends IPrintableEntity {
this.value = value
}
print() {
let xxxx = P.alt(
P.seq(
P.reg(new RegExp(`${this.lookbehind}\\s*\\(`)),
P.doubleQuotedString,
P.reg(/\s*\)/)
).map(([_0, value, _2]) => Number(value)),
P.reg(new RegExp(this.lookbehind)).map(() => 0) // InvariantTextEntity can not have arguments
)
valueOf() {
return this.value
}

View File

@@ -1,10 +1,10 @@
import P from "parsernostrum"
import Utility from "../Utility.js"
import Grammar from "../serialization/Grammar.js"
import IPrintableEntity from "./IPrintableEntity.js"
import StringEntity from "./StringEntity.js"
import IEntity from "./IEntity.js"
export default class LocalizedTextEntity extends IPrintableEntity {
export default class LocalizedTextEntity extends IEntity {
static attributeSeparator = ", "
static printKey = k => ""
@@ -41,7 +41,7 @@ export default class LocalizedTextEntity extends IPrintableEntity {
/** @type {InstanceType<typeof LocalizedTextEntity.attributes.value>} */ this.value
}
print() {
valueOf() {
return Utility.capitalFirstLetter(this.value.valueOf())
}
}

View File

@@ -51,7 +51,9 @@ export default class NumberEntity extends IEntity {
toString(
insideString = false,
indentation = "",
printKey = this.Self().printKey,
Self = this.Self(),
printKey = Self.printKey,
wrap = Self.wrap,
) {
if (this.value === Number.POSITIVE_INFINITY) {
return "+inf"

View File

@@ -16,6 +16,7 @@ import LinearColorEntity from "./LinearColorEntity.js"
import MacroGraphReferenceEntity from "./MacroGraphReferenceEntity.js"
import MirroredEntity from "./MirroredEntity.js"
import NaturalNumberEntity from "./NaturalNumberEntity.js"
import NullEntity from "./NullEntity.js"
import ObjectReferenceEntity from "./ObjectReferenceEntity.js"
import PinEntity from "./PinEntity.js"
import ScriptVariableEntity from "./ScriptVariableEntity.js"
@@ -45,6 +46,7 @@ export default class ObjectEntity extends IEntity {
ObjectRef: ObjectReferenceEntity,
BlueprintElementType: ObjectReferenceEntity,
BlueprintElementInstance: ObjectReferenceEntity,
PinTags: ArrayEntity.of(NullEntity).flagInlined(),
PinNames: ArrayEntity.of(StringEntity).flagInlined(),
AxisKey: SymbolEntity,
InputAxisKey: SymbolEntity,
@@ -280,6 +282,7 @@ export default class ObjectEntity extends IEntity {
/** @type {InstanceType<typeof ObjectEntity.attributes.OpName>} */ this.OpName
/** @type {InstanceType<typeof ObjectEntity.attributes.OutputPins>} */ this.OutputPins
/** @type {InstanceType<typeof ObjectEntity.attributes.PCGNode>} */ this.PCGNode
/** @type {InstanceType<typeof ObjectEntity.attributes.PinTags>} */ this.PinTags
/** @type {InstanceType<typeof ObjectEntity.attributes.PinNames>} */ this.PinNames
/** @type {InstanceType<typeof ObjectEntity.attributes.PositionX>} */ this.PositionX
/** @type {InstanceType<typeof ObjectEntity.attributes.PositionY>} */ this.PositionY
@@ -324,7 +327,6 @@ export default class ObjectEntity extends IEntity {
const rgbaPins = Configuration.rgba.map(pinName =>
this.getPinEntities().find(pin => pin.PinName.toString() === pinName && (pin.recomputesNodeTitleOnChange = true))
)
const attribute = {}
const silentBool = MirroredEntity.of(BooleanEntity).withDefault().flagSilent()
obj["R"] = new silentBool(() => rgbaPins[0].DefaultValue)
obj["G"] = new silentBool(() => rgbaPins[1].DefaultValue)
@@ -400,7 +402,7 @@ export default class ObjectEntity extends IEntity {
if (dropCounter) {
return this.getNameAndCounter()[0]
}
return this.Name.print()
return this.Name.valueOf()
}
/** @returns {[String, Number]} */
@@ -617,7 +619,9 @@ export default class ObjectEntity extends IEntity {
toString(
insideString = false,
indentation = "",
printKey = this.Self().printKey,
Self = this.Self(),
printKey = Self.printKey,
wrap = Self.wrap,
) {
const moreIndentation = indentation + Configuration.indentation
let result = indentation + "Begin Object"
@@ -626,7 +630,7 @@ export default class ObjectEntity extends IEntity {
+ (this.Archetype ? ` Archetype=${this.Archetype.toString(insideString)}` : "")
+ (this.ExportPath?.type || this.ExportPath?.path ? ` ExportPath=${this.ExportPath.toString(insideString)}` : "")
+ "\n"
+ super.toString(insideString, moreIndentation, k => this[k] instanceof ObjectEntity ? "" : k)
+ super.toString(insideString, moreIndentation, Self, printKey, wrap)
+ (!this.CustomProperties.Self().ignored
? this.getCustomproperties().map(pin =>
moreIndentation

View File

@@ -90,7 +90,9 @@ export default class ObjectReferenceEntity extends IEntity {
toString(
insideString = false,
indentation = "",
printKey = this.Self().printKey,
Self = this.Self(),
printKey = Self.printKey,
wrap = Self.wrap,
) {
if (insideString) {
if (this.#fullEscaped === undefined) {

View File

@@ -79,7 +79,7 @@ export default class PinEntity extends IEntity {
ParentPin: PinReferenceEntity,
DefaultValue:
ComputedTypeEntity.from(
// @ts-expect-error
/** @param {PinEntity} pinEntity */
pinEntity => pinEntity.getEntityType(true) ?? StringEntity
).flagSerialized(),
AutogeneratedDefaultValue: StringEntity,
@@ -197,6 +197,7 @@ export default class PinEntity extends IEntity {
return category
}
/** @returns {typeof IEntity} */
getEntityType(alternative = false) {
const typeString = this.getType()
const entity = PinEntity.#typeEntityMap[typeString]

View File

@@ -28,7 +28,9 @@ export default class PinReferenceEntity extends IEntity {
toString(
insideString = false,
indentation = "",
printKey = this.Self().printKey,
Self = this.Self(),
printKey = Self.printKey,
wrap = Self.wrap,
) {
return this.objectName.toString() + " " + this.pinGuid.toString()
}

View File

@@ -1,8 +1,8 @@
import P from "parsernostrum"
import Utility from "../Utility.js"
import IPrintableEntity from "./IPrintableEntity.js"
import IEntity from "./IEntity.js"
export default class StringEntity extends IPrintableEntity {
export default class StringEntity extends IEntity {
static grammar = /** @type {P<StringEntity>} */(
P.doubleQuotedString
@@ -16,10 +16,6 @@ export default class StringEntity extends IPrintableEntity {
this.value = value
}
print() {
return this.value
}
valueOf() {
return this.value
}