2022-05-01 20:33:59 +00:00
|
|
|
package settings
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"os"
|
2022-05-24 19:54:45 +00:00
|
|
|
"strings"
|
2022-05-01 20:33:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ChallengeFile is the expected name of the file containing the challenge infos.
|
|
|
|
const ChallengeFile = "challenge.json"
|
|
|
|
|
2022-05-31 16:18:08 +00:00
|
|
|
type ChallengePartner struct {
|
|
|
|
Src string `json:"img"`
|
|
|
|
Alt string `json:"alt,omitempty"`
|
|
|
|
Href string `json:"href,omitempty"`
|
|
|
|
}
|
|
|
|
|
2022-05-01 20:33:59 +00:00
|
|
|
// ChallengeInfo stores common descriptions and informations about the challenge.
|
|
|
|
type ChallengeInfo struct {
|
|
|
|
// Title is the displayed name of the challenge.
|
|
|
|
Title string `json:"title"`
|
2022-05-02 09:21:34 +00:00
|
|
|
// SubTitle is appended to the title.
|
2022-05-31 16:18:08 +00:00
|
|
|
SubTitle string `json:"subtitle,omitempty"`
|
2022-05-01 20:33:59 +00:00
|
|
|
// Authors is the group name of people making the challenge.
|
|
|
|
Authors string `json:"authors"`
|
2022-05-24 21:00:49 +00:00
|
|
|
// ExpectedDuration is the duration (in minutes) suggested when stating the challenge.
|
|
|
|
ExpectedDuration uint `json:"duration"`
|
2022-05-01 20:33:59 +00:00
|
|
|
// VideoLink is the link to explaination videos when the challenge is over.
|
2022-05-31 16:18:08 +00:00
|
|
|
VideosLink string `json:"videoslink,omitempty"`
|
2022-05-01 20:33:59 +00:00
|
|
|
|
|
|
|
// Description gives an overview of the challenge.
|
2022-05-31 16:18:08 +00:00
|
|
|
Description string `json:"description,omitempty"`
|
2022-05-01 20:33:59 +00:00
|
|
|
// Rules tell the player some help.
|
2022-05-31 16:18:08 +00:00
|
|
|
Rules string `json:"rules,omitempty"`
|
2022-05-01 20:33:59 +00:00
|
|
|
// YourMission is a small introduction to understand the goals.
|
2022-05-31 16:18:08 +00:00
|
|
|
YourMission string `json:"your_mission,omitempty"`
|
|
|
|
|
|
|
|
// MainLogo stores path to logos displayed in the header.
|
|
|
|
MainLogo []string `json:"main_logo,omitempty"`
|
|
|
|
// MainLink stores link to the parent website.
|
|
|
|
MainLink string `json:"main_link,omitempty"`
|
2023-05-12 13:41:43 +00:00
|
|
|
// DashboardBackground stores path to the background used on the public dashboard.
|
|
|
|
DashboardBackground string `json:"dashboard_background,omitempty"`
|
2022-05-31 16:18:08 +00:00
|
|
|
// Partners holds the challenge partners list.
|
|
|
|
Partners []ChallengePartner `json:"partners,omitempty"`
|
2022-05-01 20:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ReadChallenge parses the file at the given location.
|
2022-05-24 19:54:45 +00:00
|
|
|
func ReadChallengeInfo(content string) (*ChallengeInfo, error) {
|
2022-05-01 20:33:59 +00:00
|
|
|
var s ChallengeInfo
|
2022-05-24 19:54:45 +00:00
|
|
|
jdec := json.NewDecoder(strings.NewReader(content))
|
2022-05-01 20:33:59 +00:00
|
|
|
|
2022-05-24 19:54:45 +00:00
|
|
|
if err := jdec.Decode(&s); err != nil {
|
|
|
|
return &s, err
|
2022-05-01 20:33:59 +00:00
|
|
|
}
|
2022-05-24 19:54:45 +00:00
|
|
|
|
|
|
|
return &s, nil
|
2022-05-01 20:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
}
|