From 9b4b06a3ebe5bae05d8de05e9e508a7b2582e0a5 Mon Sep 17 00:00:00 2001 From: Rintim Date: Sun, 21 Apr 2024 20:59:55 +0800 Subject: [PATCH 1/6] feat: character direct image support. --- noname/init/polyfill.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/noname/init/polyfill.js b/noname/init/polyfill.js index 1f25b12d0..3f4dede17 100644 --- a/noname/init/polyfill.js +++ b/noname/init/polyfill.js @@ -165,8 +165,13 @@ Reflect.defineProperty(HTMLDivElement.prototype, "setBackground", { nameinfo = get.character(name); } } - if (!modeimage && nameinfo && nameinfo[4]) + let imgPrefixUrl; + if (!modeimage && nameinfo && nameinfo[4]) { for (const value of nameinfo[4]) { + if (value.startsWith("img:")) { + imgPrefixUrl = value.slice(4); + break; + } if (value.startsWith("ext:")) { extimage = value; break; @@ -181,7 +186,9 @@ Reflect.defineProperty(HTMLDivElement.prototype, "setBackground", { break; } } - if (extimage) src = extimage.replace(/^ext:/, "extension/"); + } + if (imgPrefixUrl) src = imgPrefixUrl; + else if (extimage) src = extimage.replace(/^ext:/, "extension/"); else if (dbimage) { this.setBackgroundDB(dbimage.slice(3)); return this; @@ -225,6 +232,8 @@ HTMLDivElement.prototype.setBackgroundImage = function (img) { .unique() .map((v) => `url("${lib.assetURL}${v}")`) .join(","); + } else if (URL.canParse(img)) { + this.style.backgroundImage = `url("${img}")`; } else { this.style.backgroundImage = `url("${lib.assetURL}${img}")`; } From a1d6180e9ac75bbf41786f6cb370031725d3344d Mon Sep 17 00:00:00 2001 From: Rintim Date: Sun, 21 Apr 2024 21:04:20 +0800 Subject: [PATCH 2/6] feat: audio blob support. --- noname/game/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/noname/game/index.js b/noname/game/index.js index 9053a1371..993b7d30c 100644 --- a/noname/game/index.js +++ b/noname/game/index.js @@ -409,7 +409,9 @@ export class Game { style.transform = "scale(1.05)"; } 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:")) uiBackground.setBackgroundImage(`extension/${background.slice(4)}`); else if (background == "default") { @@ -1441,7 +1443,8 @@ export class Game { if (_status.video) break; } 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; } const audio = document.createElement("audio"); From 0eec71eb01ed9658314785d50803f1d49a5c8b4f Mon Sep 17 00:00:00 2001 From: Rintim Date: Sun, 21 Apr 2024 21:06:57 +0800 Subject: [PATCH 3/6] feat: card audio blob support. --- noname/game/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/noname/game/index.js b/noname/game/index.js index 993b7d30c..9887c3a8b 100644 --- a/noname/game/index.js +++ b/noname/game/index.js @@ -1737,7 +1737,9 @@ export class Game { const audio = get.dynamicVariable(lib.card[card.name].audio, card, sex); if (typeof audio == "string") { 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( `${audioInfo[0]}:${audioInfo[1]}`, audioInfo[2], From 6e6662553c0eaab789c2440918238731b5bc8b57 Mon Sep 17 00:00:00 2001 From: Rintim Date: Sun, 21 Apr 2024 21:24:24 +0800 Subject: [PATCH 4/6] fix: audio path fix. --- noname/game/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/noname/game/index.js b/noname/game/index.js index 9887c3a8b..0b681754f 100644 --- a/noname/game/index.js +++ b/noname/game/index.js @@ -1469,6 +1469,7 @@ export class Game { reject ); else if (lib.path.extname(path)) resolve(`${lib.assetURL}${path}`); + else if (URL.canParse(path)) resolve(path); else resolve(`${lib.assetURL}${path}.mp3`); }).then((resolvedPath) => { audio.src = resolvedPath; @@ -1603,7 +1604,11 @@ export class Game { let path = "", format = ""; 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]); return [`${path}${audioInfo}${format}`]; } From 68129fc8c852326e9d7ced70bd7fd2e9a623f261 Mon Sep 17 00:00:00 2001 From: Rintim Date: Sun, 21 Apr 2024 21:46:51 +0800 Subject: [PATCH 5/6] feat: background music blob support. --- noname/game/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/noname/game/index.js b/noname/game/index.js index 0b681754f..26c194869 100644 --- a/noname/game/index.js +++ b/noname/game/index.js @@ -1776,7 +1776,9 @@ export class Game { _status.currentAozhan ); _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)); else if (aozhan.startsWith("ext:")) ui.backgroundMusic.src = `${lib.assetURL}extension/${aozhan.slice(4)}`; @@ -1799,7 +1801,9 @@ export class Game { ui.backgroundMusic.src = backgroundMusicSourceConfiguration; 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)); else if (music.startsWith("ext:")) ui.backgroundMusic.src = `${lib.assetURL}extension/${music.slice(4)}`; From 3215b0caa9e1e17658b24f1545eedb32d09f2ad6 Mon Sep 17 00:00:00 2001 From: Rintim Date: Sun, 21 Apr 2024 21:55:11 +0800 Subject: [PATCH 6/6] feat: some custom url support. --- noname/game/index.js | 37 ++++++++++++++++++++++--------------- noname/init/polyfill.js | 3 +-- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/noname/game/index.js b/noname/game/index.js index 26c194869..d3363b59f 100644 --- a/noname/game/index.js +++ b/noname/game/index.js @@ -4751,7 +4751,8 @@ export class Game { const audiosrc = "die:ext:" + extname + "/" + j + ".mp3"; if ( !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); @@ -4800,17 +4801,19 @@ export class Game { if (info.audio == true) { info.audio = "ext:" + extname; } - if (info.fullskin) { - if (_status.evaluatingExtension) { - info.image = "db:extension-" + extname + ":" + name + ".png"; - } else { - info.image = "ext:" + extname + "/" + name + ".png"; - } - } else if (info.fullimage) { - if (_status.evaluatingExtension) { - info.image = "db:extension-" + extname + ":" + name + ".jpg"; - } else { - info.image = "ext:" + extname + "/" + name + ".jpg"; + if (!info.image || typeof info.image !== "string") { + if (info.fullskin) { + if (_status.evaluatingExtension) { + info.image = "db:extension-" + extname + ":" + name + ".png"; + } else { + info.image = "ext:" + extname + "/" + name + ".png"; + } + } else if (info.fullimage) { + if (_status.evaluatingExtension) { + info.image = "db:extension-" + extname + ":" + name + ".jpg"; + } else { + info.image = "ext:" + extname + "/" + name + ".jpg"; + } } } lib.card[name] = info; @@ -4930,10 +4933,14 @@ export class Game { lib.translate[name] = info2.translate; let imgsrc; let extname = _status.extension || info2.extension; - if (_status.evaluatingExtension) { - imgsrc = "extension-" + extname + ":" + name + ".jpg"; + if (info.splash) { + imgsrc = info.splash; } else { - imgsrc = "ext:" + extname + "/" + name + ".jpg"; + if (_status.evaluatingExtension) { + imgsrc = "extension-" + extname + ":" + name + ".jpg"; + } else { + imgsrc = "ext:" + extname + "/" + name + ".jpg"; + } } lib.mode[name] = { name: info2.translate, diff --git a/noname/init/polyfill.js b/noname/init/polyfill.js index 3f4dede17..471c087f5 100644 --- a/noname/init/polyfill.js +++ b/noname/init/polyfill.js @@ -171,8 +171,7 @@ Reflect.defineProperty(HTMLDivElement.prototype, "setBackground", { if (value.startsWith("img:")) { imgPrefixUrl = value.slice(4); break; - } - if (value.startsWith("ext:")) { + } else if (value.startsWith("ext:")) { extimage = value; break; } else if (value.startsWith("db:")) {