Merge pull request #257 from nofficalfs/PR-Branch

Support character die-audio tag && Provide failure callback for game.getFileList.
This commit is contained in:
Spmario233 2023-09-03 20:56:22 +08:00 committed by GitHub
commit 738f276db0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 47 additions and 20 deletions

View File

@ -8437,13 +8437,13 @@
});
});
};
game.getFileList=function(dir,callback){
game.getFileList=(dir,success,failure)=>{
var files=[],folders=[];
window.resolveLocalFileSystemURL(lib.assetURL+dir,function(entry){
window.resolveLocalFileSystemURL(lib.assetURL+dir,entry=>{
var dirReader=entry.createReader();
var entries=[];
var readEntries=function(){
dirReader.readEntries(function(results){
var readEntries=()=>{
dirReader.readEntries(results=>{
if(!results.length){
entries.sort();
for(var i=0;i<entries.length;i++){
@ -8454,16 +8454,16 @@
files.push(entries[i].name);
}
}
callback(folders,files);
success(folders,files);
}
else{
entries=entries.concat(Array.from(results));
readEntries();
}
});
},failure);
};
readEntries();
});
},failure);
};
game.ensureDirectory=function(list,callback,file){
var directorylist;
@ -8625,21 +8625,39 @@
game.removeFile=function(filename,callback){
lib.node.fs.unlink(__dirname+'/'+filename,callback||function(){});
};
game.getFileList=function(dir,callback){
game.getFileList=(dir,success,failure)=>{
var files=[],folders=[];
dir=__dirname+'/'+dir;
lib.node.fs.readdir(dir,function(err,filelist){
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]);
if(typeof failure=="undefined"){
failure=err=>{
throw err;
};
}
else if(failure == null){
failure=()=>{};
}
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]);
}
}
}
}
callback(folders,files);
success(folders,files);
});
});
};
game.ensureDirectory=function(list,callback,file){
@ -18297,10 +18315,19 @@
_status.dying.remove(player);
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);
}
// else if(true){
else{
game.playAudio('die',player.name,function(){
game.playAudio('die',player.name.slice(player.name.indexOf('_')+1));