Merge pull request #257 from nofficalfs/PR-Branch
Support character die-audio tag && Provide failure callback for game.getFileList.
This commit is contained in:
commit
738f276db0
67
game/game.js
67
game/game.js
|
@ -8437,13 +8437,13 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
game.getFileList=function(dir,callback){
|
game.getFileList=(dir,success,failure)=>{
|
||||||
var files=[],folders=[];
|
var files=[],folders=[];
|
||||||
window.resolveLocalFileSystemURL(lib.assetURL+dir,function(entry){
|
window.resolveLocalFileSystemURL(lib.assetURL+dir,entry=>{
|
||||||
var dirReader=entry.createReader();
|
var dirReader=entry.createReader();
|
||||||
var entries=[];
|
var entries=[];
|
||||||
var readEntries=function(){
|
var readEntries=()=>{
|
||||||
dirReader.readEntries(function(results){
|
dirReader.readEntries(results=>{
|
||||||
if(!results.length){
|
if(!results.length){
|
||||||
entries.sort();
|
entries.sort();
|
||||||
for(var i=0;i<entries.length;i++){
|
for(var i=0;i<entries.length;i++){
|
||||||
|
@ -8454,16 +8454,16 @@
|
||||||
files.push(entries[i].name);
|
files.push(entries[i].name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
callback(folders,files);
|
success(folders,files);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
entries=entries.concat(Array.from(results));
|
entries=entries.concat(Array.from(results));
|
||||||
readEntries();
|
readEntries();
|
||||||
}
|
}
|
||||||
});
|
},failure);
|
||||||
};
|
};
|
||||||
readEntries();
|
readEntries();
|
||||||
});
|
},failure);
|
||||||
};
|
};
|
||||||
game.ensureDirectory=function(list,callback,file){
|
game.ensureDirectory=function(list,callback,file){
|
||||||
var directorylist;
|
var directorylist;
|
||||||
|
@ -8625,21 +8625,39 @@
|
||||||
game.removeFile=function(filename,callback){
|
game.removeFile=function(filename,callback){
|
||||||
lib.node.fs.unlink(__dirname+'/'+filename,callback||function(){});
|
lib.node.fs.unlink(__dirname+'/'+filename,callback||function(){});
|
||||||
};
|
};
|
||||||
game.getFileList=function(dir,callback){
|
game.getFileList=(dir,success,failure)=>{
|
||||||
var files=[],folders=[];
|
var files=[],folders=[];
|
||||||
dir=__dirname+'/'+dir;
|
dir=__dirname+'/'+dir;
|
||||||
lib.node.fs.readdir(dir,function(err,filelist){
|
if(typeof failure=="undefined"){
|
||||||
for(var i=0;i<filelist.length;i++){
|
failure=err=>{
|
||||||
if(filelist[i][0]!='.'&&filelist[i][0]!='_'){
|
throw err;
|
||||||
if(lib.node.fs.statSync(dir+'/'+filelist[i]).isDirectory()){
|
};
|
||||||
folders.push(filelist[i]);
|
}
|
||||||
}
|
else if(failure == null){
|
||||||
else{
|
failure=()=>{};
|
||||||
files.push(filelist[i]);
|
}
|
||||||
|
lib.node.fs.access(dir,lib.node.fs.constants.F_OK|lib.node.fs.constants.R_OK,err=>{
|
||||||
|
if(err) {
|
||||||
|
failure(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lib.node.fs.readdir(dir,(err,filelist)=>{
|
||||||
|
if(err){
|
||||||
|
failure(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for(var i=0;i<filelist.length;i++){
|
||||||
|
if(filelist[i][0]!='.'&&filelist[i][0]!='_'){
|
||||||
|
if(lib.node.fs.statSync(dir+'/'+filelist[i]).isDirectory()){
|
||||||
|
folders.push(filelist[i]);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
files.push(filelist[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
success(folders,files);
|
||||||
callback(folders,files);
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
game.ensureDirectory=function(list,callback,file){
|
game.ensureDirectory=function(list,callback,file){
|
||||||
|
@ -18297,10 +18315,19 @@
|
||||||
_status.dying.remove(player);
|
_status.dying.remove(player);
|
||||||
|
|
||||||
if(lib.config.background_speak){
|
if(lib.config.background_speak){
|
||||||
if(lib.character[player.name]&&lib.character[player.name][4].contains('die_audio')){
|
if(lib.character[player.name]&&lib.character[player.name][4].some(tag=>/^die:.+$/.test(tag))){
|
||||||
|
const tag=lib.character[player.name][4].find(tag=>/^die:.+$/.test(tag));
|
||||||
|
const reg=new RegExp("^ext:(.+)?/");
|
||||||
|
const match=tag.match(/^die:(.+)$/);
|
||||||
|
if(match){
|
||||||
|
let path=match[1];
|
||||||
|
if(reg.test(path)) path=path.replace(reg,(_o,p)=>`../extension/${p}/`);
|
||||||
|
game.playAudio(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(lib.character[player.name]&&lib.character[player.name][4].contains('die_audio')){
|
||||||
game.playAudio('die',player.name);
|
game.playAudio('die',player.name);
|
||||||
}
|
}
|
||||||
// else if(true){
|
|
||||||
else{
|
else{
|
||||||
game.playAudio('die',player.name,function(){
|
game.playAudio('die',player.name,function(){
|
||||||
game.playAudio('die',player.name.slice(player.name.indexOf('_')+1));
|
game.playAudio('die',player.name.slice(player.name.indexOf('_')+1));
|
||||||
|
|
Loading…
Reference in New Issue