@zerospacegg/iolin
Version:
Pure TypeScript implementation of ZeroSpace game data processing (PKL-free)
71 lines • 2.29 kB
JavaScript
"use strict";
/**
* Child - Base class for embedded objects like abilities, talents, upgrades
* These don't have their own files but live inside entities
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Child = void 0;
const core_js_1 = require("./core.cjs");
const universal_js_1 = require("./universal.cjs");
/**
* Child class for embedded content that needs parent context
* Usage: new SomeChild("Name", parentId, (child) => { child.description = "..."; })
*/
class Child extends universal_js_1.Universal {
// Getter/setter for parent ID
get parentId() {
return typeof this._parentId === "function" ? this._parentId() : this._parentId || "";
}
set parentId(value) {
this._parentId = value;
}
// Getter/setter for parent UUID
get parentUUID() {
return typeof this._parentUUID === "function" ? this._parentUUID() : this._parentUUID || "";
}
set parentUUID(value) {
this._parentUUID = value;
}
/** Auto-generated slug from name */
get slug() {
return (0, core_js_1.slugify)(this.name);
}
/** Auto-generated ID from parent ID + type + slug */
get id() {
if (this.parentId) {
return `${this.parentId}/${this.type}/${this.slug}`;
}
return `${this.type}/${this.slug}`;
}
/**
* Auto-generated hierarchical UUID from parent UUID + child path
* Format: {parentUuid}:{childPathSuffix}
*/
get uuid() {
if (this.parentUUID && this.parentId) {
// Extract the child path suffix (everything after parent ID)
const childPathSuffix = `${this.type}/${this.slug}`;
return `${this.parentUUID}:${childPathSuffix}`;
}
return this._uuid || "";
}
set uuid(value) {
this._uuid = value;
}
/** JSON.stringify() calls this automatically */
toJSON() {
return {
name: this.name,
type: this.type,
subtype: this.subtype,
id: this.id,
slug: this.slug,
parentId: this.parentId,
parentUUID: this.parentUUID,
uuid: this.uuid,
className: this.className,
};
}
}
exports.Child = Child;
//# sourceMappingURL=child.js.map