GithubHelp home page GithubHelp logo

rlugojr / save-manager-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gamelab/save-manager-plugin

0.0 2.0 0.0 483 KB

This is an Save Manager plugin created for the HTML5 Game Engine Kiwi.JS

License: MIT License

JavaScript 100.00%

save-manager-plugin's Introduction

#Save Manager Plugin v1.0.2

This is a free Kiwi plugin that provides an easy way for developers to manage different methods of saving information relating to a Kiwi Game.

Included with this Plugin is also a LocalStorage method of saving data, which the SaveManager uses by default to save data/information locally on either a Browser or CocoonJS app.

You can view a tutorial on using the Save Manager Plugin on the Kiwi.JS website.

If you have any problems then feel free to contact us via our contact page

##Versions: 1.0.2

  • Issue where the plugin could not update values when setting them to false

1.0.1

  • General Bug fixes and updates.

1.0.0

  • Initial Plugin created.

##How to Include:

First Step: Copy either the saveManager.js or the saveManager.min.js file (they should be right next to this one right now) into your project directory. We recommend that you save the files under a plugin directory that lives inside of your project directory so that you can easily manage all of the plugins but that is not required.

Second: Link in the JavaScript file (that you have just copied across in the first step) into your HTML file. Make sure you link it in underneath the link to the main Kiwi.js file otherwise the plugin will not register and you can come across some errors.

Third: Now that you have linked in the plugin, the next step is to tell the game to use this plugin. To do so, when you create a new Kiwi.Game you need to pass 'SaveGame' the confiration object's plugins item. You can see an example of the code below.

var game = new Kiwi.Game('domElement', 'GameName', 'State', { plugins: ["SaveGame"]});

Just make sure if you are including more than one System plugin that you pass other plugin's that you want to use also.

Lastly: Now that you have successfully include the plugin you can start using it. You can access the 'saveManager' through the game object.

##How to use.

###Take Note! Right now all of the information is saved to a single index on LocalStorage as a JSON object. The index of the information is the name of the game so be careful with saving information for multiple different games that have the same name.

###Boot Sequence: This plugin use's the games boot sequence to check to see if a this game has previously had information 'saved' in localStorage or not. If it has it will automatically retrieve that information, if it hasn't it will create the a new item in localStorage for this game. Note: The key in localStorage is based off of the games name so make sure they are always unique when having multiple instances of a game on a since website/page.

###Saving Information:

Add the Information: To save information using this plugin you first use the 'add' the information to the localstorage object (or the saveManager).

When you add the information you have to provide a key for the information you are saving. This is so that when you try to access that information again you know what one you are wanting.

this.game.saveManager.add('key', 'data');

Run the Save Method: Once the information has been added you then need to tell localStorage to 'save' the information.

this.game.saveManager.save(); 

//Alternatively you can also pass `true` as the third argument to the `add` method which will tell the plugin to automatically execute the `save` method.
this.game.saveManager.add('key', 'data', true);

###Loading Information:

By default when this plugin is included into a game it will automatically get any information that it has previous saved, but at any time you can always get what is currently stored in localStorage by using the 'load' method.

this.game.saveManager.load();

Note: When you do load information any 'unsaved' information will be overriden/lost.

###Data Exists To see if a value exists for a particular key you can execute the exists method.

if( this.game.saveManager.exists( 'key' ) ) {
    //Get you data here...
} else {
    //Data doesn't exist. Set a default value?
}

###Getting Information: If you want to retrieve some information from you have two options.

The first is to use the 'getData' method, in which you pass a key for the information you want to get. If no information was retrieve this method will return 'null'.

var data = this.game.saveManager.getData('key');

The second option is to access the 'data' property on the localStorage object which holds all of the information currently added. Note that this object is read only though.

var dataObj = this.game.saveManager.localStorage.data;

save-manager-plugin's People

Contributors

benjaminharding avatar zfreiberg avatar

Watchers

 avatar  avatar

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.