fix: misc fixes
This commit is contained in:
@@ -16,7 +16,6 @@ import '@/components/aklive2d.css'
|
|||||||
export default class AKLive2D {
|
export default class AKLive2D {
|
||||||
#el = document.createElement("div")
|
#el = document.createElement("div")
|
||||||
#appEl
|
#appEl
|
||||||
#widgetEl
|
|
||||||
#queries = new URLSearchParams(window.location.search)
|
#queries = new URLSearchParams(window.location.search)
|
||||||
#voice = new Voice()
|
#voice = new Voice()
|
||||||
#music = new Music()
|
#music = new Music()
|
||||||
@@ -25,7 +24,7 @@ export default class AKLive2D {
|
|||||||
#logo = new Logo()
|
#logo = new Logo()
|
||||||
#insight = new Insight()
|
#insight = new Insight()
|
||||||
|
|
||||||
constructor(appEl, widgetEl) {
|
constructor(appEl) {
|
||||||
document.title = import.meta.env.VITE_TITLE
|
document.title = import.meta.env.VITE_TITLE
|
||||||
console.log("All resources are extracted from Arknights. Github: https://gura.ch/aklive2d-gh")
|
console.log("All resources are extracted from Arknights. Github: https://gura.ch/aklive2d-gh")
|
||||||
|
|
||||||
@@ -33,24 +32,23 @@ export default class AKLive2D {
|
|||||||
document.addEventListener("gesturestart", e => e.preventDefault());
|
document.addEventListener("gesturestart", e => e.preventDefault());
|
||||||
|
|
||||||
this.#appEl = appEl
|
this.#appEl = appEl
|
||||||
this.#widgetEl = widgetEl
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
if (isWebGLSupported) {
|
this.#logo.init(this.#appEl);
|
||||||
this.#logo.init(this.#appEl);
|
this.#background.init(this.#appEl);
|
||||||
this.#background.init(this.#appEl, this.#widgetEl);
|
this.#voice.init(this.#appEl);
|
||||||
this.#voice.init(this.#appEl, this.#widgetEl);
|
this.#music.init(this.#appEl);
|
||||||
this.#music.init(this.#appEl);
|
if (isWebGLSupported()) {
|
||||||
this.#player.init(this.#widgetEl, this);
|
this.#player.init(this.#appEl);
|
||||||
} else {
|
} else {
|
||||||
(new Fallback()).init(this.#widgetEl)
|
(new Fallback()).init(this.#appEl)
|
||||||
}
|
}
|
||||||
this.#el.id = "settings-box"
|
this.#el.id = "settings-box"
|
||||||
this.#el.hidden = true
|
this.#el.hidden = true
|
||||||
this.#el.innerHTML = `
|
this.#el.innerHTML = `
|
||||||
<div>
|
<div>
|
||||||
${this.#logo.HTML}
|
${this.#logo.HTML}
|
||||||
${this.#background.HTML}
|
${this.#background.HTML}
|
||||||
${this.#player.HTML}
|
${this.#player.HTML}
|
||||||
${this.#voice.HTML}
|
${this.#voice.HTML}
|
||||||
@@ -103,6 +101,7 @@ export default class AKLive2D {
|
|||||||
success() {
|
success() {
|
||||||
this.#music.link(this.#background)
|
this.#music.link(this.#background)
|
||||||
this.#background.link(this.#music)
|
this.#background.link(this.#music)
|
||||||
|
this.#voice.link(this.#player)
|
||||||
this.#voice.success()
|
this.#voice.success()
|
||||||
this.#music.success()
|
this.#music.success()
|
||||||
this.#insight.success()
|
this.#insight.success()
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import {
|
import {
|
||||||
insertHTMLNodeBefore,
|
|
||||||
readFile,
|
readFile,
|
||||||
updateHTMLOptions,
|
updateHTMLOptions,
|
||||||
showRelatedHTML,
|
showRelatedHTML,
|
||||||
syncHTMLValue,
|
syncHTMLValue,
|
||||||
|
insertHTMLChild,
|
||||||
} from "@/components/helper";
|
} from "@/components/helper";
|
||||||
import "@/components/background.css"
|
import "@/components/background.css"
|
||||||
|
|
||||||
@@ -20,14 +20,14 @@ export default class Background {
|
|||||||
}
|
}
|
||||||
#musicObj
|
#musicObj
|
||||||
|
|
||||||
init(el, widgetEl) {
|
init(el) {
|
||||||
this.#parentEl = el
|
this.#parentEl = el
|
||||||
this.#el.id = "background-box"
|
this.#el.id = "background-box"
|
||||||
this.image = this.#default.location + this.#default.image
|
this.image = this.#default.location + this.#default.image
|
||||||
this.#el.innerHTML = `
|
this.#el.innerHTML = `
|
||||||
<video autoplay loop disablepictureinpicture id="video-src" />
|
<video autoplay loop disablepictureinpicture id="video-src" />
|
||||||
`
|
`
|
||||||
insertHTMLNodeBefore(this.#parentEl, widgetEl, this.#el)
|
insertHTMLChild(this.#parentEl, this.#el)
|
||||||
this.#videoEl = document.getElementById("video-src")
|
this.#videoEl = document.getElementById("video-src")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
#fallback-box {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
#fallback {
|
#fallback {
|
||||||
margin: auto;
|
margin: auto;
|
||||||
background-position: center;
|
background-position: center;
|
||||||
|
|||||||
@@ -2,25 +2,29 @@ import { insertHTMLChild } from "@/components/helper";
|
|||||||
import '@/components/fallback.css'
|
import '@/components/fallback.css'
|
||||||
|
|
||||||
export default class Fallback {
|
export default class Fallback {
|
||||||
#el = document.createElement("div")
|
#el = document.createElement("div")
|
||||||
|
|
||||||
init(parentEl) {
|
init(parentEl) {
|
||||||
alert('WebGL is unavailable. Fallback image will be used.');
|
alert('WebGL is unavailable. Fallback image will be used.');
|
||||||
const calculateScale = (width, height) => {
|
const calculateScale = (width, height) => {
|
||||||
return { x: window.innerWidth / width, y: window.innerHeight / height };
|
return { x: window.innerWidth / width, y: window.innerHeight / height };
|
||||||
}
|
|
||||||
const fallback = () => {
|
|
||||||
const scale = calculateScale(import.meta.env.VITE_IMAGE_WIDTH, import.meta.env.VITE_IMAGE_HEIGHT);
|
|
||||||
this.#el.style.width = import.meta.env.VITE_IMAGE_WIDTH * (scale.x > scale.y ? scale.y : scale.x) + "px";
|
|
||||||
this.#el.style.height = import.meta.env.VITE_IMAGE_HEIGHT * (scale.x > scale.y ? scale.y : scale.x) + "px";
|
|
||||||
}
|
|
||||||
fallback();
|
|
||||||
window.addEventListener('resize', fallback, true);
|
|
||||||
this.#el.innerHTML = `
|
|
||||||
<div id="fallback"
|
|
||||||
style="background-image: url(./assets/${import.meta.env.VITE_FALLBACK_FILENAME}.png)"
|
|
||||||
/>
|
|
||||||
`
|
|
||||||
insertHTMLChild(parentEl, this.#el)
|
|
||||||
}
|
}
|
||||||
|
const fallback = () => {
|
||||||
|
const el = document.getElementById("fallback-container")
|
||||||
|
const scale = calculateScale(import.meta.env.VITE_IMAGE_WIDTH, import.meta.env.VITE_IMAGE_HEIGHT);
|
||||||
|
el.style.width = "100%";
|
||||||
|
el.style.height = import.meta.env.VITE_IMAGE_HEIGHT * (scale.x > scale.y ? scale.y : scale.x) + "px";
|
||||||
|
}
|
||||||
|
window.addEventListener('resize', fallback, true);
|
||||||
|
this.#el.id = "fallback-box"
|
||||||
|
this.#el.innerHTML = `
|
||||||
|
<div id="fallback-container">
|
||||||
|
<div id="fallback"
|
||||||
|
style="background-image: url(./assets/${import.meta.env.VITE_FALLBACK_FILENAME}.png)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
insertHTMLChild(parentEl, this.#el)
|
||||||
|
fallback();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -161,6 +161,10 @@ export default class Player {
|
|||||||
updateHTMLOptions(this.#spine.skeleton.data.animations.map(e => e.name), "animation-selection")
|
updateHTMLOptions(this.#spine.skeleton.data.animations.map(e => e.name), "animation-selection")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get node() {
|
||||||
|
return this.#el
|
||||||
|
}
|
||||||
|
|
||||||
#loadViewport() {
|
#loadViewport() {
|
||||||
this.#spine.updateViewport({
|
this.#spine.updateViewport({
|
||||||
padLeft: `${this.#config.padding.left}%`,
|
padLeft: `${this.#config.padding.left}%`,
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import '@/components/voice.css'
|
|||||||
export default class Voice {
|
export default class Voice {
|
||||||
#el = document.createElement("div")
|
#el = document.createElement("div")
|
||||||
#parentEl
|
#parentEl
|
||||||
#widgetEl
|
|
||||||
#default = {
|
#default = {
|
||||||
region: charword_table.config.default_region,
|
region: charword_table.config.default_region,
|
||||||
duration: {
|
duration: {
|
||||||
@@ -58,6 +57,7 @@ export default class Voice {
|
|||||||
},
|
},
|
||||||
duration: {...this.#default.duration}
|
duration: {...this.#default.duration}
|
||||||
}
|
}
|
||||||
|
#playerObj
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.#default.language.voice = this.#voice.languages[0]
|
this.#default.language.voice = this.#voice.languages[0]
|
||||||
@@ -259,9 +259,8 @@ export default class Voice {
|
|||||||
return this.duration.next
|
return this.duration.next
|
||||||
}
|
}
|
||||||
|
|
||||||
init(el, widgetEl) {
|
init(el) {
|
||||||
this.#parentEl = el
|
this.#parentEl = el
|
||||||
this.#widgetEl = widgetEl
|
|
||||||
this.#el.id = "voice-box"
|
this.#el.id = "voice-box"
|
||||||
this.#el.hidden = true
|
this.#el.hidden = true
|
||||||
this.#el.innerHTML = `
|
this.#el.innerHTML = `
|
||||||
@@ -294,7 +293,7 @@ export default class Voice {
|
|||||||
this.#audio.el.addEventListener('ended', audioEndedFunc)
|
this.#audio.el.addEventListener('ended', audioEndedFunc)
|
||||||
this.#playEntryVoice()
|
this.#playEntryVoice()
|
||||||
this.#initNextVoiceTimer()
|
this.#initNextVoiceTimer()
|
||||||
this.#widgetEl.addEventListener('click', () => {
|
this.#playerObj.node.addEventListener('click', () => {
|
||||||
this.#audio.lastClickToNext = true
|
this.#audio.lastClickToNext = true
|
||||||
this.#nextVoice()
|
this.#nextVoice()
|
||||||
})
|
})
|
||||||
@@ -305,6 +304,10 @@ export default class Voice {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
link(playerObj) {
|
||||||
|
this.#playerObj = playerObj
|
||||||
|
}
|
||||||
|
|
||||||
#getVoiceLocations() {
|
#getVoiceLocations() {
|
||||||
const folders = JSON.parse(import.meta.env.VITE_VOICE_FOLDERS)
|
const folders = JSON.parse(import.meta.env.VITE_VOICE_FOLDERS)
|
||||||
const customVoiceName = this.#voice.languages.filter(i => !folders.sub.map(e => e.lang).includes(i))[0]
|
const customVoiceName = this.#voice.languages.filter(i => !folders.sub.map(e => e.lang).includes(i))[0]
|
||||||
|
|||||||
@@ -2,8 +2,5 @@ import '@/index.css'
|
|||||||
import '@/libs/wallpaper_engine'
|
import '@/libs/wallpaper_engine'
|
||||||
import AKLive2D from '@/components/aklive2d'
|
import AKLive2D from '@/components/aklive2d'
|
||||||
|
|
||||||
document.getElementById('app').innerHTML = `
|
window.aklive2d = new AKLive2D(document.getElementById('app'))
|
||||||
<div id="widget-wrapper" />
|
|
||||||
`
|
|
||||||
window.aklive2d = new AKLive2D(document.getElementById('app'), document.getElementById('widget-wrapper'))
|
|
||||||
window.aklive2d.init()
|
window.aklive2d.init()
|
||||||
|
|||||||
Reference in New Issue
Block a user