This commit is contained in:
libccy 2017-04-14 12:00:49 +08:00
parent f58b92aa6b
commit 16c458793f
1 changed files with 63 additions and 26 deletions

View File

@ -792,7 +792,7 @@
if(name.indexOf('.')!=-1){ if(name.indexOf('.')!=-1){
name=name.slice(0,name.indexOf('.')); name=name.slice(0,name.indexOf('.'));
} }
var link='custom_'+name; var link=(game.writeFile?'cdv_':'custom_')+name;
if(item[link]){ if(item[link]){
for(var i=1;i<1000;i++){ for(var i=1;i<1000;i++){
if(!item[link+'_'+i]){ if(!item[link+'_'+i]){
@ -801,12 +801,18 @@
} }
} }
item[link]=name; item[link]=name;
game.putDB('image',link,file,function(){ var callback=function(){
create(link); create(link,node.parentNode.defaultNode);
node.parentNode.updateBr(); node.parentNode.updateBr();
lib.config.customBackgroundPack.add(link); lib.config.customBackgroundPack.add(link);
game.saveConfig('customBackgroundPack',lib.config.customBackgroundPack); game.saveConfig('customBackgroundPack',lib.config.customBackgroundPack);
}); };
if(game.writeFile){
game.writeFile(file,'image/background',link+'.jpg',callback);
}
else{
game.putDB('image',link,file,callback);
}
if(node.lastChild.classList.contains('active')){ if(node.lastChild.classList.contains('active')){
editbg.call(node.lastChild); editbg.call(node.lastChild);
} }
@ -821,7 +827,7 @@
if(link&&link!='default'){ if(link&&link!='default'){
var str; var str;
if(this.classList.contains('active')){ if(this.classList.contains('active')){
if(link.indexOf('custom_')==0){ if(link.indexOf('custom_')==0||link.indexOf('cdv_')==0){
str='删除背景'; str='删除背景';
} }
else{ else{
@ -862,6 +868,9 @@
fileReader.readAsDataURL(fileToLoad, "UTF-8"); fileReader.readAsDataURL(fileToLoad, "UTF-8");
}); });
} }
else{
node.parentNode.defaultNode=node;
}
} }
else{ else{
node.setBackgroundImage('image/background/'+link+'.jpg'); node.setBackgroundImage('image/background/'+link+'.jpg');
@ -898,7 +907,12 @@
menu.updateBr(); menu.updateBr();
lib.config.customBackgroundPack.remove(background); lib.config.customBackgroundPack.remove(background);
game.saveConfig('customBackgroundPack',lib.config.customBackgroundPack); game.saveConfig('customBackgroundPack',lib.config.customBackgroundPack);
if(background.indexOf('cdv_')==0){
game.removeFile('image/background/'+background+'.jpg');
}
else{
game.deleteDB('image',background); game.deleteDB('image',background);
}
delete lib.configMenu.appearence.config.image_background.item[background]; delete lib.configMenu.appearence.config.image_background.item[background];
if(lib.config.image_background==background){ if(lib.config.image_background==background){
background='default'; background='default';
@ -5910,6 +5924,25 @@
},onerror); },onerror);
},onerror); },onerror);
}; };
game.writeFile=function(data,path,name,callback){
if(Object.prototype.toString.call(data)=='[object File]'){
var fileReader = new FileReader();
fileReader.onload = function(e){
game.writeFile(e.target.result,path,name,callback);
};
fileReader.readAsArrayBuffer(data, "UTF-8");
}
else{
window.resolveLocalFileSystemURL(lib.assetURL+path,function(entry){
entry.getFile(name,{create:true},function(fileEntry){
fileEntry.createWriter(function(fileWriter){
fileWriter.onwriteend=callback;
fileWriter.write(data);
});
});
});
}
};
game.removeFile=function(dir,callback){ game.removeFile=function(dir,callback){
window.resolveLocalFileSystemURL(lib.assetURL,function(entry){ window.resolveLocalFileSystemURL(lib.assetURL,function(entry){
entry.getFile(dir,{},function(fileEntry){ entry.getFile(dir,{},function(fileEntry){
@ -6068,6 +6101,21 @@
} }
}); });
}; };
game.writeFile=function(data,path,name,callback){
if(Object.prototype.toString.call(data)=='[object File]'){
var fileReader = new FileReader();
fileReader.onload = function(e){
game.writeFile(e.target.result,path,name,callback);
};
fileReader.readAsArrayBuffer(data, "UTF-8");
}
else{
get.zip(function(zip){
zip.file('i',data);
lib.node.fs.writeFile(__dirname+'/'+path+'/'+name,zip.files.i.asNodeBuffer(),null,callback);
});
}
};
game.removeFile=function(filename,callback){ game.removeFile=function(filename,callback){
lib.node.fs.unlink(__dirname+'/'+filename); lib.node.fs.unlink(__dirname+'/'+filename);
}; };
@ -6241,7 +6289,7 @@
} }
for(var i=0;i<lib.config.customBackgroundPack.length;i++){ for(var i=0;i<lib.config.customBackgroundPack.length;i++){
var link=lib.config.customBackgroundPack[i]; var link=lib.config.customBackgroundPack[i];
lib.configMenu.appearence.config.image_background.item[link]=link.slice(7); lib.configMenu.appearence.config.image_background.item[link]=link.slice(link.indexOf('_')+1);
} }
lib.configMenu.appearence.config.image_background.item.default='默认'; lib.configMenu.appearence.config.image_background.item.default='默认';
} }
@ -26832,11 +26880,16 @@
var updateVisual=function(){ var updateVisual=function(){
config.visualMenu(this,this._link,config.item[this._link],config); config.visualMenu(this,this._link,config.item[this._link],config);
}; };
var createNode=function(i){ var createNode=function(i,before){
var visualMenu=ui.create.div(); var visualMenu=ui.create.div();
if(config.visualBar){ if(config.visualBar){
if(before){
node._link.menu.insertBefore(visualMenu,before);
}
else{
node._link.menu.insertBefore(visualMenu,node._link.menu.lastChild); node._link.menu.insertBefore(visualMenu,node._link.menu.lastChild);
} }
}
else{ else{
node._link.menu.appendChild(visualMenu); node._link.menu.appendChild(visualMenu);
} }
@ -28194,23 +28247,7 @@
if(fileToLoad){ if(fileToLoad){
var fileReader = new FileReader(); var fileReader = new FileReader();
fileReader.onload = function(e){ fileReader.onload = function(e){
if(lib.node&&lib.node.fs){ game.writeFile(e.target.result,path,fileToLoad.name,refresh);
get.zip(function(zip){
zip.file('i',e.target.result);
lib.node.fs.writeFile(__dirname+'/'+path+'/'+fileToLoad.name,zip.files.i.asNodeBuffer(),null,refresh);
});
}
else{
game.print(lib.assetURL+path);
window.resolveLocalFileSystemURL(lib.assetURL+path,function(entry){
entry.getFile(fileToLoad.name,{create:true},function(fileEntry){
fileEntry.createWriter(function(fileWriter){
fileWriter.onwriteend=refresh;
fileWriter.write(e.target.result);
});
});
});
}
}; };
fileReader.readAsArrayBuffer(fileToLoad, "UTF-8"); fileReader.readAsArrayBuffer(fileToLoad, "UTF-8");
} }