Merge pull request #1255 from Rintim/Dev-feat-BlobResource

增加对Blob链接的部分支持
This commit is contained in:
Spmario233 2024-04-21 22:13:30 +08:00 committed by GitHub
commit a0e8557dcd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 53 additions and 24 deletions

View File

@ -409,7 +409,9 @@ export class Game {
style.transform = "scale(1.05)"; style.transform = "scale(1.05)";
} }
document.body.insertBefore(uiBackground, document.body.firstChild); document.body.insertBefore(uiBackground, document.body.firstChild);
if (background.startsWith("db:")) uiBackground.setBackgroundDB(background.slice(3)); if (background.startsWith("blob:") || background.startsWith("data:")) {
uiBackground.setBackgroundImage(background);
} else if (background.startsWith("db:")) uiBackground.setBackgroundDB(background.slice(3));
else if (background.startsWith("ext:")) else if (background.startsWith("ext:"))
uiBackground.setBackgroundImage(`extension/${background.slice(4)}`); uiBackground.setBackgroundImage(`extension/${background.slice(4)}`);
else if (background == "default") { else if (background == "default") {
@ -1441,7 +1443,8 @@ export class Game {
if (_status.video) break; if (_status.video) break;
} }
if (path.startsWith("ext:")) path = path.replace(/^ext:/, "extension/"); if (path.startsWith("ext:")) path = path.replace(/^ext:/, "extension/");
else if (!path.startsWith("db:")) path = `audio/${path}`; else if (!["db:", "blob:", "data:"].some((prefix) => path.startsWith(prefix)))
path = `audio/${path}`;
if (!lib.config.repeat_audio && _status.skillaudio.includes(path)) return; if (!lib.config.repeat_audio && _status.skillaudio.includes(path)) return;
} }
const audio = document.createElement("audio"); const audio = document.createElement("audio");
@ -1466,6 +1469,7 @@ export class Game {
reject reject
); );
else if (lib.path.extname(path)) resolve(`${lib.assetURL}${path}`); else if (lib.path.extname(path)) resolve(`${lib.assetURL}${path}`);
else if (URL.canParse(path)) resolve(path);
else resolve(`${lib.assetURL}${path}.mp3`); else resolve(`${lib.assetURL}${path}.mp3`);
}).then((resolvedPath) => { }).then((resolvedPath) => {
audio.src = resolvedPath; audio.src = resolvedPath;
@ -1600,7 +1604,11 @@ export class Game {
let path = "", let path = "",
format = ""; format = "";
if (!/^db:|^ext:|\//.test(audioInfo)) path = "skill/"; if (!/^db:|^ext:|\//.test(audioInfo)) path = "skill/";
if (!/\.\w+$/.test(audioInfo)) format = ".mp3"; if (
!/\.\w+$/.test(audioInfo) &&
!["data:", "blob:"].some((name) => audioInfo.startsWith(name))
)
format = ".mp3";
if (path && format) return parseAudio(audioInfo, options, [true, 2]); if (path && format) return parseAudio(audioInfo, options, [true, 2]);
return [`${path}${audioInfo}${format}`]; return [`${path}${audioInfo}${format}`];
} }
@ -1734,7 +1742,9 @@ export class Game {
const audio = get.dynamicVariable(lib.card[card.name].audio, card, sex); const audio = get.dynamicVariable(lib.card[card.name].audio, card, sex);
if (typeof audio == "string") { if (typeof audio == "string") {
const audioInfo = audio.split(":"); const audioInfo = audio.split(":");
if (audio.startsWith("db:")) if (["blob:", "data:"].some((prefix) => audio.startsWith(prefix))) {
game.playAudio(audio);
} else if (audio.startsWith("db:"))
game.playAudio( game.playAudio(
`${audioInfo[0]}:${audioInfo[1]}`, `${audioInfo[0]}:${audioInfo[1]}`,
audioInfo[2], audioInfo[2],
@ -1766,7 +1776,9 @@ export class Game {
_status.currentAozhan _status.currentAozhan
); );
_status.currentAozhan = aozhan; _status.currentAozhan = aozhan;
if (aozhan.startsWith("db:")) if (["blob:", "data:"].some((prefix) => aozhan.startsWith(prefix))) {
ui.backgroundMusic.src = aozhan;
} else if (aozhan.startsWith("db:"))
game.getDB("image", aozhan.slice(3)).then((result) => (ui.backgroundMusic.src = result)); game.getDB("image", aozhan.slice(3)).then((result) => (ui.backgroundMusic.src = result));
else if (aozhan.startsWith("ext:")) else if (aozhan.startsWith("ext:"))
ui.backgroundMusic.src = `${lib.assetURL}extension/${aozhan.slice(4)}`; ui.backgroundMusic.src = `${lib.assetURL}extension/${aozhan.slice(4)}`;
@ -1789,7 +1801,9 @@ export class Game {
ui.backgroundMusic.src = backgroundMusicSourceConfiguration; ui.backgroundMusic.src = backgroundMusicSourceConfiguration;
return; return;
} }
if (music.startsWith("db:")) if (["blob:", "data:"].some((prefix) => music.startsWith(prefix))) {
ui.backgroundMusic.src = music;
} else if (music.startsWith("db:"))
game.getDB("image", music.slice(3)).then((result) => (ui.backgroundMusic.src = result)); game.getDB("image", music.slice(3)).then((result) => (ui.backgroundMusic.src = result));
else if (music.startsWith("ext:")) else if (music.startsWith("ext:"))
ui.backgroundMusic.src = `${lib.assetURL}extension/${music.slice(4)}`; ui.backgroundMusic.src = `${lib.assetURL}extension/${music.slice(4)}`;
@ -4737,7 +4751,8 @@ export class Game {
const audiosrc = "die:ext:" + extname + "/" + j + ".mp3"; const audiosrc = "die:ext:" + extname + "/" + j + ".mp3";
if ( if (
!pack[i][j][4].some( !pack[i][j][4].some(
(str) => typeof str == "string" && /^(?:db:extension-|ext:):(?:.+)/.test(str) (str) =>
typeof str == "string" && /^(?:db:extension-.+?|ext|img):(?:.+)/.test(str)
) )
) )
pack[i][j][4].add(imgsrc); pack[i][j][4].add(imgsrc);
@ -4786,6 +4801,7 @@ export class Game {
if (info.audio == true) { if (info.audio == true) {
info.audio = "ext:" + extname; info.audio = "ext:" + extname;
} }
if (!info.image || typeof info.image !== "string") {
if (info.fullskin) { if (info.fullskin) {
if (_status.evaluatingExtension) { if (_status.evaluatingExtension) {
info.image = "db:extension-" + extname + ":" + name + ".png"; info.image = "db:extension-" + extname + ":" + name + ".png";
@ -4799,6 +4815,7 @@ export class Game {
info.image = "ext:" + extname + "/" + name + ".jpg"; info.image = "ext:" + extname + "/" + name + ".jpg";
} }
} }
}
lib.card[name] = info; lib.card[name] = info;
lib.translate[name] = info2.translate; lib.translate[name] = info2.translate;
lib.translate[name + "_info"] = info2.description; lib.translate[name + "_info"] = info2.description;
@ -4916,11 +4933,15 @@ export class Game {
lib.translate[name] = info2.translate; lib.translate[name] = info2.translate;
let imgsrc; let imgsrc;
let extname = _status.extension || info2.extension; let extname = _status.extension || info2.extension;
if (info.splash) {
imgsrc = info.splash;
} else {
if (_status.evaluatingExtension) { if (_status.evaluatingExtension) {
imgsrc = "extension-" + extname + ":" + name + ".jpg"; imgsrc = "extension-" + extname + ":" + name + ".jpg";
} else { } else {
imgsrc = "ext:" + extname + "/" + name + ".jpg"; imgsrc = "ext:" + extname + "/" + name + ".jpg";
} }
}
lib.mode[name] = { lib.mode[name] = {
name: info2.translate, name: info2.translate,
config: info2.config, config: info2.config,

View File

@ -165,9 +165,13 @@ Reflect.defineProperty(HTMLDivElement.prototype, "setBackground", {
nameinfo = get.character(name); nameinfo = get.character(name);
} }
} }
if (!modeimage && nameinfo && nameinfo[4]) let imgPrefixUrl;
if (!modeimage && nameinfo && nameinfo[4]) {
for (const value of nameinfo[4]) { for (const value of nameinfo[4]) {
if (value.startsWith("ext:")) { if (value.startsWith("img:")) {
imgPrefixUrl = value.slice(4);
break;
} else if (value.startsWith("ext:")) {
extimage = value; extimage = value;
break; break;
} else if (value.startsWith("db:")) { } else if (value.startsWith("db:")) {
@ -181,7 +185,9 @@ Reflect.defineProperty(HTMLDivElement.prototype, "setBackground", {
break; break;
} }
} }
if (extimage) src = extimage.replace(/^ext:/, "extension/"); }
if (imgPrefixUrl) src = imgPrefixUrl;
else 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;
@ -225,6 +231,8 @@ HTMLDivElement.prototype.setBackgroundImage = function (img) {
.unique() .unique()
.map((v) => `url("${lib.assetURL}${v}")`) .map((v) => `url("${lib.assetURL}${v}")`)
.join(","); .join(",");
} else if (URL.canParse(img)) {
this.style.backgroundImage = `url("${img}")`;
} else { } else {
this.style.backgroundImage = `url("${lib.assetURL}${img}")`; this.style.backgroundImage = `url("${lib.assetURL}${img}")`;
} }