This is a documentation for Board Game Arena: play board games online !
BgaScoreSheet
Jump to navigation
Jump to search
Overview
bga-score-sheet is a javascript component to help you display an animated score sheet at the end of the game.
Usage
Load the lib:
define([
"dojo","dojo/_base/declare",
"ebg/core/gamegui",
"ebg/counter",
getLibUrl('bga-score-sheet', '1.x'),
],
function (dojo, declare, gamegui, counter, BgaScoreSheet) { // note that the index of `BgaScoreSheet` must match the index of the define array
At the end of your game setup:
this.scoreSheet = new BgaScoreSheet.ScoreSheet(
document.getElementById(`my-score-sheet`), // an empty div on your template to place the score sheet on
{
animationsActive: () => game.bgaAnimationsActive(), // so the animation doesn't trigger on replay fast mode
playerNameWidth: 80,
playerNameHeight: 30,
entryLabelWidth: 120,
entryLabelHeight: 20,
classes: 'score-sheet-background',
players: gamedatas.players,
entries: [
{
property: 'conquest-cards',
label: _('Conquest cards'),
labelClasses: 'entries-label',
},
{
property: 'politics-cards',
label: _('Politics cards'),
labelClasses: 'entries-label',
},
{
property: 'diplomacy-cards',
label: _('Diplomacy cards'),
labelClasses: 'entries-label',
},
{
property: 'total',
label: _('Total'),
labelClasses: 'entries-label',
scoresClasses: 'total',
width: 80,
height: 40,
},
],
scores: gamedatas.scores, // to defined if the game state is 99, else null, so the score displays directly on reload when the game is ended. If unset, the score sheet will be hidden by default.
onScoreDisplayed: (property, playerId, score) => { // if you want to do something when a score is revealed
if (property === 'total') {
this.scoreCtrl[playerId].setValue(score);
}
},
}
);
On the notification sending the end score details (supposing you use bgaSetupPromiseNotifications for async notifs) :
async notif_endScores(args: NotifEndScoresArgs) {
// setting scores will make the score sheet visible if it isn't already
await this.scoreSheet.setScores(args.endScores, {
startBy: this.getPlayerId()
});
}
The endScores object sent on the notification should look like this :
{
156463: { // key is player id
'conquest-cards': 18, // the score code must match the entry name
'politics-cards': 4,
'diplomacy-cards': 12,
'total': 34
},
278971: {
'conquest-cards': 31,
'politics-cards': 7,
'diplomacy-cards': 5,
'total': 41
},
}
Versioning
The lib is using semver, so you can require 1.x to be sure to have the last fixes without risking a breaking change. Any breaking change will be noted on the Changelog section.
Changelog
1.0.0: Initial version