Distribute and handle challenge.json
This commit is contained in:
parent
e8f6a03cd9
commit
dff4f4eb63
20 changed files with 167 additions and 48 deletions
59
settings/challenge.go
Normal file
59
settings/challenge.go
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
package settings
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
)
|
||||
|
||||
// ChallengeFile is the expected name of the file containing the challenge infos.
|
||||
const ChallengeFile = "challenge.json"
|
||||
|
||||
// ChallengeInfo stores common descriptions and informations about the challenge.
|
||||
type ChallengeInfo struct {
|
||||
// Title is the displayed name of the challenge.
|
||||
Title string `json:"title"`
|
||||
// Authors is the group name of people making the challenge.
|
||||
Authors string `json:"authors"`
|
||||
// VideoLink is the link to explaination videos when the challenge is over.
|
||||
VideosLink string `json:"videoslink"`
|
||||
|
||||
// Description gives an overview of the challenge.
|
||||
Description string `json:"description"`
|
||||
// Rules tell the player some help.
|
||||
Rules string `json:"rules"`
|
||||
// YourMission is a small introduction to understand the goals.
|
||||
YourMission string `json:"your_mission"`
|
||||
}
|
||||
|
||||
// ReadChallenge parses the file at the given location.
|
||||
func ReadChallengeInfo(path string) (*ChallengeInfo, error) {
|
||||
var s ChallengeInfo
|
||||
if fd, err := os.Open(path); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer fd.Close()
|
||||
jdec := json.NewDecoder(fd)
|
||||
|
||||
if err := jdec.Decode(&s); err != nil {
|
||||
return &s, err
|
||||
}
|
||||
|
||||
return &s, nil
|
||||
}
|
||||
}
|
||||
|
||||
// SaveChallenge saves challenge at the given location.
|
||||
func SaveChallengeInfo(path string, s *ChallengeInfo) error {
|
||||
if fd, err := os.Create(path); err != nil {
|
||||
return err
|
||||
} else {
|
||||
defer fd.Close()
|
||||
jenc := json.NewEncoder(fd)
|
||||
|
||||
if err := jenc.Encode(s); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
@ -22,12 +22,6 @@ var SettingsDir string = "./SETTINGS"
|
|||
|
||||
// Settings represents the settings panel.
|
||||
type Settings struct {
|
||||
// Title is the displayed name of the challenge.
|
||||
Title string `json:"title"`
|
||||
// Authors is the group name of people making the challenge.
|
||||
Authors string `json:"authors"`
|
||||
// VideoLink is the link to explaination videos when the challenge is over.
|
||||
VideosLink string `json:"videoslink"`
|
||||
// WorkInProgress indicates if the current challenge is under development or if it is in production.
|
||||
WorkInProgress bool `json:"wip,omitempty"`
|
||||
|
||||
|
|
|
|||
Reference in a new issue