StoryForge - Comprehensive World Building Tools

Note: As we move on to world building tools, we'll focus on creating a flexible and extensible system that can integrate with our existing APIs and provide a rich framework for creating detailed story worlds.

World Building System

Let's create a world building system that can work alongside our existing APIs:


// worldBuilding.js

const { StoryElement } = require('./storyElements');

class WorldElement extends StoryElement {
  constructor(name, type, properties = {}) {
    super(name, { ...properties, type });
  }
}

class Location extends WorldElement {
  constructor(name, properties = {}) {
    super(name, 'location', properties);
    this.subLocations = new Map();
  }

  addSubLocation(location) {
    this.subLocations.set(location.name, location);
  }

  getSubLocation(name) {
    return this.subLocations.get(name);
  }
}

class Culture extends WorldElement {
  constructor(name, properties = {}) {
    super(name, 'culture', properties);
  }
}

class Technology extends WorldElement {
  constructor(name, properties = {}) {
    super(name, 'technology', properties);
  }
}

class SocialStructure extends WorldElement {
  constructor(name, properties = {}) {
    super(name, 'socialStructure', properties);
  }
}

class WorldManager {
  constructor() {
    this.elements = new Map();
  }

  addElement(element) {
    this.elements.set(element.name, element);
  }

  getElement(name) {
    return this.elements.get(name);
  }

  createLocation(name, properties) {
    const location = new Location(name, properties);
    this.addElement(location);
    return location;
  }

  createCulture(name, properties) {
    const culture = new Culture(name, properties);
    this.addElement(culture);
    return culture;
  }

  createTechnology(name, properties) {
    const technology = new Technology(name, properties);
    this.addElement(technology);
    return technology;
  }

  createSocialStructure(name, properties) {
    const socialStructure = new SocialStructure(name, properties);
    this.addElement(socialStructure);
    return socialStructure;
  }

  generateWorldDescription() {
    // Generate a description of the world based on its elements
    let description = "World Overview:\n\n";
    this.elements.forEach((element, name) => {
      description += `${name} (${element.properties.type}):\n`;
      Object.entries(element.properties).forEach(([key, value]) => {
        if (key !== 'type') {
          description += `  ${key}: ${value}\n`;
        }
      });
      description += '\n';
    });
    return description;
  }
}

module.exports = {
  WorldElement,
  Location,
  Culture,
  Technology,
  SocialStructure,
  WorldManager
};
    

Now, let's create a way to integrate this with our existing genre extensions:


// worldBuildingIntegration.js

const { WorldManager } = require('./worldBuilding');

function integrateWorldBuilding(genreExtension) {
  const worldManager = new WorldManager();

  class EnhancedSetting extends genreExtension.Setting {
    constructor(name, properties = {}) {
      super(name, properties);
      this.worldManager = worldManager;
    }

    addWorldElement(element) {
      this.worldManager.addElement(element);
    }

    getWorldDescription() {
      return this.worldManager.generateWorldDescription();
    }
  }

  return {
    ...genreExtension,
    Setting: EnhancedSetting,
    WorldManager: worldManager
  };
}

module.exports = integrateWorldBuilding;
    

To use this in our main story generator:


// updatedStoryGenerator.js

const { StoryContext } = require('./storyContext');
const { SceneGenerator } = require('./sceneGenerator');
const { FeedbackLoopManager } = require('./feedbackLoopManager');
const CharacterManager = require('./characterManager');
const integrateWorldBuilding = require('./worldBuildingIntegration');

class EnhancedStoryGenerator {
  constructor(genreExtension) {
    const enhancedGenreExtension = integrateWorldBuilding(genreExtension);

    this.context = new StoryContext();
    this.sceneGenerator = new SceneGenerator();
    this.feedbackLoop = new FeedbackLoopManager();
    this.characterManager = new CharacterManager();
    this.worldManager = enhancedGenreExtension.WorldManager;

    // Set up genre-specific components
    this.sceneGenerator.actionGenerator.registerActionProvider(new enhancedGenreExtension.ActionProvider());
    this.feedbackLoop.registerImpactAnalyzer(new enhancedGenreExtension.ImpactAnalyzer());

    this.SettingClass = enhancedGenreExtension.Setting;
    this.CharacterClass = enhancedGenreExtension.Character;
  }

  initializeStory(settingName, settingProperties, characters, worldElements) {
    const setting = new this.SettingClass(settingName, settingProperties);
    this.context.addElement(setting);

    // Add world elements
    worldElements.forEach(element => {
      setting.addWorldElement(element);
    });

    // Add characters
    characters.forEach(charData => {
      const char = new this.CharacterClass(charData.name, charData.backstory, ...charData.traits);
      this.context.addElement(char);
      this.characterManager.addCharacter(char);
    });
  }

  generateStoryBeat() {
    this.characterManager.updateCharacters(this.context);
    const beat = this.feedbackLoop.generateNextStoryBeat(this.context);
    // Update world state based on the generated beat
    return beat;
  }

  getWorldDescription() {
    return this.context.getElement('setting').getWorldDescription();
  }
}

module.exports = EnhancedStoryGenerator;
    

Benefits of the Comprehensive World Building Tools

Next Steps

With our world building tools in place, we can move on to other areas of improvement. What would you like to focus on next?