Skip to content

Commit

Permalink
fix ijru@4 presentation quick tallies
Browse files Browse the repository at this point in the history
  • Loading branch information
swantzter committed Nov 2, 2024
1 parent 83c3bc9 commit 0b20763
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 37 deletions.
1 change: 0 additions & 1 deletion src/hooks/scoresheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ function processMark <Schema extends string> (tally: Ref<Readonly<ScoreTally<Sch
if (markReducer.value != null) {
markReducer.value.addMark(mark)
tally.value = markReducer.value.tally
console.log(tally.value)
}
} catch (err) {
if (err instanceof Error) pushNotification({ message: err.message, color: 'red' })
Expand Down
63 changes: 27 additions & 36 deletions src/views/scoring/ijru@4.0.0/Presentation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,75 +7,75 @@
label="Creativity -"
class="row-start-2"
color="red"
:value="tally('creaMinus')"
:value="simpleTally.creaMinus ?? 0"
:disabled="!!scoresheet?.completedAt"
@click="addMark({ schema: 'creaMinus' })"
/>
<score-button
label="Musicality -"
class="row-start-3"
color="red"
:value="tally('musicMinus')"
:value="simpleTally.musicMinus ?? 0"
:disabled="!!scoresheet?.completedAt"
@click="addMark({ schema: 'musicMinus' })"
/>
<score-button
label="Entertainment -"
class="row-start-4"
color="red"
:value="tally('entMinus')"
:value="simpleTally.entMinus ?? 0"
:disabled="!!scoresheet?.completedAt"
@click="addMark({ schema: 'entMinus' })"
/>
<score-button
label="Form -"
class="row-start-5"
color="red"
:value="tally('formMinus')"
:value="simpleTally.formMinus ?? 0"
:disabled="!!scoresheet?.completedAt"
@click="addMark({ schema: 'formMinus' })"
/>
<score-button
label="Repetitive -"
class="row-start-6"
color="red"
:value="tally('variMinus')"
:value="simpleTally.variMinus ?? 0"
:disabled="!!scoresheet?.completedAt"
@click="addMark({ schema: 'variMinus' })"
/>

<score-button
label="Creativity +"
class="row-start-2 col-start-3"
:value="tally('creaPlus')"
:value="simpleTally.creaPlus ?? 0"
:disabled="!!scoresheet?.completedAt"
@click="addMark({ schema: 'creaPlus' })"
/>
<score-button
label="Musicality +"
class="row-start-3 col-start-3"
:value="tally('musicPlus')"
:value="simpleTally.musicPlus ?? 0"
:disabled="!!scoresheet?.completedAt"
@click="addMark({ schema: 'musicPlus' })"
/>
<score-button
label="Entertainment +"
class="row-start-4 col-start-3"
:value="tally('entPlus')"
:value="simpleTally.entPlus ?? 0"
:disabled="!!scoresheet?.completedAt"
@click="addMark({ schema: 'entPlus' })"
/>
<score-button
label="Form +"
class="row-start-5 col-start-3"
:value="tally('formPlus')"
:value="simpleTally.formPlus ?? 0"
:disabled="!!scoresheet?.completedAt"
@click="addMark({ schema: 'formPlus' })"
/>
<score-button
label="Variety +"
class="row-start-6 col-start-3"
:value="tally('variPlus')"
:value="simpleTally.variPlus ?? 0"
:disabled="!!scoresheet?.completedAt"
@click="addMark({ schema: 'variPlus' })"
/>
Expand Down Expand Up @@ -153,8 +153,8 @@
>
<span>0</span>
<div class="flex content-center justify-center flex-wrap w-full m-2">
<div>{{ componentScore(component) }}</div>
<progress class="w-full" max="24" :value="componentScore(component)" />
<div>{{ tally(component) }}</div>
<progress class="w-full" max="24" :value="tally(component)" />
</div>
<span>24</span>
</div>
Expand Down Expand Up @@ -196,14 +196,15 @@
import ScoreButton from '../../../components/ScoreButton.vue'
import { useScoresheet } from '../../../hooks/scoresheet'
import { computed, type PropType } from 'vue'
import { computed, type PropType, ref } from 'vue'
import type { Model } from '../../../models'
import { clamp } from '@vueuse/core'
import { createMarkReducer, type ScoreTally, simpleReducer } from '@ropescore/rulesets'
const components = ['crea', 'music', 'ent', 'form', 'vari'] as const
type Component = typeof components[number]
export type Schema = 'miss' | `${Component}${'Plus' | 'Minus'}${'' | 'Adj'}`
export type Schema = 'miss' | `${Component}${'Plus' | 'Minus'}${'' | 'Adj'}` | Component
defineProps({
model: {
Expand All @@ -216,25 +217,15 @@ defineProps({
},
})
const { addMark, tally, scoresheet } = useScoresheet<Schema>()
const { addMark: _addMark, tally, scoresheet } = useScoresheet<Schema>()
const CHANGE = 1
const mr = ref(createMarkReducer(simpleReducer))
const simpleTally = ref<ScoreTally<Schema>>({})
function componentScore (type: Component) {
let score = 12
score += tally(`${type}Plus`) * CHANGE
score -= tally(`${type}Minus`) * CHANGE
score -= tally('miss') * CHANGE
score = Math.round(clamp(score, 0, 24))
for (const mark of scoresheet.value?.marks ?? []) {
if (mark.schema === `${type}PlusAdj` && score < 24) score += CHANGE
else if (mark.schema === `${type}MinusAdj` && score > 0) score -= CHANGE
}
return Math.round(clamp(score, 0, 24))
const addMark: typeof _addMark = async (mark) => {
await _addMark(mark)
mr.value?.addMark(mark)
simpleTally.value = mr.value.tally
}
const weights = {
Expand All @@ -247,11 +238,11 @@ const weights = {
const result = computed(() => {
const componentScores: Record<Component, number> = {
music: componentScore('music'),
form: componentScore('form'),
ent: componentScore('ent'),
crea: componentScore('crea'),
vari: componentScore('vari')
music: tally('music'),
form: tally('form'),
ent: tally('ent'),
crea: tally('crea'),
vari: tally('vari')
}
let sum = 0
Expand Down

0 comments on commit 0b20763

Please sign in to comment.