@@ -12,6 +12,16 @@ import (
12
12
"sort"
13
13
)
14
14
15
+ type Names struct {
16
+ Name []SystemInfo
17
+ }
18
+
19
+ type SystemInfo struct {
20
+ System string `json:"system"`
21
+ Name string `json:"name"`
22
+ SortKey string `json:"sort_key"`
23
+ }
24
+
15
25
// Find は指定された識別子を持つゲームシステムのダイスボットのコンストラクタを返す。
16
26
// ゲームシステムが見つからなかった場合はエラーを返す。
17
27
func Find (gameID string ) (dicebot.DiceBotConstructor , error ) {
@@ -48,5 +58,32 @@ func AvailableGameIDs(includeBasicDiceBot bool) []string {
48
58
return gameIDsWithBasicDiceBot
49
59
}
50
60
61
+ // AvailableGameInfos は利用可能なゲームシステムの情報のスライスを返す。
62
+ func AvailableGameInfos (includeBasicDiceBot bool ) Names {
63
+ games := make ([]SystemInfo , 0 , len (gameIDToDiceBotConstructor ))
64
+ for _ , k := range gameIDToDiceBotConstructor {
65
+ info := SystemInfo {
66
+ System : k ().GameID (),
67
+ Name : k ().GameName (),
68
+ SortKey : k ().SortKey (),
69
+ }
70
+ games = append (games , info )
71
+ }
72
+ sort .Slice (games , func (i , j int ) bool { return games [i ].SortKey < games [j ].SortKey })
73
+
74
+ if ! includeBasicDiceBot {
75
+ return Names {Name : games }
76
+ }
77
+ gamesWithBasicDiceBot := make ([]SystemInfo , 1 , len (games )+ 1 )
78
+ info := SystemInfo {
79
+ System : basic .BasicInfo ().GameID ,
80
+ Name : basic .BasicInfo ().GameName ,
81
+ SortKey : basic .BasicInfo ().SortKey ,
82
+ }
83
+ gamesWithBasicDiceBot [0 ] = info
84
+ gamesWithBasicDiceBot = append (gamesWithBasicDiceBot , games ... )
85
+ return Names {Name : gamesWithBasicDiceBot }
86
+ }
87
+
51
88
// ゲーム識別子とダイスボットのコンストラクタとの対応
52
89
var gameIDToDiceBotConstructor = map [string ]dicebot.DiceBotConstructor {}
0 commit comments