mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-27 02:34:45 +08:00
Tests for various entity classes and update entity class implementations
This commit is contained in:
@@ -2,64 +2,44 @@ 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"
|
||||
|
||||
export default class LocalizedTextEntity extends IPrintableEntity {
|
||||
|
||||
static attributeSeparator = ", "
|
||||
static printKey = k => ""
|
||||
static lookbehind = "NSLOCTEXT"
|
||||
static attributes = {
|
||||
...super.attributes,
|
||||
namespace: StringEntity.withDefault(),
|
||||
key: StringEntity.withDefault(),
|
||||
value: StringEntity.withDefault(),
|
||||
}
|
||||
static grammar = P.regArray(new RegExp(
|
||||
String.raw`${this.lookbehind}\s*\(`
|
||||
+ String.raw`\s*"(${Grammar.Regex.InsideString.source})"\s*,`
|
||||
+ String.raw`\s*"(${Grammar.Regex.InsideString.source})"\s*,`
|
||||
+ String.raw`\s*"(${Grammar.Regex.InsideString.source})"\s*`
|
||||
+ String.raw`(,\s+)?`
|
||||
String.raw`${LocalizedTextEntity.lookbehind}\s*\(`
|
||||
+ String.raw`\s*"(?<namespace>${Grammar.Regex.InsideString.source})"\s*,`
|
||||
+ String.raw`\s*"(?<key>${Grammar.Regex.InsideString.source})"\s*,`
|
||||
+ String.raw`\s*"(?<value>${Grammar.Regex.InsideString.source})"\s*`
|
||||
+ String.raw`(?<trailing>,\s+)?`
|
||||
+ String.raw`\)`,
|
||||
"m"
|
||||
)).map(matchResult => {
|
||||
const self = matchResult[4] ? this.flagTrailing() : this
|
||||
return new self(
|
||||
Utility.unescapeString(matchResult[1]),
|
||||
Utility.unescapeString(matchResult[2]),
|
||||
Utility.unescapeString(matchResult[3]),
|
||||
)
|
||||
)).map(({ groups: { namespace, key, value, trailing } }) => {
|
||||
const self = trailing ? this.flagTrailing() : this
|
||||
return new self({
|
||||
namespace: new (this.attributes.namespace)(Utility.unescapeString(namespace)),
|
||||
key: new (this.attributes.namespace)(Utility.unescapeString(key)),
|
||||
value: new (this.attributes.namespace)(Utility.unescapeString(value)),
|
||||
})
|
||||
}).label("LocalizedTextEntity")
|
||||
|
||||
#namespace
|
||||
get namespace() {
|
||||
return this.#namespace
|
||||
}
|
||||
set namespace(value) {
|
||||
this.#namespace = value
|
||||
}
|
||||
|
||||
#key
|
||||
get key() {
|
||||
return this.#key
|
||||
}
|
||||
set key(value) {
|
||||
this.#key = value
|
||||
}
|
||||
|
||||
#value
|
||||
get value() {
|
||||
return this.#value
|
||||
}
|
||||
set value(value) {
|
||||
this.#value = value
|
||||
}
|
||||
|
||||
constructor(namespace = "", key = "", value = "") {
|
||||
super()
|
||||
this.namespace = namespace
|
||||
this.key = key
|
||||
this.value = value
|
||||
constructor(values = {}) {
|
||||
super(values)
|
||||
/** @type {InstanceType<typeof LocalizedTextEntity.attributes.namespace>} */ this.namespace
|
||||
/** @type {InstanceType<typeof LocalizedTextEntity.attributes.key>} */ this.key
|
||||
/** @type {InstanceType<typeof LocalizedTextEntity.attributes.value>} */ this.value
|
||||
}
|
||||
|
||||
print() {
|
||||
return Utility.capitalFirstLetter(this.value)
|
||||
}
|
||||
|
||||
toString() {
|
||||
const trailer = this.Self().trailing ? ", " : ""
|
||||
return `${this.lookbehind}(${this.namespace}, ${this.key}, ${this.value}${trailer})`
|
||||
return Utility.capitalFirstLetter(this.value.valueOf())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user