修改game.parseSkillAudio的实现
This commit is contained in:
parent
ae95f1f4e8
commit
e156a934dc
|
@ -1451,109 +1451,7 @@ export class Game {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
parseSkillAudio(skill, player, skillInfo) {
|
parseSkillAudio(skill, player, skillInfo) {
|
||||||
if (typeof player === "string") player = { name: player };
|
return game.parseSkillTextMap(skill, player, skillInfo).map(data => data.file);
|
||||||
else if (typeof player !== "object" || player === null) player = {};
|
|
||||||
|
|
||||||
if (skillInfo && (typeof skillInfo !== "object" || Array.isArray(skillInfo))) skillInfo = { audio: skillInfo };
|
|
||||||
|
|
||||||
const checkSkill = (skill, history) => {
|
|
||||||
if (!lib.skill[skill]) return false;
|
|
||||||
if (!history.includes(skill)) return true;
|
|
||||||
if (history[0] === skill) return false;
|
|
||||||
//deadlock
|
|
||||||
throw new RangeError(`parseSkillAudio: ${skill} in ${history}forms a deadlock`);
|
|
||||||
};
|
|
||||||
|
|
||||||
const getName = filter => {
|
|
||||||
const name = (player.tempname || []).find(i => filter(i));
|
|
||||||
return (
|
|
||||||
name ||
|
|
||||||
[player.name, player.name1, player.name2].reduce((result, name) => {
|
|
||||||
if (result) return result;
|
|
||||||
if (!name) return result;
|
|
||||||
if (filter(name)) return name;
|
|
||||||
let tempname = (get.character(name).trashBin || []).find(tag => tag.startsWith("tempname:"));
|
|
||||||
if (!tempname) return result;
|
|
||||||
tempname = tempname
|
|
||||||
.split(":")
|
|
||||||
.slice(1)
|
|
||||||
.find(i => filter(i));
|
|
||||||
return tempname || result;
|
|
||||||
}, void 0)
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} skill
|
|
||||||
* @param {{audioname:string[],history:string[]}} options
|
|
||||||
* @param {skillInfo} [skillInfo]
|
|
||||||
* @returns {string[]}
|
|
||||||
*/
|
|
||||||
function getAudioList(skill, options, skillInfo) {
|
|
||||||
const info = skillInfo || lib.skill[skill];
|
|
||||||
if (!info) {
|
|
||||||
console.error(new ReferenceError(`parseSkillAudio: Cannot find ${skill} in lib.skill`));
|
|
||||||
return parseAudio(skill, options, [true, 2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { audioname, history } = options;
|
|
||||||
history.unshift(skill);
|
|
||||||
let audioInfo = info.audio;
|
|
||||||
if (Array.isArray(info.audioname)) audioname.addArray(info.audioname);
|
|
||||||
if (info.audioname2) audioInfo = info.audioname2[getName(i => info.audioname2[i])] || audioInfo;
|
|
||||||
if (typeof audioInfo === "function") audioInfo = audioInfo(player);
|
|
||||||
|
|
||||||
return parseAudio(skill, options, audioInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} skill
|
|
||||||
* @param {{audioname:string[],history:string[]}} options
|
|
||||||
* @param {audioInfo} audioInfo info.audio
|
|
||||||
* @returns {string[]}
|
|
||||||
*/
|
|
||||||
function parseAudio(skill, options, audioInfo) {
|
|
||||||
const audioname = options.audioname.slice();
|
|
||||||
const history = options.history.slice();
|
|
||||||
options = { audioname, history };
|
|
||||||
if (Array.isArray(audioInfo)) {
|
|
||||||
if (typeof audioInfo[0] === "string" && typeof audioInfo[1] === "number") {
|
|
||||||
// [audioname, number]
|
|
||||||
if (checkSkill(audioInfo[0], history)) return getAudioList(audioInfo[0], options).slice(0, audioInfo[1]);
|
|
||||||
return parseAudio(audioInfo[0], options, audioInfo[1]);
|
|
||||||
}
|
|
||||||
return audioInfo.reduce((total, i) => total.addArray(parseAudio(skill, options, i)), []);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!["string", "number", "boolean"].includes(typeof audioInfo)) return parseAudio(skill, options, [true, 2]);
|
|
||||||
if (audioInfo === false) return [];
|
|
||||||
if (typeof audioInfo === "string" && checkSkill(audioInfo, history)) return getAudioList(audioInfo, options);
|
|
||||||
|
|
||||||
audioInfo = String(audioInfo);
|
|
||||||
let list = audioInfo.match(/(?:(.*):|^)(true|\d+)(?::(.*)|$)/); // [path, number|true, format]
|
|
||||||
if (!list) {
|
|
||||||
let path = "",
|
|
||||||
format = "";
|
|
||||||
if (!/^db:|^ext:|\//.test(audioInfo)) path = "skill/";
|
|
||||||
if (!/\.\w+$/.test(audioInfo) && !["data:", "blob:"].some(name => audioInfo.startsWith(name))) format = ".mp3";
|
|
||||||
if (path && format) return parseAudio(audioInfo, options, [true, 2]);
|
|
||||||
return [`${path}${audioInfo}${format}`];
|
|
||||||
}
|
|
||||||
|
|
||||||
let _audioname = getName(i => audioname.includes(i));
|
|
||||||
_audioname = _audioname ? `_${_audioname}` : "";
|
|
||||||
|
|
||||||
if (list[2] === "true") return [`${list[1] || "skill"}/${skill}${_audioname}.${list[3] || "mp3"}`];
|
|
||||||
|
|
||||||
const audioList = [];
|
|
||||||
list[2] = parseInt(list[2]);
|
|
||||||
for (let i = 1; i <= list[2]; i++) {
|
|
||||||
audioList.push(`${list[1] || "skill"}/${skill}${_audioname}${i}.${list[3] || "mp3"}`);
|
|
||||||
}
|
|
||||||
return audioList;
|
|
||||||
}
|
|
||||||
|
|
||||||
return getAudioList(skill, { audioname: [], history: [] }, skillInfo);
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 根据skill中的audio,audioname,audioname2和player来获取技能台词列表
|
* 根据skill中的audio,audioname,audioname2和player来获取技能台词列表
|
||||||
|
|
Loading…
Reference in New Issue