-
-
+ #updateSubtitlePosition() {
+ updateElementPosition(this.#el, {
+ x: this.position.x,
+ y: this.position.y - 100
+ })
+ }
+
+ #initNextVoiceTimer() {
+ this.#voice.listener.next = setInterval(() => {
+ if (!this.#voice.lastClickToNext) {
+ this.#nextVoice()
+ }
+ }, this.#config.duration.next)
+ }
+
+ #nextVoice() {
+ const getVoiceId = () => {
+ const id = this.#voice.list[Math.floor((Math.random() * this.#voice.list.length))]
+ return id === this.#voice.id.last ? getVoiceId() : id
+ }
+ this.#playVoice(getVoiceId())
+ }
+
+ #initIdleVoiceTimer() {
+ this.#voice.listener.idle = setInterval(() => {
+ this.#playSpecialVoice("闲置")
+ clearInterval(this.#voice.listener.idle)
+ this.#voice.listener.idle = -1
+ }, this.#config.duration.idle)
+ }
+
+ resetPosition() {
+ this.position = {...this.#default.subtitle}
+ document.getElementById("subtitle-padding-x-slider").value = this.#default.subtitle.x
+ document.getElementById("subtitle-padding-x-input").value = this.#default.subtitle.x
+ document.getElementById("subtitle-padding-y-slider").value = this.#default.subtitle.y
+ document.getElementById("subtitle-padding-y-input").value = this.#default.subtitle.y
+ }
+
+ reset() {
+ this.resetPosition()
+ }
+
+ get HTML() {
+ return `
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
`
}
+
+ get listeners() {
+ return [
+ {
+ event: "voice-set-usevoice", handler: e => this.useVoice = e.detail
+ }, {
+ event: "voice-set-language", handler: e => this.language = e.detail
+ }, {
+ event: "voice-set-duration", handler: e => this.duration = e.detail
+ }, {
+ event: "voice-set-usesubtitle", handler: e => this.useSubtitle = e.detail
+ }, {
+ event: "voice-set-subtitlelanguage", handler: e => this.subtitleLanguage = e.detail
+ }, {
+ event: "voice-set-subtitleposition", handler: e => this.position = e.detail
+ }, {
+ event: "voice-set-usevoiceactor", handler: e => this.useVoiceActor = e.detail
+ }, {
+ id: "voice", event: "click", handler: e => {
+ showRelatedHTML(e.currentTarget, "voice-realted");
+ this.useVoice = e.currentTarget.checked;
+ }
+ }, {
+ id: "voice-lang-select", event: "change", handler: e => {
+ this.language = e.currentTarget.value
+ }
+ }, {
+ id: "voice-idle-duration-input", event: "change", handler: e => {
+ this.duration = {
+ idle: e.currentTarget.value
+ }
+ }
+ }, {
+ id: "voice-next-duration-input", event: "change", handler: e => {
+ this.duration = {
+ next: e.currentTarget.value
+ }
+ }
+ }, {
+ id: "subtitle", event: "click", handler: e => {
+ showRelatedHTML(e.currentTarget, "subtitle-realted");
+ this.useSubtitle = e.currentTarget.checked;
+ }
+ }, {
+ id: "subtitle-lang-select", event: "change", handler: e => this.subtitleLanguage = e.currentTarget.value
+ }, {
+ id: "subtitle-padding-x-slider", event: "input", handler: e => {
+ syncHTMLValue(e.currentTarget, "subtitle-padding-x-input");
+ this.position = {
+ x: e.currentTarget.value
+ }
+ }
+ }, {
+ id: "subtitle-padding-x-input", event: "change", handler: e => {
+ syncHTMLValue(e.currentTarget, "subtitle-padding-x-slider");
+ this.position = {
+ x: e.currentTarget.value
+ }
+ }
+ }, {
+ id: "subtitle-padding-y-slider", event: "input", handler: e => {
+ syncHTMLValue(e.currentTarget, "subtitle-padding-y-input");
+ this.position = {
+ y: e.currentTarget.value
+ }
+ }
+ }, {
+ id: "subtitle-padding-y-input", event: "change", handler: e => {
+ syncHTMLValue(e.currentTarget, "subtitle-padding-y-slider");
+ this.position = {
+ y: e.currentTarget.value
+ }
+ }
+ }, {
+ id: "voice-actor", event: "click", handler: e => {
+ this.useVoiceActor = e.currentTarget.checked;
+ }
+ }
+ ]
+ }
}
\ No newline at end of file
diff --git a/showcase/src/index.css b/showcase/src/index.css
index fdc130d..81c96c0 100644
--- a/showcase/src/index.css
+++ b/showcase/src/index.css
@@ -1,7 +1,4 @@
html {
- -ms-user-select: none;
- -webkit-user-select: none;
- -moz-user-select: none;
user-select: none;
height: 100%;
width: 100%;
@@ -11,50 +8,15 @@ html {
body,
#app {
margin: 0;
- background-position: center;
- background-repeat: no-repeat;
- background-size: cover;
height: 100%;
width: 100%;
touch-action: none;
- -ms-touch-action: none;
}
#widget-wrapper {
display: flex;
+ justify-content: center;
align-items: center;
width: 100%;
height: 100%;
}
-
-.logo {
- position: fixed;
- left: 0;
- top: 0;
- z-index: -1;
-}
-
-.invert-filter {
- filter: invert(1);
- opacity: 0.3;
-}
-
-#video_background {
- position: absolute;
- top: 0;
- bottom: 0;
- width: 100%;
- height: 100%;
- overflow: hidden;
-}
-
-#video_background video {
- min-width: 100%;
- min-height: 100%;
- width: auto;
- height: auto;
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%,-50%);
-}
\ No newline at end of file
diff --git a/showcase/src/index.js b/showcase/src/index.js
index ba30522..42540b1 100644
--- a/showcase/src/index.js
+++ b/showcase/src/index.js
@@ -1,39 +1,9 @@
import '@/index.css'
import '@/libs/wallpaper_engine'
-import check_web_gl from '@/libs/check_web_gl'
-import Settings from '@/components/settings'
-import Voice from '@/components/voice'
-import Music from '@/components/music'
+import AKLive2D from '@/components/aklive2d'
-document.querySelector('#app').innerHTML = `
-

-
-
-
-
-
-
-
+document.getElementById('app').innerHTML = `
+
`
-window.voice = new Voice(document.querySelector('#voice_box'), document.querySelector('#widget-wrapper'))
-window.voice.init()
-window.music = new Music(document.querySelector('#music_box'))
-window.settings = new Settings(document.querySelector('#settings'), document.querySelector('#logo'))
-document.title = import.meta.env.VITE_TITLE
-console.log("All resources are extracted from Arknights. Github: https://gura.ch/aklive2d-gh")
-
-if (check_web_gl()) {
- import('@/components/player').then(({ default: spinePlayer }) => {
- window.settings.spinePlayer = spinePlayer(document.querySelector('#player'))
- })
-} else {
- import('@/components/fallback').then(({ default: fallback }) => {
- fallback(document.querySelector('#fallback'))
- })
-}
+window.aklive2d = new AKLive2D(document.getElementById('app'), document.getElementById('widget-wrapper'))
+window.aklive2d.init()
diff --git a/showcase/src/libs/check_web_gl.js b/showcase/src/libs/check_web_gl.js
deleted file mode 100644
index 35481a6..0000000
--- a/showcase/src/libs/check_web_gl.js
+++ /dev/null
@@ -1,9 +0,0 @@
-export default function check_web_gl() {
- try {
- const canvas = document.createElement("canvas");
- const ctx = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
- return ctx != null;
- } catch (e) {
- return false;
- }
-}
\ No newline at end of file
diff --git a/showcase/src/libs/spine-player.js b/showcase/src/libs/spine-player.js
index cf183ba..af1d409 100644
--- a/showcase/src/libs/spine-player.js
+++ b/showcase/src/libs/spine-player.js
@@ -9669,10 +9669,10 @@ var spine;
var canvas = this.canvas;
var w = canvas.clientWidth;
var h = canvas.clientHeight;
- var devicePixelRatio = window.devicePixelRatio || 1;
- if (canvas.width != Math.floor(w * devicePixelRatio) || canvas.height != Math.floor(h * devicePixelRatio)) {
- canvas.width = Math.floor(w * devicePixelRatio);
- canvas.height = Math.floor(h * devicePixelRatio);
+ var devicePixelRatio = () => window.devicePixelRatio || 1;
+ if (canvas.width != Math.floor(w * devicePixelRatio()) || canvas.height != Math.floor(h * devicePixelRatio())) {
+ canvas.width = Math.floor(w * devicePixelRatio());
+ canvas.height = Math.floor(h * devicePixelRatio());
}
this.context.gl.viewport(0, 0, canvas.width, canvas.height);
if (resizeMode === ResizeMode.Stretch) {
@@ -11084,16 +11084,16 @@ var spine;
config.showControls = true;
if (typeof config.defaultMix === "undefined")
config.defaultMix = 0.25;
- config.devicePixelRatio = window.devicePixelRatio || 1;
- config.settingsScale = 1;
- if (typeof window.settings !== "undefined")
- config.settingsScale = window.settings.scale;
+ config.devicePixelRatio = () => window.devicePixelRatio || 1;
+ if (typeof config.scale === "undefined")
+ config.scale = 1;
return config;
};
+ SpinePlayer.prototype.setOperatorScale = function (v) {
+ this.config.scale = v
+ };
SpinePlayer.prototype.getOperatorScale = function () {
- if (typeof window.settings !== "undefined")
- return window.settings.scale;
- return this.config.settingsScale
+ return this.config.scale
};
SpinePlayer.prototype.showError = function (error) {
var errorDom = findWithClass(this.dom, "spine-player-error")[0];
@@ -11416,7 +11416,7 @@ var spine;
height: oldViewport.height + (viewport.height - oldViewport.height) * transitionAlpha
};
}
- var devicePixelRatio = this.config.devicePixelRatio;
+ var devicePixelRatio = this.config.devicePixelRatio();
var viewportSize = this.scale(viewport.width, viewport.height, this.canvas.width, this.canvas.height);
// this.sceneRenderer.camera.zoom = viewport.width * devicePixelRatio / viewportSize.x;
diff --git a/showcase/src/libs/wallpaper_engine.js b/showcase/src/libs/wallpaper_engine.js
index 65f3124..ef0d228 100644
--- a/showcase/src/libs/wallpaper_engine.js
+++ b/showcase/src/libs/wallpaper_engine.js
@@ -1,133 +1,155 @@
+import * as Event from "@/components/event"
+
window.wallpaperPropertyListener = {
- applyGeneralProperties: function (properties) {
- if (properties.fps) {
- window.settings.setFPS(properties.fps)
- }
- },
- applyUserProperties: function (properties) {
- if (properties.privacydonottrack) {
- window.settings.insight(true, !properties.privacydonottrack.value)
- }
- if (properties.logo) {
- window.settings.setLogoDisplay(!properties.logo.value)
- }
- if (properties.logoratio) {
- if (properties.logoratio.value) {
- window.settings.setLogoRatio(properties.logoratio.value)
- }
- }
- if (properties.logoopacity) {
- if (properties.logoopacity.value) {
- window.settings.setLogoOpacity(properties.logoopacity.value)
- }
- }
- if (properties.logoimage) {
- if (properties.logoimage.value) {
- window.settings.setLogo('file:///' + properties.logoimage.value)
- } else {
- window.settings.resetLogoImage()
- }
- }
- if (properties.logox) {
- window.settings.logoPadding("x", properties.logox.value)
- }
- if (properties.logoy) {
- window.settings.logoPadding("y", properties.logoy.value)
- }
- if (properties.defaultbackground) {
- if (properties.defaultbackground.value) {
- window.settings.setDefaultBackground(properties.defaultbackground.value)
- }
- }
- if (properties.background) {
- if (properties.background.value) {
- window.settings.setBackgoundImage(`url('file:///${properties.background.value}')`)
- } else {
- window.settings.resetBackground()
- }
- }
- if (properties.voicetitle) {
- window.voice.useVoice = properties.voicetitle.value
- }
- if (properties.voicelanguage) {
- window.voice.language = properties.voicelanguage.value
- }
- if (properties.voiceidle) {
- window.voice.idleDuration = parseInt(properties.voiceidle.value)
- }
- if (properties.voicenext) {
- window.voice.nextDuration = parseInt(properties.voicenext.value)
- }
- if (properties.voicesubtitle) {
- window.voice.useSubtitle = properties.voicesubtitle.value
- }
- if (properties.voicesubtitlelanguage) {
- window.voice.subtitleLanguage = properties.voicesubtitlelanguage.value
- }
- if (properties.voicesubtitlex) {
- window.voice.subtitleX = properties.voicesubtitlex.value
- }
- if (properties.voicesubtitley) {
- window.voice.subtitleY = properties.voicesubtitley.value
- }
- if (properties.voiceactor) {
- window.voice.useVoiceActor = properties.voiceactor.value
- }
- if (properties.music_selection) {
- window.music.changeMusic(properties.music_selection.value)
- }
- if (properties.music_title) {
- window.music.useMusic = properties.music_title.value
- }
- if (properties.music_volume) {
- window.music.volume = properties.music_volume.value
- }
- if (properties.custom_music) {
- if (properties.custom_music.value) {
- window.settings.setMusicFromWE(`file:///${properties.custom_music.value}`)
- } else {
- window.settings.resetMusic()
- }
- }
- if (properties.custom_video) {
- if (properties.custom_video.value) {
- window.settings.setVideoFromWE(`file:///${properties.custom_video.value}`)
- } else {
- window.settings.resetVideo()
- }
- }
- if (properties.video_volume) {
- window.settings.setVideoVolume(properties.video_volume.value)
- }
- if (properties.scale) {
- window.settings.setScale(properties.scale.value)
- }
- if (properties.position) {
- if (!properties.position.value) {
- window.settings.positionReset()
- } else {
- window.settings.positionPadding(null, {
- left: properties.paddingleft.value,
- right: properties.paddingright.value,
- top: properties.paddingtop.value,
- bottom: properties.paddingbottom.value,
- })
- }
- }
- if (properties.paddingleft) {
- window.settings.positionPadding("left", properties.paddingleft.value)
- }
- if (properties.paddingright) {
- window.settings.positionPadding("right", properties.paddingright.value)
- }
- if (properties.paddingtop) {
- window.settings.positionPadding("top", properties.paddingtop.value)
- }
- if (properties.paddingbottom) {
- window.settings.positionPadding("bottom", properties.paddingbottom.value)
- }
- if (properties.useStartAnimation) {
- window.settings.useStartAnimation = properties.useStartAnimation.value
- }
- },
+ applyGeneralProperties: function (properties) {
+ if (properties.fps) {
+ document.dispatchEvent(Event.PlayerSetFPSEventFn(properties.fps))
+ }
+ },
+ applyUserProperties: function (properties) {
+ if (properties.privacydonottrack) {
+ document.dispatchEvent(Event.InsightRegisterEventFn(!properties.privacydonottrack.value))
+ }
+ if (properties.logo) {
+ document.dispatchEvent(Event.LogoSetHiddenEventFn(!properties.logo.value))
+ }
+ if (properties.logoratio) {
+ if (properties.logoratio.value) {
+ document.dispatchEvent(Event.LogoSetRatioEventFn(properties.logoratio.value))
+ }
+ }
+ if (properties.logoopacity) {
+ if (properties.logoopacity.value) {
+ document.dispatchEvent(Event.LogoSetOpacityEventFn(properties.logoopacity.value))
+ }
+ }
+ if (properties.logoimage) {
+ if (properties.logoimage.value) {
+ document.dispatchEvent(Event.LogoSetImageEventFn('file:///' + properties.logoimage.value))
+ } else {
+ document.dispatchEvent(Event.LogoResetImageEvent)
+ }
+ }
+ if (properties.logox) {
+ document.dispatchEvent(Event.LogoSetPositionEventFn({
+ x: properties.logox.value
+ }))
+ }
+ if (properties.logoy) {
+ document.dispatchEvent(Event.LogoSetPositionEventFn({
+ y: properties.logoy.value
+ }))
+ }
+ if (properties.defaultbackground) {
+ if (properties.defaultbackground.value) {
+ document.dispatchEvent(Event.BackgroundSetDefaultEventFn(properties.defaultbackground.value))
+ }
+ }
+ if (properties.background) {
+ if (properties.background.value) {
+ document.dispatchEvent(Event.BackgroundSetCustomEventFn(`file:///${properties.background.value}`))
+ } else {
+ document.dispatchEvent(Event.BackgroundResetImageEvent)
+ }
+ }
+ if (properties.voicetitle) {
+ document.dispatchEvent(Event.VoiceSetUseVoiceEventFn(properties.voicetitle.value))
+ }
+ if (properties.voicelanguage) {
+ document.dispatchEvent(Event.VoiceSetLanguageEventFn(properties.voicelanguage.value))
+ }
+ if (properties.voiceidle) {
+ document.dispatchEvent(Event.VoiceSetDurationEventFn({
+ idle: properties.voiceidle.value
+ }))
+ }
+ if (properties.voicenext) {
+ document.dispatchEvent(Event.VoiceSetDurationEventFn({
+ next: properties.voicenext.value
+ }))
+ }
+ if (properties.voicesubtitle) {
+ document.dispatchEvent(Event.VoiceSetUseSubtitleEventFn(properties.voicesubtitle.value))
+ }
+ if (properties.voicesubtitlelanguage) {
+ document.dispatchEvent(Event.VoiceSetSubtitleLanguageEventFn(properties.voicesubtitlelanguage.value))
+ }
+ if (properties.voicesubtitlex) {
+ document.dispatchEvent(Event.VoiceSetSubtitlePositionEventFn({
+ x: properties.voicesubtitlex.value
+ }))
+ }
+ if (properties.voicesubtitley) {
+ document.dispatchEvent(Event.VoiceSetSubtitlePositionEventFn({
+ y: properties.voicesubtitley.value
+ }))
+ }
+ if (properties.voiceactor) {
+ document.dispatchEvent(Event.VoiceSetUseVoiceActorEventFn(properties.voiceactor.value))
+ }
+ if (properties.music_selection) {
+ document.dispatchEvent(Event.MusicSetMusicEventFn(properties.music_selection.value))
+ }
+ if (properties.music_title) {
+ document.dispatchEvent(Event.MusicSetUseMusicEventFn(properties.music_title.value))
+ }
+ if (properties.music_volume) {
+ document.dispatchEvent(Event.MusicSetVolumeEventFn(properties.music_volume.value))
+ }
+ if (properties.custom_music) {
+ if (properties.custom_music.value) {
+ document.dispatchEvent(Event.MusicSetCustomEventFn(`file:///${properties.custom_music.value}`))
+ } else {
+ document.dispatchEvent(Event.MusicResetEvent)
+ }
+ }
+ if (properties.custom_video) {
+ if (properties.custom_video.value) {
+ document.dispatchEvent(Event.BackgroundSetVideoEventFn(`file:///${properties.custom_video.value}`))
+ } else {
+ document.dispatchEvent(Event.BackgroundResetVideoEvent)
+ }
+ }
+ if (properties.video_volume) {
+ document.dispatchEvent(Event.BackgroundSetVolumeEventFn(properties.video_volume.value))
+ }
+ if (properties.scale) {
+ document.dispatchEvent(Event.PlayerSetScaleEventFn(properties.scale.value))
+ }
+ if (properties.position) {
+ if (!properties.position.value) {
+ document.dispatchEvent(Event.PlayerResetPaddingEvent)
+ } else {
+ document.dispatchEvent(Event.PlayerSetPaddingEventFn({
+ left: properties.paddingleft.value,
+ right: properties.paddingright.value,
+ top: properties.paddingtop.value,
+ bottom: properties.paddingbottom.value,
+ }))
+ }
+ }
+ if (properties.paddingleft) {
+ document.dispatchEvent(Event.PlayerSetPaddingEventFn({
+ left: properties.paddingleft.value,
+ }))
+ }
+ if (properties.paddingright) {
+ document.dispatchEvent(Event.PlayerSetPaddingEventFn({
+ right: properties.paddingright.value,
+ }))
+ }
+ if (properties.paddingtop) {
+ document.dispatchEvent(Event.PlayerSetPaddingEventFn({
+ top: properties.paddingtop.value,
+ }))
+ }
+ if (properties.paddingbottom) {
+ document.dispatchEvent(Event.PlayerSetPaddingEventFn({
+ bottom: properties.paddingbottom.value,
+ }))
+ }
+ if (properties.useStartAnimation) {
+ document.dispatchEvent(Event.PlayerSetUseStartAnimationEventFn(properties.useStartAnimation.value))
+ }
+ },
};
\ No newline at end of file