-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b321de2
commit 3652cf0
Showing
10 changed files
with
535 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { storage } from "./storage"; | ||
import { DynamicGameState, DynamicQuestionState } from "./types"; | ||
import Alpine from "alpinejs"; | ||
|
||
export function initControllerData() { | ||
Alpine.data("controller", (state: DynamicGameState) => { | ||
return { | ||
get view() { | ||
return state.currentView; | ||
}, | ||
set view(view: DynamicGameState["currentView"]) { | ||
state.changeView(view); | ||
}, | ||
progress: { | ||
questions: { | ||
get max() { | ||
return state.questions.length; | ||
}, | ||
get value() { | ||
return state.activeQuestion + 1; | ||
} | ||
}, | ||
points: { | ||
total: { | ||
get max() { | ||
return state.questions.reduce((accumulator, { maximumPoints }) => accumulator + maximumPoints, 0); | ||
}, | ||
get value() { | ||
return state.teams.reduce((accumulator, { points }) => accumulator + points, 0); | ||
} | ||
} | ||
} | ||
}, | ||
get currentQuestion() { | ||
return state.questions[state.activeQuestion]; | ||
}, | ||
get plan() { | ||
return state.questions.map((question: DynamicQuestionState) => { | ||
return { | ||
get teamA() { | ||
return { | ||
get id() { | ||
return question._teamA; | ||
}, | ||
set id(value) { | ||
question._teamA = value; | ||
}, | ||
get name() { | ||
return question.teamA?.name; | ||
} | ||
} | ||
}, | ||
get teamB() { | ||
return { | ||
get id() { | ||
return question._teamB; | ||
}, | ||
set id(value) { | ||
question._teamB = value; | ||
}, | ||
get name() { | ||
return question.teamB?.name; | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
}, | ||
get teams() { | ||
return state.teams.map(({ id, name, points }) => { | ||
return { | ||
id, | ||
name, | ||
points | ||
} | ||
}); | ||
}, | ||
get rankedTeams() { | ||
return this.teams.toSorted((a, b) => b.points - a.points); | ||
}, | ||
deleteGame() { | ||
return () => { | ||
const shouldDelete = confirm("Do you really wish to delete the entire game state, including teams, questions and given answers and points?"); | ||
if (shouldDelete) { | ||
storage.delete("game"); | ||
location.reload(); | ||
} | ||
} | ||
}, | ||
nextQuestion() { | ||
state.nextQuestion(); | ||
}, | ||
prevQuestion() { | ||
state.prevQuestion(); | ||
} | ||
} | ||
}); | ||
} |
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,12 +1,14 @@ | ||
import Alpine from "alpinejs"; | ||
import { revealDirective } from "./reveal-directive"; | ||
import { initGameState } from "./gameState"; | ||
import { initControllerData } from "./controller"; | ||
|
||
// @ts-ignore | ||
window["Alpine"] = Alpine; | ||
|
||
Alpine.directive("reveal", revealDirective); | ||
|
||
initGameState(); | ||
initControllerData(); | ||
|
||
Alpine.start(); |
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,43 @@ | ||
article hgroup { | ||
--pico-typography-spacing-vertical: 0; | ||
} | ||
|
||
article :is(h1, h2, h3, h4, h5, h6) { | ||
--pico-font-size: 1.1rem; | ||
} | ||
|
||
td>select:last-child { | ||
--pico-spacing: 0; | ||
} | ||
|
||
details>summary { | ||
position: relative; | ||
padding-inline-end: calc(1rem + var(--pico-spacing)); | ||
} | ||
|
||
details>summary::after { | ||
position: absolute; | ||
float: none; | ||
margin: 0; | ||
inset-inline-end: 0; | ||
inset-block-start: calc(50% - 0.5rem); | ||
} | ||
|
||
article>details { | ||
margin: 0; | ||
} | ||
|
||
fieldset:last-child { | ||
margin-bottom: 0; | ||
} | ||
|
||
table:last-child { | ||
margin-bottom: 0; | ||
} | ||
|
||
tfoot [type="button"] { | ||
--pico-font-weight: 400; | ||
--pico-form-element-spacing-vertical: 0.25rem; | ||
--pico-form-element-spacing-horizontal: 0.5rem; | ||
font-size: 0.7rem; | ||
} |
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