0.1.0 • Published 6 years ago

simtegalib v0.1.0

Weekly downloads
2
License
MIT
Repository
-
Last release
6 years ago

SIMTEGA Lib

Simple Text Game Library

That's all it is. Let simtega manage your state and scenes while you manage your interface. Primarily intended for text games but maybe one day there'll be a plugin for visual games.

Basically, install simtega with

$ npm i --save simtegalib

import with

import Game from 'simtegalib';

or

const Game = require('simtegalib').default;

make an update function

const update = (type) => console.log("updating ", type);

initialize simtega

const game = new Game(update);

and kick off the game by loading the first scene

game.loadScene({
  text: "hello!",
  buttons: [
    {
      text: "button1",
      onClick: () => console.log("clicked button1")
    }
  ]
})

you are now ready to start using simtega!

Using Simtega

Loading Scenes

Scenes are the most important part of simtega. Everything it does centers around them and the state (more on that later). Scenes are interacted with in two ways: pushing them into the game with game.loadScene and getting the current scene's properties with game.currentScene.

All scenes are objects with two required properties: text and buttons. text is the description of the scene--what players see when they're in the scene. buttons is an array of button objects, an example of which can be seen above. Scene objects can also contain onEnter and onLeave methods.

Here is an example of a scenes with all properties:

{
  text: "This is a scene with onEnter & onLeave methods",
  onEnter: () => doSomething(),
  onLeave: () => doSomethingElse(),
  buttons: [
    {
      text: "button1",
      onClick: () => click1()
    },
    {
      text: "button2",
      onClick: () => click2()
    }
  ]
}

That's a scene! For most text games, this is more than enough to create a full game.

Updating the UI

When you push a new scene, you'll probably want to update your UI. To facilitate this, your update function will be called with "scene" as the first parameter. Get the parts of the scene in update with game.currentScene, i.e. game.currentScene.text.

Managing State

In simtega, state for an entire game is in one place. game.setState sets a value and game.getState gets a value. Each value in simtega's state has a path, like a path in your filesystem. There are two root "directories," var (persistent) and tmp (temporary). All subdirectories are created on the fly when you set them. For example, some valid paths include 'var/player/hp' or 'tmp/ui/textBox'.

Other things to note:

  • When you set the state, any directories or properties that do not exist are created for you.
  • If a segment is a number ('var/player/inventory/0/name'), an array will automatically be used to ease iteration.

Updating the UI

Like updating the scene, updating the state will trigger a call to your update function, but the type will be "state".

Plugins

Using Plugins

Include an array of plugins as the second parameter to the Game constructor after following the plugins' instructions.

Example:

import Game from 'simtegalib';
import Static from 'simtega-plugin-static';
import scenes from './scenes.json';
import utils from './utils';

const game = new Game(update, [new Static(scenes, utils, true)]);

Available Plugins:

  • (static plugin coming soon)