Skip to content

Procedural world generator (galaxies, systems, stars, planets)

Notifications You must be signed in to change notification settings

duchu-net/xenocide-world-generator

Repository files navigation

@xenocide/world-generator

"Dear World, You are the best for Us!" - Artifexian
TypeScript world generator for 4X like games in 3D space

In heavy development mess xD

For CodeSandbox example, use git source with tag prealpha_0.0.2-rc.1, package.json example:

"dependencies": {
  "xenocide-world-generator": "https://github.com/duchu-net/xenocide-world-generator@prealpha_0.0.2-rc.1",
}

For now generator is developed as part of a private project (galaxy simulator with nx),
so currently without plans to release as a separate bundle (but can be used as git submodule).

@xenocide/world-generator available on NPM and with TS from 0.0.4!

Image

Install

npm i @xenocide/[email protected]

Usage

const { GalaxyGenerator, GalaxyClass } = require('@xenocide/world-generator');
// or
import { GalaxyGenerator, GalaxyClass } from '@xenocide/world-generator';

Supports ESM and CommonJS modules.

Examples

New examples coming soon...

Galaxy generator with React and SVG (live demo).
Planet generator with React and @react-three/fiber (live demo).
[*alpha JS version] Full featured generator demo with React, Redux and react-three-fiber (live demo, video).
[*alpha JS version] Name generation with Markov Chains. live demo

Code

import { GalaxyGenerator, GalaxyClass, PlanetGenerator } from '@xenocide/world-generator';

// Spiral shape
const world = new GalaxyGenerator(
  { id: 'demo', classification: GalaxyClass.Spiral },
  { seed: 123, spiral: { size: 500 } }
);
// Grid shape
const world = new GalaxyGenerator(
  { id: 'demo', classification: GalaxyClass.Grid },
  { seed: 123, grid: { size: 15, spacing: 5 } }
);

const systems = [];
for (const system of world.generateSystems()) {
  systems.push(system.path);

  for (const star of system.generateStars()) {
    // console.log('*** Star generated:', star.path, star.toModel());
  }

  /** don't generate too much for tests */
  if (systems.length <= 3) {
    for (const planet of system.generatePlanets()) {
      // console.log('*** Planet/Belt/Etc. generated:', planet.path, planet.toModel());
      if (planet instanceof PlanetGenerator) {
        for (const region of planet.generateSurface()) {
          // console.log('**** Regions generated:', region.path);
        }
      }
    }
  }
}

// Get Plain Object
const model = world.toModel();

Inspired by

Other links

todo

  • own tsconfig build, not from nx