Ability to save state

This commit is contained in:
Victor 2015-12-11 22:54:58 +02:00
parent 4de12e0532
commit 5e920f760d
2 changed files with 31 additions and 1 deletions

View File

@ -104,3 +104,11 @@ Menu.prototype.getPosition = function (itemIndex) {
return this.items[itemIndex].position;
};
function SaveInfo(time, position, variables, characterNames, backgroundType, backgroundName) {
this.time = time;
this.position = position;
this.variables = variables;
this.characterNames = characterNames;
this.backgroundType = backgroundType;
this.backgroundName = backgroundName;
}

View File

@ -1,4 +1,4 @@
/* global TextUtils, PathResolver, ViewActivity, transitions, Transition */
/* global TextUtils, PathResolver, ViewActivity, transitions, Transition, rpyscript, Variables */
function Views(parser) {
this.parser = parser;
@ -383,6 +383,10 @@ Views.prototype.showMainMenu = function () {
this.addMainMenuItem("Следующая сцена", function() {
views.parser.nextScene();
});
this.addMainMenuItem("Сохранить", function() {
$('#menu').hide();
views.saveState();
});
this.addMainMenuItem("Закрыть", function() {
$('#menu').hide();
});
@ -551,3 +555,21 @@ Views.prototype.stopAmbience = function (fade) {
this.ambiencePlayerAudio.pause();
}
};
Views.prototype.saveState = function () {
var saves = JSON.parse(localStorage.saves || null) || {};
saves[rpyscript] = saves[rpyscript] || [];
saves[rpyscript].push(this.createSave());
localStorage.saves = JSON.stringify(saves);
};
Views.prototype.createSave = function () {
var save = new SaveInfo();
save.position = this.parser.lastPosition;
save.time = String(new Date());
save.variables = Variables.variables;
save.characterNames = this.characters.names;
save.backgroundType = this.backgroundType;
save.backgroundName = this.backgroundName;
return save;
};