├── .github
└── ISSUE_TEMPLATE.md
├── .gitignore
├── .npmignore
├── Gruntfile.js
├── LICENSE
├── README.md
├── build
├── phaser-storage-helper.d.ts
├── phaser-storage-helper.js
├── phaser-storage-helper.js.map
├── phaser-storage-helper.min.js
├── phaser-super-storage.d.ts
├── phaser-super-storage.js
├── phaser-super-storage.js.map
└── phaser-super-storage.min.js
├── config
├── tsconfig.json
└── tslint.json
├── example
├── cordova.html
├── frame.html
├── framed.html
└── index.html
├── package-lock.json
├── package.json
├── ts
├── StorageAdapters
│ ├── CookieStorage.ts
│ ├── CordovaStorage.ts
│ ├── IStorage.ts
│ ├── IframeStorage.ts
│ └── LocalStorage.ts
├── SuperStorage.ts
├── Utils
│ ├── Helper.ts
│ └── Storage.ts
└── definitions.d.ts
└── vendor
└── NativeStorage.d.ts
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | Before opening this issue _please_ check we haven't already fixed it! Check the [Closed issues](https://github.com/azerion/phaser-super-storage/issues?q=is%3Aissue+is%3Aclosed)
2 | This Issue is about (delete as applicable)
3 |
4 | * A bug in the API (always say which version you're using!)
5 | * An error in the documentation
6 | * An error in the example
7 | * A problem with my own code
8 |
9 | API errors must include example code showing what happens, and why you don't believe this is the expected behavior. Issues posted without code take _far_ longer to get resolved, _if ever_.
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .idea
3 | .tscache
4 | ts/**/*.js
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | Gruntfile.js
2 | example
3 | ts
4 | .idea
5 | config
--------------------------------------------------------------------------------
/Gruntfile.js:
--------------------------------------------------------------------------------
1 | module.exports = function (grunt) {
2 | 'use strict';
3 |
4 | grunt.initConfig({
5 | //Get some details from the package.json
6 | pkg: grunt.file.readJSON('package.json'),
7 | banner: '/*!\n' +
8 | ' * <%= pkg.config.name %> - version <%= pkg.version %> \n' +
9 | ' * <%= pkg.description %>\n' +
10 | ' *\n' +
11 | ' * <%= pkg.author %>\n' +
12 | ' * Build at <%= grunt.template.today("dd-mm-yyyy") %>\n' +
13 | ' * Released under MIT License \n' +
14 | ' */\n',
15 | usebanner: {
16 | dist: {
17 | options: {
18 | position: 'top',
19 | banner: '<%= banner %>'
20 | },
21 | files: {
22 | src: [ 'build/*.js' ]
23 | }
24 | }
25 | },
26 | //Typescript settings per build
27 | ts: {
28 | dist: {
29 | tsconfig: './config/tsconfig.json',
30 | src: ['ts/**/*.ts', '!ts/Utils/Helper.ts'],
31 | dest: 'build/<%= pkg.config.name %>.js'
32 | },
33 | helper: {
34 | tsconfig: './config/tsconfig.json',
35 | src: ['ts/Utils/Storage.ts', 'ts/StorageAdapters/LocalStorage.ts', 'ts/StorageAdapters/IStorage.ts', 'ts/Utils/Helper.ts'],
36 | dest: 'build/phaser-storage-helper.js'
37 | }
38 | },
39 | watch: {
40 | files: ['ts/**/*.ts'],
41 | tasks: ['ts'],
42 | options: {
43 | livereload: true
44 | }
45 | },
46 | connect: {
47 | server: {
48 | options: {
49 | port: 8080
50 | }
51 | }
52 | },
53 | uglify: {
54 | options: {
55 | compress: {
56 | sequences: true,
57 | dead_code: true,
58 | conditionals: true,
59 | booleans: true,
60 | unused: true,
61 | if_return: true,
62 | join_vars: true,
63 | drop_console: false
64 | },
65 | mangle: true,
66 | beautify: false
67 | },
68 | dist: {
69 | files: {
70 | 'build/<%= pkg.config.name %>.min.js': [
71 | 'build/<%= pkg.config.name %>.js'
72 | ],
73 | 'build/phaser-storage-helper.min.js': [
74 | 'build/phaser-storage-helper.js'
75 | ]
76 | }
77 | }
78 | },
79 | clean: {
80 | dist: ['build']
81 | },
82 | tslint: {
83 | options: {
84 | // can be a configuration object or a filepath to tslint.json
85 | configuration: "./config/tslint.json"
86 | },
87 | dist: {
88 | src: [
89 | 'ts/**/*.ts'
90 | ]
91 | }
92 | }
93 | });
94 |
95 | grunt.loadNpmTasks('grunt-contrib-clean');
96 | grunt.loadNpmTasks('grunt-contrib-uglify');
97 | grunt.loadNpmTasks('grunt-banner');
98 | grunt.loadNpmTasks('grunt-ts');
99 | grunt.loadNpmTasks('grunt-tslint');
100 | grunt.loadNpmTasks('grunt-contrib-connect');
101 | grunt.loadNpmTasks('grunt-contrib-watch');
102 |
103 | //dist Build
104 | grunt.registerTask('dist', [
105 | 'tslint',
106 | 'clean:dist', //Clean the dist folder
107 | 'ts:dist',//Run typescript on the preprocessed files, for dist (client)
108 | 'ts:helper',
109 | 'uglify:dist', //Minify everything
110 | 'usebanner:dist' //Minify everything
111 | ]);
112 |
113 | grunt.registerTask('dev', [
114 | 'ts',
115 | 'connect',
116 | 'watch'
117 | ]);
118 |
119 | };
120 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Azerion
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Phaser Super Storage
2 | ====================
3 | A cross platform pluggable storage plugin for Phaser.
4 |
5 | Key features:
6 | - Cross browser support
7 | - Cookie Fallback
8 | - Support for iframes with helper script
9 | - Support for custom storage adapters
10 |
11 | Requirements
12 | - If you use TypeScript, also include the types for es6-promise in your project
13 |
14 | Getting Started
15 | ===============
16 | First you want to get a fresh copy of the plugin. You can get it from this repo or from npm, ain't that handy.
17 | ```
18 | npm install @azerion/phaser-super-storage --save-dev
19 | ```
20 |
21 | Next up you'd want to add it to your list of js sources you load into your game
22 | ```html
23 |
24 | ```
25 |
26 | After adding the script to the page you can activate it by enabling the plugin:
27 | ```javascript
28 | game.add.plugin(PhaserSuperStorage.StoragePlugin);
29 | ```
30 |
31 | Usage
32 | =====
33 | When you load the plugin, it automatically checks for availability of localStorage and fallbacks to cookies if it's not available.
34 | Both of these are StorageAdapters and will be overwritten if you register a custom StorageAdaper, but more on this later.
35 |
36 | The plugin will append the Phaser game object with a storage object, you can reference this object with exactly the same API as localStorage, and should therefore be fairly easy for you to implement.
37 |
38 | ```javascript
39 | //Store Tetris at FavoriteGame
40 | game.storage.setItem('FavoriteGame', 'Tetris');
41 |
42 | //Get FavoriteGame
43 | var favoriteGame = game.storage.getItem('FavoriteGame'); // Tetris
44 |
45 | //Remove FavoriteGame
46 | game.storage.removeItem('FavoriteGame');
47 |
48 | //get the length of all items in storage
49 | var l = game.storage.length; // 1
50 |
51 | //Get the name of the key at the n'th position
52 | var keyName = game.storage.key(0); // FavoriteGame
53 |
54 | //Clear all keys
55 | game.storage.clear();
56 | ```
57 |
58 | Namespaces
59 | ----------
60 | If you are like us, and put multiple games on the same domain, you might want to add namespaces to your localStorage. Namespaces get prepended to any key value pair you set, and all API calls to the storage object are segregated by namespaces.
61 | This allows you to set a 'score' key for multiple games on the same domain, and they'll always get their own stored value
62 |
63 | ```javascript
64 | game.storage.setNamespace('tetris');
65 | game.storage.setItem('score', 250);
66 |
67 | game.storage.setNamespace('pong');
68 |
69 | //Length also takes namespaces into account
70 | var l = game.storage.length; // 0
71 |
72 | //this won't do because the score was registered under a different namespace
73 | var value = game.storage.get('score'); // null
74 |
75 | ```
76 |
77 | Promises
78 | --------
79 | Both Cookies and localStorage work synchronous, meaning you immediately get a return value after calling a function, e.g; `getItem('key');`
80 | But when you are using a HTTP service (Amazon Cognito Sync, or custom REST server) or when you are using the iFrameStorage supported by this library, the results are coming back in an asynchronous manner.
81 | In order for you to parse your result nicely phaser-super-storage uses Promises to get you the result.
82 |
83 | It is also possible to enable promises on the Cookie and localStorage adapters by setting forcePromises to true.
84 | ```javascript
85 | //classical way of getting your item
86 | var item = game.storage.getItem('key');
87 |
88 | //Now we are gonna force promises
89 | game.storage.forcePromises = true;
90 | game.storage.getItem('key').then(function (item) {
91 | //do something with the item here
92 | });
93 | ```
94 |
95 | Adapters
96 | ========
97 | The actual Storage of content happens within these so-called StorageAdapters. Basicly a StorageAdapter can store data somewhere, as long as it implements the following interface:
98 | ```typescript
99 | interface IStorage {
100 | //Promises or no Promises
101 | forcePromises: boolean;
102 |
103 | //The amount of items in the storage
104 | length: number;
105 |
106 | //The namespace for the current storage
107 | namespace:string;
108 |
109 | //Get an item from the storage
110 | getItem(key: string): any | Promise;
111 |
112 | //remove an item from the localStorage
113 | removeItem(key: string): any | Promise;
114 |
115 | //Set an item in the storage
116 | setItem(key: string, value:any): void | Promise;
117 |
118 | //Get the n'th key
119 | key(n: number): any | Promise;
120 |
121 | //empty the (namespaced) storage
122 | clear(): void | Promise;
123 |
124 | setNamespace(namespace: string): void | Promise;
125 | }
126 | ```
127 |
128 | Local & Cookie Storage
129 | ----------------------
130 | The default usage of phaser-super-storage require the LocalStorage and CookieStorage adapter. It will always try to use the LocalStorage Adapater, but when all fails it falls back to Cookie storage, no configuration needed!
131 |
132 | Cordova
133 | -------
134 | You can now also use the CordovaStorage adapter, which uses the NativeStorage plugin of Cordova. This prevents the auto-deletion of data on IOS when not having enough memory. If you are using the adapter, please note that passing the namespace in the constructor is not allowed and that it is only testable in a Cordova application. It can be enabled by the following command:
135 | ```javascript
136 | game.storage.setAdapter(new PhaserSuperStorage.StorageAdapters.CordovaStorage());
137 | ```
138 |
139 |
140 | Iframe
141 | ------
142 | We publish our games on HTML5 game portals through the usage of iframes, a downside of this is that for iOS both localStorage and Cookies aren't persisted for iframes. In order to counter this we included an IframeStorage adapter that should be set in the game, then the helper script included in the build folder should be loaded in the parent frame.
143 | This way we'll utilize the storage capacity of the parent frame to store our data
144 |
145 | ```html
146 |
147 |
148 | ```
149 |
150 | ```javascript
151 | //Then in our game we add the iframe adapter
152 | var iframeAdapter = new IframeStorage(
153 | '', //The namespace to store the data under
154 | document.referrer //Then url of the parent domain, you need this for security reasons
155 | );
156 |
157 | //We call init first to see if the helper script is available, result as a Promise due to asynchronous communication
158 | iframeAdapter.init().then(function() {
159 | //It succeeded! Now set the iframe adapter as the main storage adapter
160 | game.storage.setAdapter(iframeAdapter);
161 | }).catch(function (e) {
162 | //failed to start communication with parent, so lets enable promises on the original storage adapter to keep the API the same
163 | game.storage.forcePromises = true;
164 | });
165 | ```
166 |
167 | Caveats
168 | =======
169 | Although we try our best to store data, in some cases you can consider data lost when a user closes his browser or ends his session. I'm talking of course about private browsing. Both LocalStorage and Cookies will be cleared, so if you want to keep userdata alive there I suggest you try to get people to login and use a custom StorageAdapter to save the data server-side. Please note that we use the colon as namespace appendix, so we advice you not to use it yourself.
170 |
171 | Disclaimer
172 | ==========
173 | We at Azerion just love playing and creating awesome games. We aren't affiliated with Phaser.io. We just needed to storage some awesome data in our awesome HTML5 games. Feel free to use it for enhancing your own awesome games!
174 |
175 | Phaser Super Storage is distributed under the MIT license. All 3rd party libraries and components are distributed under their
176 | respective license terms.
177 |
--------------------------------------------------------------------------------
/build/phaser-storage-helper.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 | declare module PhaserSuperStorage {
3 | interface IStorageMessage {
4 | command: StorageCommand;
5 | status?: string;
6 | key?: string;
7 | value?: any;
8 | length?: number;
9 | }
10 | enum StorageCommand {
11 | init = 0,
12 | setItem = 1,
13 | getItem = 2,
14 | removeItem = 3,
15 | clear = 4,
16 | setNamespace = 5,
17 | length = 6,
18 | key = 7,
19 | error = 8,
20 | }
21 | class StorageUtils {
22 | static isLocalStorageSupport(): boolean;
23 | static validateMessage(data: IStorageMessage): IStorageMessage;
24 | static nameSpaceKeyFilter(keys: string[], namespace: string): string[];
25 | }
26 | }
27 | declare module PhaserSuperStorage {
28 | module StorageAdapters {
29 | /**
30 | * Storage driver for browser's localStorage
31 | */
32 | class LocalStorage implements IStorage {
33 | namespace: string;
34 | forcePromises: boolean;
35 | constructor(spacedName?: string);
36 | readonly length: number;
37 | key(n: number): any | Promise;
38 | private _key(n);
39 | getItem(key: string): any | Promise;
40 | private _getItem(key);
41 | setItem(key: string, value: any): void | Promise;
42 | private _setItem(key, value);
43 | removeItem(key: string): void | Promise;
44 | private _removeItem(key);
45 | clear(): void | Promise;
46 | private _clear();
47 | setNamespace(spacedName: string): void | Promise;
48 | private _setNameSpace(spacedName);
49 | private promisefy(value, args);
50 | }
51 | }
52 | }
53 | declare module PhaserSuperStorage {
54 | module StorageAdapters {
55 | interface IStorage {
56 | forcePromises: boolean;
57 | length: number;
58 | namespace: string;
59 | getItem(key: string): any | Promise;
60 | removeItem(key: string): any | Promise;
61 | setItem(key: string, value: any): void | Promise;
62 | key(n: number): any | Promise;
63 | clear(): void | Promise;
64 | setNamespace(namespace: string): void | Promise;
65 | }
66 | }
67 | }
68 | import StorageCommand = PhaserSuperStorage.StorageCommand;
69 | import StorageUtils = PhaserSuperStorage.StorageUtils;
70 | import LocalStorage = PhaserSuperStorage.StorageAdapters.LocalStorage;
71 |
--------------------------------------------------------------------------------
/build/phaser-storage-helper.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * phaser-super-storage - version 1.0.4
3 | * A cross platform storage plugin for Phaser
4 | *
5 | * Azerion
6 | * Build at 15-03-2019
7 | * Released under MIT License
8 | */
9 |
10 | var PhaserSuperStorage;
11 | (function (PhaserSuperStorage) {
12 | var StorageCommand;
13 | (function (StorageCommand) {
14 | StorageCommand[StorageCommand["init"] = 0] = "init";
15 | StorageCommand[StorageCommand["setItem"] = 1] = "setItem";
16 | StorageCommand[StorageCommand["getItem"] = 2] = "getItem";
17 | StorageCommand[StorageCommand["removeItem"] = 3] = "removeItem";
18 | StorageCommand[StorageCommand["clear"] = 4] = "clear";
19 | StorageCommand[StorageCommand["setNamespace"] = 5] = "setNamespace";
20 | StorageCommand[StorageCommand["length"] = 6] = "length";
21 | StorageCommand[StorageCommand["key"] = 7] = "key";
22 | StorageCommand[StorageCommand["error"] = 8] = "error";
23 | })(StorageCommand = PhaserSuperStorage.StorageCommand || (PhaserSuperStorage.StorageCommand = {}));
24 | var StorageUtils = (function () {
25 | function StorageUtils() {
26 | }
27 | StorageUtils.isLocalStorageSupport = function () {
28 | try {
29 | if (typeof localStorage === 'object') {
30 | localStorage.setItem('testingLocalStorage', 'foo');
31 | localStorage.removeItem('testingLocalStorage');
32 | return true;
33 | }
34 | }
35 | catch (e) {
36 | return false;
37 | }
38 | return false;
39 | };
40 | StorageUtils.validateMessage = function (data) {
41 | if (data.hasOwnProperty('command')) {
42 | return data;
43 | }
44 | return null;
45 | };
46 | StorageUtils.nameSpaceKeyFilter = function (keys, namespace) {
47 | return keys.filter(function (keyName) {
48 | return (keyName.substring(0, namespace.length) === namespace);
49 | });
50 | };
51 | return StorageUtils;
52 | }());
53 | PhaserSuperStorage.StorageUtils = StorageUtils;
54 | })(PhaserSuperStorage || (PhaserSuperStorage = {}));
55 | var PhaserSuperStorage;
56 | (function (PhaserSuperStorage) {
57 | var StorageAdapters;
58 | (function (StorageAdapters) {
59 | /**
60 | * Storage driver for browser's localStorage
61 | */
62 | var LocalStorage = (function () {
63 | function LocalStorage(spacedName) {
64 | if (spacedName === void 0) { spacedName = ''; }
65 | this.namespace = '';
66 | this.forcePromises = false;
67 | this.setNamespace(spacedName);
68 | }
69 | Object.defineProperty(LocalStorage.prototype, "length", {
70 | get: function () {
71 | var keys = Object.keys(localStorage);
72 | return PhaserSuperStorage.StorageUtils.nameSpaceKeyFilter(keys, this.namespace).length;
73 | },
74 | enumerable: true,
75 | configurable: true
76 | });
77 | LocalStorage.prototype.key = function (n) {
78 | return this.forcePromises ?
79 | this.promisefy(this._key, arguments) :
80 | this._key(n);
81 | };
82 | LocalStorage.prototype._key = function (n) {
83 | var keys = Object.keys(localStorage);
84 | var spacedKeys = PhaserSuperStorage.StorageUtils.nameSpaceKeyFilter(keys, this.namespace);
85 | var item = localStorage.getItem(spacedKeys[n]);
86 | return item;
87 | };
88 | LocalStorage.prototype.getItem = function (key) {
89 | return this.forcePromises ?
90 | this.promisefy(this._getItem, arguments) :
91 | this._getItem(key);
92 | };
93 | LocalStorage.prototype._getItem = function (key) {
94 | return localStorage.getItem(this.namespace + key);
95 | };
96 | LocalStorage.prototype.setItem = function (key, value) {
97 | return this.forcePromises ?
98 | this.promisefy(this._setItem, arguments) :
99 | this._setItem(key, value);
100 | };
101 | LocalStorage.prototype._setItem = function (key, value) {
102 | return localStorage.setItem(this.namespace + key, value);
103 | };
104 | LocalStorage.prototype.removeItem = function (key) {
105 | return this.forcePromises ?
106 | this.promisefy(this._removeItem, arguments) :
107 | this._removeItem(key);
108 | };
109 | LocalStorage.prototype._removeItem = function (key) {
110 | return localStorage.removeItem(this.namespace + key);
111 | };
112 | LocalStorage.prototype.clear = function () {
113 | return this.forcePromises ?
114 | this.promisefy(this._clear, arguments) :
115 | this._clear();
116 | };
117 | LocalStorage.prototype._clear = function () {
118 | var keys = Object.keys(localStorage);
119 | var spacedKeys = PhaserSuperStorage.StorageUtils.nameSpaceKeyFilter(keys, this.namespace);
120 | for (var i = 0; i < spacedKeys.length; i++) {
121 | localStorage.removeItem(spacedKeys[i]);
122 | }
123 | return;
124 | };
125 | LocalStorage.prototype.setNamespace = function (spacedName) {
126 | return this.forcePromises ?
127 | this.promisefy(this._setNameSpace, arguments) :
128 | this._setNameSpace(spacedName);
129 | };
130 | LocalStorage.prototype._setNameSpace = function (spacedName) {
131 | if (spacedName) {
132 | this.namespace = spacedName + ':';
133 | }
134 | };
135 | LocalStorage.prototype.promisefy = function (value, args) {
136 | var _this = this;
137 | return new Promise(function (resolve, reject) {
138 | resolve(value.apply(_this, args));
139 | });
140 | };
141 | return LocalStorage;
142 | }());
143 | StorageAdapters.LocalStorage = LocalStorage;
144 | })(StorageAdapters = PhaserSuperStorage.StorageAdapters || (PhaserSuperStorage.StorageAdapters = {}));
145 | })(PhaserSuperStorage || (PhaserSuperStorage = {}));
146 | var StorageCommand = PhaserSuperStorage.StorageCommand;
147 | var StorageUtils = PhaserSuperStorage.StorageUtils;
148 | var LocalStorage = PhaserSuperStorage.StorageAdapters.LocalStorage;
149 | (function () {
150 | var gameOrigin = window.gameOrigin || '*';
151 | var localStorageSupported = StorageUtils.isLocalStorageSupport();
152 | var storage = localStorageSupported ? new LocalStorage() : null;
153 | window.addEventListener('message', function (event) {
154 | if (gameOrigin !== '*' && event.origin !== gameOrigin) {
155 | return;
156 | }
157 | var message = StorageUtils.validateMessage(event.data);
158 | var source = event.ports[0];
159 | if (typeof source === 'undefined' || !source) {
160 | //No source to return too, skipping
161 | return;
162 | }
163 | var sendError = function (command, errorMessage) {
164 | source.postMessage({
165 | status: 'error',
166 | command: command,
167 | value: errorMessage
168 | });
169 | };
170 | if (null !== message) {
171 | if (!localStorageSupported) {
172 | sendError(message.command, 'localStorage not supported');
173 | }
174 | switch (message.command) {
175 | case StorageCommand.init:
176 | source.postMessage({
177 | status: 'ok',
178 | command: message.command,
179 | length: storage.length
180 | });
181 | break;
182 | case StorageCommand.getItem:
183 | try {
184 | var item = storage.getItem(message.key);
185 | source.postMessage({
186 | status: 'ok',
187 | command: message.command,
188 | value: item,
189 | length: storage.length
190 | });
191 | }
192 | catch (e) {
193 | sendError(message.command, e.message);
194 | }
195 | break;
196 | case StorageCommand.setItem:
197 | try {
198 | storage.setItem(message.key, message.value);
199 | source.postMessage({
200 | status: 'ok',
201 | command: message.command,
202 | length: storage.length
203 | });
204 | }
205 | catch (e) {
206 | sendError(message.command, e.message);
207 | }
208 | break;
209 | case StorageCommand.removeItem:
210 | try {
211 | storage.removeItem(message.key);
212 | source.postMessage({
213 | status: 'ok',
214 | command: message.command,
215 | length: storage.length
216 | });
217 | }
218 | catch (e) {
219 | sendError(message.command, e.message);
220 | }
221 | break;
222 | case StorageCommand.setNamespace:
223 | try {
224 | storage.setNamespace(message.value);
225 | source.postMessage({
226 | status: 'ok',
227 | command: message.command,
228 | value: message.value,
229 | length: storage.length
230 | });
231 | }
232 | catch (e) {
233 | sendError(message.command, e.message);
234 | }
235 | break;
236 | case StorageCommand.clear:
237 | try {
238 | storage.clear();
239 | source.postMessage({
240 | status: 'ok',
241 | command: message.command,
242 | length: storage.length
243 | });
244 | }
245 | catch (e) {
246 | sendError(message.command, e.message);
247 | }
248 | break;
249 | case StorageCommand.length:
250 | try {
251 | source.postMessage({
252 | status: 'ok',
253 | command: message.command,
254 | value: storage.length,
255 | length: storage.length
256 | });
257 | }
258 | catch (e) {
259 | sendError(message.command, e.message);
260 | }
261 | break;
262 | case StorageCommand.key:
263 | try {
264 | var nkey = storage.key(message.value);
265 | source.postMessage({
266 | status: 'ok',
267 | command: message.command,
268 | value: nkey,
269 | length: storage.length
270 | });
271 | }
272 | catch (e) {
273 | sendError(message.command, e.message);
274 | }
275 | break;
276 | default:
277 | sendError(message.command, 'Command not found');
278 | break;
279 | }
280 | }
281 | else {
282 | sendError(StorageCommand.error, 'Empty message!');
283 | }
284 | });
285 | })();
286 | //# sourceMappingURL=phaser-storage-helper.js.map
--------------------------------------------------------------------------------
/build/phaser-storage-helper.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"phaser-storage-helper.js","sourceRoot":"","sources":["../ts/Utils/Storage.ts","../ts/StorageAdapters/LocalStorage.ts","../ts/StorageAdapters/IStorage.ts","../ts/Utils/Helper.ts"],"names":[],"mappings":"AAAA,IAAO,kBAAkB,CAkDxB;AAlDD,WAAO,kB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MAAM,EAAE,OAAO,CAAC,MAAM;yBACzB,CAAC,CAAC;oBACP,CAAC;oBAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;wBACT,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;oBAC1C,CAAC;oBACD,KAAK,CAAC;gBACV,KAAK,cAAc,CAAC,GAAG;oBACnB,IAAI,CAAC;wBACD,IAAI,IAAI,GAAQ,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;wBAE3C,MAAM,CAAC,WAAW,CAAqC;4BACnD,MAAM,EAAE,IAAI;4BACZ,OAAO,EAAE,OAAO,CAAC,OAAO;4BACxB,KAAK,EAAE,IAAI;4BACX,MAAM,EAAE,OAAO,CAAC,MAAM;yBACzB,CAAC,CAAC;oBACP,CAAC;oBAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;wBACT,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;oBAC1C,CAAC;oBACD,KAAK,CAAC;gBACV;oBACI,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;oBAChD,KAAK,CAAC;YACd,CAAC;QACL,CAAC;QAAC,IAAI,CAAC,CAAC;YACJ,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;QACtD,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,EAAE,CAAC"}
--------------------------------------------------------------------------------
/build/phaser-storage-helper.min.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * phaser-super-storage - version 1.0.4
3 | * A cross platform storage plugin for Phaser
4 | *
5 | * Azerion
6 | * Build at 15-03-2019
7 | * Released under MIT License
8 | */
9 |
10 | var PhaserSuperStorage;!function(a){var b;!function(a){a[a.init=0]="init",a[a.setItem=1]="setItem",a[a.getItem=2]="getItem",a[a.removeItem=3]="removeItem",a[a.clear=4]="clear",a[a.setNamespace=5]="setNamespace",a[a.length=6]="length",a[a.key=7]="key",a[a.error=8]="error"}(b=a.StorageCommand||(a.StorageCommand={}));var c=function(){function a(){}return a.isLocalStorageSupport=function(){try{if("object"==typeof localStorage)return localStorage.setItem("testingLocalStorage","foo"),localStorage.removeItem("testingLocalStorage"),!0}catch(a){return!1}return!1},a.validateMessage=function(a){return a.hasOwnProperty("command")?a:null},a.nameSpaceKeyFilter=function(a,b){return a.filter(function(a){return a.substring(0,b.length)===b})},a}();a.StorageUtils=c}(PhaserSuperStorage||(PhaserSuperStorage={}));var PhaserSuperStorage;!function(a){var b;!function(b){var c=function(){function b(a){void 0===a&&(a=""),this.namespace="",this.forcePromises=!1,this.setNamespace(a)}return Object.defineProperty(b.prototype,"length",{get:function(){var b=Object.keys(localStorage);return a.StorageUtils.nameSpaceKeyFilter(b,this.namespace).length},enumerable:!0,configurable:!0}),b.prototype.key=function(a){return this.forcePromises?this.promisefy(this._key,arguments):this._key(a)},b.prototype._key=function(b){var c=Object.keys(localStorage),d=a.StorageUtils.nameSpaceKeyFilter(c,this.namespace),e=localStorage.getItem(d[b]);return e},b.prototype.getItem=function(a){return this.forcePromises?this.promisefy(this._getItem,arguments):this._getItem(a)},b.prototype._getItem=function(a){return localStorage.getItem(this.namespace+a)},b.prototype.setItem=function(a,b){return this.forcePromises?this.promisefy(this._setItem,arguments):this._setItem(a,b)},b.prototype._setItem=function(a,b){return localStorage.setItem(this.namespace+a,b)},b.prototype.removeItem=function(a){return this.forcePromises?this.promisefy(this._removeItem,arguments):this._removeItem(a)},b.prototype._removeItem=function(a){return localStorage.removeItem(this.namespace+a)},b.prototype.clear=function(){return this.forcePromises?this.promisefy(this._clear,arguments):this._clear()},b.prototype._clear=function(){for(var b=Object.keys(localStorage),c=a.StorageUtils.nameSpaceKeyFilter(b,this.namespace),d=0;d
2 | declare module PhaserSuperStorage {
3 | module StorageAdapters {
4 | /**
5 | * Storage driver for cookies
6 | */
7 | class CookieStorage implements IStorage {
8 | private reg;
9 | namespace: string;
10 | forcePromises: boolean;
11 | constructor(spacedName?: string);
12 | readonly length: number;
13 | key(n: number): any | Promise;
14 | getItem(key: string): string | Promise;
15 | setItem(key: string, value: any): void | Promise;
16 | removeItem(key: string): void | Promise;
17 | clear(): void | Promise;
18 | setNamespace(namespace: string): void | Promise;
19 | private getNameSpaceMatches();
20 | private getCookiesForNameSpace();
21 | private promisefy(value);
22 | }
23 | }
24 | }
25 | declare module PhaserSuperStorage {
26 | module StorageAdapters {
27 | /**
28 | * Storage driver for browser's localStorage
29 | */
30 | class CordovaStorage implements IStorage {
31 | namespace: string;
32 | private keys;
33 | forcePromises: boolean;
34 | constructor();
35 | readonly length: number;
36 | key(n: number): Promise;
37 | getItem(key: string): Promise;
38 | setItem(key: string, value: any): Promise;
39 | removeItem(key: string): Promise;
40 | clear(): Promise;
41 | setNamespace(spacedName?: string): Promise;
42 | private promisefy(value);
43 | private load();
44 | private save();
45 | }
46 | }
47 | }
48 | declare module PhaserSuperStorage {
49 | module StorageAdapters {
50 | /**
51 | * Storage driver for browser's localStorage
52 | */
53 | class IframeStorage implements IStorage {
54 | namespace: string;
55 | expectedOrigin: string;
56 | private storageLength;
57 | private enabled;
58 | forcePromises: boolean;
59 | constructor(spacedName?: string, expectedOrigin?: string);
60 | readonly length: number;
61 | init(): Promise;
62 | key(n: number): Promise;
63 | getItem(key: string): Promise;
64 | setItem(key: string, value: any): Promise;
65 | removeItem(key: string): Promise;
66 | clear(): Promise;
67 | setNamespace(spacedName: string): Promise;
68 | private sendMessage(message);
69 | }
70 | }
71 | }
72 | declare module PhaserSuperStorage {
73 | module StorageAdapters {
74 | interface IStorage {
75 | forcePromises: boolean;
76 | length: number;
77 | namespace: string;
78 | getItem(key: string): any | Promise;
79 | removeItem(key: string): any | Promise;
80 | setItem(key: string, value: any): void | Promise;
81 | key(n: number): any | Promise;
82 | clear(): void | Promise;
83 | setNamespace(namespace: string): void | Promise;
84 | }
85 | }
86 | }
87 | declare module PhaserSuperStorage {
88 | module StorageAdapters {
89 | /**
90 | * Storage driver for browser's localStorage
91 | */
92 | class LocalStorage implements IStorage {
93 | namespace: string;
94 | forcePromises: boolean;
95 | constructor(spacedName?: string);
96 | readonly length: number;
97 | key(n: number): any | Promise;
98 | private _key(n);
99 | getItem(key: string): any | Promise;
100 | private _getItem(key);
101 | setItem(key: string, value: any): void | Promise;
102 | private _setItem(key, value);
103 | removeItem(key: string): void | Promise;
104 | private _removeItem(key);
105 | clear(): void | Promise;
106 | private _clear();
107 | setNamespace(spacedName: string): void | Promise;
108 | private _setNameSpace(spacedName);
109 | private promisefy(value, args);
110 | }
111 | }
112 | }
113 | declare module 'phaser-super-storage' {
114 | export = PhaserSuperStorage;
115 | }
116 | declare module PhaserSuperStorage {
117 | interface ISuperStorageGame extends Phaser.Game {
118 | storage: PhaserSuperStorage.StoragePlugin;
119 | }
120 | class StoragePlugin {
121 | private storage;
122 | private static instance;
123 | constructor(game?: Phaser.Game);
124 | setAdapter(storageAdapter: StorageAdapters.IStorage): void;
125 | forcePromises: boolean;
126 | readonly length: number;
127 | setNamespace(namedSpace: string): void | Promise;
128 | key(n: number): string | Promise;
129 | getItem(key: string): any | Promise;
130 | setItem(key: string, value: string): void | Promise;
131 | removeItem(key: string): void | Promise;
132 | clear(): void | Promise;
133 | }
134 | }
135 | declare module PhaserSuperStorage {
136 | interface IStorageMessage {
137 | command: StorageCommand;
138 | status?: string;
139 | key?: string;
140 | value?: any;
141 | length?: number;
142 | }
143 | enum StorageCommand {
144 | init = 0,
145 | setItem = 1,
146 | getItem = 2,
147 | removeItem = 3,
148 | clear = 4,
149 | setNamespace = 5,
150 | length = 6,
151 | key = 7,
152 | error = 8,
153 | }
154 | class StorageUtils {
155 | static isLocalStorageSupport(): boolean;
156 | static validateMessage(data: IStorageMessage): IStorageMessage;
157 | static nameSpaceKeyFilter(keys: string[], namespace: string): string[];
158 | }
159 | }
160 |
--------------------------------------------------------------------------------
/build/phaser-super-storage.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * phaser-super-storage - version 1.0.4
3 | * A cross platform storage plugin for Phaser
4 | *
5 | * Azerion
6 | * Build at 15-03-2019
7 | * Released under MIT License
8 | */
9 |
10 | var PhaserSuperStorage;
11 | (function (PhaserSuperStorage) {
12 | var StorageAdapters;
13 | (function (StorageAdapters) {
14 | /**
15 | * Storage driver for cookies
16 | */
17 | var CookieStorage = (function () {
18 | function CookieStorage(spacedName) {
19 | if (spacedName === void 0) { spacedName = ''; }
20 | this.namespace = '';
21 | this.forcePromises = false;
22 | this.setNamespace(spacedName);
23 | }
24 | Object.defineProperty(CookieStorage.prototype, "length", {
25 | get: function () {
26 | return (this.getNameSpaceMatches() !== null) ? this.getNameSpaceMatches().length : 0;
27 | },
28 | enumerable: true,
29 | configurable: true
30 | });
31 | CookieStorage.prototype.key = function (n) {
32 | var key = this.getNameSpaceMatches()[n];
33 | var result = this.getCookiesForNameSpace()[key] || null;
34 | if (this.forcePromises) {
35 | return this.promisefy(result);
36 | }
37 | return result;
38 | };
39 | CookieStorage.prototype.getItem = function (key) {
40 | var result = this.getCookiesForNameSpace()[key] || null;
41 | if (this.forcePromises) {
42 | return this.promisefy(result);
43 | }
44 | return result;
45 | };
46 | CookieStorage.prototype.setItem = function (key, value) {
47 | document.cookie = encodeURIComponent(this.namespace + key) + '=' + encodeURIComponent(value) + '; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/';
48 | if (this.forcePromises) {
49 | return this.promisefy(null);
50 | }
51 | };
52 | CookieStorage.prototype.removeItem = function (key) {
53 | document.cookie = encodeURIComponent(this.namespace + key) + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
54 | if (this.forcePromises) {
55 | return this.promisefy(null);
56 | }
57 | };
58 | CookieStorage.prototype.clear = function () {
59 | var cookies = this.getCookiesForNameSpace();
60 | for (var key in cookies) {
61 | if (cookies.hasOwnProperty(key)) {
62 | this.removeItem(key);
63 | }
64 | }
65 | if (this.forcePromises) {
66 | return this.promisefy(null);
67 | }
68 | };
69 | CookieStorage.prototype.setNamespace = function (namespace) {
70 | if (namespace) {
71 | this.namespace = namespace + ':';
72 | this.reg = new RegExp('^' + this.namespace + '[a-zA-Z0-9]*', 'g');
73 | }
74 | if (this.forcePromises) {
75 | return this.promisefy(namespace);
76 | }
77 | };
78 | CookieStorage.prototype.getNameSpaceMatches = function () {
79 | var _this = this;
80 | var cookies = decodeURIComponent(document.cookie).split('; ');
81 | return cookies.filter(function (val) {
82 | return (val.match(_this.reg) !== null) ? val.match(_this.reg).length > 0 : false;
83 | });
84 | };
85 | CookieStorage.prototype.getCookiesForNameSpace = function () {
86 | var _this = this;
87 | var cookies = {};
88 | this.getNameSpaceMatches().forEach(function (cookie) {
89 | var temp = cookie.replace(_this.namespace, '').split('=');
90 | cookies[temp[0]] = temp[1];
91 | });
92 | return cookies;
93 | };
94 | CookieStorage.prototype.promisefy = function (value) {
95 | return new Promise(function (resolve, reject) {
96 | resolve(value);
97 | });
98 | };
99 | return CookieStorage;
100 | }());
101 | StorageAdapters.CookieStorage = CookieStorage;
102 | })(StorageAdapters = PhaserSuperStorage.StorageAdapters || (PhaserSuperStorage.StorageAdapters = {}));
103 | })(PhaserSuperStorage || (PhaserSuperStorage = {}));
104 | var PhaserSuperStorage;
105 | (function (PhaserSuperStorage) {
106 | var StorageAdapters;
107 | (function (StorageAdapters) {
108 | /**
109 | * Storage driver for browser's localStorage
110 | */
111 | var CordovaStorage = (function () {
112 | // Due to async /w promise it is not possible to pass namespace in constructor
113 | function CordovaStorage() {
114 | this.namespace = '';
115 | this.keys = [];
116 | }
117 | Object.defineProperty(CordovaStorage.prototype, "forcePromises", {
118 | get: function () {
119 | return true;
120 | },
121 | set: function (v) {
122 | //Do nothing
123 | },
124 | enumerable: true,
125 | configurable: true
126 | });
127 | Object.defineProperty(CordovaStorage.prototype, "length", {
128 | get: function () {
129 | return this.keys.length;
130 | },
131 | enumerable: true,
132 | configurable: true
133 | });
134 | CordovaStorage.prototype.key = function (n) {
135 | return this.promisefy(this.keys[n]);
136 | };
137 | CordovaStorage.prototype.getItem = function (key) {
138 | var _this = this;
139 | return new Promise(function (resolve, reject) {
140 | NativeStorage.getItem(_this.namespace + key, function (value) {
141 | resolve(value);
142 | }, function (error) {
143 | if (error.code === 2) {
144 | resolve(null);
145 | }
146 | else {
147 | reject(error);
148 | }
149 | });
150 | });
151 | };
152 | CordovaStorage.prototype.setItem = function (key, value) {
153 | var _this = this;
154 | if (key.length < 1) {
155 | console.error('CordovaStorage: Key cannot be an empty string!');
156 | return;
157 | }
158 | return new Promise(function (resolve, reject) {
159 | NativeStorage.setItem(_this.namespace + key, value, function () {
160 | if (_this.keys.indexOf(key) < 0) {
161 | _this.keys.push(key);
162 | _this.save();
163 | }
164 | resolve(null);
165 | }, function (error) {
166 | reject(error);
167 | });
168 | });
169 | };
170 | CordovaStorage.prototype.removeItem = function (key) {
171 | var _this = this;
172 | return new Promise(function (resolve, reject) {
173 | NativeStorage.remove(_this.namespace + key, function () {
174 | var id = _this.keys.indexOf(key);
175 | if (id >= 0) {
176 | _this.keys.splice(id, 1);
177 | _this.save();
178 | }
179 | resolve(null);
180 | }, function (error) {
181 | reject(error);
182 | });
183 | });
184 | };
185 | CordovaStorage.prototype.clear = function () {
186 | var _this = this;
187 | return new Promise(function (resolve, reject) {
188 | var counter = 0;
189 | for (var i = 0; i < _this.keys.length; i++) {
190 | NativeStorage.remove(_this.namespace + _this.keys[i], function () {
191 | if (++counter >= _this.keys.length) {
192 | _this.keys = [];
193 | _this.save();
194 | resolve(null);
195 | }
196 | }, function (error) {
197 | reject(error);
198 | });
199 | }
200 | });
201 | };
202 | CordovaStorage.prototype.setNamespace = function (spacedName) {
203 | var _this = this;
204 | if (spacedName === void 0) { spacedName = ''; }
205 | this.namespace = spacedName + ':';
206 | this.keys = [];
207 | return new Promise(function (resolve, reject) {
208 | _this.load().then(resolve).catch(resolve);
209 | });
210 | };
211 | CordovaStorage.prototype.promisefy = function (value) {
212 | return new Promise(function (resolve, reject) {
213 | resolve(value);
214 | });
215 | };
216 | CordovaStorage.prototype.load = function () {
217 | var _this = this;
218 | return new Promise(function (resolve, reject) {
219 | NativeStorage.getItem(_this.namespace, function (value) {
220 | _this.keys = JSON.parse(value);
221 | resolve(null);
222 | }, function (error) {
223 | reject(error);
224 | });
225 | });
226 | };
227 | CordovaStorage.prototype.save = function () {
228 | NativeStorage.setItem(this.namespace, JSON.stringify(this.keys), function () {
229 | return;
230 | }, function (error) {
231 | console.warn('CordovaStorage: Failed to save keys of namespace.');
232 | });
233 | };
234 | return CordovaStorage;
235 | }());
236 | StorageAdapters.CordovaStorage = CordovaStorage;
237 | })(StorageAdapters = PhaserSuperStorage.StorageAdapters || (PhaserSuperStorage.StorageAdapters = {}));
238 | })(PhaserSuperStorage || (PhaserSuperStorage = {}));
239 | var PhaserSuperStorage;
240 | (function (PhaserSuperStorage) {
241 | var StorageAdapters;
242 | (function (StorageAdapters) {
243 | /**
244 | * Storage driver for browser's localStorage
245 | */
246 | var IframeStorage = (function () {
247 | function IframeStorage(spacedName, expectedOrigin) {
248 | if (spacedName === void 0) { spacedName = ''; }
249 | if (expectedOrigin === void 0) { expectedOrigin = '*'; }
250 | this.namespace = '';
251 | this.expectedOrigin = '';
252 | this.storageLength = 0;
253 | this.enabled = false;
254 | if (spacedName !== '') {
255 | this.setNamespace(spacedName);
256 | }
257 | this.expectedOrigin = expectedOrigin;
258 | }
259 | Object.defineProperty(IframeStorage.prototype, "forcePromises", {
260 | get: function () {
261 | return true;
262 | },
263 | set: function (v) {
264 | //Do nothing
265 | },
266 | enumerable: true,
267 | configurable: true
268 | });
269 | Object.defineProperty(IframeStorage.prototype, "length", {
270 | get: function () {
271 | return this.storageLength;
272 | },
273 | enumerable: true,
274 | configurable: true
275 | });
276 | IframeStorage.prototype.init = function () {
277 | var _this = this;
278 | return this.sendMessage({
279 | command: PhaserSuperStorage.StorageCommand.init
280 | }).then(function () {
281 | _this.enabled = true;
282 | });
283 | };
284 | IframeStorage.prototype.key = function (n) {
285 | return this.sendMessage({
286 | command: PhaserSuperStorage.StorageCommand.key,
287 | value: n
288 | });
289 | };
290 | IframeStorage.prototype.getItem = function (key) {
291 | return this.sendMessage({
292 | command: PhaserSuperStorage.StorageCommand.getItem,
293 | key: key
294 | });
295 | };
296 | IframeStorage.prototype.setItem = function (key, value) {
297 | return this.sendMessage({
298 | command: PhaserSuperStorage.StorageCommand.setItem,
299 | key: key,
300 | value: value
301 | });
302 | };
303 | IframeStorage.prototype.removeItem = function (key) {
304 | return this.sendMessage({
305 | command: PhaserSuperStorage.StorageCommand.removeItem,
306 | key: key
307 | });
308 | };
309 | IframeStorage.prototype.clear = function () {
310 | return this.sendMessage({
311 | command: PhaserSuperStorage.StorageCommand.clear
312 | });
313 | };
314 | IframeStorage.prototype.setNamespace = function (spacedName) {
315 | return this.sendMessage({
316 | command: PhaserSuperStorage.StorageCommand.setNamespace,
317 | value: spacedName
318 | });
319 | };
320 | IframeStorage.prototype.sendMessage = function (message) {
321 | var _this = this;
322 | var returnedResult;
323 | if (message.command === PhaserSuperStorage.StorageCommand.init) {
324 | returnedResult = false;
325 | }
326 | var messageChannel = new MessageChannel();
327 | return new Promise(function (resolve, reject) {
328 | if (!_this.enabled && message.command !== PhaserSuperStorage.StorageCommand.init) {
329 | reject('Messaging not enabled!');
330 | }
331 | if (message.command === PhaserSuperStorage.StorageCommand.init) {
332 | //small timeout to see if stuff is enabled
333 | setTimeout(function () {
334 | if (!returnedResult) {
335 | reject('Unable to get a response in time');
336 | }
337 | }, 1000);
338 | }
339 | messageChannel.port1.onmessage = function (event) {
340 | console.log('Frame received message', event);
341 | var receivedMessage = PhaserSuperStorage.StorageUtils.validateMessage(event.data);
342 | if (receivedMessage.command === PhaserSuperStorage.StorageCommand.init) {
343 | returnedResult = true;
344 | }
345 | if (receivedMessage.status === undefined || receivedMessage.status !== 'ok') {
346 | reject(receivedMessage.value);
347 | }
348 | if (receivedMessage.length !== undefined) {
349 | _this.storageLength = receivedMessage.length;
350 | }
351 | switch (receivedMessage.command) {
352 | case PhaserSuperStorage.StorageCommand.setNamespace:
353 | _this.namespace = receivedMessage.value + ':';
354 | case PhaserSuperStorage.StorageCommand.getItem:
355 | case PhaserSuperStorage.StorageCommand.length:
356 | case PhaserSuperStorage.StorageCommand.key:
357 | resolve(receivedMessage.value);
358 | break;
359 | case PhaserSuperStorage.StorageCommand.setItem:
360 | case PhaserSuperStorage.StorageCommand.removeItem:
361 | case PhaserSuperStorage.StorageCommand.clear:
362 | case PhaserSuperStorage.StorageCommand.init:
363 | resolve(receivedMessage.status);
364 | break;
365 | default:
366 | reject(receivedMessage.value);
367 | break;
368 | }
369 | };
370 | if (_this.enabled || message.command === PhaserSuperStorage.StorageCommand.init) {
371 | console.log('Sending message to parent: ', message);
372 | window.parent.postMessage(message, _this.expectedOrigin, [messageChannel.port2]);
373 | }
374 | });
375 | };
376 | return IframeStorage;
377 | }());
378 | StorageAdapters.IframeStorage = IframeStorage;
379 | })(StorageAdapters = PhaserSuperStorage.StorageAdapters || (PhaserSuperStorage.StorageAdapters = {}));
380 | })(PhaserSuperStorage || (PhaserSuperStorage = {}));
381 | var PhaserSuperStorage;
382 | (function (PhaserSuperStorage) {
383 | var StorageAdapters;
384 | (function (StorageAdapters) {
385 | /**
386 | * Storage driver for browser's localStorage
387 | */
388 | var LocalStorage = (function () {
389 | function LocalStorage(spacedName) {
390 | if (spacedName === void 0) { spacedName = ''; }
391 | this.namespace = '';
392 | this.forcePromises = false;
393 | this.setNamespace(spacedName);
394 | }
395 | Object.defineProperty(LocalStorage.prototype, "length", {
396 | get: function () {
397 | var keys = Object.keys(localStorage);
398 | return PhaserSuperStorage.StorageUtils.nameSpaceKeyFilter(keys, this.namespace).length;
399 | },
400 | enumerable: true,
401 | configurable: true
402 | });
403 | LocalStorage.prototype.key = function (n) {
404 | return this.forcePromises ?
405 | this.promisefy(this._key, arguments) :
406 | this._key(n);
407 | };
408 | LocalStorage.prototype._key = function (n) {
409 | var keys = Object.keys(localStorage);
410 | var spacedKeys = PhaserSuperStorage.StorageUtils.nameSpaceKeyFilter(keys, this.namespace);
411 | var item = localStorage.getItem(spacedKeys[n]);
412 | return item;
413 | };
414 | LocalStorage.prototype.getItem = function (key) {
415 | return this.forcePromises ?
416 | this.promisefy(this._getItem, arguments) :
417 | this._getItem(key);
418 | };
419 | LocalStorage.prototype._getItem = function (key) {
420 | return localStorage.getItem(this.namespace + key);
421 | };
422 | LocalStorage.prototype.setItem = function (key, value) {
423 | return this.forcePromises ?
424 | this.promisefy(this._setItem, arguments) :
425 | this._setItem(key, value);
426 | };
427 | LocalStorage.prototype._setItem = function (key, value) {
428 | return localStorage.setItem(this.namespace + key, value);
429 | };
430 | LocalStorage.prototype.removeItem = function (key) {
431 | return this.forcePromises ?
432 | this.promisefy(this._removeItem, arguments) :
433 | this._removeItem(key);
434 | };
435 | LocalStorage.prototype._removeItem = function (key) {
436 | return localStorage.removeItem(this.namespace + key);
437 | };
438 | LocalStorage.prototype.clear = function () {
439 | return this.forcePromises ?
440 | this.promisefy(this._clear, arguments) :
441 | this._clear();
442 | };
443 | LocalStorage.prototype._clear = function () {
444 | var keys = Object.keys(localStorage);
445 | var spacedKeys = PhaserSuperStorage.StorageUtils.nameSpaceKeyFilter(keys, this.namespace);
446 | for (var i = 0; i < spacedKeys.length; i++) {
447 | localStorage.removeItem(spacedKeys[i]);
448 | }
449 | return;
450 | };
451 | LocalStorage.prototype.setNamespace = function (spacedName) {
452 | return this.forcePromises ?
453 | this.promisefy(this._setNameSpace, arguments) :
454 | this._setNameSpace(spacedName);
455 | };
456 | LocalStorage.prototype._setNameSpace = function (spacedName) {
457 | if (spacedName) {
458 | this.namespace = spacedName + ':';
459 | }
460 | };
461 | LocalStorage.prototype.promisefy = function (value, args) {
462 | var _this = this;
463 | return new Promise(function (resolve, reject) {
464 | resolve(value.apply(_this, args));
465 | });
466 | };
467 | return LocalStorage;
468 | }());
469 | StorageAdapters.LocalStorage = LocalStorage;
470 | })(StorageAdapters = PhaserSuperStorage.StorageAdapters || (PhaserSuperStorage.StorageAdapters = {}));
471 | })(PhaserSuperStorage || (PhaserSuperStorage = {}));
472 | var PhaserSuperStorage;
473 | (function (PhaserSuperStorage) {
474 | var StoragePlugin = (function () {
475 | function StoragePlugin(game) {
476 | if (undefined !== game) {
477 | Object.defineProperty(game, 'storage', {
478 | value: this
479 | });
480 | }
481 | else {
482 | if (StoragePlugin.instance === null) {
483 | StoragePlugin.instance = this;
484 | }
485 | else {
486 | return StoragePlugin.instance;
487 | }
488 | }
489 | if (PhaserSuperStorage.StorageUtils.isLocalStorageSupport()) {
490 | this.setAdapter(new PhaserSuperStorage.StorageAdapters.LocalStorage());
491 | }
492 | else {
493 | this.setAdapter(new PhaserSuperStorage.StorageAdapters.CookieStorage());
494 | }
495 | }
496 | StoragePlugin.prototype.setAdapter = function (storageAdapter) {
497 | this.storage = storageAdapter;
498 | };
499 | Object.defineProperty(StoragePlugin.prototype, "forcePromises", {
500 | get: function () {
501 | return this.storage.forcePromises;
502 | },
503 | set: function (forceIt) {
504 | this.storage.forcePromises = forceIt;
505 | },
506 | enumerable: true,
507 | configurable: true
508 | });
509 | Object.defineProperty(StoragePlugin.prototype, "length", {
510 | get: function () {
511 | if (this.storage === null) {
512 | return 0;
513 | }
514 | return this.storage.length;
515 | },
516 | enumerable: true,
517 | configurable: true
518 | });
519 | StoragePlugin.prototype.setNamespace = function (namedSpace) {
520 | if (this.storage !== null) {
521 | return this.storage.setNamespace(namedSpace);
522 | }
523 | };
524 | StoragePlugin.prototype.key = function (n) {
525 | if (this.storage === null) {
526 | return '';
527 | }
528 | return this.storage.key(n);
529 | };
530 | StoragePlugin.prototype.getItem = function (key) {
531 | if (this.storage === null) {
532 | return null;
533 | }
534 | return this.storage.getItem(key);
535 | };
536 | StoragePlugin.prototype.setItem = function (key, value) {
537 | if (this.storage !== null) {
538 | return this.storage.setItem(key, value);
539 | }
540 | };
541 | StoragePlugin.prototype.removeItem = function (key) {
542 | if (this.storage !== null) {
543 | return this.storage.removeItem(key);
544 | }
545 | };
546 | StoragePlugin.prototype.clear = function () {
547 | if (this.storage !== null) {
548 | return this.storage.clear();
549 | }
550 | };
551 | return StoragePlugin;
552 | }());
553 | StoragePlugin.instance = null;
554 | PhaserSuperStorage.StoragePlugin = StoragePlugin;
555 | })(PhaserSuperStorage || (PhaserSuperStorage = {}));
556 | if (window.Phaser !== undefined) {
557 | Phaser.Utils.mixinPrototype(PhaserSuperStorage.StoragePlugin, Phaser.Plugin);
558 | }
559 | var PhaserSuperStorage;
560 | (function (PhaserSuperStorage) {
561 | var StorageCommand;
562 | (function (StorageCommand) {
563 | StorageCommand[StorageCommand["init"] = 0] = "init";
564 | StorageCommand[StorageCommand["setItem"] = 1] = "setItem";
565 | StorageCommand[StorageCommand["getItem"] = 2] = "getItem";
566 | StorageCommand[StorageCommand["removeItem"] = 3] = "removeItem";
567 | StorageCommand[StorageCommand["clear"] = 4] = "clear";
568 | StorageCommand[StorageCommand["setNamespace"] = 5] = "setNamespace";
569 | StorageCommand[StorageCommand["length"] = 6] = "length";
570 | StorageCommand[StorageCommand["key"] = 7] = "key";
571 | StorageCommand[StorageCommand["error"] = 8] = "error";
572 | })(StorageCommand = PhaserSuperStorage.StorageCommand || (PhaserSuperStorage.StorageCommand = {}));
573 | var StorageUtils = (function () {
574 | function StorageUtils() {
575 | }
576 | StorageUtils.isLocalStorageSupport = function () {
577 | try {
578 | if (typeof localStorage === 'object') {
579 | localStorage.setItem('testingLocalStorage', 'foo');
580 | localStorage.removeItem('testingLocalStorage');
581 | return true;
582 | }
583 | }
584 | catch (e) {
585 | return false;
586 | }
587 | return false;
588 | };
589 | StorageUtils.validateMessage = function (data) {
590 | if (data.hasOwnProperty('command')) {
591 | return data;
592 | }
593 | return null;
594 | };
595 | StorageUtils.nameSpaceKeyFilter = function (keys, namespace) {
596 | return keys.filter(function (keyName) {
597 | return (keyName.substring(0, namespace.length) === namespace);
598 | });
599 | };
600 | return StorageUtils;
601 | }());
602 | PhaserSuperStorage.StorageUtils = StorageUtils;
603 | })(PhaserSuperStorage || (PhaserSuperStorage = {}));
604 | //# sourceMappingURL=phaser-super-storage.js.map
--------------------------------------------------------------------------------
/build/phaser-super-storage.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"phaser-super-storage.js","sourceRoot":"","sources":["../ts/StorageAdapters/CookieStorage.ts","../ts/StorageAdapters/CordovaStorage.ts","../ts/StorageAdapters/IframeStorage.ts","../ts/StorageAdapters/IStorage.ts","../ts/StorageAdapters/LocalStorage.ts","../ts/SuperStorage.ts","../ts/Utils/Storage.ts"],"names":[],"mappings":"AAAA,IAAO,kBAAkB,CA4GxB;AA5GD,WAAO,kBAAkB;IACrB,IAAc,eAAe,CA0G5B;IA1GD,WAAc,eAAe;QAKzB;;WAEG;QACH;YAOI,uBAAY,UAAuB;gBAAvB,2BAAA,EAAA,eAAuB;gBAJ5B,cAAS,GAAW,EAAE,CAAC;gBAEvB,kBAAa,GAAY,KAAK,CAAC;gBAGlC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;YAClC,CAAC;YAED,sBAAI,iCAAM;qBAAV;oBACI,MAAM,CAAC,CAAC,IAAI,CAAC,mBAAmB,EAAE,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,mBAAmB,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;gBACzF,CAAC;;;eAAA;YAEM,2BAAG,GAAV,UAAW,CAAS;gBAChB,IAAI,GAAG,GAAW,IAAI,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAAC,CAAC;gBAChD,IAAI,MAAM,GAAQ,IAAI,CAAC,sBAAsB,EAAE,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;gBAE7D,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;oBACrB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;gBAClC,CAAC;gBAED,MAAM,CAAC,MAAM,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gBAC/B,MAAM,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC;YAClE,CAAC,CAAC,CAAC;QACP,CAAC;QACL,mBAAC;IAAD,CAAC,AA5BD,IA4BC;IA5BY,+BAAY,eA4BxB,CAAA;AACL,CAAC,EAlDM,kBAAkB,KAAlB,kBAAkB,QAkDxB"}
--------------------------------------------------------------------------------
/build/phaser-super-storage.min.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * phaser-super-storage - version 1.0.4
3 | * A cross platform storage plugin for Phaser
4 | *
5 | * Azerion
6 | * Build at 15-03-2019
7 | * Released under MIT License
8 | */
9 |
10 | var PhaserSuperStorage;!function(a){var b;!function(a){var b=function(){function a(a){void 0===a&&(a=""),this.namespace="",this.forcePromises=!1,this.setNamespace(a)}return Object.defineProperty(a.prototype,"length",{get:function(){return null!==this.getNameSpaceMatches()?this.getNameSpaceMatches().length:0},enumerable:!0,configurable:!0}),a.prototype.key=function(a){var b=this.getNameSpaceMatches()[a],c=this.getCookiesForNameSpace()[b]||null;return this.forcePromises?this.promisefy(c):c},a.prototype.getItem=function(a){var b=this.getCookiesForNameSpace()[a]||null;return this.forcePromises?this.promisefy(b):b},a.prototype.setItem=function(a,b){if(document.cookie=encodeURIComponent(this.namespace+a)+"="+encodeURIComponent(b)+"; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/",this.forcePromises)return this.promisefy(null)},a.prototype.removeItem=function(a){if(document.cookie=encodeURIComponent(this.namespace+a)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/",this.forcePromises)return this.promisefy(null)},a.prototype.clear=function(){var a=this.getCookiesForNameSpace();for(var b in a)a.hasOwnProperty(b)&&this.removeItem(b);if(this.forcePromises)return this.promisefy(null)},a.prototype.setNamespace=function(a){if(a&&(this.namespace=a+":",this.reg=new RegExp("^"+this.namespace+"[a-zA-Z0-9]*","g")),this.forcePromises)return this.promisefy(a)},a.prototype.getNameSpaceMatches=function(){var a=this,b=decodeURIComponent(document.cookie).split("; ");return b.filter(function(b){return null!==b.match(a.reg)&&b.match(a.reg).length>0})},a.prototype.getCookiesForNameSpace=function(){var a=this,b={};return this.getNameSpaceMatches().forEach(function(c){var d=c.replace(a.namespace,"").split("=");b[d[0]]=d[1]}),b},a.prototype.promisefy=function(a){return new Promise(function(b,c){b(a)})},a}();a.CookieStorage=b}(b=a.StorageAdapters||(a.StorageAdapters={}))}(PhaserSuperStorage||(PhaserSuperStorage={}));var PhaserSuperStorage;!function(a){var b;!function(a){var b=function(){function a(){this.namespace="",this.keys=[]}return Object.defineProperty(a.prototype,"forcePromises",{get:function(){return!0},set:function(a){},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"length",{get:function(){return this.keys.length},enumerable:!0,configurable:!0}),a.prototype.key=function(a){return this.promisefy(this.keys[a])},a.prototype.getItem=function(a){var b=this;return new Promise(function(c,d){NativeStorage.getItem(b.namespace+a,function(a){c(a)},function(a){2===a.code?c(null):d(a)})})},a.prototype.setItem=function(a,b){var c=this;return a.length<1?void console.error("CordovaStorage: Key cannot be an empty string!"):new Promise(function(d,e){NativeStorage.setItem(c.namespace+a,b,function(){c.keys.indexOf(a)<0&&(c.keys.push(a),c.save()),d(null)},function(a){e(a)})})},a.prototype.removeItem=function(a){var b=this;return new Promise(function(c,d){NativeStorage.remove(b.namespace+a,function(){var d=b.keys.indexOf(a);d>=0&&(b.keys.splice(d,1),b.save()),c(null)},function(a){d(a)})})},a.prototype.clear=function(){var a=this;return new Promise(function(b,c){for(var d=0,e=0;e=a.keys.length&&(a.keys=[],a.save(),b(null))},function(a){c(a)})})},a.prototype.setNamespace=function(a){var b=this;return void 0===a&&(a=""),this.namespace=a+":",this.keys=[],new Promise(function(a,c){b.load().then(a).catch(a)})},a.prototype.promisefy=function(a){return new Promise(function(b,c){b(a)})},a.prototype.load=function(){var a=this;return new Promise(function(b,c){NativeStorage.getItem(a.namespace,function(c){a.keys=JSON.parse(c),b(null)},function(a){c(a)})})},a.prototype.save=function(){NativeStorage.setItem(this.namespace,JSON.stringify(this.keys),function(){},function(a){console.warn("CordovaStorage: Failed to save keys of namespace.")})},a}();a.CordovaStorage=b}(b=a.StorageAdapters||(a.StorageAdapters={}))}(PhaserSuperStorage||(PhaserSuperStorage={}));var PhaserSuperStorage;!function(a){var b;!function(b){var c=function(){function b(a,b){void 0===a&&(a=""),void 0===b&&(b="*"),this.namespace="",this.expectedOrigin="",this.storageLength=0,this.enabled=!1,""!==a&&this.setNamespace(a),this.expectedOrigin=b}return Object.defineProperty(b.prototype,"forcePromises",{get:function(){return!0},set:function(a){},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"length",{get:function(){return this.storageLength},enumerable:!0,configurable:!0}),b.prototype.init=function(){var b=this;return this.sendMessage({command:a.StorageCommand.init}).then(function(){b.enabled=!0})},b.prototype.key=function(b){return this.sendMessage({command:a.StorageCommand.key,value:b})},b.prototype.getItem=function(b){return this.sendMessage({command:a.StorageCommand.getItem,key:b})},b.prototype.setItem=function(b,c){return this.sendMessage({command:a.StorageCommand.setItem,key:b,value:c})},b.prototype.removeItem=function(b){return this.sendMessage({command:a.StorageCommand.removeItem,key:b})},b.prototype.clear=function(){return this.sendMessage({command:a.StorageCommand.clear})},b.prototype.setNamespace=function(b){return this.sendMessage({command:a.StorageCommand.setNamespace,value:b})},b.prototype.sendMessage=function(b){var c,d=this;b.command===a.StorageCommand.init&&(c=!1);var e=new MessageChannel;return new Promise(function(f,g){d.enabled||b.command===a.StorageCommand.init||g("Messaging not enabled!"),b.command===a.StorageCommand.init&&setTimeout(function(){c||g("Unable to get a response in time")},1e3),e.port1.onmessage=function(b){console.log("Frame received message",b);var e=a.StorageUtils.validateMessage(b.data);switch(e.command===a.StorageCommand.init&&(c=!0),void 0!==e.status&&"ok"===e.status||g(e.value),void 0!==e.length&&(d.storageLength=e.length),e.command){case a.StorageCommand.setNamespace:d.namespace=e.value+":";case a.StorageCommand.getItem:case a.StorageCommand.length:case a.StorageCommand.key:f(e.value);break;case a.StorageCommand.setItem:case a.StorageCommand.removeItem:case a.StorageCommand.clear:case a.StorageCommand.init:f(e.status);break;default:g(e.value)}},(d.enabled||b.command===a.StorageCommand.init)&&(console.log("Sending message to parent: ",b),window.parent.postMessage(b,d.expectedOrigin,[e.port2]))})},b}();b.IframeStorage=c}(b=a.StorageAdapters||(a.StorageAdapters={}))}(PhaserSuperStorage||(PhaserSuperStorage={}));var PhaserSuperStorage;!function(a){var b;!function(b){var c=function(){function b(a){void 0===a&&(a=""),this.namespace="",this.forcePromises=!1,this.setNamespace(a)}return Object.defineProperty(b.prototype,"length",{get:function(){var b=Object.keys(localStorage);return a.StorageUtils.nameSpaceKeyFilter(b,this.namespace).length},enumerable:!0,configurable:!0}),b.prototype.key=function(a){return this.forcePromises?this.promisefy(this._key,arguments):this._key(a)},b.prototype._key=function(b){var c=Object.keys(localStorage),d=a.StorageUtils.nameSpaceKeyFilter(c,this.namespace),e=localStorage.getItem(d[b]);return e},b.prototype.getItem=function(a){return this.forcePromises?this.promisefy(this._getItem,arguments):this._getItem(a)},b.prototype._getItem=function(a){return localStorage.getItem(this.namespace+a)},b.prototype.setItem=function(a,b){return this.forcePromises?this.promisefy(this._setItem,arguments):this._setItem(a,b)},b.prototype._setItem=function(a,b){return localStorage.setItem(this.namespace+a,b)},b.prototype.removeItem=function(a){return this.forcePromises?this.promisefy(this._removeItem,arguments):this._removeItem(a)},b.prototype._removeItem=function(a){return localStorage.removeItem(this.namespace+a)},b.prototype.clear=function(){return this.forcePromises?this.promisefy(this._clear,arguments):this._clear()},b.prototype._clear=function(){for(var b=Object.keys(localStorage),c=a.StorageUtils.nameSpaceKeyFilter(b,this.namespace),d=0;d
2 |
3 |
4 |
5 |
6 |
7 |
8 | Phaser Super Storage example
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
22 |
23 |
24 |
25 |
26 |
NOT LOADED
27 |
28 |
29 |
30 |
31 |
129 |
--------------------------------------------------------------------------------
/example/frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Phaser Super Storage Iframe example
9 |
10 |
11 |
12 |
18 |
19 |
20 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/example/framed.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Phaser Super Storage Iframe child
9 |
10 |
11 |
12 |
13 |
19 |
20 |
21 |
50 |
51 |
52 |
55 |
56 |
--------------------------------------------------------------------------------
/example/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Phaser Super Storage example
9 |
10 |
11 |
12 |
13 |
19 |
20 |
21 |
46 |
47 |
48 |
51 |
52 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@azerion/phaser-super-storage",
3 | "author": "Azerion",
4 | "version": "1.0.4",
5 | "description": "A cross platform storage plugin for Phaser",
6 | "contributors": [
7 | {
8 | "name": "Ale Bles",
9 | "email": "a.bles@azerion.com"
10 | }
11 | ],
12 | "repository": {
13 | "type": "git",
14 | "url": "git@github.com:azerion/phaser-super-storage.git"
15 | },
16 | "licenses": [
17 | {
18 | "type": "MIT",
19 | "url": "https://github.com/azerion/phaser-super-storage/raw/master/LICENSE"
20 | }
21 | ],
22 | "bugs": [
23 | {
24 | "url": "https://github.com/azerion/phaser-super-storage/issues"
25 | }
26 | ],
27 | "config": {
28 | "name": "phaser-super-storage"
29 | },
30 | "devDependencies": {
31 | "@types/es6-promise": "0.0.32",
32 | "grunt": "1.0.x",
33 | "grunt-banner": "^0.6.0",
34 | "grunt-contrib-clean": "1.0.x",
35 | "grunt-contrib-concat": "1.0.x",
36 | "grunt-contrib-connect": "1.0.x",
37 | "grunt-contrib-uglify": "2.0.x",
38 | "grunt-contrib-watch": "1.0.x",
39 | "grunt-ts": "^6.0.0-beta.3",
40 | "grunt-tslint": "^3.3.0",
41 | "phaser": "2.6.2",
42 | "tslint": "^3.15.1",
43 | "typescript": "2.1.x"
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/ts/StorageAdapters/CookieStorage.ts:
--------------------------------------------------------------------------------
1 | module PhaserSuperStorage {
2 | export module StorageAdapters {
3 | interface ICookieStore {
4 | [name: string]: string;
5 | }
6 |
7 | /**
8 | * Storage driver for cookies
9 | */
10 | export class CookieStorage implements IStorage {
11 | private reg: RegExp;
12 |
13 | public namespace: string = '';
14 |
15 | public forcePromises: boolean = false;
16 |
17 | constructor(spacedName: string = '') {
18 | this.setNamespace(spacedName);
19 | }
20 |
21 | get length(): number {
22 | return (this.getNameSpaceMatches() !== null) ? this.getNameSpaceMatches().length : 0;
23 | }
24 |
25 | public key(n: number): any | Promise {
26 | let key: string = this.getNameSpaceMatches()[n];
27 | let result: any = this.getCookiesForNameSpace()[key] || null;
28 |
29 | if (this.forcePromises) {
30 | return this.promisefy(result);
31 | }
32 |
33 | return result;
34 | }
35 |
36 | public getItem(key: string): string | Promise {
37 | let result: any = this.getCookiesForNameSpace()[key] || null;
38 | if (this.forcePromises) {
39 | return this.promisefy(result);
40 | }
41 |
42 | return result;
43 | }
44 |
45 | public setItem(key: string, value: any): void | Promise {
46 | document.cookie = encodeURIComponent(this.namespace + key) + '=' + encodeURIComponent(value) + '; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/';
47 |
48 | if (this.forcePromises) {
49 | return this.promisefy(null);
50 | }
51 | }
52 |
53 | public removeItem(key: string): void | Promise {
54 | document.cookie = encodeURIComponent(this.namespace + key) + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
55 |
56 | if (this.forcePromises) {
57 | return this.promisefy(null);
58 | }
59 | }
60 |
61 | public clear(): void | Promise {
62 | let cookies: ICookieStore = this.getCookiesForNameSpace();
63 | for (let key in cookies) {
64 | if (cookies.hasOwnProperty(key)) {
65 | this.removeItem(key);
66 | }
67 | }
68 |
69 | if (this.forcePromises) {
70 | return this.promisefy(null);
71 | }
72 | }
73 |
74 | public setNamespace(namespace: string): void | Promise {
75 | if (namespace) {
76 | this.namespace = namespace + ':';
77 | this.reg = new RegExp('^' + this.namespace + '[a-zA-Z0-9]*', 'g');
78 | }
79 |
80 | if (this.forcePromises) {
81 | return this.promisefy(namespace);
82 | }
83 | }
84 |
85 | private getNameSpaceMatches(): string[] {
86 | let cookies: string[] = decodeURIComponent(document.cookie).split('; ');
87 |
88 | return cookies.filter((val: string) => {
89 | return (val.match(this.reg) !== null) ? val.match(this.reg).length > 0 : false;
90 | });
91 | }
92 |
93 | private getCookiesForNameSpace(): ICookieStore {
94 | let cookies: ICookieStore = {};
95 | this.getNameSpaceMatches().forEach((cookie: string) => {
96 | let temp: string[] = cookie.replace(this.namespace, '').split('=');
97 | cookies[temp[0]] = temp[1];
98 | });
99 | return cookies;
100 | }
101 |
102 | private promisefy(value: any): Promise {
103 | return new Promise((resolve: (value?: any | Thenable) => void, reject: (error?: any) => void) => {
104 | resolve(value);
105 | });
106 | }
107 | }
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/ts/StorageAdapters/CordovaStorage.ts:
--------------------------------------------------------------------------------
1 | module PhaserSuperStorage {
2 | export module StorageAdapters {
3 | /**
4 | * Storage driver for browser's localStorage
5 | */
6 | export class CordovaStorage implements IStorage {
7 | public namespace: string = '';
8 | private keys: string[];
9 |
10 | public get forcePromises(): boolean {
11 | return true;
12 | }
13 |
14 | public set forcePromises(v: boolean) {
15 | //Do nothing
16 | }
17 |
18 | // Due to async /w promise it is not possible to pass namespace in constructor
19 | constructor() {
20 | this.keys = [];
21 | }
22 |
23 | public get length(): number {
24 | return this.keys.length;
25 | }
26 |
27 | public key(n: number): Promise {
28 | return this.promisefy(this.keys[n]);
29 | }
30 |
31 | public getItem(key: string): Promise {
32 | return new Promise((resolve: (value?: string) => void, reject: (error?: INativeStorageError) => void) => {
33 | NativeStorage.getItem(this.namespace + key, (value: string) => {
34 | resolve(value);
35 | }, (error: INativeStorageError) => {
36 | if (error.code === 2) {
37 | resolve(null);
38 | } else {
39 | reject(error);
40 | }
41 | });
42 | });
43 | }
44 |
45 | public setItem(key: string, value: any): Promise {
46 | if (key.length < 1) {
47 | console.error('CordovaStorage: Key cannot be an empty string!');
48 | return;
49 | }
50 | return new Promise((resolve: (value?: void) => void, reject: (error?: INativeStorageError) => void) => {
51 | NativeStorage.setItem(this.namespace + key, value, () => {
52 | if (this.keys.indexOf(key) < 0) {
53 | this.keys.push(key);
54 | this.save();
55 | }
56 | resolve(null);
57 | }, (error: INativeStorageError) => {
58 | reject(error);
59 | });
60 | });
61 | }
62 |
63 | public removeItem(key: string): Promise {
64 | return new Promise((resolve: (value?: void) => void, reject: (error?: INativeStorageError) => void) => {
65 | NativeStorage.remove(this.namespace + key, () => {
66 | let id: number = this.keys.indexOf(key);
67 | if (id >= 0) {
68 | this.keys.splice(id, 1);
69 | this.save();
70 | }
71 | resolve(null);
72 | }, (error: INativeStorageError) => {
73 | reject(error);
74 | });
75 | });
76 | }
77 |
78 | public clear(): Promise {
79 | return new Promise((resolve: (value?: void) => void, reject: (error?: INativeStorageError) => void) => {
80 | let counter: number = 0;
81 | for (let i: number = 0; i < this.keys.length; i++) {
82 | NativeStorage.remove(this.namespace + this.keys[i], () => {
83 | if (++counter >= this.keys.length) {
84 | this.keys = [];
85 | this.save();
86 | resolve(null);
87 | }
88 | }, (error: INativeStorageError) => {
89 | reject(error);
90 | });
91 | }
92 | });
93 | }
94 |
95 | public setNamespace(spacedName: string = ''): Promise {
96 | this.namespace = spacedName + ':';
97 | this.keys = [];
98 | return new Promise((resolve: (value?: void) => void, reject: (error?: INativeStorageError) => void) => {
99 | this.load().then(resolve).catch(resolve);
100 | });
101 | }
102 |
103 | private promisefy(value: any): Promise {
104 | return new Promise((resolve: (value?: string) => void, reject: (error?: INativeStorageError) => void) => {
105 | resolve(value);
106 | });
107 | }
108 |
109 | private load(): Promise {
110 | return new Promise((resolve: (value?: void) => void, reject: (error?: INativeStorageError) => void) => {
111 | NativeStorage.getItem(this.namespace, (value: string) => {
112 | this.keys = JSON.parse(value);
113 | resolve(null);
114 | }, (error: INativeStorageError) => {
115 | reject(error);
116 | });
117 | });
118 | }
119 |
120 | private save(): void {
121 | NativeStorage.setItem(this.namespace, JSON.stringify(this.keys), () => {
122 | return;
123 | }, (error: any) => {
124 | console.warn('CordovaStorage: Failed to save keys of namespace.');
125 | });
126 | }
127 | }
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/ts/StorageAdapters/IStorage.ts:
--------------------------------------------------------------------------------
1 | module PhaserSuperStorage {
2 | export module StorageAdapters {
3 | export interface IStorage {
4 | forcePromises: boolean;
5 |
6 | //The amount of items in the storage
7 | length: number;
8 |
9 | //The namespace for the current storge
10 | namespace: string;
11 |
12 | //Get an item from the storage
13 | getItem(key: string): any | Promise;
14 |
15 | //remove an item from the localStorage
16 | removeItem(key: string): any | Promise;
17 |
18 | //Set an item in the storage
19 | setItem(key: string, value: any): void | Promise;
20 |
21 | key(n: number): any | Promise;
22 |
23 | //empty the (namespaced) storage
24 | clear(): void | Promise;
25 |
26 | setNamespace(namespace: string): void | Promise;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/ts/StorageAdapters/IframeStorage.ts:
--------------------------------------------------------------------------------
1 | module PhaserSuperStorage {
2 | export module StorageAdapters {
3 | /**
4 | * Storage driver for browser's localStorage
5 | */
6 | export class IframeStorage implements IStorage {
7 | public namespace: string = '';
8 |
9 | public expectedOrigin: string = '';
10 |
11 | private storageLength: number = 0;
12 |
13 | private enabled: boolean = false;
14 |
15 | get forcePromises(): boolean {
16 | return true;
17 | }
18 |
19 | set forcePromises(v: boolean) {
20 | //Do nothing
21 | }
22 |
23 | constructor(spacedName: string = '', expectedOrigin: string = '*') {
24 | if (spacedName !== '') {
25 | this.setNamespace(spacedName);
26 | }
27 |
28 | this.expectedOrigin = expectedOrigin;
29 | }
30 |
31 | get length(): number {
32 | return this.storageLength;
33 | }
34 |
35 | public init(): Promise {
36 | return this.sendMessage({
37 | command: StorageCommand.init
38 | }).then(() => {
39 | this.enabled = true;
40 | });
41 | }
42 |
43 | public key(n: number): Promise {
44 | return this.sendMessage({
45 | command: StorageCommand.key,
46 | value: n
47 | });
48 | }
49 |
50 | public getItem(key: string): Promise {
51 | return this.sendMessage({
52 | command: StorageCommand.getItem,
53 | key: key
54 | });
55 | }
56 |
57 | public setItem(key: string, value: any): Promise {
58 | return this.sendMessage({
59 | command: StorageCommand.setItem,
60 | key: key,
61 | value: value
62 | });
63 | }
64 |
65 | public removeItem(key: string): Promise {
66 | return this.sendMessage({
67 | command: StorageCommand.removeItem,
68 | key: key
69 | });
70 | }
71 |
72 | public clear(): Promise {
73 | return this.sendMessage({
74 | command: StorageCommand.clear
75 | });
76 | }
77 |
78 | public setNamespace(spacedName: string): Promise {
79 | return this.sendMessage({
80 | command: StorageCommand.setNamespace,
81 | value: spacedName
82 | });
83 | }
84 |
85 | private sendMessage(message: IStorageMessage): Promise {
86 | let returnedResult: boolean;
87 | if (message.command === StorageCommand.init) {
88 | returnedResult = false;
89 | }
90 |
91 | let messageChannel: MessageChannel = new MessageChannel();
92 |
93 | return new Promise((resolve: (value?: any | Thenable) => void, reject: (error?: any) => void) => {
94 | if (!this.enabled && message.command !== StorageCommand.init) {
95 | reject('Messaging not enabled!');
96 | }
97 |
98 | if (message.command === StorageCommand.init) {
99 | //small timeout to see if stuff is enabled
100 | setTimeout(() => {
101 | if (!returnedResult) {
102 | reject('Unable to get a response in time');
103 | }
104 | }, 1000);
105 | }
106 |
107 | messageChannel.port1.onmessage = (event: MessageEvent) => {
108 | console.log('Frame received message', event);
109 |
110 | let receivedMessage: PhaserSuperStorage.IStorageMessage = StorageUtils.validateMessage(event.data);
111 |
112 | if (receivedMessage.command === StorageCommand.init) {
113 | returnedResult = true;
114 | }
115 |
116 | if (receivedMessage.status === undefined || receivedMessage.status !== 'ok') {
117 | reject(receivedMessage.value);
118 | }
119 |
120 | if (receivedMessage.length !== undefined) {
121 | this.storageLength = receivedMessage.length;
122 | }
123 |
124 | switch (receivedMessage.command) {
125 | case StorageCommand.setNamespace:
126 | this.namespace = receivedMessage.value + ':';
127 | case StorageCommand.getItem:
128 | case StorageCommand.length:
129 | case StorageCommand.key:
130 | resolve(receivedMessage.value);
131 | break;
132 | case StorageCommand.setItem:
133 | case StorageCommand.removeItem:
134 | case StorageCommand.clear:
135 | case StorageCommand.init:
136 | resolve(receivedMessage.status);
137 | break;
138 | default:
139 | reject(receivedMessage.value);
140 | break;
141 | }
142 | };
143 |
144 | if (this.enabled || message.command === StorageCommand.init) {
145 | console.log('Sending message to parent: ', message);
146 | window.parent.postMessage(message, this.expectedOrigin, [messageChannel.port2]);
147 | }
148 | });
149 | }
150 | }
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/ts/StorageAdapters/LocalStorage.ts:
--------------------------------------------------------------------------------
1 | module PhaserSuperStorage {
2 | export module StorageAdapters {
3 | /**
4 | * Storage driver for browser's localStorage
5 | */
6 | export class LocalStorage implements IStorage {
7 | public namespace: string = '';
8 |
9 | public forcePromises: boolean = false;
10 |
11 | constructor(spacedName: string = '') {
12 | this.setNamespace(spacedName);
13 | }
14 |
15 | get length(): number {
16 | let keys: string [] = Object.keys(localStorage);
17 |
18 | return StorageUtils.nameSpaceKeyFilter(keys, this.namespace).length;
19 | }
20 |
21 | public key(n: number): any | Promise {
22 | return this.forcePromises ?
23 | this.promisefy(this._key, arguments) :
24 | this._key(n);
25 | }
26 |
27 | private _key(n: number): any {
28 | let keys: string[] = Object.keys(localStorage);
29 | let spacedKeys: string[] = StorageUtils.nameSpaceKeyFilter(keys, this.namespace);
30 |
31 | let item: any = localStorage.getItem(spacedKeys[n]);
32 |
33 | return item;
34 | }
35 |
36 | public getItem(key: string): any | Promise {
37 | return this.forcePromises ?
38 | this.promisefy(this._getItem, arguments) :
39 | this._getItem(key);
40 | }
41 |
42 | private _getItem(key: string): string {
43 | return localStorage.getItem(this.namespace + key);
44 | }
45 |
46 | public setItem(key: string, value: any): void | Promise {
47 | return this.forcePromises ?
48 | this.promisefy(this._setItem, arguments) :
49 | this._setItem(key, value);
50 | }
51 |
52 | private _setItem(key: string, value: any): void {
53 | return localStorage.setItem(this.namespace + key, value);
54 | }
55 |
56 | public removeItem(key: string): void | Promise {
57 | return this.forcePromises ?
58 | this.promisefy(this._removeItem, arguments) :
59 | this._removeItem(key);
60 | }
61 |
62 | private _removeItem(key: string): void {
63 | return localStorage.removeItem(this.namespace + key);
64 | }
65 |
66 | public clear(): void | Promise {
67 | return this.forcePromises ?
68 | this.promisefy(this._clear, arguments) :
69 | this._clear();
70 | }
71 |
72 | private _clear(): void {
73 | let keys: string[] = Object.keys(localStorage);
74 | let spacedKeys: string[] = StorageUtils.nameSpaceKeyFilter(keys, this.namespace);
75 |
76 | for (let i: number = 0; i < spacedKeys.length; i++) {
77 | localStorage.removeItem(spacedKeys[i]);
78 | }
79 |
80 | return;
81 | }
82 |
83 | public setNamespace(spacedName: string): void | Promise {
84 | return this.forcePromises ?
85 | this.promisefy(this._setNameSpace, arguments) :
86 | this._setNameSpace(spacedName);
87 | }
88 |
89 | private _setNameSpace(spacedName: string): void {
90 | if (spacedName) {
91 | this.namespace = spacedName + ':';
92 | }
93 | }
94 |
95 | private promisefy(value: any, args: any): Promise {
96 | return new Promise((resolve: (value?: any | Thenable) => void, reject: (error?: any) => void) => {
97 | resolve(value.apply(this, args));
98 | });
99 | }
100 | }
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/ts/SuperStorage.ts:
--------------------------------------------------------------------------------
1 | declare module 'phaser-super-storage' {
2 | export = PhaserSuperStorage;
3 | }
4 |
5 | module PhaserSuperStorage {
6 | export interface ISuperStorageGame extends Phaser.Game {
7 | storage: PhaserSuperStorage.StoragePlugin;
8 | }
9 |
10 | export class StoragePlugin {
11 | private storage: StorageAdapters.IStorage;
12 |
13 | private static instance: StoragePlugin = null;
14 |
15 | constructor(game?: Phaser.Game) {
16 | if (undefined !== game) {
17 | Object.defineProperty(game, 'storage', {
18 | value: this
19 | });
20 | } else {
21 | if (StoragePlugin.instance === null) {
22 | StoragePlugin.instance = this;
23 | } else {
24 | return StoragePlugin.instance;
25 | }
26 | }
27 |
28 | if (StorageUtils.isLocalStorageSupport()) {
29 | this.setAdapter(new StorageAdapters.LocalStorage());
30 | } else {
31 | this.setAdapter(new StorageAdapters.CookieStorage());
32 | }
33 | }
34 |
35 | public setAdapter(storageAdapter: StorageAdapters.IStorage): void {
36 | this.storage = storageAdapter;
37 | }
38 |
39 | get forcePromises(): boolean {
40 | return this.storage.forcePromises;
41 | }
42 |
43 | set forcePromises(forceIt: boolean) {
44 | this.storage.forcePromises = forceIt;
45 | }
46 |
47 | get length(): number {
48 | if (this.storage === null) {
49 | return 0;
50 | }
51 |
52 | return this.storage.length;
53 | }
54 |
55 | public setNamespace(namedSpace: string): void | Promise {
56 | if (this.storage !== null) {
57 | return this.storage.setNamespace(namedSpace);
58 | }
59 | }
60 |
61 | public key(n: number): string | Promise {
62 | if (this.storage === null) {
63 | return '';
64 | }
65 |
66 | return this.storage.key(n);
67 | }
68 |
69 | public getItem(key: string): any | Promise {
70 | if (this.storage === null) {
71 | return null;
72 | }
73 |
74 | return this.storage.getItem(key);
75 | }
76 |
77 | public setItem(key: string, value: string): void | Promise {
78 | if (this.storage !== null) {
79 | return this.storage.setItem(key, value);
80 | }
81 | }
82 |
83 | public removeItem(key: string): void | Promise {
84 | if (this.storage !== null) {
85 | return this.storage.removeItem(key);
86 | }
87 | }
88 |
89 | public clear(): void | Promise {
90 | if (this.storage !== null) {
91 | return this.storage.clear();
92 | }
93 | }
94 | }
95 | }
96 |
97 | if ((window).Phaser !== undefined) {
98 | Phaser.Utils.mixinPrototype(PhaserSuperStorage.StoragePlugin, Phaser.Plugin);
99 | }
100 |
--------------------------------------------------------------------------------
/ts/Utils/Helper.ts:
--------------------------------------------------------------------------------
1 | import StorageCommand = PhaserSuperStorage.StorageCommand;
2 | import StorageUtils = PhaserSuperStorage.StorageUtils;
3 | import LocalStorage = PhaserSuperStorage.StorageAdapters.LocalStorage;
4 |
5 | (() => {
6 | let gameOrigin: string = (window).gameOrigin || '*';
7 | let localStorageSupported: boolean = StorageUtils.isLocalStorageSupport();
8 | let storage: LocalStorage = localStorageSupported ? new LocalStorage() : null;
9 |
10 | window.addEventListener('message', (event: MessageEvent) => {
11 | if (gameOrigin !== '*' && event.origin !== gameOrigin) {
12 | return;
13 | }
14 |
15 | let message: PhaserSuperStorage.IStorageMessage = StorageUtils.validateMessage(event.data);
16 | let source: MessagePort = event.ports[0];
17 |
18 | if (typeof source === 'undefined' || !source) {
19 | //No source to return too, skipping
20 | return;
21 | }
22 |
23 | let sendError: (command: StorageCommand, message: string) => void = (command: StorageCommand, errorMessage: string): void => {
24 | source.postMessage({
25 | status: 'error',
26 | command: command,
27 | value: errorMessage
28 | });
29 | };
30 |
31 | if (null !== message) {
32 | if (!localStorageSupported) {
33 | sendError(message.command, 'localStorage not supported');
34 | }
35 |
36 | switch (message.command) {
37 | case StorageCommand.init:
38 | source.postMessage({
39 | status: 'ok',
40 | command: message.command,
41 | length: storage.length
42 | });
43 | break;
44 | case StorageCommand.getItem:
45 | try {
46 | let item: string = storage.getItem(message.key);
47 |
48 | source.postMessage({
49 | status: 'ok',
50 | command: message.command,
51 | value: item,
52 | length: storage.length
53 | });
54 | } catch (e) {
55 | sendError(message.command, e.message);
56 | }
57 | break;
58 | case StorageCommand.setItem:
59 | try {
60 | storage.setItem(message.key, message.value);
61 |
62 | source.postMessage({
63 | status: 'ok',
64 | command: message.command,
65 | length: storage.length
66 | });
67 | } catch (e) {
68 | sendError(message.command, e.message);
69 | }
70 | break;
71 | case StorageCommand.removeItem:
72 | try {
73 | storage.removeItem(message.key);
74 |
75 | source.postMessage({
76 | status: 'ok',
77 | command: message.command,
78 | length: storage.length
79 | });
80 | } catch (e) {
81 | sendError(message.command, e.message);
82 | }
83 | break;
84 | case StorageCommand.setNamespace:
85 | try {
86 | storage.setNamespace(message.value);
87 |
88 | source.postMessage({
89 | status: 'ok',
90 | command: message.command,
91 | value: message.value,
92 | length: storage.length
93 | });
94 | } catch (e) {
95 | sendError(message.command, e.message);
96 | }
97 | break;
98 | case StorageCommand.clear:
99 | try {
100 | storage.clear();
101 |
102 | source.postMessage({
103 | status: 'ok',
104 | command: message.command,
105 | length: storage.length
106 | });
107 | } catch (e) {
108 | sendError(message.command, e.message);
109 | }
110 | break;
111 | case StorageCommand.length:
112 | try {
113 | source.postMessage({
114 | status: 'ok',
115 | command: message.command,
116 | value: storage.length,
117 | length: storage.length
118 | });
119 | } catch (e) {
120 | sendError(message.command, e.message);
121 | }
122 | break;
123 | case StorageCommand.key:
124 | try {
125 | let nkey: any = storage.key(message.value);
126 |
127 | source.postMessage({
128 | status: 'ok',
129 | command: message.command,
130 | value: nkey,
131 | length: storage.length
132 | });
133 | } catch (e) {
134 | sendError(message.command, e.message);
135 | }
136 | break;
137 | default:
138 | sendError(message.command, 'Command not found');
139 | break;
140 | }
141 | } else {
142 | sendError(StorageCommand.error, 'Empty message!');
143 | }
144 | });
145 | })();
146 |
--------------------------------------------------------------------------------
/ts/Utils/Storage.ts:
--------------------------------------------------------------------------------
1 | module PhaserSuperStorage {
2 | export interface IStorageMessage {
3 | command: StorageCommand;
4 | status?: string;
5 | key?: string;
6 | value?: any;
7 | length?: number;
8 | }
9 |
10 | export enum StorageCommand {
11 | init,
12 | setItem,
13 | getItem,
14 | removeItem,
15 | clear,
16 | setNamespace,
17 | length,
18 | key,
19 | error
20 | }
21 |
22 | export class StorageUtils {
23 | public static isLocalStorageSupport(): boolean {
24 | try {
25 | if (typeof localStorage === 'object') {
26 | localStorage.setItem('testingLocalStorage', 'foo');
27 | localStorage.removeItem('testingLocalStorage');
28 | return true;
29 | }
30 | } catch (e) {
31 | return false;
32 | }
33 |
34 | return false;
35 | }
36 |
37 | public static validateMessage(data: IStorageMessage): IStorageMessage {
38 | if (data.hasOwnProperty('command')) {
39 | return data;
40 | }
41 |
42 | return null;
43 | }
44 |
45 | public static nameSpaceKeyFilter(keys: string[], namespace: string): string[] {
46 | return keys.filter((keyName: string) => {
47 | return (keyName.substring(0, namespace.length) === namespace);
48 | });
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/ts/definitions.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 | ///
4 |
--------------------------------------------------------------------------------
/vendor/NativeStorage.d.ts:
--------------------------------------------------------------------------------
1 | interface INativeStorage {
2 | getItem(key: string, onSucceed: (value: string) => void, onError: (error: any) => void): void;
3 | setItem(key: string, value: string, onSucceed: (value: string) => void, onError: (error: any) => void): void;
4 | remove(key: string, onSucceed: (value: string) => void, onError: (error: any) => void): void;
5 | }
6 |
7 | declare enum NativeStorageErrorCode {
8 | NATIVE_WRITE_FAILED = 1,
9 | ITEM_NOT_FOUND = 2,
10 | NULL_REFERENCE = 3,
11 | UNDEFINED_TYPE = 4,
12 | JSON_ERROR = 5,
13 | WRONG_PARAMETER = 6,
14 |
15 | }
16 |
17 | interface INativeStorageError {
18 | code: NativeStorageErrorCode;
19 | source: string;
20 | exception: any;
21 | }
22 |
23 | declare var NativeStorage: INativeStorage;
24 |
--------------------------------------------------------------------------------