Still WIP

This commit is contained in:
barsdeveloper
2024-05-28 16:44:39 +02:00
parent 70b4cabb97
commit 1c2778fbf8
62 changed files with 2480 additions and 2853 deletions

View File

@@ -1,44 +1,55 @@
import Parsernostrum from "parsernostrum"
import P from "parsernostrum"
import Utility from "../Utility.js"
import Grammar from "../serialization/Grammar.js"
import AttributeInfo from "./AttributeInfo.js"
import IEntity from "./IEntity.js"
export default class LocalizedTextEntity extends IEntity {
static attributes = {
...super.attributes,
namespace: AttributeInfo.createValue(""),
key: AttributeInfo.createValue(""),
value: AttributeInfo.createValue(""),
lookbehind: new AttributeInfo({
...super.attributes.lookbehind,
default: "NSLOCTEXT",
}),
}
static grammar = this.createGrammar()
static lookbehind = "NSLOCTEXT"
static grammar = P.regArray(new RegExp(
String.raw`${this.attributes.lookbehind.default}\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`\)`,
"m"
)).map(matchResult => new this(
Utility.unescapeString(matchResult[1]),
Utility.unescapeString(matchResult[2]),
Utility.unescapeString(matchResult[3]),
))
static createGrammar() {
return Parsernostrum.regArray(new RegExp(
String.raw`${this.attributes.lookbehind.default}\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`\)`,
"m"
)).map(matchResult => new this({
namespace: Utility.unescapeString(matchResult[1]),
key: Utility.unescapeString(matchResult[2]),
value: Utility.unescapeString(matchResult[3]),
}))
#namespace
get namespace() {
return this.#namespace
}
set namespace(value) {
this.#namespace = value
}
constructor(values) {
super(values)
/** @type {String} */ this.namespace
/** @type {String} */ this.key
/** @type {String} */ this.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
}
toString() {