aboutsummaryrefslogtreecommitdiffstats
path: root/examples/scores.aup
blob: 14620e9d8fbd5eafe15649c4a05df13fb3f8629d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# A table: a table view without a label column. Every column shows; a tone
# column colors a row.
use vega

record Player {
  name: text
  score = 0
}

state players: list of Player
state at: index of players

input join = text
input up = key ArrowUp
input down = key ArrowDown
input win = key KeyW
input lose = key KeyL

on join {
  players.append(Player { name: join })
  at = players.last
}
on up.down { at = at - 1 }
on down.down { at = at + 1 }
on win.down { at.score = at.score + 1 }
on lose.down { at.score = at.score - 1 }

view title = "Scores"
view board = each p in players {
  name = p.name
  score = p.score
  rank = if p.score > 2 { "gold" } else if p.score > 0 { "silver" } else { "-" }
  tone = if p.score < 0 { vega.danger } else { vega.when(p.score > 2, vega.good) }
}
view board_focus = at.position