mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-13 00:24:48 +08:00
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
import IEntity from "./IEntity.js"
|
|
|
|
/** @template {typeof IEntity} T */
|
|
export default class MirroredEntity extends IEntity {
|
|
|
|
/** @type {typeof IEntity} */
|
|
static type
|
|
|
|
/** @param {() => InstanceType<T>} getter */
|
|
constructor(getter = null) {
|
|
super()
|
|
this.getter = getter
|
|
}
|
|
|
|
/**
|
|
* @template {typeof IEntity} T
|
|
* @param {T} type
|
|
*/
|
|
static of(type) {
|
|
const result = this.asUniqueClass()
|
|
result.type = type
|
|
result.grammar = result.getTargetType().grammar.map(v => new this())
|
|
return result
|
|
}
|
|
|
|
/** @returns {typeof IEntity} */
|
|
static getTargetType() {
|
|
const result = this.type
|
|
if (result.prototype instanceof MirroredEntity) {
|
|
return /** @type {typeof MirroredEntity} */(result).getTargetType()
|
|
}
|
|
return result
|
|
}
|
|
|
|
toString(
|
|
insideString = false,
|
|
indentation = "",
|
|
Self = this.Self(),
|
|
printKey = Self.printKey,
|
|
wrap = Self.wrap,
|
|
) {
|
|
this.toString = this.getter.toString.bind(this.getter())
|
|
return this.toString(insideString, indentation, Self, printKey, wrap)
|
|
}
|
|
}
|