Skip to content

Commit

Permalink
use videos for Aikido-Föderation
Browse files Browse the repository at this point in the history
  • Loading branch information
nknapp committed Aug 18, 2024
1 parent 8e1b623 commit 52a9dc7
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 21 deletions.
8 changes: 4 additions & 4 deletions src/YoutubePlayer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { youtubeEnabled } from "$core/store/youtube.ts";
import { loadYoutubeAdapter } from "@/YoutubePlayer/adapter.ts";

export interface YoutubePlayer {
loadVideo(videoId: string): Promise<void>;
loadVideo(videoId: string, startSeconds?: number, endSeconds?: number): Promise<void>;
play(): Promise<void>;
stop(): Promise<void>;
waitForStop(): Promise<void>;
}

export async function playVideo(youtubeLink: YoutubeLink): Promise<void> {
const player = await getOrCreatePlayer();
await player.loadVideo(youtubeLink.videoId);
await player.loadVideo(youtubeLink.videoId, youtubeLink.startSeconds, youtubeLink.endSeconds);
await player.play();
await player.waitForStop();
await player.stop();
Expand Down Expand Up @@ -43,8 +43,8 @@ async function createPlayer(): Promise<YoutubePlayer> {
updatePlayerSize();

const result = {
loadVideo(videoId: string) {
return player.loadVideoById(videoId);
loadVideo(videoId: string, startSeconds?: number, endSeconds?: number) {
return player.loadVideoById(videoId, startSeconds, endSeconds);
},
async play() {
await player.playVideo();
Expand Down
4 changes: 2 additions & 2 deletions src/components/solid/organisms/Reader/Reader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { type DelayControl, DelayIndicator } from "@/components/solid/atoms/Dela
import { youtubeEnabled } from "$core/store/youtube.ts";
import { usePersistentStore } from "@/components/solid/hooks/usePersistentStore.ts";
import { YoutubePlayButton } from "@/components/solid/atoms/YoutubePlayButton.tsx";
import { coerceToArray } from "$core/utils/coerceToArray.ts";
import { resolveYoutubeLinks } from "@/utils/resolveYoutubeLinks.ts";

export const Reader: Component<{ dojoInfo: DojoInfo; speechPack: SpeechPack }> = (props) => {
const techniqueStore = createTechniqueStore(props.dojoInfo.id);
Expand Down Expand Up @@ -57,7 +57,7 @@ export const Reader: Component<{ dojoInfo: DojoInfo; speechPack: SpeechPack }> =
ready={playerLoaded()}
onClickAutoPlay={() => setAutoPlay(!autoPlay())}
autoPlayEnabled={autoPlay()}
youtube={coerceToArray(lastTechnique()?.metadata?.youtube)}
youtube={resolveYoutubeLinks(lastTechnique())}
/>
<DelayIndicator setDelayControl={setDelayControl} disabled={!autoPlay()} />
<ExamScroll
Expand Down
27 changes: 14 additions & 13 deletions src/components/solid/organisms/TechniqueChooser/ExamSheet.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import { type Component, createMemo, For, Match, Show, Switch } from "solid-js";
import { SINGLE_DIRECTION, type Technique, type TechniqueMetadata, type YoutubeLink } from "$core/model";
import { type BaseTechnique, SINGLE_DIRECTION, type Technique, type YoutubeLink } from "$core/model";
import { ForEntries } from "./ForEntries.tsx";
import { buildExamTable } from "$core/buildExamTable";
import { t } from "@/i18n";
import { youtubeEnabled } from "$core/store/youtube.ts";
import { usePersistentStore } from "@/components/solid/hooks/usePersistentStore.ts";
import { YoutubePlayButton } from "@/components/solid/atoms/YoutubePlayButton.tsx";
import { resolveYoutubeLinks } from "@/utils/resolveYoutubeLinks.ts";
import { buildTechniqueTree } from "$core/buildExamTable/buildExamTable.ts";

export interface ExamSheetProps {
techniques: Technique[];
}

export const ExamSheet: Component<ExamSheetProps> = (props) => {
const examTable = createMemo(() =>
buildTechniqueTree(props.techniques, (technique) => {
return technique;
}),
);
return (
<div>
<ForEntries object={buildExamTable(props.techniques)}>
<ForEntries object={examTable()}>
{(execution, attacks) => (
<div>
<h2 class={"border-b border-1 border-secondary break-after-avoid"}>{execution}</h2>
Expand Down Expand Up @@ -49,7 +55,7 @@ export const ExamSheet: Component<ExamSheetProps> = (props) => {
};

interface DirectionsProps {
directions: Record<string, TechniqueMetadata>;
directions: Record<string, BaseTechnique>;
}

const ShowDirections: Component<DirectionsProps> = (props) => {
Expand All @@ -60,7 +66,7 @@ const ShowDirections: Component<DirectionsProps> = (props) => {
return (
<Switch>
<Match when={singleDirection()}>
<YoutubeLink metadata={props.directions[SINGLE_DIRECTION]} />
<YoutubeLink technique={props.directions[SINGLE_DIRECTION]} />
</Match>
<Match when={!singleDirection()}>
<span class={"text-sm"}>
Expand All @@ -70,7 +76,7 @@ const ShowDirections: Component<DirectionsProps> = (props) => {
return (
<span>
{direction}
<YoutubeLink metadata={metadata} />
<YoutubeLink technique={metadata} />
</span>
);
}}
Expand All @@ -82,14 +88,9 @@ const ShowDirections: Component<DirectionsProps> = (props) => {
);
};

const YoutubeLink: Component<{ metadata: TechniqueMetadata }> = (props) => {
const YoutubeLink: Component<{ technique: BaseTechnique }> = (props) => {
const showYoutube = usePersistentStore(youtubeEnabled, false);
const youtube =
props.metadata.youtube == null
? []
: Array.isArray(props.metadata.youtube)
? props.metadata.youtube
: [props.metadata.youtube];
const youtube = resolveYoutubeLinks(props.technique);
return (
<Show when={showYoutube()}>
<span class={"print:hidden"}>
Expand Down
46 changes: 44 additions & 2 deletions src/data/videopacks/aikido-kompendium/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default {
videoId: "3yd1kGHIviA",
durationSeconds: 20,
id: "0",
startSeconds: 0,
startSeconds: 6,
endSeconds: 20,
},
],
Expand All @@ -27,7 +27,7 @@ export default {
videoId: "HZOkvZDAh34",
durationSeconds: 27,
id: "13",
startSeconds: 0,
startSeconds: 6,
endSeconds: 27,
},
],
Expand All @@ -37,6 +37,8 @@ export default {
videoId: "QUNg_jthIqM",
durationSeconds: 21,
id: "14",
startSeconds: 6,
endSeconds: 21,
},
],
},
Expand All @@ -47,6 +49,8 @@ export default {
videoId: "dHhOLufvx3U",
durationSeconds: 24,
id: "15",
startSeconds: 6,
endSeconds: 24,
},
],
},
Expand All @@ -59,6 +63,8 @@ export default {
videoId: "ODF1mKYFT50",
durationSeconds: 21,
id: "16",
startSeconds: 6,
endSeconds: 21,
},
],
ura: [
Expand All @@ -67,6 +73,8 @@ export default {
videoId: "dm7lj0RaEzw",
durationSeconds: 19,
id: "17",
startSeconds: 6,
endSeconds: 19,
},
],
},
Expand All @@ -77,6 +85,8 @@ export default {
videoId: "ZrvHAhQXyyE",
durationSeconds: 22,
id: "18",
startSeconds: 6,
endSeconds: 22,
},
],
},
Expand All @@ -87,6 +97,8 @@ export default {
videoId: "meNnP_iyjSY",
durationSeconds: 30,
id: "59",
startSeconds: 6,
endSeconds: 30,
},
],
ura: [
Expand All @@ -95,6 +107,8 @@ export default {
videoId: "2gWlA-rMtic",
durationSeconds: 31,
id: "60",
startSeconds: 6,
endSeconds: 31,
},
],
},
Expand All @@ -105,6 +119,8 @@ export default {
videoId: "OaKRmnjJdK8",
durationSeconds: 29,
id: "61",
startSeconds: 6,
endSeconds: 29,
},
],
ura: [
Expand All @@ -113,6 +129,8 @@ export default {
videoId: "f3gHuS8Bp3A",
durationSeconds: 29,
id: "62",
startSeconds: 6,
endSeconds: 29,
},
],
},
Expand All @@ -123,6 +141,8 @@ export default {
videoId: "X-fctXW0Lmg",
durationSeconds: 21,
id: "63",
startSeconds: 6,
endSeconds: 21,
},
],
ura: [
Expand All @@ -131,6 +151,8 @@ export default {
videoId: "a-jasPR2So0",
durationSeconds: 26,
id: "64",
startSeconds: 6,
endSeconds: 26,
},
],
},
Expand All @@ -141,6 +163,8 @@ export default {
videoId: "9HNkdOJmT3k",
durationSeconds: 28,
id: "65",
startSeconds: 6,
endSeconds: 28,
},
],
},
Expand All @@ -151,6 +175,8 @@ export default {
videoId: "t9aPIPxxdzs",
durationSeconds: 22,
id: "227",
startSeconds: 2,
endSeconds: 22,
},
],
},
Expand All @@ -163,6 +189,8 @@ export default {
videoId: "i3bgZsdTmyQ",
durationSeconds: 24,
id: "51",
startSeconds: 6,
endSeconds: 24,
},
],
ura: [
Expand All @@ -171,6 +199,8 @@ export default {
videoId: "dQF5oxxDD30",
durationSeconds: 24,
id: "52",
startSeconds: 6,
endSeconds: 24,
},
],
},
Expand All @@ -181,6 +211,8 @@ export default {
videoId: "ypXXzb2YHFY",
durationSeconds: 29,
id: "53",
startSeconds: 6,
endSeconds: 29,
},
],
ura: [
Expand All @@ -189,6 +221,8 @@ export default {
videoId: "6JBCfxORKJQ",
durationSeconds: 29,
id: "54",
startSeconds: 6,
endSeconds: 29,
},
],
},
Expand All @@ -199,6 +233,8 @@ export default {
videoId: "B5fVD3L47zg",
durationSeconds: 25,
id: "150",
startSeconds: 6,
endSeconds: 25,
},
],
ura: [
Expand All @@ -207,6 +243,8 @@ export default {
videoId: "sunQhz4qybw",
durationSeconds: 24,
id: "151",
startSeconds: 6,
endSeconds: 24,
},
],
},
Expand All @@ -217,6 +255,8 @@ export default {
videoId: "Y8Qym8RlPOw",
durationSeconds: 20,
id: "152",
startSeconds: 2,
endSeconds: 20,
},
],
ura: [
Expand All @@ -225,6 +265,8 @@ export default {
videoId: "cf9NaXqF_Ck",
durationSeconds: 24,
id: "153",
startSeconds: 6,
endSeconds: 24,
},
],
},
Expand Down
11 changes: 11 additions & 0 deletions src/utils/resolveYoutubeLinks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { BaseTechnique, YoutubeLink } from "$core/model";
import aikidoKompendium from "@/data/videopacks/aikido-kompendium";

export function resolveYoutubeLinks(technique: BaseTechnique | null): YoutubeLink[] {
if (technique == null) return [];

return (
// @ts-expect-error Partial objects resolve to any, which is not relevant in our case.
aikidoKompendium.videos[technique.execution]?.[technique.attack]?.[technique.defence]?.[technique.direction] ?? []
);
}

0 comments on commit 52a9dc7

Please sign in to comment.