Skip to content

Commit baa1f8c

Browse files
committed
fix: user tools config merging & tools type checking
1 parent fe83acb commit baa1f8c

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

client/options.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ValaxyAddon } from 'valaxy'
22
import type { Live2DCollection, Live2dOptions, Live2dTips } from '../types'
3+
import defu from 'defu'
34
import { useRuntimeConfig } from 'valaxy'
45
import { computed } from 'vue'
56
import { live2DCollection } from '../constants/live2dCollection'
@@ -10,19 +11,19 @@ import { filterLive2DCollection, mergeConfigs } from '../utils/config'
1011
export function useAddonLive2dConfig() {
1112
const runtimeConfig = useRuntimeConfig()
1213
return computed<Live2dOptions>(() => {
13-
const { options } = runtimeConfig.value.addons['valaxy-addon-live2d'] as ValaxyAddon<Live2dOptions>
14+
const { options: userOptions } = runtimeConfig.value.addons['valaxy-addon-live2d'] as ValaxyAddon<Live2dOptions>
1415

15-
const enableLive2D = options?.enableLive2D ?? 'all'
16-
const mergedLive2DCollection: Live2DCollection = { ...live2DCollection, ...options?.live2DCollection }
16+
const enableLive2D = userOptions?.enableLive2D ?? 'all'
17+
const mergedLive2DCollection: Live2DCollection = { ...live2DCollection, ...userOptions?.live2DCollection }
1718

1819
const filteredAndSortedLive2DCollection: Live2DCollection = (enableLive2D === 'all')
1920
? mergedLive2DCollection
2021
: filterLive2DCollection(enableLive2D, mergedLive2DCollection)
2122

22-
const mergedLive2dTips = mergeConfigs(live2dTips, options?.live2dTips || {}) as Live2dTips
23+
const mergedLive2dTips = mergeConfigs(live2dTips, userOptions?.live2dTips || {}) as Live2dTips
24+
const options = defu(userOptions, defaultLive2DOptions)
2325

2426
return {
25-
...defaultLive2DOptions,
2627
...options,
2728

2829
live2DCollection: filteredAndSortedLive2DCollection,

helpers/tips.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,6 @@ export class Live2dTipsHandler {
170170
return
171171
}
172172

173-
console.log("priority", priority);
174-
console.log("this.currentPriority", this.currentPriority);
175-
176173
if (priority < this.currentPriority)
177174
return
178175

node/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Live2dOptions } from '../types'
2-
import { captureLive2dImage, loadAsteroids, showHitokoto } from '../utils/tools'
2+
import { captureLive2dImage, loadAsteroids } from '../utils/tools'
33

44
export const defaultLive2DOptions: Live2dOptions = {
55
widthLimit: 250,

types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export interface Live2dOptions {
4646
/**
4747
* 启用的工具列表
4848
*/
49-
tools?: Record<Live2DToolId, Live2DToolConfig>
49+
tools?: Partial<Record<Live2DToolId, Partial<Live2DToolConfig>>>
5050
/**
5151
* 是否开启调试模式
5252
* @defaultValue false

0 commit comments

Comments
 (0)