Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: restores tween data correctly when focusing other inputs #837

Merged
merged 1 commit into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 42 additions & 6 deletions src/components/Controls/TweenControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<c span="2">
<Select
:class="color"
v-model.number="modelEasing"
v-model="modelEasing"
:disabled="!!modelSteps"
@input="updateValue"
>
Expand All @@ -34,7 +34,13 @@
</c>

<c span="1+1">Use BPM</c>
<c><Checkbox :class="color" v-model="modelUseBpm" @input="updateValue"/></c>
<c
><Checkbox
:class="color"
v-model="modelUseBpm"
@input="updateValue"
emitBoolean
/></c>

<c span="1+1"><label :for="`${111}-bpmDivision`">BPM Division</label></c>
<c span="2">
Expand Down Expand Up @@ -91,7 +97,7 @@ export default {
modelData: "",
modelDuration: 1000,
modelEasing: "linear",
useBpm: true,
modelUseBpm: true,
modelBpmDivision: 32,
modelDurationAsTotalTime: false,
modelSteps: 0
Expand All @@ -100,7 +106,7 @@ export default {

created() {
if (this.value) {
this.modelData = JSON.stringify(this.value.data);
this.setDefaultData(this.value);
}
},

Expand All @@ -115,7 +121,7 @@ export default {
const data = this.modelData.length ? JSON.parse(this.modelData) : [];
const duration = this.modelDuration;
const easing = this.modelEasing;
const useBpm = this.useBpm;
const useBpm = this.modelUseBpm;
const bpmDivision = this.modelBpmDivision;
const durationAsTotalTime = this.modelDurationAsTotalTime;
const steps = this.modelSteps;
Expand All @@ -130,15 +136,45 @@ export default {
durationAsTotalTime,
steps
});
},

setData(value) {
this.modelData = value.data && JSON.stringify(value.data);
this.modelDuration = value.duration;
this.modelEasing = value.easing;
this.modelUseBpm = value.useBpm;
this.modelBpmDivision = value.bpmDivision;
this.modelDurationAsTotalTime = value.durationAsTotalTime;
this.modelSteps = value.steps;
},

setDefaultData() {
this.setData({
data: "",
duration: 1000,
easing: "linear",
useBpm: true,
bpmDivision: 32,
durationAsTotalTime: false,
steps: 0
});
}
},

watch: {
"$store.state.bpm"(value) {
if (this.useBpm) {
if (this.modelUseBpm) {
this.modelDuration = value / this.modelBpmDivision;
this.updateValue();
}
},

value(value) {
if (!value) {
this.setDefaultData();
} else {
this.setData(value);
}
}
}
};
Expand Down
12 changes: 11 additions & 1 deletion src/components/InputLinkComponents/Tween.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default {
async makeLink() {
const tween = await this.$modV.store.dispatch("dataTypes/createType", {
type: "tween",
args: this.localCache
args: { id: this.inputId, ...this.localCache }
});

this.hasLink = await this.$modV.store.dispatch("inputs/createInputLink", {
Expand All @@ -62,6 +62,16 @@ export default {
inputId: this.inputId
});
}
},

watch: {
inputId() {
if (this.hasLink) {
this.localCache = this.$modV.store.state.tweens.tweens[this.inputId];
} else {
this.localCache = null;
}
}
}
};
</script>