-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialog.go
56 lines (47 loc) · 977 Bytes
/
dialog.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
package ospokemon
import "taylz.io/types"
const PARTdialog = "dialog"
type Dialog struct {
Id uint
Parent uint
Lead string
Text string
Tests []DialogTest
Choices []*Dialog
Scripts map[string]*Scripter
}
func MakeDialog() *Dialog {
return &Dialog{
Tests: make([]DialogTest, 0),
Choices: make([]*Dialog, 0),
Scripts: make(map[string]*Scripter),
}
}
func (d *Dialog) Next(lead string) *Dialog {
for _, choice := range d.Choices {
if choice.Lead == lead {
return choice
}
}
return nil
}
func (d *Dialog) Part() string {
return PARTdialog
}
func (parts Parts) GetDialog() *Dialog {
dialog, _ := parts[PARTdialog].(*Dialog)
return dialog
}
func (dialog *Dialog) Json() types.Dict {
json := types.Dict{
"id": dialog.Id,
"lead": dialog.Lead,
"text": dialog.Text,
}
choices := make([]string, 0)
for _, choice := range dialog.Choices {
choices = append(choices, choice.Lead)
}
json["choices"] = choices
return json
}