node package manager

properjs-gamestate

GameState

Arbitrary game data management using localStorage.

Installation

npm install properjs-gamestate --save-dev

Usage

GameState will utilize localStorage. So, quest state is persisted and it will try to load from storage on initialization.

var GameState = require( "properjs-gamestate" );
var gameState = new GameState();
 
// Set initial game state 
gameState.pushState({
    "level": 1,
    "hp": 100,
    "xp": 1000,
    "cash": 50,
    "stats": {
        "magic": 10,
        "power": 10
    }
});
 
// Set state as you go 
gameState.setValue( "level", 2 );
 
// Set a deep state value 
gameState.setValueDeep( "stats", "power", 20 );
 
// Also 
gameState.getState();
gameState.getValue( id );
gameState.getValueDeep( id, prop );
 
// Manually save to localStorage 
// GameState does this for you though as you go 
gameState.setState();