Skip to content

Commit

Permalink
Add Storage configuration options
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyuchia committed Dec 10, 2018
1 parent 02164aa commit e7da273
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 5 deletions.
74 changes: 73 additions & 1 deletion core/lib/monogatari.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $_, Space, Platform, Preload, Util, FileSystem } from '@aegis-framework/artemis';
import { $_, Space, SpaceAdapter, Platform, Preload, Util, FileSystem, Text } from '@aegis-framework/artemis';
import moment from 'moment';
import { FancyError } from './FancyError';

Expand Down Expand Up @@ -431,6 +431,9 @@ class Monogatari {
static preferences (object = null) {
if (object !== null) {
Monogatari._preferences = Object.assign ({}, Monogatari._preferences, object);
if (Monogatari.Storage.configuration ().name === '') {
Monogatari.setupStorage ();
}
Monogatari.Storage.update ('Settings', Monogatari._preferences);
} else {
return Monogatari._preferences;
Expand Down Expand Up @@ -1749,7 +1752,51 @@ class Monogatari {
return Promise.all (promises);
}

static setupStorage () {

if (Monogatari.setting ('Storage').Adapter.trim () !== '') {
let adapter;

switch (Monogatari.setting ('Storage').Adapter) {
case 'LocalStorage':
adapter = SpaceAdapter.LocalStorage;
break;

case 'SessionStorage':
adapter = SpaceAdapter.SessionStorage;
break;

case 'IndexedDB':
adapter = SpaceAdapter.IndexedDB;
break;

case 'RemoteStorage':
adapter = SpaceAdapter.RemoteStorage;
break;

default:
adapter = SpaceAdapter.LocalStorage;
break;
}

Monogatari.Storage = new Space (adapter, {
name: Text.friendly (Monogatari.setting ('Name')),
version: Monogatari.setting ('Version'),
store: Monogatari.setting ('Storage').Store,
endpoint: Monogatari.setting ('Storage').Endpoint,
props: {
keyPath: 'id'
}
});
}
}

static init (selector = '#monogatari') {

if (Monogatari.Storage.configuration ().name === '') {
Monogatari.setupStorage ();
}

Monogatari.selector = selector;
FancyError.init ();

Expand Down Expand Up @@ -1813,6 +1860,8 @@ Monogatari._script = {};
Monogatari._characters = {};
Monogatari._storage = {};

Monogatari.Storage = new Space ();

Monogatari._mediaPlayers = {
music: {},
sound: {},
Expand Down Expand Up @@ -1860,6 +1909,14 @@ Monogatari._assets = {
// update experience
Monogatari._settings = {

// The name of your game, this will be used to store all the data so once
// you've released a game using one name, it shouldn't change. Please use the
// Version Setting to indicate a new release of your game!
'Name': 'My Visual Novel',

// The version of your game in semantic versioning (https://semver.org/).
'Version': '0.1.0',

// Initial Label *
'Label': 'Start',

Expand Down Expand Up @@ -1936,6 +1993,19 @@ Monogatari._settings = {
'ui': 'ui',
'video': 'video',
'voice': 'voice'
},
// Define what storage engine should be used to save the game data. *
// Adapters Available:
// - LocalStorage: This one is used by default
// - SessionStorage: Same as LocalStorage but will be cleared when the page
// is closed.
// - IndexedDB: The information is saved using the IndexedDB web API
// - RemoteStorage: The information will be sent and retrieved from a given
// URL Endpoint providing a REST API.
'Storage': {
'Adapter': 'LocalStorage',
'Store': 'GameData',
'Endpoint': ''
}
};

Expand Down Expand Up @@ -2001,4 +2071,6 @@ Monogatari._html = `
</section>
`;

Monogatari.version = '2.0.0';

export { Monogatari };
4 changes: 2 additions & 2 deletions dist/engine/monogatari.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/engine/monogatari.map

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion dist/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ const { Monogatari: monogatari } = Monogatari;

monogatari.settings({

// The name of your game, this will be used to store all the data so once
// you've released a game using one name, it shouldn't change. Please use the
// Version Setting to indicate a new release of your game!
'Name': 'My Visual Novel',

// The version of your game in semantic versioning (https://semver.org/).
'Version': '0.1.0',

// Initial Label *
'Label': 'Start',

Expand Down Expand Up @@ -49,7 +57,7 @@ monogatari.settings({
// Enables or disables the typing text animation for the whole game.
'TypeAnimation': true,

// Enables or disables the typing text animation in NVL dialogs for the
// Enables or disables the typing text animation in NVL dialogs for the
// whole game.
'NVLTypeAnimation': true,

Expand Down Expand Up @@ -90,6 +98,18 @@ monogatari.settings({
'ui': 'ui',
'video': 'video',
'voice': 'voice'
// Define what storage engine should be used to save the game data. *
// Adapters Available:
// - LocalStorage: This one is used by default
// - SessionStorage: Same as LocalStorage but will be cleared when the page
// is closed.
// - IndexedDB: The information is saved using the IndexedDB web API
// - RemoteStorage: The information will be sent and retrieved from a given
// URL Endpoint providing a REST API.
'Storage': {
'Adapter': 'LocalStorage',
'Store': 'GameData',
'Endpoint': ''
}
});

Expand Down

0 comments on commit e7da273

Please sign in to comment.