Multiple hints
This commit is contained in:
parent
22e8937879
commit
25bf34e82c
9 changed files with 217 additions and 35 deletions
|
|
@ -13,10 +13,17 @@ type myTeamFile struct {
|
|||
Checksum string `json:"checksum"`
|
||||
Size int64 `json:"size"`
|
||||
}
|
||||
type myTeamHint struct {
|
||||
HintId int64 `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
Cost int64 `json:"cost"`
|
||||
Unlocked bool `json:"unlocked"`
|
||||
}
|
||||
type myTeamExercice struct {
|
||||
ThemeId int `json:"theme_id"`
|
||||
Statement string `json:"statement"`
|
||||
Hint string `json:"hint"`
|
||||
Hints []myTeamHint `json:"hints"`
|
||||
Gain int64 `json:"gain"`
|
||||
Files []myTeamFile `json:"files"`
|
||||
Keys []string `json:"keys"`
|
||||
|
|
@ -35,6 +42,8 @@ type myTeam struct {
|
|||
|
||||
func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
||||
ret := myTeam{}
|
||||
|
||||
// Fill information about the team
|
||||
if t == nil {
|
||||
ret.Id = 0
|
||||
} else {
|
||||
|
|
@ -46,8 +55,9 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
}
|
||||
|
||||
}
|
||||
ret.Exercices = map[string]myTeamExercice{}
|
||||
|
||||
// Fill exercices, only if the challenge is started
|
||||
ret.Exercices = map[string]myTeamExercice{}
|
||||
if exos, err := GetExercices(); err != nil {
|
||||
return ret, err
|
||||
} else if started {
|
||||
|
|
@ -58,7 +68,6 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
exercice.ThemeId = tid
|
||||
}
|
||||
exercice.Statement = e.Statement
|
||||
exercice.Hint = e.Hint
|
||||
if t == nil {
|
||||
exercice.VideoURI = e.VideoURI
|
||||
exercice.Solved = true
|
||||
|
|
@ -67,6 +76,36 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
exercice.Solved, exercice.SolvedTime, exercice.SolvedNumber = t.HasSolved(e)
|
||||
}
|
||||
|
||||
// Expose exercice files
|
||||
|
||||
exercice.Files = []myTeamFile{}
|
||||
|
||||
if files, err := e.GetFiles(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
for _, f := range files {
|
||||
exercice.Files = append(exercice.Files, myTeamFile{path.Join(FilesDir, f.Path), f.Name, hex.EncodeToString(f.Checksum), f.Size})
|
||||
}
|
||||
}
|
||||
|
||||
// Expose exercice hints
|
||||
|
||||
exercice.Hints = []myTeamHint{}
|
||||
|
||||
if hints, err := e.GetHints(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
for _, h := range hints {
|
||||
if t == nil || t.HasHint(h) {
|
||||
exercice.Hints = append(exercice.Hints, myTeamHint{h.Id, h.Title, h.Content, h.Cost, true})
|
||||
} else {
|
||||
exercice.Hints = append(exercice.Hints, myTeamHint{h.Id, h.Title, "", h.Cost, false})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Expose exercice keys
|
||||
|
||||
exercice.Keys = []string{}
|
||||
|
||||
if keys, err := e.GetKeys(); err != nil {
|
||||
|
|
@ -81,16 +120,7 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
exercice.Files = []myTeamFile{}
|
||||
|
||||
if files, err := e.GetFiles(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
for _, f := range files {
|
||||
exercice.Files = append(exercice.Files, myTeamFile{path.Join(FilesDir, f.Path), f.Name, hex.EncodeToString(f.Checksum), f.Size})
|
||||
}
|
||||
}
|
||||
|
||||
// Hash table ordered by exercice Id
|
||||
ret.Exercices[fmt.Sprintf("%d", e.Id)] = exercice
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue