save & load v2.6
This commit is contained in:
parent
845ed191ea
commit
676dc50092
@ -16,7 +16,7 @@ var functions_comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "不同难度分别设置初始属性"
|
||||
"_data": "设置初始属性"
|
||||
},
|
||||
"win": {
|
||||
"_leaf": true,
|
||||
@ -34,73 +34,61 @@ var functions_comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "正在切换楼层过程中的操作\n此函数的执行时间是在切换楼层过程中屏幕完全变黑的一刻"
|
||||
"_data": "切换楼层中"
|
||||
},
|
||||
"afterChangeFloor": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "转换楼层结束的事件\n此函数会在整个楼层切换完全结束后执行"
|
||||
"_data": "切换楼层后"
|
||||
},
|
||||
"beforeBattle": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "战斗前发生的事件"
|
||||
"_data": "战前事件"
|
||||
},
|
||||
"afterBattle": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "战斗结束后触发的事件"
|
||||
"_data": "战后事件"
|
||||
},
|
||||
"afterOpenDoor": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "开一个门后触发的事件"
|
||||
"_data": "开门后事件"
|
||||
},
|
||||
"afterGetItem": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "获得一个道具后触发的事件"
|
||||
"_data": "获得道具后事件"
|
||||
},
|
||||
"afterChangeLight": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "改变亮灯之后,可以触发的事件"
|
||||
"_data": "改变亮灯事件"
|
||||
},
|
||||
"afterPushBox": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "推箱子后的事件"
|
||||
"_data": "推箱子事件"
|
||||
},
|
||||
"afterUseBomb": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "使用炸弹/圣锤后的事件"
|
||||
},
|
||||
"beforeSaveData": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "即将存档前可以执行的操作"
|
||||
},
|
||||
"afterLoadData": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "读档事件后,载入事件前,可以执行的操作"
|
||||
"_data": "炸弹事件"
|
||||
},
|
||||
"canUseQuickShop": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "当前能否使用快捷商店"
|
||||
"_data": "能否用快捷商店"
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -111,25 +99,25 @@ var functions_comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "怪物特殊属性的定义(获得怪物的特殊属性)"
|
||||
"_data": "怪物特殊属性定义"
|
||||
},
|
||||
"getEnemyInfo": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "获得某个怪物的当前属性数据\n该函数主要是会被伤害计算和怪物手册等使用"
|
||||
"_data": "获得怪物真实属性"
|
||||
},
|
||||
"getDamageInfo": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "获得战斗伤害信息(实际伤害计算函数)"
|
||||
"_data": "获得战斗伤害信息"
|
||||
},
|
||||
"updateEnemys": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "更新怪物数据,可以在这里对怪物属性和数据进行动态更新"
|
||||
"_data": "更新怪物数据"
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -140,18 +128,30 @@ var functions_comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "按键处理;可以在这里自定义快捷键,详见文档-个性化-自定义快捷键"
|
||||
"_data": "按键处理"
|
||||
}
|
||||
}
|
||||
},
|
||||
"control": {
|
||||
"_type": "object",
|
||||
"_data": {
|
||||
"saveData": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "存档操作"
|
||||
},
|
||||
"loadData": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "读档操作"
|
||||
},
|
||||
"flyTo": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "使用楼层传送器飞到某层"
|
||||
"_data": "楼层飞行"
|
||||
},
|
||||
"updateStatusBar": {
|
||||
"_leaf": true,
|
||||
@ -163,19 +163,19 @@ var functions_comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "阻激夹域的伤害值计算"
|
||||
"_data": "阻激夹域伤害"
|
||||
},
|
||||
"moveOneStep": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "勇士每走一步的操作"
|
||||
"_data": "每一步后的操作"
|
||||
},
|
||||
"moveDirectly": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "瞬间移动"
|
||||
"_data": "瞬间移动处理"
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -186,19 +186,19 @@ var functions_comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "自定义绘制状态栏。\n当状态栏canvas化开启时,可以在这里对状态栏进行自定义绘制。\n仅当statusCanvas开启时有效。"
|
||||
"_data": "自绘状态栏"
|
||||
},
|
||||
"drawStatistics": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "地图数据统计项的注册"
|
||||
"_data": "地图数据统计"
|
||||
},
|
||||
"drawAbout": {
|
||||
"_leaf": true,
|
||||
"_type": "textarea",
|
||||
"_lint": true,
|
||||
"_data": "绘制“关于”界面"
|
||||
"_data": "绘制关于界面"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -2061,6 +2061,8 @@ actions.prototype._clickStorageRemove = function (x, y) {
|
||||
var selection = y - topIndex;
|
||||
switch (selection) {
|
||||
case 0:
|
||||
if (!confirm("你确定要清除【全部塔】的所有本地存档?\n此行为不可逆!!!"))
|
||||
break;
|
||||
if (core.platform.useLocalForage) {
|
||||
core.ui.drawWaiting("正在清空,请稍后...");
|
||||
localforage.clear(function () {
|
||||
@ -2078,6 +2080,8 @@ actions.prototype._clickStorageRemove = function (x, y) {
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (!confirm("你确定要清除本塔的所有本地存档?\n此行为不可逆!!!"))
|
||||
break;
|
||||
if (core.platform.useLocalForage) {
|
||||
core.ui.drawWaiting("正在清空,请稍后...");
|
||||
Object.keys(core.saves.ids).forEach(function (v) {
|
||||
|
||||
459
libs/control.js
459
libs/control.js
@ -1365,7 +1365,7 @@ control.prototype._replayAction_fly = function (action) {
|
||||
if (!core.canUseItem('fly')) return false;
|
||||
core.ui.drawFly(toIndex);
|
||||
setTimeout(function () {
|
||||
if (!core.control.flyTo(floorId, core.replay))
|
||||
if (!core.flyTo(floorId, core.replay))
|
||||
core.control._replay_error(action);
|
||||
}, core.control.__replay_getTimeout());
|
||||
return true;
|
||||
@ -1450,27 +1450,19 @@ control.prototype._replayAction_key = function (action) {
|
||||
control.prototype.autosave = function (removeLast) {
|
||||
if (core.status.event.id!=null) return;
|
||||
var x=null;
|
||||
if (removeLast)
|
||||
x=core.status.route.pop();
|
||||
if (removeLast) x=core.status.route.pop();
|
||||
core.status.route.push("turn:"+core.getHeroLoc('direction'));
|
||||
// core.setLocalForage("autoSave", core.saveData());
|
||||
// ----- Add to autosaveData
|
||||
core.saves.autosave.data = core.saveData();
|
||||
core.saves.autosave.updated = true;
|
||||
core.saves.ids[0] = true;
|
||||
// ----- Updated every 5s
|
||||
core.status.route.pop();
|
||||
if (removeLast && core.isset(x))
|
||||
core.status.route.push(x);
|
||||
if (x) core.status.route.push(x);
|
||||
}
|
||||
|
||||
/////// 实际进行自动存档 //////
|
||||
control.prototype.checkAutosave = function () {
|
||||
|
||||
if (!core.animateFrame || !core.saves || !core.saves.autosave) return;
|
||||
|
||||
core.setLocalStorage('totalTime', core.animateFrame.totalTime);
|
||||
|
||||
if (core.saves.autosave.data == null || !core.saves.autosave.updated) return;
|
||||
core.saves.autosave.updated = false;
|
||||
core.setLocalForage("autoSave", core.saves.autosave.data);
|
||||
@ -1478,168 +1470,152 @@ control.prototype.checkAutosave = function () {
|
||||
|
||||
////// 实际进行存读档事件 //////
|
||||
control.prototype.doSL = function (id, type) {
|
||||
if (type=='save') {
|
||||
if (id=='autoSave') {
|
||||
core.drawTip('不能覆盖自动存档!');
|
||||
return;
|
||||
}
|
||||
// 事件中的存档
|
||||
if (core.status.event.interval != null) {
|
||||
core.setFlag("__events__", core.status.event.interval);
|
||||
}
|
||||
core.setLocalForage("save"+id, core.saveData(), function() {
|
||||
if (id!="autoSave") {
|
||||
core.saves.saveIndex=id;
|
||||
core.setLocalStorage('saveIndex', core.saves.saveIndex);
|
||||
}
|
||||
if (core.events.recoverEvents(core.status.event.interval)) {
|
||||
core.drawTip("存档成功!");
|
||||
return;
|
||||
}
|
||||
switch (type) {
|
||||
case 'save': this._doSL_save(id); break;
|
||||
case 'load': this._doSL_load(id); break;
|
||||
case 'replayLoad': this._doSL_replayLoad(id); break;
|
||||
}
|
||||
}
|
||||
|
||||
control.prototype._doSL_save = function (id) {
|
||||
if (id=='autoSave') return core.drawTip('不能覆盖自动存档!');
|
||||
// 在事件中的存档
|
||||
if (core.status.event.interval != null)
|
||||
core.setFlag("__events__", core.status.event.interval);
|
||||
core.setLocalForage("save"+id, core.saveData(), function() {
|
||||
core.saves.saveIndex=id;
|
||||
core.setLocalStorage('saveIndex', core.saves.saveIndex);
|
||||
// 恢复事件
|
||||
if (!core.events.recoverEvents(core.status.event.interval))
|
||||
core.ui.closePanel();
|
||||
core.drawTip('存档成功!');
|
||||
core.drawTip('存档成功!');
|
||||
}, function(err) {
|
||||
main.log(err);
|
||||
if (core.platform.useLocalForage) {
|
||||
alert("存档失败,错误信息:\n"+err);
|
||||
}
|
||||
else {
|
||||
alert("存档失败,错误信息:\n"+err+"\n建议使用垃圾存档清理工具进行清理!");
|
||||
}
|
||||
});
|
||||
core.removeFlag("__events__");
|
||||
return;
|
||||
}
|
||||
|
||||
control.prototype._doSL_load = function (id) {
|
||||
if (id == 'autoSave' && core.saves.autosave.data != null) {
|
||||
this._doSL_load_afterGet(id, core.clone(core.saves.autosave.data));
|
||||
}
|
||||
else {
|
||||
core.getLocalForage(id=='autoSave'?id:"save"+id, null, function(data) {
|
||||
if (id == 'autoSave') core.saves.autosave.data = core.clone(data);
|
||||
core.control._doSL_load_afterGet(id, data);
|
||||
}, function(err) {
|
||||
console.info(err);
|
||||
if (core.platform.useLocalForage) {
|
||||
alert("存档失败,错误信息:\n"+err);
|
||||
}
|
||||
else {
|
||||
alert("存档失败,错误信息:\n"+err+"\n建议使用垃圾存档清理工具进行清理!");
|
||||
}
|
||||
});
|
||||
core.removeFlag("__events__");
|
||||
main.log(err);
|
||||
alert("无效的存档");
|
||||
})
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
control.prototype._doSL_load_afterGet = function (id, data) {
|
||||
if (!data) return alert("无效的存档");
|
||||
if (core.flags.checkConsole && data.hashCode != null && data.hashCode != core.hashCode(data.hero)) {
|
||||
if (confirm("存档校验失败,请勿修改存档文件!\n你想回放此存档的录像吗?"))
|
||||
core.startGame(data.hard, data.hero.flags.__seed__, core.decodeRoute(data.route));
|
||||
return;
|
||||
}
|
||||
else if (type=='load') {
|
||||
var afterGet = function (data) {
|
||||
if (!core.isset(data)) {
|
||||
alert("无效的存档");
|
||||
return;
|
||||
}
|
||||
if (core.flags.checkConsole && core.isset(data.hashCode) && data.hashCode != core.utils.hashCode(data.hero)) {
|
||||
if (confirm("存档校验失败,请勿修改存档文件!\n你想回放此存档的录像吗?")) {
|
||||
core.startGame(data.hard, data.hero.flags.__seed__, core.decodeRoute(data.route));
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (data.version != core.firstData.version) {
|
||||
// core.drawTip("存档版本不匹配");
|
||||
if (confirm("存档版本不匹配!\n你想回放此存档的录像吗?\n可以随时停止录像播放以继续游戏。")) {
|
||||
core.startGame(data.hard, data.hero.flags.__seed__, core.decodeRoute(data.route));
|
||||
}
|
||||
return;
|
||||
}
|
||||
core.ui.closePanel();
|
||||
core.loadData(data, function() {
|
||||
core.drawTip("读档成功");
|
||||
if (id!="autoSave") {
|
||||
core.saves.saveIndex=id;
|
||||
core.setLocalStorage('saveIndex', core.saves.saveIndex);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (id == 'autoSave' && core.saves.autosave.data != null) {
|
||||
afterGet(core.clone(core.saves.autosave.data));
|
||||
}
|
||||
else {
|
||||
core.getLocalForage(id=='autoSave'?id:"save"+id, null, function(data) {
|
||||
if (id == 'autoSave') core.saves.autosave.data = core.clone(data);
|
||||
afterGet(data);
|
||||
}, function(err) {
|
||||
main.log(err);
|
||||
alert("无效的存档");
|
||||
})
|
||||
}
|
||||
if (data.version != core.firstData.version) {
|
||||
if (confirm("存档版本不匹配!\n你想回放此存档的录像吗?\n可以随时停止录像播放以继续游戏。"))
|
||||
core.startGame(data.hard, data.hero.flags.__seed__, core.decodeRoute(data.route));
|
||||
return;
|
||||
}
|
||||
else if (type == 'replayLoad') {
|
||||
var afterGet = function (data) {
|
||||
if (!core.isset(data)) {
|
||||
core.drawTip("无效的存档");
|
||||
return;
|
||||
}
|
||||
if (data.version != core.firstData.version) {
|
||||
core.drawTip("存档版本不匹配");
|
||||
return;
|
||||
}
|
||||
if (data.hard != core.status.hard) {
|
||||
core.drawTip("游戏难度不匹配!");
|
||||
return;
|
||||
}
|
||||
if (core.isset(data.hashCode) && data.hashCode != core.utils.hashCode(data.hero)) {
|
||||
alert("存档校验失败,请勿修改存档文件!");
|
||||
return;
|
||||
}
|
||||
var route = core.subarray(core.status.route, core.decodeRoute(data.route));
|
||||
if (!core.isset(route) || data.hero.flags.__seed__!=core.getFlag('__seed__')) {
|
||||
core.drawTip("无法从此存档回放录像");
|
||||
return;
|
||||
}
|
||||
core.loadData(data, function () {
|
||||
core.startReplay(route);
|
||||
core.drawTip("回退到存档节点");
|
||||
});
|
||||
}
|
||||
if (id == 'autoSave' && core.saves.autosave.data != null) {
|
||||
afterGet(core.clone(core.saves.autosave.data));
|
||||
}
|
||||
else {
|
||||
core.getLocalForage(id=='autoSave'?id:"save"+id, null, function(data) {
|
||||
if (id == 'autoSave') core.saves.autosave.data = core.clone(data);
|
||||
afterGet(data);
|
||||
}, function(err) {
|
||||
main.log(err);
|
||||
alert("无效的存档");
|
||||
})
|
||||
core.ui.closePanel();
|
||||
core.loadData(data, function() {
|
||||
core.drawTip("读档成功");
|
||||
if (id!="autoSave") {
|
||||
core.saves.saveIndex=id;
|
||||
core.setLocalStorage('saveIndex', core.saves.saveIndex);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
control.prototype._doSL_replayLoad = function (id) {
|
||||
if (id == 'autoSave' && core.saves.autosave.data != null) {
|
||||
this._doSL_replayLoad_afterGet(core.clone(core.saves.autosave.data));
|
||||
}
|
||||
else{
|
||||
core.getLocalForage(id=='autoSave'?id:"save"+id, null, function(data) {
|
||||
if (id == 'autoSave') core.saves.autosave.data = core.clone(data);
|
||||
core.control._doSL_replayLoad_afterGet(data);
|
||||
}, function(err) {
|
||||
main.log(err);
|
||||
alert("无效的存档");
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
control.prototype._doSL_replayLoad_afterGet = function (id, data) {
|
||||
if (!data) return core.drawTip("无效的存档");
|
||||
if (data.version != core.firstData.version) return core.drawTip("存档版本不匹配");
|
||||
if (data.hard != core.status.hard) core.drawTip("游戏难度不匹配!");
|
||||
if (data.hashCode != null && data.hashCode != core.utils.hashCode(data.hero))
|
||||
return alert("存档校验失败,请勿修改存档文件!");
|
||||
var route = core.subarray(core.status.route, core.decodeRoute(data.route));
|
||||
if (route == null || data.hero.flags.__seed__ != core.getFlag('__seed__'))
|
||||
return core.drawTip("无法从此存档回放录像");
|
||||
core.loadData(data, function () {
|
||||
core.startReplay(route);
|
||||
core.drawTip("回退到存档节点");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
////// 同步存档到服务器 //////
|
||||
control.prototype.syncSave = function (type) {
|
||||
core.ui.drawWaiting("正在同步,请稍后...");
|
||||
core.control.getSaves(type=='all'?null:core.saves.saveIndex, function (saves) {
|
||||
if (!core.isset(saves)) {
|
||||
core.drawText("没有要同步的存档");
|
||||
return;
|
||||
if (!saves) return core.drawText("没有要同步的存档");
|
||||
core.control._syncSave_http(saves);
|
||||
})
|
||||
}
|
||||
|
||||
control.prototype._syncSave_http = function (saves) {
|
||||
var formData = new FormData();
|
||||
formData.append('type', 'save');
|
||||
formData.append('name', core.firstData.name);
|
||||
formData.append('data', JSON.stringify(saves));
|
||||
|
||||
core.http("POST", "/games/sync.php", formData, function (data) {
|
||||
var response = JSON.parse(data);
|
||||
if (response.code<0) {
|
||||
core.drawText("出错啦!\n无法同步存档到服务器。\n错误原因:"+response.msg);
|
||||
}
|
||||
|
||||
var formData = new FormData();
|
||||
formData.append('type', 'save');
|
||||
formData.append('name', core.firstData.name);
|
||||
var save_text = JSON.stringify(saves);
|
||||
formData.append('data', save_text);
|
||||
|
||||
core.http("POST", "/games/sync.php", formData, function (data) {
|
||||
var response = JSON.parse(data);
|
||||
if (response.code<0) {
|
||||
core.drawText("出错啦!\n无法同步存档到服务器。\n错误原因:"+response.msg);
|
||||
}
|
||||
else {
|
||||
core.drawText((type=='all'?"所有存档":"存档"+core.saves.saveIndex)+"同步成功!\n\n您的存档编号: "
|
||||
+response.code+"\n您的存档密码: "+response.msg
|
||||
+"\n\n请牢记以上两个信息(如截图等),在从服务器\n同步存档时使用。")
|
||||
}
|
||||
}, function (e) {
|
||||
core.drawText("出错啦!\n无法同步存档到服务器。\n错误原因:"+e);
|
||||
})
|
||||
else {
|
||||
core.drawText((type=='all'?"所有存档":"存档"+core.saves.saveIndex)+"同步成功!\n\n您的存档编号: "
|
||||
+response.code+"\n您的存档密码: "+response.msg
|
||||
+"\n\n请牢记以上两个信息(如截图等),在从服务器\n同步存档时使用。")
|
||||
}
|
||||
}, function (e) {
|
||||
core.drawText("出错啦!\n无法同步存档到服务器。\n错误原因:"+e);
|
||||
})
|
||||
}
|
||||
|
||||
////// 从服务器加载存档 //////
|
||||
control.prototype.syncLoad = function () {
|
||||
core.interval.onDownInterval = 'tmp';
|
||||
var id = prompt("请输入存档编号:");
|
||||
if (id==null || id=="") {
|
||||
core.ui.drawSyncSave(); return;
|
||||
}
|
||||
var id = prompt("请输入存档编号:") || "";
|
||||
if (id=="") return core.ui.drawSyncSave();
|
||||
core.interval.onDownInterval = 'tmp';
|
||||
var password = prompt("请输入存档密码:");
|
||||
if (password==null || password=="") {
|
||||
core.ui.drawSyncSave(); return;
|
||||
}
|
||||
core.ui.drawWaiting("正在同步,请稍后...");
|
||||
var password = prompt("请输入存档密码:") || "";
|
||||
if (password=="") return core.ui.drawSyncSave();
|
||||
|
||||
core.ui.drawWaiting("正在同步,请稍后...");
|
||||
this._syncLoad_http(id, password);
|
||||
}
|
||||
|
||||
control.prototype._syncLoad_http = function (id, password) {
|
||||
var formData = new FormData();
|
||||
formData.append('type', 'load');
|
||||
formData.append('name', core.firstData.name);
|
||||
@ -1648,141 +1624,67 @@ control.prototype.syncLoad = function () {
|
||||
|
||||
core.http("POST", "/games/sync.php", formData, function (data) {
|
||||
var response = JSON.parse(data);
|
||||
switch (response.code) {
|
||||
case 0:
|
||||
// 成功
|
||||
var data=JSON.parse(response.msg);
|
||||
if (data instanceof Array) {
|
||||
core.status.event.selection=1;
|
||||
core.ui.drawConfirmBox("所有本地存档都将被覆盖,确认?", function () {
|
||||
for (var i=1;i<=5*(main.savePages||30);i++) {
|
||||
if (i<=data.length) {
|
||||
// core.setLocalStorage("save"+i, data[i-1]);
|
||||
core.setLocalForage("save"+i, data[i-1]);
|
||||
}
|
||||
else {
|
||||
if (core.saves.ids[i])
|
||||
core.removeLocalForage("save"+i);
|
||||
}
|
||||
}
|
||||
core.ui.closePanel();
|
||||
core.drawText("同步成功!\n你的本地所有存档均已被覆盖。");
|
||||
}, function () {
|
||||
core.status.event.selection=0;
|
||||
core.ui.drawSyncSave();
|
||||
})
|
||||
}
|
||||
else {
|
||||
// 只覆盖单存档
|
||||
core.setLocalForage("save"+core.saves.saveIndex, data, function() {
|
||||
core.drawText("同步成功!\n单存档已覆盖至存档"+core.saves.saveIndex);
|
||||
});
|
||||
}
|
||||
break;
|
||||
case -1:
|
||||
core.drawText("出错啦!\n存档编号"+id+"不存在!");
|
||||
break;
|
||||
case -2:
|
||||
core.drawText("出错啦!\n存档密码错误!");
|
||||
break;
|
||||
default:
|
||||
core.drawText("出错啦!\n无法从服务器同步存档。\n错误原因:"+response.msg);
|
||||
break;
|
||||
if (response.code == 0) {
|
||||
core.control._syncLoad_write(JSON.parse(response.msg));
|
||||
}
|
||||
else {
|
||||
core.drawText("出错啦!\n无法从服务器同步存档。\n错误原因:"+response.msg);
|
||||
}
|
||||
}, function (e) {
|
||||
core.drawText("出错啦!\n无法从服务器同步存档。\n错误原因:"+e);
|
||||
});
|
||||
}
|
||||
|
||||
control.prototype._syncLoad_write = function (data) {
|
||||
if (data instanceof Array) {
|
||||
core.status.event.selection=1;
|
||||
core.ui.drawConfirmBox("所有本地存档都将被覆盖,确认?", function () {
|
||||
for (var i=1;i<=5*(main.savePages||30);i++) {
|
||||
if (i<=data.length)
|
||||
core.setLocalForage("save"+i, data[i-1]);
|
||||
else if (core.saves.ids[i])
|
||||
core.removeLocalForage("save"+i);
|
||||
}
|
||||
core.ui.closePanel();
|
||||
core.drawText("同步成功!\n你的本地所有存档均已被覆盖。");
|
||||
}, function () {
|
||||
core.status.event.selection=0;
|
||||
core.ui.drawSyncSave();
|
||||
});
|
||||
}
|
||||
else {
|
||||
// 只覆盖单存档
|
||||
core.setLocalForage("save"+core.saves.saveIndex, data, function() {
|
||||
core.drawText("同步成功!\n单存档已覆盖至存档"+core.saves.saveIndex);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
////// 存档到本地 //////
|
||||
control.prototype.saveData = function() {
|
||||
var hero = core.clone(core.status.hero);
|
||||
var hashCode = core.utils.hashCode(hero);
|
||||
|
||||
var data = {
|
||||
'floorId': core.status.floorId,
|
||||
'hero': hero,
|
||||
'hard': core.status.hard,
|
||||
'maps': core.maps.saveMap(),
|
||||
'route': core.encodeRoute(core.status.route),
|
||||
'values': core.clone(core.values),
|
||||
'shops': {},
|
||||
'version': core.firstData.version,
|
||||
"time": new Date().getTime(),
|
||||
"hashCode": hashCode
|
||||
};
|
||||
// set shop times
|
||||
for (var shop in core.status.shops) {
|
||||
data.shops[shop]={
|
||||
'times': core.status.shops[shop].times || 0,
|
||||
'visited': core.status.shops[shop].visited || false
|
||||
}
|
||||
}
|
||||
core.events.beforeSaveData(data);
|
||||
|
||||
return data;
|
||||
return this.controldata.saveData();
|
||||
}
|
||||
|
||||
////// 从本地读档 //////
|
||||
control.prototype.loadData = function (data, callback) {
|
||||
|
||||
core.resetGame(data.hero, data.hard, data.floorId, core.maps.loadMap(data.maps), data.values);
|
||||
core.status.route = core.decodeRoute(data.route);
|
||||
|
||||
// load shop times
|
||||
for (var shop in core.status.shops) {
|
||||
if (core.isset(data.shops[shop])) {
|
||||
core.status.shops[shop].times = data.shops[shop].times;
|
||||
core.status.shops[shop].visited = data.shops[shop].visited;
|
||||
}
|
||||
}
|
||||
|
||||
core.status.textAttribute = core.getFlag('textAttribute', core.status.textAttribute);
|
||||
var toAttribute = core.getFlag('globalAttribute', core.status.globalAttribute);
|
||||
// if (core.utils.hashCode(toAttribute) != core.utils.hashCode(core.status.globalAttribute)) {
|
||||
if (!core.same(toAttribute, core.status.globalAttribute)) {
|
||||
core.status.globalAttribute = toAttribute;
|
||||
core.control.updateGlobalAttribute(Object.keys(toAttribute));
|
||||
}
|
||||
|
||||
// 重置音量
|
||||
core.events.setVolume(core.getFlag("__volume__", 1), 0);
|
||||
|
||||
// load icons
|
||||
var icon = core.getFlag("heroIcon", "hero.png");
|
||||
if (core.isset(core.material.images.images[icon])) {
|
||||
core.material.images.hero.src = core.material.images.images[icon].src;
|
||||
core.material.icons.hero.height = core.material.images.images[icon].height/4;
|
||||
}
|
||||
|
||||
core.events.afterLoadData(data);
|
||||
|
||||
core.changeFloor(data.floorId, null, data.hero.loc, 0, function() {
|
||||
if (core.isset(callback)) callback();
|
||||
}, true);
|
||||
return this.controldata.loadData(data, callback);
|
||||
}
|
||||
|
||||
control.prototype.getSaves = function (index, callback) {
|
||||
if (core.isset(index)) {
|
||||
if (index != null) {
|
||||
core.getLocalForage("save"+index, null, function(data) {
|
||||
if (core.isset(callback)) callback(data);
|
||||
if (callback) callback(data);
|
||||
}, function(err) {
|
||||
main.log(err);
|
||||
if (core.isset(callback))
|
||||
callback(null);
|
||||
if (callback) callback(null);
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
var ids = Object.keys(core.saves.ids).filter(function(x){return x!=0;})
|
||||
.sort(function(a,b) {return a-b;}), number = ids.length;
|
||||
|
||||
// 不计0
|
||||
var saves = [];
|
||||
|
||||
.sort(function(a,b) {return a-b;}), number = ids.length, saves = [];
|
||||
var load = function (index, callback) {
|
||||
if (index > number) {
|
||||
if (core.isset(callback)) callback(saves);
|
||||
if (callback) callback(saves);
|
||||
return;
|
||||
}
|
||||
core.getLocalForage("save"+ids[index], null, function (data) {
|
||||
@ -1799,33 +1701,32 @@ control.prototype.getSaves = function (index, callback) {
|
||||
////// 获得所有存在存档的存档位 //////
|
||||
control.prototype.getSaveIndexes = function (callback) {
|
||||
var indexes = {};
|
||||
|
||||
var getIndex = function (name) {
|
||||
var e = new RegExp('^'+core.firstData.name+"_(save\\d+|autoSave)$").exec(name);
|
||||
if (e!=null) {
|
||||
if (e[1]=='autoSave') indexes[0]=true;
|
||||
else indexes[parseInt(e[1].substring(4))] = true;
|
||||
}
|
||||
};
|
||||
|
||||
if (!core.platform.useLocalForage) {
|
||||
if (core.platform.useLocalForage) {
|
||||
localforage.iterate(function (value, key, n) {
|
||||
core.control._getSaveIndexes_getIndex(indexes, key);
|
||||
}, function () {
|
||||
callback(indexes);
|
||||
});
|
||||
}
|
||||
else {
|
||||
Object.keys(localStorage).forEach(function (key) {
|
||||
getIndex(key);
|
||||
core.control._getSaveIndexes_getIndex(indexes, key);
|
||||
});
|
||||
callback(indexes);
|
||||
}
|
||||
else {
|
||||
localforage.iterate(function (value, key, n) {
|
||||
getIndex(key)
|
||||
}, function () {
|
||||
callback(indexes);
|
||||
})
|
||||
}
|
||||
|
||||
control.prototype._getSaveIndexes_getIndex = function (indexes, name) {
|
||||
var e = new RegExp('^'+core.firstData.name+"_(save\\d+|autoSave)$").exec(name);
|
||||
if (e) {
|
||||
if (e[1]=='autoSave') indexes[0]=true;
|
||||
else indexes[parseInt(e[1].substring(4))] = true;
|
||||
}
|
||||
}
|
||||
|
||||
////// 判断某个存档位是否存在存档 //////
|
||||
control.prototype.hasSave = function (index) {
|
||||
return core.saves.ids[index]||false;
|
||||
return core.saves.ids[index] || false;
|
||||
}
|
||||
|
||||
// ------ 属性,状态,位置,buff,变量,锁定控制等 ------ //
|
||||
|
||||
@ -2157,16 +2157,6 @@ events.prototype.afterUseBomb = function () {
|
||||
return this.eventdata.afterUseBomb();
|
||||
}
|
||||
|
||||
////// 即将存档前可以执行的操作 //////
|
||||
events.prototype.beforeSaveData = function (data) {
|
||||
return this.eventdata.beforeSaveData(data);
|
||||
}
|
||||
|
||||
////// 读档事件后,载入事件前,可以执行的操作 //////
|
||||
events.prototype.afterLoadData = function (data) {
|
||||
return this.eventdata.afterLoadData(data);
|
||||
}
|
||||
|
||||
////// 上传当前数据 //////
|
||||
events.prototype.uploadCurrent = function (username) {
|
||||
var formData = new FormData();
|
||||
|
||||
@ -63,7 +63,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
|
||||
// 设置已经到过的楼层
|
||||
core.setFlag("__visited__", {});
|
||||
|
||||
core.events.afterLoadData();
|
||||
core.updateEnemys();
|
||||
},
|
||||
"win": function(reason, norank) {
|
||||
// 游戏获胜事件
|
||||
@ -401,16 +401,6 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
|
||||
}
|
||||
*/
|
||||
|
||||
},
|
||||
"beforeSaveData": function(data) {
|
||||
// 即将存档前可以执行的操作
|
||||
|
||||
},
|
||||
"afterLoadData": function(data) {
|
||||
// 读档事件后,载入事件前,可以执行的操作
|
||||
// 怪物数据的动态修改迁移到了“脚本编辑 - updateEnemys”中,详见文档说明
|
||||
|
||||
core.enemys.updateEnemys();
|
||||
},
|
||||
"canUseQuickShop": function(shopId) {
|
||||
// 当前能否使用某个快捷商店
|
||||
@ -719,6 +709,8 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
|
||||
},
|
||||
"updateEnemys": function () {
|
||||
// 更新怪物数据,可以在这里对怪物属性和数据进行动态更新,详见文档——事件——怪物数据的动态修改
|
||||
// 此函数执行时间:重新开始游戏、读档后、通过事件调用“更新怪物数据”时
|
||||
|
||||
// 比如下面这个例子,如果flag:xxx为真,则将绿头怪的攻击设为100,金币设为20
|
||||
/*
|
||||
if (core.hasFlag('xxx')) {
|
||||
@ -726,7 +718,6 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
|
||||
core.material.enemys.greenSlime.money = 20;
|
||||
}
|
||||
*/
|
||||
// 别忘了在事件中调用“更新怪物数据”事件!
|
||||
}
|
||||
},
|
||||
"actions": {
|
||||
@ -895,6 +886,78 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
|
||||
}
|
||||
},
|
||||
"control": {
|
||||
"saveData": function () {
|
||||
// 存档操作,此函数应该返回“具体要存档的内容”
|
||||
|
||||
// 勇士和hash值(防改存档文件来作弊)
|
||||
var hero = core.clone(core.status.hero),
|
||||
hashCode = core.utils.hashCode(hero);
|
||||
// 差异化存储values
|
||||
var values = {};
|
||||
for (var key in core.values) {
|
||||
if (!core.same(core.values[key], core.data.values[key]))
|
||||
values[key] = core.clone(core.values[key]);
|
||||
}
|
||||
|
||||
// 要存档的内容
|
||||
var data = {
|
||||
'floorId': core.status.floorId,
|
||||
'hero': hero,
|
||||
'hard': core.status.hard,
|
||||
'maps': core.maps.saveMap(),
|
||||
'route': core.encodeRoute(core.status.route),
|
||||
'values': values,
|
||||
'shops': {},
|
||||
'version': core.firstData.version,
|
||||
"time": new Date().getTime(),
|
||||
"hashCode": hashCode
|
||||
};
|
||||
// 设置商店次数
|
||||
for (var shopId in core.status.shops) {
|
||||
data.shops[shopId] = {
|
||||
'times': core.status.shops[shopId].times || 0,
|
||||
'visited': core.status.shops[shopId].visited || false
|
||||
};
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
"loadData": function (data, callback) {
|
||||
// 读档操作;从存储中读取了内容后的行为
|
||||
|
||||
// 重置游戏和路线
|
||||
core.resetGame(data.hero, data.hard, data.floorId, core.maps.loadMap(data.maps), data.values);
|
||||
core.status.route = core.decodeRoute(data.route);
|
||||
// 加载商店信息
|
||||
for (var shopId in core.status.shops) {
|
||||
if (data.shops[shopId]) {
|
||||
core.status.shops[shopId].times = data.shops[shopId].times;
|
||||
core.status.shops[shopId].visited = data.shops[shopId].visited;
|
||||
}
|
||||
}
|
||||
// 文字属性,全局属性
|
||||
core.status.textAttribute = core.getFlag('textAttribute', core.status.textAttribute);
|
||||
var toAttribute = core.getFlag('globalAttribute', core.status.globalAttribute);
|
||||
if (!core.same(toAttribute, core.status.globalAttribute)) {
|
||||
core.status.globalAttribute = toAttribute;
|
||||
core.control.updateGlobalAttribute(Object.keys(toAttribute));
|
||||
}
|
||||
// 重置音量
|
||||
core.events.setVolume(core.getFlag("__volume__", 1), 0);
|
||||
// 加载勇士图标
|
||||
var icon = core.getFlag("heroIcon", "hero.png");
|
||||
if (core.material.images.images[icon]) {
|
||||
core.material.images.hero.src = core.material.images.images[icon].src;
|
||||
core.material.icons.hero.height = core.material.images.images[icon].height / 4;
|
||||
}
|
||||
// 刷新怪物数据
|
||||
core.updateEnemys();
|
||||
|
||||
// TODO:增加自己的一些读档处理
|
||||
|
||||
// 切换到对应的楼层
|
||||
core.changeFloor(data.floorId, null, data.hero.loc, 0, callback, true);
|
||||
},
|
||||
"flyTo": function (toId, callback) {
|
||||
// 楼层传送器的使用,从当前楼层飞往toId
|
||||
// 如果不能飞行请返回false
|
||||
|
||||
Loading…
Reference in New Issue
Block a user