Skip to content

Commit

Permalink
asyncRoll done and tested
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlindHawk committed Apr 11, 2024
1 parent 9e279b2 commit 29dd8ad
Show file tree
Hide file tree
Showing 11 changed files with 375 additions and 288 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
test:
script:
- npm install
- npx vitest --reporter=verbose
artifacts:
reports:
coverage_report:
coverage_format: clover
path: coverage/clover.xml
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,12 @@ interface AudioData = {

### roll options

| Function | Comment |
| ------------------------ | ------------------------------------------------------- |
| roll(value) | rolls the roulette to an index with said value |
| rollByIndex(index) | rolls the roulette to said index |
| rollProbabilities(probs) | rolls the roulette using custom probabilities[] |
| Function | Comment |
| ------------------------- | ------------------------------------------------------------- |
| roll(value) | rolls the roulette to an index with said value |
| rollByIndex(index) | rolls the roulette to said index |
| rollProbabilities(probs) | rolls the roulette using custom probabilities[] |
| asyncRollByIndex(promise) | rolls the roulette while waiting for the value in the promise |

</br>

Expand Down Expand Up @@ -292,7 +293,7 @@ const roulette = new Roulette({
padding: 20,
color: '#000',
shift: 0,
}
},
sections: [{
value: 'fail',
probability: 7,
Expand Down Expand Up @@ -329,20 +330,20 @@ const roulette = new Roulette({
width: 4,
color: 'grey',
},
}
},
colors: [ 'yellow', 'white', 'white', 'white' ],
audio: {
src: 'https://link_to_some_audio'
volume: 1,
play: { once: true },
}
},
});
```

You can then roll the roulette like so.

```
roll() // to a random value given equal probabilities
rollIndex(2) // to the grey car
rollProbabilities() // using the probabilities given in the costructor
```typescript
roulette.roll() // to a random value given equal probabilities
roulette.rollIndex(2) // to the grey car
roulette.rollProbabilities() // using the probabilities given in the costructor
```
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ <h2>You rolled on: </h2>
document.getElementById('start-doughnut').addEventListener('click', () => {
rouletteDoughnut.roll();
});
const { promise, resolve, reject } = Promise.withResolvers()
rouletteImage.asyncRollByIndex(promise)
await new Promise(r => setTimeout(r, 10000));
console.log(rouletteImage.sections[3].value)
resolve(rouletteImage.sections[3].value)
</script>
</body>
</html>
Loading

0 comments on commit 29dd8ad

Please sign in to comment.