mirror of
https://github.com/ayangweb/BongoCat.git
synced 2026-03-12 17:51:48 +08:00
refactor: dynamic lookup of model master profiles (#365)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { LogicalSize, PhysicalSize } from '@tauri-apps/api/dpi'
|
||||
import { resolveResource } from '@tauri-apps/api/path'
|
||||
import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { round } from 'es-toolkit'
|
||||
import { watch } from 'vue'
|
||||
|
||||
@@ -29,17 +30,21 @@ export function useModel() {
|
||||
}, { immediate: true })
|
||||
|
||||
async function handleLoad() {
|
||||
if (!modelStore.currentModel) return
|
||||
try {
|
||||
if (!modelStore.currentModel) return
|
||||
|
||||
const { path } = modelStore.currentModel
|
||||
const { path } = modelStore.currentModel
|
||||
|
||||
await resolveResource(path)
|
||||
await resolveResource(path)
|
||||
|
||||
const data = await live2d.load(path)
|
||||
const data = await live2d.load(path)
|
||||
|
||||
handleResize()
|
||||
handleResize()
|
||||
|
||||
Object.assign(modelStore, data)
|
||||
Object.assign(modelStore, data)
|
||||
} catch (error) {
|
||||
message.error(String(error))
|
||||
}
|
||||
}
|
||||
|
||||
function handleDestroy() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Cubism4InternalModel } from 'pixi-live2d-display'
|
||||
|
||||
import { convertFileSrc } from '@tauri-apps/api/core'
|
||||
import { readTextFile } from '@tauri-apps/plugin-fs'
|
||||
import { readDir, readTextFile } from '@tauri-apps/plugin-fs'
|
||||
import { Cubism4ModelSettings, Live2DModel } from 'pixi-live2d-display'
|
||||
import { Application, Ticker } from 'pixi.js'
|
||||
|
||||
@@ -34,7 +34,15 @@ class Live2d {
|
||||
|
||||
this.destroy()
|
||||
|
||||
const modelPath = join(path, 'cat.model3.json')
|
||||
const files = await readDir(path)
|
||||
|
||||
const modelFile = files.find(file => file.name.endsWith('.model3.json'))
|
||||
|
||||
if (!modelFile) {
|
||||
throw new Error('未找到模型主配置文件,请确认模型文件是否完整。')
|
||||
}
|
||||
|
||||
const modelPath = join(path, modelFile.name)
|
||||
|
||||
const modelJSON = JSON.parse(await readTextFile(modelPath))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user