Skip to content

Commit

Permalink
Configurable default options for matches
Browse files Browse the repository at this point in the history
  • Loading branch information
thordy committed Dec 7, 2024
1 parent e73897a commit d1b934e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ A preview of major changes can be found in the Wiki ([Latest Changes](https://gi
- Holding score buttons to score same dart three times
- Support `Max Rounds` to play for `x01`
- Added option to configure `players` on match presets
- Configurable default options for starting matches
- Lots of new Badges

#### Changed
Expand Down
6 changes: 4 additions & 2 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ router.get('/', function (req, res, next) {
axios.get(`${req.app.locals.kcapp.api}/venue`),
axios.get(`${req.app.locals.kcapp.api}/office`),
axios.get(`${req.app.locals.kcapp.api}/preset`),
]).then(axios.spread((players, matchModes, oweTypes, matchTypes, outshots, venues, offices, presets) => {
axios.get(`${req.app.locals.kcapp.api}/option/default`),
]).then(axios.spread((players, matchModes, oweTypes, matchTypes, outshots, venues, offices, presets, defaults) => {
res.marko(indexTemplate, {
players: _.sortBy(players.data, (player) => player.name),
modes: matchModes.data,
Expand All @@ -36,7 +37,8 @@ router.get('/', function (req, res, next) {
venues: venues.data,
stakes: oweTypes.data,
offices: offices.data,
presets: presets.data
presets: presets.data,
defaults: defaults.data,
});
})).catch(error => {
debug(`Error when getting data for / ${error}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ module.exports = {
officeId: 0,
venues: input.venues,
options: {
starting_score: 501,
game_type: types.X01,
game_mode: 1,
outshot_type: types.OUTSHOT_DOUBLE,
starting_score: input.defaults.starting_score || 501,
game_type: input.defaults.match_type.id,
game_mode: input.defaults.match_mode.id,
outshot_type: input.defaults.outshot_type.id,
max_rounds: input.defaults.max_rounds,
stake: null,
venue_id: null
},
Expand Down
6 changes: 3 additions & 3 deletions src/pages/index/components/new-game-form/new-game-form.marko
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ $ const types = require('../../../../components/scorecard/components/match_types
<game-option-selector values=input.types options=state.options key="game-type" label="Type" attribute="game_type" defaultValue=state.options.game_type on-value-changed('onGameTypeChanged')/>
<game-option-selector values=input.scores options=state.options key="starting-score" label="Starting Score" attribute="starting_score" defaultValue=state.options.starting_score/>
<if(state.options.game_type == types.X01 || state.options.game_type == types.X01HANDICAP)>
<game-option-selector values=input.outshots options=state.options key="outshot-type" label="Outshot Type" attribute="outshot_type" defaultValue=types.OUTSHOT_DOUBLE/>
<game-option-selector values=state.maxRounds options=state.options key="max-rounds-x01" label="Max Rounds" attribute="max_rounds" defaultValue=-1/>
<game-option-selector values=input.outshots options=state.options key="outshot-type" label="Outshot Type" attribute="outshot_type" defaultValue=state.options.outshot_type/>
<game-option-selector values=state.maxRounds options=state.options key="max-rounds-x01" label="Max Rounds" attribute="max_rounds" defaultValue=state.options.max_rounds/>
</if>
<if(state.options.game_type == types.TIC_TAC_TOE)>
<game-option-selector values=input.outshots options=state.options key="outshot-type" label="Outshot Type" attribute="outshot_type" defaultValue=types.OUTSHOT_DOUBLE/>
<game-option-selector values=input.outshots options=state.options key="outshot-type" label="Outshot Type" attribute="outshot_type" defaultValue=state.options.outshot_type/>
</if>
<if(state.options.game_type == types.KNOCKOUT)>
<game-option-selector values=input.lives options=state.options key="starting-lives" label="Starting Lives" attribute="starting_lives" defaultValue=5/>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/index/index-template.marko
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Layout from "../layout.marko"
outshots=input.outshots lives=input.lives points_to_win=input.points_to_win
max_rounds_170=input.max_rounds_170
max_rounds_x01=input.max_rounds_x01
venues=input.venues stakes=input.stakes offices=input.offices presets=input.presets/>
venues=input.venues stakes=input.stakes offices=input.offices presets=input.presets
defaults=input.defaults />
</@body>
</>

0 comments on commit d1b934e

Please sign in to comment.