-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscen.go
More file actions
78 lines (62 loc) · 1.77 KB
/
Copy pathscen.go
File metadata and controls
78 lines (62 loc) · 1.77 KB
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
73
74
75
76
77
78
package main
import (
"log"
"os"
"github.com/BurntSushi/toml"
)
type RoleplayScenario struct {
ID string
Action string `toml:"action"`
ActionDesc string `toml:"action_desc"`
MsgRequest string `toml:"msg_request"`
MsgSuccess string `toml:"msg_success"`
MsgForced string `toml:"msg_forced"`
MsgDenied string `toml:"msg_denied"`
IsDeniable bool `toml:"is_deniable"`
IsForceable bool `toml:"is_forceable"`
SortLevel int `toml:"sort_level"`
}
type BySortLevelThenID []RoleplayScenario
func (s BySortLevelThenID) Len() int { return len(s) }
func (s BySortLevelThenID) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s BySortLevelThenID) Less(i, j int) bool {
if s[i].SortLevel != s[j].SortLevel {
return s[i].SortLevel < s[j].SortLevel
}
return s[i].ID < s[j].ID
}
func rpScenFileReader(filePath string) ([]RoleplayScenario) {
var r map[string]toml.Primitive
meta, err := toml.DecodeFile(filePath, &r)
if err != nil {
log.Printf("failed to parse TOML file %s: %s", filePath, err)
return []RoleplayScenario{}
}
actions := make([]RoleplayScenario, 0, len(r))
for id, p := range r {
var a RoleplayScenario
a.ID = id
a.IsDeniable = true
a.IsForceable = true
err := meta.PrimitiveDecode(p, &a)
if err != nil {
log.Printf("failed to decode action %s: %s", id, err)
return []RoleplayScenario{}
}
actions = append(actions, a)
rpScensRes[a.ID+"_y"] = a.MsgSuccess
rpScensRes[a.ID+"_n"] = a.MsgDenied
rpScensRes[a.ID+"_f"] = a.MsgForced
}
return actions
}
func rpScenReadDir(actionsDir string) {
items, _ := os.ReadDir(actionsDir)
for _, item := range items {
if item.IsDir() {
rpScenReadDir(actionsDir+"/"+item.Name())
} else {
rpScens = append(rpScens, rpScenFileReader(actionsDir+"/"+item.Name())...)
}
}
}