diff --git a/public_html/js/Utils.js b/public_html/js/Utils.js index 0963ad5..d4bfc21 100644 --- a/public_html/js/Utils.js +++ b/public_html/js/Utils.js @@ -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; +} \ No newline at end of file diff --git a/public_html/js/Views.js b/public_html/js/Views.js index a8e3f2e..141da98 100644 --- a/public_html/js/Views.js +++ b/public_html/js/Views.js @@ -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(); }); @@ -550,4 +554,22 @@ Views.prototype.stopAmbience = function (fade) { } else { 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; }; \ No newline at end of file