-
Notifications
You must be signed in to change notification settings - Fork 0
/
interaction.go
72 lines (57 loc) · 1.25 KB
/
interaction.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"encoding/csv"
"log"
"strings"
_ "embed"
)
//go:embed res/dialogues.csv
var dialoguesCsv string
var soundSystem *SoundSystem
type Dialog struct {
name string
value string
}
func NewDialog(name, value string) *Dialog {
return &Dialog{
name: name,
value: value,
}
}
func getDialogues() []*Dialog {
// Parse the CSV
records, err := csv.NewReader(strings.NewReader(dialoguesCsv)).ReadAll()
if err != nil {
log.Fatal(err)
}
// Create the dialogues
dialogues := make([]*Dialog, 0)
for i := 1; i < len(records); i++ {
record := records[i]
dialogues = append(dialogues, NewDialog(record[0], record[1]))
}
return dialogues
}
func displayDialogue(dialogues []*Dialog, name string, state *State) {
dialogue := getDialogue(dialogues, name)
if text, err := NewText(state, dialogue, 0, 0, 1, 1); err != nil {
panic(err)
} else {
state.text = text
}
if soundSystem == nil {
soundSystem = NewSoundSystem()
soundSystem.InitSpeaker(state.decodeded_sounds[name].format)
}
if err := soundSystem.PlaySound(name, state); err != nil {
panic(err)
}
}
func getDialogue(dialogues []*Dialog, name string) string {
for _, dialogue := range dialogues {
if dialogue.name == name {
return dialogue.value
}
}
return ""
}