* feat: migrate top turbo * ci: ci test * fix: fix codeql issues * feat: ci test * chore: lint * chore: misc changes * feat: rename vite helpers * feat: use fetch to handle assets * feat: update directory * feat: fetch charword table * feat: migrate download game data and detect missing voice files * feat: symlink relative path * feat: finish wrangler upload * feat: migrate wrangler download * feat: finish * chore: auto update * ci: update ci * ci: update ci --------- Co-authored-by: Halyul <Halyul@users.noreply.github.com>
41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
import { insertHTMLChild } from '@/components/helper'
|
|
import '@/components/fallback.css'
|
|
import buildConfig from '!/config.json'
|
|
|
|
export default class Fallback {
|
|
#el = document.createElement('div')
|
|
|
|
constructor(parentEl) {
|
|
alert('WebGL is unavailable. Fallback image will be used.')
|
|
const calculateScale = (width, height) => {
|
|
return {
|
|
x: window.innerWidth / width,
|
|
y: window.innerHeight / height,
|
|
}
|
|
}
|
|
const fallback = () => {
|
|
const el = document.getElementById('fallback-container')
|
|
const scale = calculateScale(
|
|
buildConfig.image_width,
|
|
buildConfig.image_height
|
|
)
|
|
el.style.width = '100%'
|
|
el.style.height =
|
|
buildConfig.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/${buildConfig.fallback_name}.png)"
|
|
/>
|
|
</div>
|
|
`
|
|
insertHTMLChild(parentEl, this.#el)
|
|
fallback()
|
|
}
|
|
}
|