Skip to content

Commit

Permalink
fix: correctly update themes image
Browse files Browse the repository at this point in the history
  • Loading branch information
shezard committed Feb 11, 2024
1 parent 317082c commit aba3259
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/lib/components/Menu.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { currentTheme, image, themes } from '$lib/store';
import { currentTheme, step, themes } from '$lib/store';
import { RadioGroup, RadioItem } from '@skeletonlabs/skeleton';
let isOpen = false;
Expand All @@ -10,7 +10,7 @@
function closeMenu() {
isOpen = false;
image.next();
step.next();
}
</script>

Expand Down
29 changes: 16 additions & 13 deletions src/lib/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const createApplicationState = function () {
subscribe,
update: (applicationState: 'started' | 'paused' | 'clear') => {
if (applicationState === 'clear') {
image.next();
step.next();
applicationState = 'paused';
}
set(applicationState);
Expand All @@ -36,26 +36,29 @@ const createApplicationState = function () {

export const applicationState = createApplicationState();

const images = derived([currentTheme], ([$currentTheme]) => {
return themeData[$currentTheme];
});

const createImage = function () {
let step = 0;
const createStep = function () {

const { subscribe, set } = writable(get(images)[step]);
const { subscribe, update } = writable(0);

return {
subscribe,
next: () => {
step++;
step = step % get(images).length;
set(get(images)[step]);
update((step) => {
const length = themeData[get(currentTheme)].length;
step++;
step = step % length;
return step
});
}
};
};

export const image = createImage();
export const step = createStep();

export const image = derived([currentTheme, step], ([$currentTheme, $step]) => {
const images = themeData[$currentTheme]
return images[$step];
});;

const currentTime = readable(0, (set) => {
let rafId: number;
Expand Down Expand Up @@ -134,7 +137,7 @@ export const mm = derived(secondTiming, ($secondTiming) => {

export const ss = derived([secondTiming, poseDuration], ([$secondTiming, $poseDuration]) => {
if ($secondTiming > 0 && $secondTiming % $poseDuration === 0) {
image.next();
step.next();
}

return ($secondTiming % 60).toString().padStart(2, '0');
Expand Down

0 comments on commit aba3259

Please sign in to comment.