Drarig29 / brackets-manager.js

A simple library to manage tournament brackets (round-robin, single elimination, double elimination).
https://drarig29.github.io/brackets-docs
MIT License
245 stars 38 forks source link

Getting started docs #144

Closed GrimLothar closed 1 year ago

GrimLothar commented 2 years ago

Hey!! This seems like a great library, but is there any chance we can get a bit more documentation on how to use it?

I see in the getting started how to create a stage. But how do we update matches? how to get all the matches in the current round? how to know if a round is finished and get all the matches for the next round? etc

Thanks!

Drarig29 commented 1 year ago

Hey!! Thanks!

Sorry for the (big) delay, I don't have much time anymore to spend on this project.

But how do we update matches?

You can use manager.update.match(). You have to update matches one by one, because the lib is intended to be used on an event basis, when a tournament is running. See the latest README.

How to get all the matches in the current round?

See https://github.com/Drarig29/brackets-manager.js/pull/147 (released in v1.5.0)

How to know if a round is finished

See https://github.com/Drarig29/brackets-manager.js/pull/147 (released in v1.5.0)

Get all the matches for the next round?

If you know the current round (with manager.get.currentRound() for example), depending on how your storage works, you can either search for a round which has an ID of currentRound.id + 1 or a round number of currentRound.number + 1 in the same group.

If you know that IDs are consecutive in your storage (e.g. auto-incremented with SQL, or you use the JSON storage), you can directly query manager.storage.select('match', { round_id: currentRound.id + 1 }).

Otherwise, you'll first have to first find the next round:

const nextRound = await manager.storage.select('round', { group_id: currentRound.group_id, number: currentRound.number + 1 });

And then:

const nextRoundMatches = await manager.storage.select('match', { round_id: nextRound.id });
Drarig29 commented 1 year ago

Closing for now, but don't hesitate to ask more questions :wink:

GrimLothar commented 1 year ago

Oh this is awesome!! Thank you! Been focusing on building the actual game first, but now i'm getting back to this, so timing is perfect! (+/- a couple of months lol)