-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialog.go
47 lines (37 loc) · 868 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
package main
import (
"encoding/json"
"fmt"
"strings"
)
type dialog struct {
Text string `json:"text"`
Sayer string `json:"sayer"`
}
func loadDialogs(data []byte) map[string][]dialog {
var dialogMap map[string][]dialog
if err := json.Unmarshal(data, &dialogMap); err != nil {
panic("Can't unmarshal dialogs")
}
for key, chain := range dialogMap {
dialogMap[key] = splitTexts(chain)
}
return dialogMap
}
func splitTexts(dialogs []dialog) []dialog {
var modifiedDialogs []dialog
for _, d := range dialogs {
fmt.Println(d.Text)
var splitted []string
for i, char := range d.Text {
if i%40 == 0 {
splitted = append(splitted, "\n")
}
splitted = append(splitted, fmt.Sprintf("%c", char))
}
d.Text = strings.Join(splitted, "")
fmt.Println(d.Text)
modifiedDialogs = append(modifiedDialogs, d)
}
return modifiedDialogs
}