getLocalForage defaultValue
This commit is contained in:
parent
740b3bffc9
commit
03deefde2a
@ -2203,25 +2203,12 @@ control.prototype.doSL = function (id, type) {
|
||||
console.info(err);
|
||||
core.drawTip("存档失败,请将控制台的报错信息反馈给管理员。");
|
||||
})
|
||||
/*
|
||||
if (core.setLocalStorage("save"+id, core.saveData())) {
|
||||
core.ui.closePanel();
|
||||
core.drawTip('存档成功!');
|
||||
if (id!="autoSave") {
|
||||
core.status.saveIndex=id;
|
||||
core.setLocalStorage('saveIndex2', core.status.saveIndex);
|
||||
}
|
||||
}
|
||||
else {
|
||||
core.drawTip('存储空间不足,请覆盖已有的存档或在菜单栏中进行清理');
|
||||
}
|
||||
*/
|
||||
return;
|
||||
}
|
||||
else if (type=='load') {
|
||||
// var data = core.getLocalStorage(id=='autoSave'?id:"save"+id, null);
|
||||
|
||||
core.getLocalForage(id=='autoSave'?id:"save"+id, function(data) {
|
||||
core.getLocalForage(id=='autoSave'?id:"save"+id, null, function(data) {
|
||||
if (!core.isset(data)) {
|
||||
core.drawTip("无效的存档");
|
||||
return;
|
||||
@ -2250,6 +2237,7 @@ control.prototype.doSL = function (id, type) {
|
||||
}
|
||||
});
|
||||
}, function(err) {
|
||||
console.log(err);
|
||||
core.drawTip("无效的存档");
|
||||
})
|
||||
|
||||
@ -2257,7 +2245,7 @@ control.prototype.doSL = function (id, type) {
|
||||
}
|
||||
else if (type == 'replayLoad') {
|
||||
// var data = core.getLocalStorage(id=='autoSave'?id:"save"+id, null);
|
||||
core.getLocalForage(id=='autoSave'?id:"save"+id, function(data) {
|
||||
core.getLocalForage(id=='autoSave'?id:"save"+id, null, function(data) {
|
||||
if (!core.isset(data)) {
|
||||
core.drawTip("无效的存档");
|
||||
return;
|
||||
@ -2280,7 +2268,7 @@ control.prototype.doSL = function (id, type) {
|
||||
core.drawTip("回退到存档节点");
|
||||
});
|
||||
}, function(err) {
|
||||
console.info(err);
|
||||
console.log(err);
|
||||
core.drawTip("无效的存档");
|
||||
})
|
||||
}
|
||||
@ -2442,9 +2430,10 @@ control.prototype.loadData = function (data, callback) {
|
||||
|
||||
control.prototype.getSaves = function (index, callback) {
|
||||
if (core.isset(index)) {
|
||||
core.getLocalForage("save"+index, function(data) {
|
||||
core.getLocalForage("save"+index, null, function(data) {
|
||||
if (core.isset(callback)) callback(data);
|
||||
}, function(err) {
|
||||
console.log(err);
|
||||
if (core.isset(callback))
|
||||
callback(null);
|
||||
})
|
||||
@ -2457,11 +2446,11 @@ control.prototype.getSaves = function (index, callback) {
|
||||
if (core.isset(callback)) callback(saves);
|
||||
return;
|
||||
}
|
||||
core.getLocalForage("save"+index, function (data) {
|
||||
core.getLocalForage("save"+index, null, function (data) {
|
||||
saves.push(data);
|
||||
load(index+1, callback);
|
||||
}, function(err) {
|
||||
// saves.push(null);
|
||||
console.log(err);
|
||||
load(index+1, callback);
|
||||
})
|
||||
}
|
||||
|
||||
@ -901,8 +901,8 @@ core.prototype.setLocalForage = function (key, value, successCallback, errorCall
|
||||
core.utils.setLocalForage(key, value, successCallback, errorCallback);
|
||||
}
|
||||
|
||||
core.prototype.getLocalForage = function (key, successCallback, errorCallback) {
|
||||
core.utils.getLocalForage(key, successCallback, errorCallback);
|
||||
core.prototype.getLocalForage = function (key, defaultValue, successCallback, errorCallback) {
|
||||
core.utils.getLocalForage(key, defaultValue, successCallback, errorCallback);
|
||||
}
|
||||
|
||||
core.prototype.removeLocalForage = function (key, successCallback, errorCallback) {
|
||||
|
||||
@ -1783,11 +1783,10 @@ ui.prototype.drawSLPanel = function(index, refresh) {
|
||||
};
|
||||
|
||||
var drawSave = function (i) {
|
||||
|
||||
core.getLocalForage(i==0?"autoSave":"save"+(5*page+i), function(data) {
|
||||
core.getLocalForage(i==0?"autoSave":"save"+(5*page+i), null, function(data) {
|
||||
draw(data, i);
|
||||
}, function(err) {
|
||||
draw(null, i);
|
||||
console.log(err);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -135,7 +135,7 @@ utils.prototype.setLocalForage = function (key, value, successCallback, errorCal
|
||||
});
|
||||
}
|
||||
|
||||
utils.prototype.getLocalForage = function (key, successCallback, errorCallback) {
|
||||
utils.prototype.getLocalForage = function (key, defaultValue, successCallback, errorCallback) {
|
||||
localforage.getItem(core.firstData.name+"_"+key, function (err, value) {
|
||||
if (core.isset(err)) {
|
||||
if (core.isset(errorCallback)) errorCallback(err);
|
||||
@ -155,7 +155,8 @@ utils.prototype.getLocalForage = function (key, successCallback, errorCallback)
|
||||
successCallback(JSON.parse(value));
|
||||
return;
|
||||
}
|
||||
if (core.isset(errorCallback)) errorCallback("Value is null");
|
||||
if (core.isset(successCallback))
|
||||
successCallback(defaultValue);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user