Skip to content

Commit ab3bb03

Browse files
committed
Clean up example in README
1 parent 0ecd2a2 commit ab3bb03

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,20 @@ func main() {
4646
p := dem.NewParser(f, dem.WarnToStdErr)
4747

4848
// Parse header
49-
p.ParseHeader()
50-
51-
// Get T / CT team state references (contain scores)
52-
tState := p.TState()
53-
ctState := p.CTState()
49+
h, err := p.ParseHeader()
50+
if err != nil {
51+
t.Fatal(err)
52+
}
53+
fmt.Println("Map:", h.MapName)
5454

5555
// Register handler on round end to figure out who won
5656
p.RegisterEventHandler(func(e events.RoundEndedEvent) {
57-
if e.Winner == common.TeamTerrorists {
58-
fmt.Println("T-side won the round - score:", tState.Score()+1) // Score + 1 because it hasn't actually been updated yet
59-
} else if e.Winner == common.TeamCounterTerrorists {
60-
fmt.Println("CT-side won the round - score:", ctState.Score()+1)
61-
} else {
57+
switch e.Winner {
58+
case common.TeamTerrorists:
59+
fmt.Println("T-side won the round - score:", p.TState().Score()+1) // Score + 1 because it hasn't actually been updated yet
60+
case common.TeamCounterTerrorists:
61+
fmt.Println("CT-side won the round - score:", p.CTState().Score()+1)
62+
default:
6263
fmt.Println("Apparently neither the Ts nor CTs won the round, interesting")
6364
}
6465
})

example_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,20 @@ func TestExample(t *testing.T) {
2121
p := dem.NewParser(f, dem.WarnToStdErr)
2222

2323
// Parse header
24-
p.ParseHeader()
25-
26-
// Get T / CT team state references (contain scores)
27-
tState := p.TState()
28-
ctState := p.CTState()
24+
h, err := p.ParseHeader()
25+
if err != nil {
26+
t.Fatal(err)
27+
}
28+
fmt.Println("Map:", h.MapName)
2929

3030
// Register handler on round end to figure out who won
3131
p.RegisterEventHandler(func(e events.RoundEndedEvent) {
32-
if e.Winner == common.TeamTerrorists {
33-
fmt.Println("T-side won the round - score:", tState.Score()+1) // Score + 1 because it hasn't actually been updated yet
34-
} else if e.Winner == common.TeamCounterTerrorists {
35-
fmt.Println("CT-side won the round - score:", ctState.Score()+1)
36-
} else {
32+
switch e.Winner {
33+
case common.TeamTerrorists:
34+
fmt.Println("T-side won the round - score:", p.TState().Score()+1) // Score + 1 because it hasn't actually been updated yet
35+
case common.TeamCounterTerrorists:
36+
fmt.Println("CT-side won the round - score:", p.CTState().Score()+1)
37+
default:
3738
fmt.Println("Apparently neither the Ts nor CTs won the round, interesting")
3839
}
3940
})

0 commit comments

Comments
 (0)