Change game.playAudio.

This commit is contained in:
Tipx-L 2023-09-27 22:36:29 -07:00
parent 11639b6b31
commit 82e626e67d
4 changed files with 84 additions and 61 deletions

View File

@ -6805,7 +6805,7 @@ game.import('character',function(lib,game,ui,get,ai,_status){
update: function () { update: function () {
if(state.curr == state.gameOver || state.curr == state.gameSuccess) return; if(state.curr == state.gameOver || state.curr == state.gameSuccess) return;
this.x -= dx * deltaTime; this.x -= dx * deltaTime;
const halfWidth = this.sprite.width / 2; const halfWidth = this.sprite.width / 4;
if(this.x <= -halfWidth) this.x += halfWidth; if(this.x <= -halfWidth) this.x += halfWidth;
}, },
}; };

View File

@ -274,7 +274,7 @@
if(typeof background!='string') background=''; if(typeof background!='string') background='';
if(!Array.isArray(lineColor)||lineColor.length!=3) lineColor=[]; if(!Array.isArray(lineColor)||lineColor.length!=3) lineColor=[];
else if(background.indexOf('ext:')==0){ else if(background.indexOf('ext:')==0){
background=background.replace(/ext:/,'extension/'); background=background.replace(/^ext:/,'extension/');
} }
if(linked) lib.linked.add(nature); if(linked) lib.linked.add(nature);
if(lineColor.length) lib.lineColor.set(nature,lineColor); if(lineColor.length) lib.lineColor.set(nature,lineColor);
@ -7974,7 +7974,7 @@
break; break;
} }
} }
if(extimage) src=extimage.replace(/ext:/,'extension/'); if(extimage) src=extimage.replace(/^ext:/,'extension/');
else if(dbimage){ else if(dbimage){
this.setBackgroundDB(dbimage.slice(3)); this.setBackgroundDB(dbimage.slice(3));
return this; return this;
@ -10351,7 +10351,7 @@
var avatarnode=ui.create.div(node,'.avatar'); var avatarnode=ui.create.div(node,'.avatar');
var avatarbg=lib.mode[lib.config.all.mode[i]].splash; var avatarbg=lib.mode[lib.config.all.mode[i]].splash;
if(avatarbg.indexOf('ext:')==0){ if(avatarbg.indexOf('ext:')==0){
avatarnode.setBackgroundImage(avatarbg.replace(/ext:/,'extension/')); avatarnode.setBackgroundImage(avatarbg.replace(/^ext:/,'extension/'));
} }
else{ else{
avatarnode.setBackgroundDB(avatarbg); avatarnode.setBackgroundDB(avatarbg);
@ -17523,11 +17523,10 @@
} }
const audio=lib.card[card.name].audio; const audio=lib.card[card.name].audio;
if(typeof audio=='string'){ if(typeof audio=='string'){
const audioInfo=audio.split('::'); const audioInfo=audio.split(':');
if(audioInfo.length<2) audioInfo.push('mp3'); if(audio.indexOf('db:')==0) game.playAudio(`${audioInfo[0]}:${audioInfo[1]}`,audioInfo[2],`${card.name}_${sex}.${audioInfo[3]||'mp3'}`);
if(audio.indexOf('db:')==0) game.playAudio(`${audioInfo[0]}${card.name}_${sex}.${audioInfo[1]}`); else if(audio.indexOf('ext:')==0) game.playAudio(`${audioInfo[0]}:${audioInfo[1]}`,`${card.name}_${sex}.${audioInfo[2]||'mp3'}`);
else if(audio.indexOf('ext:')==0) game.playAudio('..','extension',audioInfo[0].slice(4),`${card.name}_${sex}.${audioInfo[1]}`); else game.playAudio('card',sex,`${audioInfo[0]}.${audioInfo[1]||'mp3'}`);
else game.playAudio('card',sex,`${audioInfo[0]}.${audioInfo[1]}`);
} }
else game.playAudio('card',sex,card.name); else game.playAudio('card',sex,card.name);
},player,card); },player,card);
@ -28977,7 +28976,7 @@
this.classList.add('fullskin'); this.classList.add('fullskin');
if(img){ if(img){
if(img.indexOf('ext:')==0){ if(img.indexOf('ext:')==0){
this.node.image.setBackgroundImage(img.replace(/ext:/,'extension/')); this.node.image.setBackgroundImage(img.replace(/^ext:/,'extension/'));
} }
else{ else{
this.node.image.setBackgroundDB(img); this.node.image.setBackgroundDB(img);
@ -29012,7 +29011,7 @@
this.classList.add('fullimage'); this.classList.add('fullimage');
if(img){ if(img){
if(img.indexOf('ext:')==0){ if(img.indexOf('ext:')==0){
this.setBackgroundImage(img.replace(/ext:/,'extension/')); this.setBackgroundImage(img.replace(/^ext:/,'extension/'));
this.style.backgroundSize='cover'; this.style.backgroundSize='cover';
} }
else{ else{
@ -29056,7 +29055,7 @@
} }
if(img){ if(img){
if(img.indexOf('ext:')==0){ if(img.indexOf('ext:')==0){
this.node.avatar.setBackgroundImage(img.replace(/ext:/,'extension/')); this.node.avatar.setBackgroundImage(img.replace(/^ext:/,'extension/'));
this.node.avatar.style.backgroundSize='cover'; this.node.avatar.style.backgroundSize='cover';
} }
else{ else{
@ -29088,7 +29087,7 @@
else if(typeof lib.card[bg].image=='string'&&!lib.card[bg].fullskin){ else if(typeof lib.card[bg].image=='string'&&!lib.card[bg].fullskin){
if(img){ if(img){
if(img.indexOf('ext:')==0){ if(img.indexOf('ext:')==0){
this.setBackgroundImage(img.replace(/ext:/,'extension/')); this.setBackgroundImage(img.replace(/^ext:/,'extension/'));
this.style.backgroundSize='cover'; this.style.backgroundSize='cover';
} }
else{ else{
@ -34470,15 +34469,23 @@
}, },
playAudio:function(){ playAudio:function(){
if(_status.video&&arguments[1]!='video') return; if(_status.video&&arguments[1]!='video') return;
let path='',onError=null; let path='',emptyPath=true,notCheckDBPath=true,onError=null;
for(const argument of arguments){ for(const argument of arguments){
if(typeof argument==='string'||typeof argument=='number'){ if(typeof argument==='string'||typeof argument=='number'){
if(path) path+='/'; if(emptyPath) emptyPath=false;
else if(notCheckDBPath){
notCheckDBPath=false;
if(/^db:extension-[^:]*$/.test(path)) path+=':';
else path+='/';
}
else path+='/';
path+=argument; path+=argument;
} }
else if(typeof argument=='function') onError=argument; else if(typeof argument=='function') onError=argument;
if(_status.video) break; if(_status.video) break;
} }
if(path.indexOf('ext:')==0) path=path.replace(/^ext:/,'extension/');
else if(path.indexOf('db:')!=0) path=`audio/${path}`;
if(!lib.config.repeat_audio&&_status.skillaudio.contains(path)) return; if(!lib.config.repeat_audio&&_status.skillaudio.contains(path)) return;
_status.skillaudio.add(path); _status.skillaudio.add(path);
game.addVideo('playAudio',null,path); game.addVideo('playAudio',null,path);
@ -34500,8 +34507,8 @@
audio.oncanplay=()=>Promise.resolve(audio.play()).catch(()=>void 0); audio.oncanplay=()=>Promise.resolve(audio.play()).catch(()=>void 0);
new Promise((resolve,reject)=>{ new Promise((resolve,reject)=>{
if(path.indexOf('db:')==0) game.getDB('file',path.slice(3)).then(octetStream=>resolve(get.objectURL(octetStream)),reject); if(path.indexOf('db:')==0) game.getDB('file',path.slice(3)).then(octetStream=>resolve(get.objectURL(octetStream)),reject);
else if(lib.path.extname(path)) resolve(`${lib.assetURL}audio/${path}`); else if(lib.path.extname(path)) resolve(`${lib.assetURL}${path}`);
else resolve(`${lib.assetURL}audio/${path}.mp3`); else resolve(`${lib.assetURL}${path}.mp3`);
}).then(resolvedPath=>{ }).then(resolvedPath=>{
audio.src=resolvedPath; audio.src=resolvedPath;
ui.window.appendChild(audio); ui.window.appendChild(audio);
@ -34518,63 +34525,73 @@
if(info.direct&&!directaudio) return; if(info.direct&&!directaudio) return;
if(lib.skill.global.includes(skill)&&!lib.skill[skill].forceaudio) return; if(lib.skill.global.includes(skill)&&!lib.skill[skill].forceaudio) return;
} }
var audioname=skill; var audioName=skill;
var audioinfo=info.audio; var audioInfo=info.audio;
var fixednum; var fixedNum;
if(info.audioname2){ if(info.audioname2){
if(info.audioname2[player.name]){ if(info.audioname2[player.name]){
audioname+='_'+player.name; audioName+='_'+player.name;
audioinfo=info.audioname2[player.name]; audioInfo=info.audioname2[player.name];
} }
else if(info.audioname2[player.name1]){ else if(info.audioname2[player.name1]){
audioname+='_'+player.name1; audioName+='_'+player.name1;
audioinfo=info.audioname2[player.name1]; audioInfo=info.audioname2[player.name1];
} }
else if(info.audioname2[player.name2]){ else if(info.audioname2[player.name2]){
audioname+='_'+player.name2; audioName+='_'+player.name2;
audioinfo=info.audioname2[player.name2]; audioInfo=info.audioname2[player.name2];
} }
} }
var history=[]; var history=[];
while(true){//可以嵌套引用了 while(true){//可以嵌套引用了
if(history.includes(audioname)) break; if(history.includes(audioName)) break;
history.push(audioname); history.push(audioName);
if(typeof audioinfo=='string'&&lib.skill[audioinfo]){ if(typeof audioInfo=='string'&&lib.skill[audioInfo]){
audioname=audioinfo; audioName=audioInfo;
audioinfo=lib.skill[audioname].audio; audioInfo=lib.skill[audioName].audio;
continue; continue;
} }
if(Array.isArray(audioinfo)){ if(Array.isArray(audioInfo)){
audioname=audioinfo[0]; audioName=audioInfo[0];
if(!fixednum) fixednum=audioinfo[1];//数组会取第一个指定语音数 if(!fixedNum) fixedNum=audioInfo[1];//数组会取第一个指定语音数
audioinfo=lib.skill[audioname].audio; audioInfo=lib.skill[audioName].audio;
continue; continue;
} }
break; break;
} }
if(Array.isArray(info.audioname)&&player){ if(Array.isArray(info.audioname)&&player){
if(info.audioname.includes(player.name)&&(!info.audioname2||!info.audioname2[player.name])) audioname+='_'+player.name; if(info.audioname.includes(player.name)&&(!info.audioname2||!info.audioname2[player.name])) audioName+='_'+player.name;
else if(info.audioname.includes(player.name1)&&(!info.audioname2||!info.audioname2[player.name1])) audioname+='_'+player.name1; else if(info.audioname.includes(player.name1)&&(!info.audioname2||!info.audioname2[player.name1])) audioName+='_'+player.name1;
else if(info.audioname.includes(player.name2)&&(!info.audioname2||!info.audioname2[player.name2])) audioname+='_'+player.name2; else if(info.audioname.includes(player.name2)&&(!info.audioname2||!info.audioname2[player.name2])) audioName+='_'+player.name2;
} }
if(typeof audioinfo=='string'){ if(typeof audioInfo=='string'){
if(audioinfo.indexOf('ext:')!=0) return; if(audioInfo.indexOf('db:')==0){
audioinfo=audioinfo.split(':'); audioInfo=audioInfo.split(':');
if(audioinfo.length!=3) return; if(audioInfo.length<4) return;
if(audioinfo[2]=='true') game.playAudio('..','extension',audioinfo[1],audioname); if(audioInfo[3]=='true') game.playAudio(`${audioInfo[0]}:${audioInfo[1]}`,audioInfo[2],`${audioName}.${audioInfo[4]||'mp3'}`);
else{ else{
audioinfo[2]=parseInt(audioinfo[2]); audioInfo[3]=fixedNum?Math.min(parseInt(audioInfo[3]),fixedNum):parseInt(audioInfo[3]);
if(fixednum) audioinfo[2]=Math.min(audioinfo[2],fixednum); if(!audioInfo[3]) return;
if(!audioinfo[2]) return; game.playAudio(`${audioInfo[0]}:${audioInfo[1]}`,audioInfo[2],`${audioName}${Math.floor(audioInfo[3]*Math.random())+1}.${audioInfo[4]||'mp3'}`);
game.playAudio('..','extension',audioinfo[1],audioname+Math.ceil(audioinfo[2]*Math.random())); }
}
else if(audioInfo.indexOf('ext:')==0){
audioInfo=audioInfo.split(':');
if(audioInfo.length<3) return;
if(audioInfo[2]=='true') game.playAudio(`${audioInfo[0]}:${audioInfo[1]}`,`${audioName}.${audioInfo[3]||'mp3'}`);
else{
audioInfo[2]=fixedNum?Math.min(parseInt(audioInfo[2]),fixedNum):parseInt(audioInfo[2]);
if(!audioInfo[2]) return;
game.playAudio(`${audioInfo[0]}:${audioInfo[1]}`,`${audioName}${Math.floor(audioInfo[2]*Math.random())+1}.${audioInfo[3]||'mp3'}`);
}
} }
} }
else if(typeof audioinfo=='number'){ else if(typeof audioInfo=='number'){
if(fixednum) audioinfo=Math.min(audioinfo, fixednum); if(fixedNum) audioInfo=Math.min(audioInfo, fixedNum);
game.playAudio('skill',audioname+Math.ceil(audioinfo*Math.random())); game.playAudio('skill',`${audioName}${Math.floor(audioInfo*Math.random())+1}`);
} }
else if(audioinfo) game.playAudio('skill',audioname); else if(audioInfo) game.playAudio('skill',audioName);
else if(info.audio!==false) game.playSkillAudio(audioname); else if(info.audio!==false) game.playSkillAudio(audioName);
}, },
playSkillAudio:function(name,index){ playSkillAudio:function(name,index){
if(_status.video&&arguments[1]!='video') return; if(_status.video&&arguments[1]!='video') return;
@ -41037,7 +41054,7 @@
if(lib.card[cardName].fullskin){ if(lib.card[cardName].fullskin){
if(img){ if(img){
if(img.indexOf('ext:')==0){ if(img.indexOf('ext:')==0){
bg.setBackgroundImage(img.replace(/ext:/,'extension/')); bg.setBackgroundImage(img.replace(/^ext:/,'extension/'));
} }
else{ else{
bg.setBackgroundDB(img); bg.setBackgroundDB(img);
@ -41060,7 +41077,7 @@
else if(lib.card[cardName].fullimage){ else if(lib.card[cardName].fullimage){
if(img){ if(img){
if(img.indexOf('ext:')==0){ if(img.indexOf('ext:')==0){
bg.setBackgroundImage(img.replace(/ext:/,'extension/')); bg.setBackgroundImage(img.replace(/^ext:/,'extension/'));
bg.style.backgroundSize='cover'; bg.style.backgroundSize='cover';
} }
else{ else{
@ -41092,7 +41109,7 @@
else if(typeof lib.card[cardName].image=='string'&&!lib.card[cardName].fullskin){ else if(typeof lib.card[cardName].image=='string'&&!lib.card[cardName].fullskin){
if(img){ if(img){
if(img.indexOf('ext:')==0){ if(img.indexOf('ext:')==0){
bg.setBackgroundImage(img.replace(/ext:/,'extension/')); bg.setBackgroundImage(img.replace(/^ext:/,'extension/'));
bg.style.backgroundSize='cover'; bg.style.backgroundSize='cover';
} }
else{ else{
@ -54034,7 +54051,7 @@
const image=information.image; const image=information.image;
if(!image) resolve(`${lib.assetURL}image/card/${imageName}.png`); if(!image) resolve(`${lib.assetURL}image/card/${imageName}.png`);
else if(image.indexOf('db:')==0) game.getDB('file',image.slice(3)).then(resolve,reject); else if(image.indexOf('db:')==0) game.getDB('file',image.slice(3)).then(resolve,reject);
else if(image.indexOf('ext:')==0) resolve(`${lib.assetURL}${image.replace(/ext:/,'extension/')}`); else if(image.indexOf('ext:')==0) resolve(`${lib.assetURL}${image.replace(/^ext:/,'extension/')}`);
else resolve(`${lib.assetURL}${image}`); else resolve(`${lib.assetURL}${image}`);
}).then(source=>new Promise((resolve,reject)=>{ }).then(source=>new Promise((resolve,reject)=>{
const image=new Image(); const image=new Image();
@ -54049,7 +54066,7 @@
const image=information.image; const image=information.image;
if(!image) resolve(`${lib.assetURL}image/card/${imageName}.png`); if(!image) resolve(`${lib.assetURL}image/card/${imageName}.png`);
else if(image.indexOf('db:')==0) game.getDB('file',image.slice(3)).then(resolve,reject); else if(image.indexOf('db:')==0) game.getDB('file',image.slice(3)).then(resolve,reject);
else if(image.indexOf('ext:')==0) resolve(`${lib.assetURL}${image.replace(/ext:/,'extension/')}`); else if(image.indexOf('ext:')==0) resolve(`${lib.assetURL}${image.replace(/^ext:/,'extension/')}`);
else resolve(`${lib.assetURL}${image}`); else resolve(`${lib.assetURL}${image}`);
}).then(source=>new Promise((resolve,reject)=>{ }).then(source=>new Promise((resolve,reject)=>{
const image=new Image(); const image=new Image();
@ -54069,7 +54086,7 @@
const image=information.image; const image=information.image;
if(!image) resolve(`${lib.assetURL}image/card/${imageName}.png`); if(!image) resolve(`${lib.assetURL}image/card/${imageName}.png`);
else if(image.indexOf('db:')==0) game.getDB('file',image.slice(3)).then(resolve,reject); else if(image.indexOf('db:')==0) game.getDB('file',image.slice(3)).then(resolve,reject);
else if(image.indexOf('ext:')==0) resolve(`${lib.assetURL}${image.replace(/ext:/,'extension/')}`); else if(image.indexOf('ext:')==0) resolve(`${lib.assetURL}${image.replace(/^ext:/,'extension/')}`);
else resolve(`${lib.assetURL}${image}`); else resolve(`${lib.assetURL}${image}`);
}).then(source=>new Promise((resolve,reject)=>{ }).then(source=>new Promise((resolve,reject)=>{
const image=new Image(); const image=new Image();
@ -55412,7 +55429,10 @@
}); });
const testingNaturesList=naturesList.slice(0,naturesList.length-1); const testingNaturesList=naturesList.slice(0,naturesList.length-1);
if(every) return testingNaturesList.every((natures,index)=>naturesList.slice(index+1).every(testingNatures=>testingNatures.length==natures.length&&testingNatures.every(nature=>natures.includes(nature)))); if(every) return testingNaturesList.every((natures,index)=>naturesList.slice(index+1).every(testingNatures=>testingNatures.length==natures.length&&testingNatures.every(nature=>natures.includes(nature))));
return testingNaturesList.every((natures,index)=>naturesList.slice(index+1).some(testingNatures=>testingNatures.some(nature=>natures.includes(nature)))); return testingNaturesList.every((natures,index)=>{
const comparingNaturesList=naturesList.slice(index+1);
return natures.some(nature=>comparingNaturesList.every(testingNatures=>testingNatures.includes(nature)));
});
}, },
/** /**
* 判断传入的参数的属性是否不同参数可以为卡牌卡牌信息属性等 * 判断传入的参数的属性是否不同参数可以为卡牌卡牌信息属性等
@ -55440,7 +55460,10 @@
}); });
const testingNaturesList=naturesList.slice(0,naturesList.length-1); const testingNaturesList=naturesList.slice(0,naturesList.length-1);
if(every) return testingNaturesList.every((natures,index)=>naturesList.slice(index+1).every(testingNatures=>testingNatures.every(nature=>!natures.includes(nature)))); if(every) return testingNaturesList.every((natures,index)=>naturesList.slice(index+1).every(testingNatures=>testingNatures.every(nature=>!natures.includes(nature))));
return testingNaturesList.every((natures,index)=>naturesList.slice(index+1).some(testingNatures=>testingNatures.length!=natures.length||testingNatures.some(nature=>!natures.includes(nature)))); return testingNaturesList.every((natures,index)=>{
const comparingNaturesList=naturesList.slice(index+1);
return natures.some(nature=>comparingNaturesList.every(testingNatures=>testingNatures.some(testingNature=>testingNature!=nature)));
});
}, },
//判断一张牌是否为明置手牌 //判断一张牌是否为明置手牌
shownCard:function(card){ shownCard:function(card){

BIN
image/card/group_ye.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB