chore: Update danmuku plugin configuration handling and improve performance

This commit is contained in:
Harvey Zack committed 2024-05-29 11:16:56 +08:00
1 parent 034444d77d
commit d0f1f4a76c
3 files changed
+163 -129

No files matched your search

@@ -185,55 +185,83 @@ export default class Setting {
`;
}
get OPACITY() {
return (
this.option.OPACITY || {
min: 0,
max: 100,
steps: [],
}
);
}
get FONTSIZE() {
return (
this.option.FONTSIZE || {
min: 12,
max: 120,
steps: [],
}
);
}
get MARGIN() {
return (
this.option.MARGIN || [
{
name: '1/4',
value: [10, '75%'],
},
{
name: '半屏',
value: [10, '50%'],
},
{
name: '3/4',
value: [10, '25%'],
},
{
name: '满屏',
value: [10, 10],
},
]
this.option.MARGIN || {
min: 0,
max: 3,
steps: [
{
name: '1/4',
value: [10, '75%'],
},
{
name: '半屏',
value: [10, '50%'],
},
{
name: '3/4',
value: [10, '25%'],
},
{
name: '满屏',
value: [10, 10],
},
],
}
);
}
get SPEED() {
return (
this.option.SPEED || [
{
name: '极慢',
value: 10,
},
{
name: '较慢',
value: 7.5,
hide: true,
},
{
name: '适中',
value: 5,
},
{
name: '较快',
value: 2.5,
hide: true,
},
{
name: '极快',
value: 1,
},
]
this.option.SPEED || {
min: 0,
max: 4,
steps: [
{
name: '极慢',
value: 10,
},
{
name: '较慢',
value: 7.5,
hide: true,
},
{
name: '适中',
value: 5,
},
{
name: '较快',
value: 2.5,
hide: true,
},
{
name: '极快',
value: 1,
},
],
}
);
}
@@ -380,9 +408,7 @@ export default class Setting {
createSliders() {
this.slider.opacity = this.createSlider({
min: 0,
max: 100,
steps: [],
...this.OPACITY,
container: this.template.$opacitySlider,
findIndex: () => {
return Math.round(this.option.opacity * 100);
@@ -397,17 +423,15 @@ export default class Setting {
});
this.slider.margin = this.createSlider({
min: 0,
max: 3,
steps: this.MARGIN,
...this.MARGIN,
container: this.template.$marginSlider,
findIndex: () => {
return this.MARGIN.findIndex(
return this.MARGIN.steps.findIndex(
(item) => item.value[0] === this.option.margin[0] && item.value[1] === this.option.margin[1],
);
},
onChange: (index) => {
const margin = this.MARGIN[index];
const margin = this.MARGIN.steps[index];
if (!margin) return;
const { $marginValue } = this.template;
$marginValue.textContent = margin.name;
@@ -418,9 +442,7 @@ export default class Setting {
});
this.slider.fontSize = this.createSlider({
min: 12,
max: 120,
steps: [],
...this.FONTSIZE,
container: this.template.$fontSizeSlider,
findIndex: () => {
return Math.round(this.danmuku.fontSize);
@@ -435,15 +457,13 @@ export default class Setting {
});
this.slider.speed = this.createSlider({
min: 0,
max: 4,
steps: this.SPEED,
...this.SPEED,
container: this.template.$speedSlider,
findIndex: () => {
return this.SPEED.findIndex((item) => item.value === this.option.speed);
return this.SPEED.steps.findIndex((item) => item.value === this.option.speed);
},
onChange: (index) => {
const speed = this.SPEED[index];
const speed = this.SPEED.steps[index];
if (!speed) return;
const { $speedValue } = this.template;
$speedValue.textContent = speed.name;