Update AutoSave
This commit is contained in:
parent
5a1805486a
commit
6b80afe9ee
33
libs/core.js
33
libs/core.js
@ -461,7 +461,7 @@ core.prototype.resetStatus = function(hero, hard, floorId, maps) {
|
||||
core.status.hero = core.clone(hero);
|
||||
core.status.hard = hard;
|
||||
// 保存的Index
|
||||
core.status.saveIndex = core.getLocalStorage('saveIndex', 1);
|
||||
core.status.saveIndex = core.getLocalStorage('saveIndex2', 1);
|
||||
|
||||
core.resize(main.dom.body.clientWidth, main.dom.body.clientHeight);
|
||||
}
|
||||
@ -1001,8 +1001,8 @@ core.prototype.onmousewheel = function (direct) {
|
||||
|
||||
// 怪物手册
|
||||
if (core.status.lockControl && core.status.event.id == 'book') {
|
||||
if (direct==1) core.ui.drawBook(core.status.event.data - 1);
|
||||
if (direct==-1) core.ui.drawBook(core.status.event.data + 1);
|
||||
if (direct==1) core.ui.drawBook(core.status.event.data - 6);
|
||||
if (direct==-1) core.ui.drawBook(core.status.event.data + 6);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2035,7 +2035,7 @@ core.prototype.drawMap = function (mapName, callback) {
|
||||
}
|
||||
}
|
||||
|
||||
var mapArray = core.maps.getMapArray(core.status.maps, mapName);
|
||||
var mapArray = core.maps.getMapArray(mapBlocks);
|
||||
for (var b = 0; b < mapBlocks.length; b++) {
|
||||
// 事件启用
|
||||
var block = mapBlocks[b];
|
||||
@ -3331,7 +3331,7 @@ core.prototype.load = function (need) {
|
||||
core.status.event = {'id': 'load', 'data': null};
|
||||
core.status.lockControl = true;
|
||||
core.dom.startPanel.style.display = 'none';
|
||||
core.ui.drawSLPanel(core.getLocalStorage('saveIndex', 1));
|
||||
core.ui.drawSLPanel(core.getLocalStorage('saveIndex2', 1));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -3340,14 +3340,25 @@ core.prototype.load = function (need) {
|
||||
core.ui.drawSLPanel(core.status.saveIndex);
|
||||
}
|
||||
|
||||
////// 自动存档 //////
|
||||
core.prototype.autosave = function () {
|
||||
core.saveData("autoSave");
|
||||
}
|
||||
|
||||
////// 实际进行存读档事件 //////
|
||||
core.prototype.doSL = function (id, type) {
|
||||
core.status.saveIndex=id;
|
||||
if (type=='save') {
|
||||
if (id=='autoSave') {
|
||||
core.drawTip('不能覆盖自动存档!');
|
||||
return;
|
||||
}
|
||||
if (core.saveData("save"+id)) {
|
||||
core.ui.closePanel();
|
||||
core.drawTip('存档成功!');
|
||||
core.setLocalStorage('saveIndex', core.status.saveIndex);
|
||||
if (id!="autoSave") {
|
||||
core.status.saveIndex=id;
|
||||
core.setLocalStorage('saveIndex2', core.status.saveIndex);
|
||||
}
|
||||
}
|
||||
else {
|
||||
core.drawTip('存储空间不足,请覆盖已有的存档或在菜单栏中进行清理');
|
||||
@ -3355,7 +3366,7 @@ core.prototype.doSL = function (id, type) {
|
||||
return;
|
||||
}
|
||||
else if (type=='load') {
|
||||
var data = core.getLocalStorage("save"+id, null);
|
||||
var data = core.getLocalStorage(id=='autoSave'?id:"save"+id, null);
|
||||
if (!core.isset(data)) {
|
||||
core.drawTip("无效的存档");
|
||||
return;
|
||||
@ -3366,9 +3377,11 @@ core.prototype.doSL = function (id, type) {
|
||||
}
|
||||
core.ui.closePanel();
|
||||
core.loadData(data, function() {
|
||||
core.status.saveIndex=id;
|
||||
core.setLocalStorage('saveIndex', core.status.saveIndex);
|
||||
core.drawTip("读档成功");
|
||||
if (id!="autoSave") {
|
||||
core.status.saveIndex=id;
|
||||
core.setLocalStorage('saveIndex2', core.status.saveIndex);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ function events() {
|
||||
events.prototype.init = function () {
|
||||
this.events = {
|
||||
'battle': function (data, core, callback) {
|
||||
core.autosave();
|
||||
core.battle(data.event.id, data.x, data.y);
|
||||
if (core.isset(callback))
|
||||
callback();
|
||||
@ -16,6 +17,7 @@ events.prototype.init = function () {
|
||||
callback();
|
||||
},
|
||||
'openDoor': function (data, core, callback) {
|
||||
core.autosave();
|
||||
core.openDoor(data.event.id, data.x, data.y, true);
|
||||
if (core.isset(callback))
|
||||
callback();
|
||||
@ -131,10 +133,18 @@ events.prototype.lose = function(reason) {
|
||||
|
||||
////// 转换楼层结束的事件 //////
|
||||
events.prototype.afterChangeFloor = function (floorId) {
|
||||
if (!core.isset(core.status.event.id) && !core.hasFlag("visited_"+floorId)) {
|
||||
this.doEvents(core.floors[floorId].firstArrive);
|
||||
if (core.isset(core.status.event.id)) return; // 当前存在事件
|
||||
|
||||
if (!core.hasFlag("visited_"+floorId)) {
|
||||
this.doEvents(core.floors[floorId].firstArrive, null, null, function () {
|
||||
core.autosave();
|
||||
});
|
||||
core.setFlag("visited_"+floorId, true);
|
||||
return;
|
||||
}
|
||||
|
||||
// 自动存档
|
||||
core.autosave();
|
||||
}
|
||||
|
||||
////// 开始执行一系列自定义事件 //////
|
||||
@ -1141,13 +1151,17 @@ events.prototype.keyUpToolbox = function (keycode) {
|
||||
|
||||
////// 存读档界面时的点击操作 //////
|
||||
events.prototype.clickSL = function(x,y) {
|
||||
|
||||
var index=core.status.event.data;
|
||||
var page = parseInt(index/10), offset=index%10;
|
||||
|
||||
// 上一页
|
||||
if ((x == 3 || x == 4) && y == 12) {
|
||||
core.ui.drawSLPanel(core.status.event.data - 6);
|
||||
core.ui.drawSLPanel(10*(page-1)+offset);
|
||||
}
|
||||
// 下一页
|
||||
if ((x == 8 || x == 9) && y == 12) {
|
||||
core.ui.drawSLPanel(core.status.event.data + 6);
|
||||
core.ui.drawSLPanel(10*(page+1)+offset);
|
||||
}
|
||||
// 返回
|
||||
if (x>=10 && x<=12 && y==12) {
|
||||
@ -1158,50 +1172,77 @@ events.prototype.clickSL = function(x,y) {
|
||||
return;
|
||||
}
|
||||
|
||||
var page=parseInt((core.status.event.data-1)/6);
|
||||
var index=6*page+1;
|
||||
if (y>=1 && y<=4) {
|
||||
if (x>=1 && x<=3) core.doSL(index, core.status.event.id);
|
||||
if (x>=5 && x<=7) core.doSL(index+1, core.status.event.id);
|
||||
if (x>=9 && x<=11) core.doSL(index+2, core.status.event.id);
|
||||
if (x>=1 && x<=3) core.doSL("autoSave", core.status.event.id);
|
||||
if (x>=5 && x<=7) core.doSL(5*page+1, core.status.event.id);
|
||||
if (x>=9 && x<=11) core.doSL(5*page+2, core.status.event.id);
|
||||
}
|
||||
if (y>=7 && y<=10) {
|
||||
if (x>=1 && x<=3) core.doSL(index+3, core.status.event.id);
|
||||
if (x>=5 && x<=7) core.doSL(index+4, core.status.event.id);
|
||||
if (x>=9 && x<=11) core.doSL(index+5, core.status.event.id);
|
||||
if (x>=1 && x<=3) core.doSL(5*page+3, core.status.event.id);
|
||||
if (x>=5 && x<=7) core.doSL(5*page+4, core.status.event.id);
|
||||
if (x>=9 && x<=11) core.doSL(5*page+5, core.status.event.id);
|
||||
}
|
||||
}
|
||||
|
||||
////// 存读档界面时,按下某个键的操作 //////
|
||||
events.prototype.keyDownSL = function(keycode) {
|
||||
|
||||
var index=core.status.event.data;
|
||||
var page = parseInt(index/10), offset=index%10;
|
||||
|
||||
if (keycode==37) { // left
|
||||
core.ui.drawSLPanel(core.status.event.data - 1);
|
||||
if (offset==0) {
|
||||
core.ui.drawSLPanel(10*(page-1) + 5);
|
||||
}
|
||||
else {
|
||||
core.ui.drawSLPanel(index - 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (keycode==38) { // up
|
||||
core.ui.drawSLPanel(core.status.event.data - 3);
|
||||
if (offset<3) {
|
||||
core.ui.drawSLPanel(10*(page-1) + offset + 3);
|
||||
}
|
||||
else {
|
||||
core.ui.drawSLPanel(index - 3);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (keycode==39) { // right
|
||||
core.ui.drawSLPanel(core.status.event.data + 1);
|
||||
if (offset==5) {
|
||||
core.ui.drawSLPanel(10*(page+1));
|
||||
}
|
||||
else {
|
||||
core.ui.drawSLPanel(index + 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (keycode==40) { // down
|
||||
core.ui.drawSLPanel(core.status.event.data + 3);
|
||||
if (offset>=3) {
|
||||
core.ui.drawSLPanel(10*(page+1) + offset - 3);
|
||||
}
|
||||
else {
|
||||
core.ui.drawSLPanel(index + 3);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (keycode==33) { // PAGEUP
|
||||
core.ui.drawSLPanel(core.status.event.data - 6);
|
||||
core.ui.drawSLPanel(10*(page+1) + offset);
|
||||
return;
|
||||
}
|
||||
if (keycode==34) { // PAGEDOWN
|
||||
core.ui.drawSLPanel(core.status.event.data + 6);
|
||||
core.ui.drawSLPanel(10*(page-1) + offset);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
////// 存读档界面时,放开某个键的操作 //////
|
||||
events.prototype.keyUpSL = function (keycode) {
|
||||
|
||||
var index=core.status.event.data;
|
||||
var page = parseInt(index/10), offset=index%10;
|
||||
|
||||
if (keycode==27 || keycode==88 || (core.status.event.id == 'save' && keycode==83) || (core.status.event.id == 'load' && keycode==68)) {
|
||||
core.ui.closePanel();
|
||||
if (!core.isPlaying()) {
|
||||
@ -1210,7 +1251,12 @@ events.prototype.keyUpSL = function (keycode) {
|
||||
return;
|
||||
}
|
||||
if (keycode==13 || keycode==32 || keycode==67) {
|
||||
core.doSL(core.status.event.data, core.status.event.id);
|
||||
if (offset==0) {
|
||||
core.doSL("autoSave", core.status.event.id);
|
||||
}
|
||||
else {
|
||||
core.doSL(5*page+offset, core.status.event.id);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
13
libs/maps.js
13
libs/maps.js
@ -356,16 +356,7 @@ maps.prototype.load = function (data, floorId) {
|
||||
}
|
||||
|
||||
////// 将当前地图重新变成二维数组形式 //////
|
||||
maps.prototype.getMapArray = function (maps, floorId){
|
||||
if (!core.isset(floorId)) {
|
||||
var map = {};
|
||||
for (var id in maps) {
|
||||
map[id] = this.getMapArray(maps, id);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
var thisFloor = maps[floorId];
|
||||
maps.prototype.getMapArray = function (blockArray){
|
||||
|
||||
var blocks = [];
|
||||
for (var x=0;x<13;x++) {
|
||||
@ -374,7 +365,7 @@ maps.prototype.getMapArray = function (maps, floorId){
|
||||
blocks[x].push(0);
|
||||
}
|
||||
}
|
||||
thisFloor.blocks.forEach(function (block) {
|
||||
blockArray.forEach(function (block) {
|
||||
if (!(core.isset(block.enable) && !block.enable))
|
||||
blocks[block.y][block.x] = block.id;
|
||||
});
|
||||
|
||||
26
libs/ui.js
26
libs/ui.js
@ -1020,16 +1020,15 @@ ui.prototype.drawToolbox = function(index) {
|
||||
////// 绘制存档/读档界面 //////
|
||||
ui.prototype.drawSLPanel = function(index) {
|
||||
if (!core.isset(index)) index=1;
|
||||
if (index<=0) index=1;
|
||||
if (index>180) index=180;
|
||||
if (index<0) index=0;
|
||||
|
||||
var page = parseInt(index/10), offset=index%10;
|
||||
if (page>=30) page=30;
|
||||
if (offset>5) offset=5;
|
||||
index=10*page+offset;
|
||||
|
||||
core.status.event.data=index;
|
||||
|
||||
var page=parseInt((index-1)/6);
|
||||
|
||||
// core.status.event.data = page;
|
||||
// core.status.savePage = page;
|
||||
|
||||
core.clearMap('ui', 0, 0, 416, 416);
|
||||
core.setAlpha('ui', 0.85);
|
||||
core.fillRect('ui', 0, 0, 416, 416, '#000000');
|
||||
@ -1040,12 +1039,11 @@ ui.prototype.drawSLPanel = function(index) {
|
||||
|
||||
var name=core.status.event.id=='save'?"存档":"读档";
|
||||
for (var i=0;i<6;i++) {
|
||||
var id=6*page+i+1;
|
||||
var data=core.getLocalStorage("save"+id,null);
|
||||
|
||||
var id=5*page+i;
|
||||
var data=core.getLocalStorage(i==0?"autoSave":"save"+id, null);
|
||||
if (i<3) {
|
||||
core.fillText('ui', name+id, (2*i+1)*u, 35, '#FFFFFF', "bold 17px Verdana");
|
||||
core.strokeRect('ui', (2*i+1)*u-size/2, 50, size, size, id==index?'#FFD700':'#FFFFFF', id==index?6:2);
|
||||
core.fillText('ui', i==0?"自动存档":name+id, (2*i+1)*u, 35, '#FFFFFF', "bold 17px Verdana");
|
||||
core.strokeRect('ui', (2*i+1)*u-size/2, 50, size, size, i==offset?'#FFD700':'#FFFFFF', i==offset?6:2);
|
||||
if (core.isset(data) && core.isset(data.floorId)) {
|
||||
this.drawThumbnail(data.floorId, 'ui', core.maps.load(data.maps, data.floorId).blocks, (2*i+1)*u-size/2, 50, size, data.hero.loc);
|
||||
core.fillText('ui', core.formatDate(new Date(data.time)), (2*i+1)*u, 65+size, '#FFFFFF', '10px Verdana');
|
||||
@ -1057,7 +1055,7 @@ ui.prototype.drawSLPanel = function(index) {
|
||||
}
|
||||
else {
|
||||
core.fillText('ui', name+id, (2*i-5)*u, 230, '#FFFFFF', "bold 17px Verdana");
|
||||
core.strokeRect('ui', (2*i-5)*u-size/2, 245, size, size, id==index?'#FFD700':'#FFFFFF', id==index?6:2);
|
||||
core.strokeRect('ui', (2*i-5)*u-size/2, 245, size, size, i==offset?'#FFD700':'#FFFFFF', i==offset?6:2);
|
||||
if (core.isset(data) && core.isset(data.floorId)) {
|
||||
this.drawThumbnail(data.floorId, 'ui', core.maps.load(data.maps, data.floorId).blocks, (2*i-5)*u-size/2, 245, size, data.hero.loc);
|
||||
core.fillText('ui', core.formatDate(new Date(data.time)), (2*i-5)*u, 260+size, '#FFFFFF', '10px Verdana');
|
||||
@ -1091,7 +1089,7 @@ ui.prototype.drawThumbnail = function(floorId, canvas, blocks, x, y, size, heroL
|
||||
}
|
||||
}
|
||||
|
||||
var mapArray = core.maps.getMapArray(core.status.maps, floorId);
|
||||
var mapArray = core.maps.getMapArray(blocks);
|
||||
for (var b in blocks) {
|
||||
var block = blocks[b];
|
||||
if (core.isset(block.event) && !(core.isset(block.enable) && !block.enable)) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user