@zerospacegg/iolin
Version:
Pure TypeScript implementation of ZeroSpace game data processing (PKL-free)
127 lines • 3.46 kB
JavaScript
/**
* Game Mechanic Engine - Base classes for game mechanics
*
* This module provides the foundational classes for defining and managing
* game mechanics in ZeroSpace. Mechanics represent core gameplay systems
* and rules that apply across factions and units.
*/
/**
* Base class for all game mechanics
* Represents a core gameplay system or rule
*/
export class GameMechanic {
constructor(name, builder) {
this.uuid = "";
this.keywords = [];
this.description = "";
this.name = name;
if (builder) {
builder(this);
}
}
/**
* Get a summary of this mechanic
*/
get summary() {
return `${this.name}: ${this.description.slice(0, 100)}...`;
}
/**
* Check if this mechanic matches a search term
*/
matches(searchTerm) {
const term = searchTerm.toLowerCase();
// Check name
if (this.name.toLowerCase().includes(term)) {
return true;
}
// Check keywords
if (this.keywords.some(keyword => keyword.toLowerCase().includes(term))) {
return true;
}
// Check description
if (this.description.toLowerCase().includes(term)) {
return true;
}
return false;
}
/**
* Get mechanic data as a plain object
*/
toJSON() {
return {
name: this.name,
uuid: this.uuid,
keywords: this.keywords,
description: this.description.trim(),
};
}
}
/**
* Basic mechanic - represents fundamental gameplay concepts
*/
export class BasicMechanic extends GameMechanic {
constructor(name, builder) {
super(name, builder);
}
}
/**
* Transformation mechanic - represents complex multi-phase systems
*/
export class TransformationMechanic extends GameMechanic {
constructor(name, builder) {
super(name);
this.category = "";
this.stackable = false;
this.maxStacks = 1;
this.conflictsWith = [];
this.hasPhases = false;
this.triggersOnDeath = false;
this.tagsAdded = [];
this.tagsRemoved = [];
this.notes = "";
if (builder) {
builder(this);
}
}
/**
* Get transformation mechanic data as a plain object
*/
toJSON() {
return {
...super.toJSON(),
category: this.category,
stackable: this.stackable,
maxStacks: this.maxStacks,
conflictsWith: this.conflictsWith,
hasPhases: this.hasPhases,
triggersOnDeath: this.triggersOnDeath,
tagsAdded: this.tagsAdded,
tagsRemoved: this.tagsRemoved,
notes: this.notes.trim(),
};
}
}
/**
* Advanced transformation mechanic with detailed rules
*/
export class AdvancedTransformationMechanic extends TransformationMechanic {
constructor(name, builder) {
super(name);
if (builder) {
builder(this);
}
}
/**
* Get advanced transformation mechanic data as a plain object
*/
toJSON() {
return {
...super.toJSON(),
requirements: this.requirements,
statModifications: this.statModifications,
preDeathPhase: this.preDeathPhase,
postDeathPhase: this.postDeathPhase,
};
}
}
//# sourceMappingURL=mechanic.js.map