-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor ExamScroll, move "playArrayBuffer" to core
- Loading branch information
Showing
30 changed files
with
284 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
describe("Player", () => {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import { buildExamScroll, type ExamScrollEntry } from "$core/buildExamScroll/buildExamScroll.ts"; | ||
import { createTechnique } from "$core/model/Technique.test-helper.ts"; | ||
import { relevantTechniqueProperties } from "$core/relevantTechniqueParts/relevantTechniqueProperties.ts"; | ||
import { buildTechniqueId } from "$core/model"; | ||
|
||
describe("buildExamScroll", () => { | ||
it("returns empty scroll for empty array", () => { | ||
expect([...buildExamScroll([])]).toHaveLength(0); | ||
}); | ||
|
||
it("returns field values of each technique", () => { | ||
expect([ | ||
...buildExamScroll([ | ||
createTechnique("tachi waza", "chudan tsuki", "ikkyo", "omote"), | ||
createTechnique("hanmi handachi waza", "ai hanmi katate dori", "nikyo", "ura"), | ||
]), | ||
]).toEqual([ | ||
{ | ||
id: expect.any(String), | ||
execution: { relevant: true, value: "tachi waza" }, | ||
attack: { relevant: true, value: "chudan tsuki" }, | ||
defence: { relevant: true, value: "ikkyo" }, | ||
direction: { relevant: true, value: "omote" }, | ||
}, | ||
{ | ||
id: expect.any(String), | ||
execution: { relevant: true, value: "hanmi handachi waza" }, | ||
attack: { relevant: true, value: "ai hanmi katate dori" }, | ||
defence: { relevant: true, value: "nikyo" }, | ||
direction: { relevant: true, value: "ura" }, | ||
}, | ||
] satisfies ExamScrollEntry[]); | ||
}); | ||
|
||
it("uses all props for first technique", () => { | ||
expect([...buildExamScroll([createTechnique("tachi waza", "chudan tsuki", "ikkyo", "omote")])]).toEqual([ | ||
{ | ||
id: expect.any(String), | ||
execution: { relevant: true, value: "tachi waza" }, | ||
attack: { relevant: true, value: "chudan tsuki" }, | ||
defence: { relevant: true, value: "ikkyo" }, | ||
direction: { relevant: true, value: "omote" }, | ||
}, | ||
] satisfies ExamScrollEntry[]); | ||
|
||
expect(relevantTechniqueProperties(createTechnique("suwari waza", "kata dori", "ikkyo", "ura"), undefined)).toEqual( | ||
["execution", "attack", "defence", "direction"], | ||
); | ||
}); | ||
|
||
it("uses only direction if everything else is equal", () => { | ||
expect([ | ||
...buildExamScroll([ | ||
createTechnique("tachi waza", "chudan tsuki", "ikkyo", "omote"), | ||
createTechnique("tachi waza", "chudan tsuki", "ikkyo", "ura"), | ||
]), | ||
]).toEqual([ | ||
{ | ||
id: expect.any(String), | ||
execution: { relevant: true, value: "tachi waza" }, | ||
attack: { relevant: true, value: "chudan tsuki" }, | ||
defence: { relevant: true, value: "ikkyo" }, | ||
direction: { relevant: true, value: "omote" }, | ||
}, | ||
{ | ||
id: expect.any(String), | ||
execution: { relevant: false, value: "tachi waza" }, | ||
attack: { relevant: false, value: "chudan tsuki" }, | ||
defence: { relevant: false, value: "ikkyo" }, | ||
direction: { relevant: true, value: "ura" }, | ||
}, | ||
] satisfies ExamScrollEntry[]); | ||
}); | ||
|
||
it("uses direction and defence, if execution and attack is equal", () => { | ||
expect([ | ||
...buildExamScroll([ | ||
createTechnique("tachi waza", "chudan tsuki", "ikkyo", "omote"), | ||
createTechnique("tachi waza", "chudan tsuki", "nikyo", "omote"), | ||
]), | ||
]).toEqual([ | ||
{ | ||
id: expect.any(String), | ||
execution: { relevant: true, value: "tachi waza" }, | ||
attack: { relevant: true, value: "chudan tsuki" }, | ||
defence: { relevant: true, value: "ikkyo" }, | ||
direction: { relevant: true, value: "omote" }, | ||
}, | ||
{ | ||
id: expect.any(String), | ||
execution: { relevant: false, value: "tachi waza" }, | ||
attack: { relevant: false, value: "chudan tsuki" }, | ||
defence: { relevant: true, value: "nikyo" }, | ||
direction: { relevant: true, value: "omote" }, | ||
}, | ||
] satisfies ExamScrollEntry[]); | ||
}); | ||
|
||
it("uses attack, direction and defence, if execution is equal", () => { | ||
expect([ | ||
...buildExamScroll([ | ||
createTechnique("tachi waza", "chudan tsuki", "ikkyo", "omote"), | ||
createTechnique("tachi waza", "jodan tsuki", "ikkyo", "omote"), | ||
]), | ||
]).toEqual([ | ||
{ | ||
id: expect.any(String), | ||
execution: { relevant: true, value: "tachi waza" }, | ||
attack: { relevant: true, value: "chudan tsuki" }, | ||
defence: { relevant: true, value: "ikkyo" }, | ||
direction: { relevant: true, value: "omote" }, | ||
}, | ||
{ | ||
id: expect.any(String), | ||
execution: { relevant: false, value: "tachi waza" }, | ||
attack: { relevant: true, value: "jodan tsuki" }, | ||
defence: { relevant: true, value: "ikkyo" }, | ||
direction: { relevant: true, value: "omote" }, | ||
}, | ||
] satisfies ExamScrollEntry[]); | ||
}); | ||
|
||
it("uses execution, attack, direction and defence, if execution is different", () => { | ||
expect([ | ||
...buildExamScroll([ | ||
createTechnique("suwari waza", "chudan tsuki", "ikkyo", "omote"), | ||
createTechnique("tachi waza", "chudan tsuki", "ikkyo", "omote"), | ||
]), | ||
]).toEqual([ | ||
{ | ||
id: expect.any(String), | ||
execution: { relevant: true, value: "suwari waza" }, | ||
attack: { relevant: true, value: "chudan tsuki" }, | ||
defence: { relevant: true, value: "ikkyo" }, | ||
direction: { relevant: true, value: "omote" }, | ||
}, | ||
{ | ||
id: expect.any(String), | ||
execution: { relevant: true, value: "tachi waza" }, | ||
attack: { relevant: true, value: "chudan tsuki" }, | ||
defence: { relevant: true, value: "ikkyo" }, | ||
direction: { relevant: true, value: "omote" }, | ||
}, | ||
] satisfies ExamScrollEntry[]); | ||
}); | ||
|
||
it("omits the value for 'single-direction'", () => { | ||
expect([...buildExamScroll([createTechnique("suwari waza", "chudan tsuki", "ikkyo", "single-direction")])]).toEqual( | ||
[ | ||
{ | ||
id: expect.any(String), | ||
execution: { relevant: true, value: "suwari waza" }, | ||
attack: { relevant: true, value: "chudan tsuki" }, | ||
defence: { relevant: true, value: "ikkyo" }, | ||
direction: { relevant: false, value: "single-direction" }, | ||
}, | ||
] satisfies ExamScrollEntry[], | ||
); | ||
}); | ||
|
||
it("adds the id to each technique", () => { | ||
const technique = createTechnique("suwari waza", "chudan tsuki", "ikkyo", "single-direction"); | ||
const examScrollEntry = Array.from(buildExamScroll([technique]))[0]; | ||
expect(examScrollEntry.id).toEqual(buildTechniqueId(technique)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { | ||
type Attack, | ||
type BaseTechnique, | ||
buildTechniqueId, | ||
type Defence, | ||
type Direction, | ||
type Execution, | ||
} from "$core/model"; | ||
import { relevantTechniqueProperties } from "$core/relevantTechniqueParts/relevantTechniqueProperties.ts"; | ||
|
||
export interface ExamScrollField<T> { | ||
value: T; | ||
relevant: boolean; | ||
} | ||
|
||
export type ExamScrollEntry = { | ||
id: string; | ||
execution: ExamScrollField<Execution>; | ||
attack: ExamScrollField<Attack>; | ||
defence: ExamScrollField<Defence>; | ||
direction: ExamScrollField<Direction>; | ||
}; | ||
|
||
export function* buildExamScroll(techniques: BaseTechnique[]): Generator<ExamScrollEntry> { | ||
let lastTechnique: BaseTechnique | undefined = undefined; | ||
for (const technique of techniques) { | ||
const relevantProps = relevantTechniqueProperties(technique, lastTechnique); | ||
yield { | ||
id: buildTechniqueId(technique), | ||
execution: { | ||
value: technique.execution, | ||
relevant: relevantProps.includes("execution"), | ||
}, | ||
attack: { | ||
value: technique.attack, | ||
relevant: relevantProps.includes("attack"), | ||
}, | ||
defence: { | ||
value: technique.defence, | ||
relevant: relevantProps.includes("defence"), | ||
}, | ||
direction: { | ||
value: technique.direction, | ||
relevant: relevantProps.includes("direction"), | ||
}, | ||
}; | ||
lastTechnique = technique; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { type ExamScrollEntry, buildExamScroll } from "./buildExamScroll.ts"; |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...core/slots/SpeechPack.test-helper.test.ts → ...core/model/SpeechPack.test-helper.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/core/slots/SpeechPack.test-helper.ts → src/core/model/SpeechPack.test-helper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import type { Attack, Execution, Defence, Direction, SINGLE_DIRECTION } from "$core/model"; | ||
import type { Attack, Execution, Defence, Direction, SINGLE_DIRECTION } from "$core/model/index.ts"; | ||
|
||
export type SpeechFile = Exclude<Execution | Attack | Defence | Direction, typeof SINGLE_DIRECTION>; | ||
export type SpeechPack = Record<SpeechFile, string | URL>; |
Oops, something went wrong.