Load state menu

This commit is contained in:
Victor 2015-12-11 23:16:29 +02:00
parent 5e920f760d
commit d5ceb0afec
2 changed files with 37 additions and 0 deletions

View File

@ -12,6 +12,7 @@ function run(data) {
$(document).ready(function() { $(document).ready(function() {
if ( (typeof rpyscript === 'undefined') || TextUtils.isEmpty(rpyscript)) { if ( (typeof rpyscript === 'undefined') || TextUtils.isEmpty(rpyscript)) {
rpyscript = "undefined";
run('play music music_list["everlasting_summer"]\n' + run('play music music_list["everlasting_summer"]\n' +
'scene bg ext_square_day\n' + 'scene bg ext_square_day\n' +
'show mz smile pioneer far at fright\n' + 'show mz smile pioneer far at fright\n' +

View File

@ -387,6 +387,13 @@ Views.prototype.showMainMenu = function () {
$('#menu').hide(); $('#menu').hide();
views.saveState(); views.saveState();
}); });
var saves = JSON.parse(localStorage.saves || null) || {};
saves[rpyscript] = saves[rpyscript] || [];
if (saves[rpyscript].length > 0) {
this.addMainMenuItem("Загрузить…", function() {
views.showLoadStateMenu();
});
}
this.addMainMenuItem("Закрыть", function() { this.addMainMenuItem("Закрыть", function() {
$('#menu').hide(); $('#menu').hide();
}); });
@ -572,4 +579,33 @@ Views.prototype.createSave = function () {
save.backgroundType = this.backgroundType; save.backgroundType = this.backgroundType;
save.backgroundName = this.backgroundName; save.backgroundName = this.backgroundName;
return save; return save;
};
Views.prototype.showLoadStateMenu = function () {
var saves = JSON.parse(localStorage.saves || null) || {};
var items = saves[rpyscript] || [];
$('#menuTitle').text('Загрузить');
$('#menuChoose').empty();
this.addMainMenuItem("Закрыть", function() {
$('#menu').hide();
});
for(var i = items.length - 1; i >= 0; i--) {
var li = $('<li>', {text: items[i].time});
li.click(this.createLoadStateClickFunction(i, items[i]));
li.appendTo($('#menuChoose'));
}
$('#menu').show();
};
Views.prototype.createLoadStateClickFunction = function (index, save) {
var views = this;
return function () {
Variables.variables = save.variables;
views.characters.names = save.characterNames;
if (!TextUtils.isEmpty(save.backgroundName)) {
views.background(save.backgroundType, save.backgroundName, "");
}
views.parser.setPosition(save.position);
$('#menu').hide();
};
}; };