Giter VIP home page Giter VIP logo

swn-1's Introduction

SWN Sector Generator

Written for use with the Stars Without Number role-playing game by Sine Nomine Publishing.


Will This Be Updated For The Upcoming Revised Edition of Stars Without Number?
Short answer: yes! Longer answer: I am tracking progress on the public betas of the revised rules, and will work update the SWN Sector Generator once the final free version is published. As with the original, the updated generator will only include content from the free version.


This is the source code for a random galactic sector generator that is hosted on OpenShift. You can play around with it at http://swn.emichron.com/, or fork this repo and host it somewhere else.

The rules for generating this sector are entirely based on the Stars Without Number role-playing game. I created this generator because I loved the game, and really appreciated the insane level of detail that the author put into his tables for rolling up a random galactic sector. I also realized that the rules were so detailed, that it might take a GM quite a while to put their galaxy together.

Getting Your Head Around This Code

For years I promised myself I would clean this up, or rewrite this in a hip new language. But the problem is that a few of the libraries that I'm using have no analogs in other languages. So, let me just lay out the facts:

  1. This tool was written in Perl, using many CPAN libraries.
  2. This tool is at some risk of "bit rot", since the first lines of it were written in 2010.

Still want to know how it works? I salute you. Stiff upper lip and all that. Let's get to it.

The Front End

The index.html file contains the entire user interface and most of the front-end logic, save for the bundled jQuery library files. The JavaScript code included in this files handles the nifty UI elements, and also defines three functions that make AJAX (ooh, how Web 2.0!) calls back to the web server.

getRandSeed
This function is called when the page loads, and it asks the server for a random seed.

getSector
This function hands the random seed back to the server and receives all of the details of a random galactic sector. Then it renders all of the data for display in the UI.

Save Sector button
An anonymous function bound to this button click collects the current state of the sector as shown in the UI and passes it back to the server for processing. The server turns this data into two versions of a TiddlyWiki file, compresses the files into a .zip, and hands them back to the browser for download.

The Back End

So far, you're thinking "hey, this reasonably sane JSON-speaking API gives me a good feeling about the back end code." Whelp, here's where you may get panicky.

Remember CGI?
The CGI directory in this repo is not a cruel hoax. In order to get this ship sailing, you will need to configure your web server with CGI support.

seed.cgi
Really simple script; calls SWNUtil::tokenize_seed on a random number to provide a seed value. This is the back end of getRandSeed above.

sectorgen.cgi
This is the main processer. It can both emit and accept a big JSON object that represents an entire galactic sector. It is called by getSector and the anonymous Save Sector function.

iemap.cgi
This CGI handles a (2011) limitation of Internet Explorer, which couldn't handle data:// URLs.

Now Containerized!

This app runs great on OpenShift v2, and the latest updates make it run just as well in a container suitable for OpenShift v3.

If you just want to run your own copy of the published application, install docker and run:

docker run -d -P nhripps/swn

That will fire up an instance of this app, listening for web requests on port 8080.

If you want to hack your own modified version and build it into a container, read on.

Source-to-Image

Note that there is no Dockerfile in the repo. A previous iteration of this code did include a Dockerfile, but the container generated by that Dockerfile ran as the root user. We can avoid that by using Source to Image to generate our container.

In order to make everything work well, and to prefer RPM-packaged Perl modules over CPAN-sourced modules, I created a custom s2i builder image:

The net result is that if you want to hack on this source code and then build and deploy your own containerized version, you can install Source-to-Image and then run this command in your repo directory:

s2i build . nhripps/perl-520-centos7-swn <your_username>/<your_app_name>

Happy hacking!

Legal Notes

  • Check out the LICENSE file for information on how this app is licensed.

  • Before making this tool publicly available, I contacted the game author and agreed to limit the tool's functionality to those rules described in the free version of Stars Without Number. Take care to avoid changing this tool in any way that may infringe the copyrights of Sine Nomine Publishing or any other RPG publishers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.