This guide helps you migrate from RPG Event Generator v3.x to v4.0.0.
v4.0.0 represents a complete rebuild of the core generation system (GeneratorCore). The new architecture replaces Markov chain generation with a direct content mapping system for more reliable, coherent output.
v3.x:
generator.addTrainingData([
'A merchant approaches you in the market',
'You encounter a mysterious stranger',
'A battle breaks out in the forest'
]);
v4.0.0:
// Raw text arrays are no longer processed
// Use structured content instead:
generator.addTrainingData({
titles: {
ECONOMIC: ['Market Encounter', 'Trade Opportunity'],
SOCIAL: ['Mysterious Meeting', 'Stranger\'s Approach'],
COMBAT: ['Forest Battle', 'Unexpected Conflict']
},
descriptions: {
ECONOMIC: ['A merchant approaches you in the bustling market, wares gleaming in the sunlight.'],
// ...
},
choices: {
ECONOMIC: ['Negotiate a deal', 'Browse the wares', 'Decline politely'],
// ...
}
});
Migration:
pureMarkovMode option (see below)v3.x:
v4.0.0:
pureMarkovMode optionMigration:
pureMarkovMode:const generator = new RPGEventGenerator({
pureMarkovMode: true
});
v3.x:
v4.0.0:
MAGIC and SPELLCASTING)Migration:
validTypes arrays updatedContext integration rates have been increased:
Migration:
Custom content from any theme is now automatically discovered:
v3.x:
// Only checked 'default' theme
generator.addTrainingData({ titles: { COMBAT: ['Custom Title'] } }, 'default');
v4.0.0:
// Checks all themes, prioritizing 'default'
generator.addTrainingData({ titles: { COMBAT: ['Custom Title'] } }, 'custom_theme');
// Will be found and used automatically
Migration:
All public APIs remain compatible:
// Still works exactly the same
const event = generator.generateEvent(context);
const events = generator.generateEvents(context, 10);
generator.addTrainingData(data, theme);
// New: pureMarkovMode for traditional Markov chain generation
const generator = new RPGEventGenerator({
pureMarkovMode: true // Use Markov chains instead of content library
});
Update test files that validate event types:
// Before
const validTypes = ['ADVENTURE', 'COMBAT', 'ECONOMIC', /* ... */];
// After
const validTypes = ['ADVENTURE', 'COMBAT', 'ECONOMIC', 'MAGIC', 'SPELLCASTING', /* ... */];
Tests that rely on probabilistic behavior (e.g., "try 50 times to get a specific event type") may need adjustment:
// Consider increasing iterations or using deterministic mocks
for (let i = 0; i < 100; i++) { // Increased from 50
const event = generator.generateEvent(context);
if (event.type === 'MAGIC') {
// test assertions
break;
}
}
The new content library is significantly larger (1,870+ elements vs ~17). This means:
Consider extracting content to JSON files for:
This is a future enhancement and not required for migration.
Enable debug mode to see warnings about deprecated features:
const generator = new RPGEventGenerator({
debug: true
});
// Will warn if raw training texts are provided:
generator.addTrainingData(['raw text']); // Warning logged
If you encounter issues during migration:
debug: true to see detailed loggingpureMarkovMode if you prefer Markov chainsdebug: true to catch any deprecation warningsNote: The migration should be straightforward for most users. The API remains compatible, and the main change is improved output quality and reliability.
v5.0.0 removes all runtime npm dependencies. Randomness is handled by the built-in SeededRandom class exported from the package.
GeneratorOptions.chance → GeneratorOptions.rngv4.x:
const Chance = require('chance');
const generator = new RPGEventGenerator({ chance: new Chance(42) });
v5.0.0:
const { RPGEventGenerator, SeededRandom } = require('rpg-event-generator');
const generator = new RPGEventGenerator({ rng: new SeededRandom(42) });
World building and event generation with the same numeric seed will produce different results than v4 (PRNG algorithm changed). Reproducibility is preserved within v5 — the same seed always yields the same output on the same version.
chance option with rng: new SeededRandom(seed)chance, compromise, and natural from your own dependency lists if you only used them for this package