simc-ast-builder
Version:
Parser and AST generator for SimulationCraft files
115 lines • 3.84 kB
JavaScript
;
/**
* Registry for NodeTemplate instances
* Provides a central registry for node templates with dynamic registration
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodeRegistry = void 0;
const NodeTemplate_1 = require("./NodeTemplate");
/**
* Registry for NodeTemplate instances
*/
class NodeRegistry {
/**
* Clear all templates from the registry
*/
static clearTemplates() {
this.templates.clear();
}
/**
* Get all templates in the registry
* @returns Array of all templates in the registry
*/
static getAllTemplates() {
return Array.from(this.templates.values());
}
/**
* Get a template by type, creating it if it doesn't exist
* @param type Type of the template
* @param defaultOptions Default options to use if the template doesn't exist
* @returns The existing or newly created template
*/
static getOrCreateTemplate(type, defaultOptions = {}) {
const existing = this.getTemplate(type);
if (existing) {
return existing;
}
// Create a new template with the default options
return this.registerTemplate(type, defaultOptions);
}
/**
* Get a template from the registry by type
* @param type Type of the template to get
* @returns The template with the given type, or undefined if not found
*/
static getTemplate(type) {
return this.templates.get(type);
}
/**
* Check if a template exists in the registry
* @param type Type of the template to check
* @returns True if the template exists in the registry
*/
static hasTemplate(type) {
return this.templates.has(type);
}
/**
* Initialize the registry with default templates
*/
static initializeDefaults() {
// Register templates for common node types
this.registerTemplate("action", {
baseProperties: {
expressionType: "neutral",
},
validator: (node) => typeof node["actionName"] === "string" && node["field"] !== undefined,
});
this.registerTemplate("spell_targets", {
baseProperties: {
expressionType: "numeric",
},
validator: (node) => typeof node["actionName"] === "string",
});
this.registerTemplate("buff", {
baseProperties: {
expressionType: "boolean",
},
validator: (node) => typeof node["buffName"] === "string" && node["field"] !== undefined,
});
this.registerTemplate("debuff", {
baseProperties: {
expressionType: "boolean",
},
validator: (node) => typeof node["debuffName"] === "string" && node["field"] !== undefined,
});
// Add more default templates as needed
}
/**
* Register an existing template in the registry
* @param template Template to register
* @returns The registered template
*/
static registerExistingTemplate(template) {
this.templates.set(template.type, template);
return template;
}
/**
* Register a template in the registry
* @param type Type of the template
* @param options Options for the template
* @returns The registered template
*/
static registerTemplate(type, options = {}) {
const template = new NodeTemplate_1.NodeTemplate(type, options);
this.templates.set(type, template);
return template;
}
}
exports.NodeRegistry = NodeRegistry;
/**
* Map of template types to NodeTemplate instances
*/
NodeRegistry.templates = new Map();
// Initialize the registry with default templates
NodeRegistry.initializeDefaults();
//# sourceMappingURL=NodeRegistry.js.map