about summary refs log tree commit diff
path: root/src/lib/custom-animations/util.ts
blob: f3b9cbc5ce5503e2450371b127c9fa7c5306c6b5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// It should roll when:
// - We're going from 1 to 0 (roll backwards)
// - The count is anywhere between 1 and 999
// - The count is going up and is a multiple of 100
// - The count is going down and is 1 less than a multiple of 100
export function decideShouldRoll(isSet: boolean, count: number) {
  let shouldRoll = false
  if (!isSet && count === 1) {
    shouldRoll = true
  } else if (count > 1 && count < 1000) {
    shouldRoll = true
  } else if (count > 0) {
    const mod = count % 100
    if (isSet && mod === 0) {
      shouldRoll = true
    } else if (!isSet && mod === 99) {
      shouldRoll = true
    }
  }
  return shouldRoll
}