admin/sync: defines.txt can also contains informations about hints

This commit is contained in:
nemunaire 2018-01-10 04:42:50 +01:00
parent 332aa90931
commit ca41e4edee
2 changed files with 30 additions and 1 deletions

View file

@ -15,6 +15,11 @@ import (
)
func SyncExerciceHints(i Importer, exercice fic.Exercice) (errs []string) {
params, err := parseExerciceParams(i, exercice.Path)
if err != nil {
errs = append(errs, fmt.Sprintf("%q: defines.txt: %s", path.Base(exercice.Path), err))
}
if _, err := exercice.WipeHints(); err != nil {
errs = append(errs, err.Error())
} else if ! i.exists(path.Join(exercice.Path, "hints")) {
@ -23,6 +28,22 @@ func SyncExerciceHints(i Importer, exercice fic.Exercice) (errs []string) {
errs = append(errs, err.Error())
} else {
for n, hfile := range hints {
// Find corresponding parameters
var hint_title = fmt.Sprintf("Astuce #%d", n + 1)
var hint_cost = exercice.Gain / 4
for _, hp := range params.Hints {
if hp.Filename == hfile {
if hp.Cost > 0 {
hint_cost = hp.Cost
}
if hp.Title != "" {
hint_title = hp.Title
}
break
}
}
// Extract hint content
var hint_cnt string
if fi, err := i.stat(path.Join(exercice.Path, "hints", hfile)); err != nil {
@ -59,7 +80,8 @@ func SyncExerciceHints(i Importer, exercice fic.Exercice) (errs []string) {
continue
}
if _, err := exercice.AddHint(fmt.Sprintf("Astuce #%d", n + 1), hint_cnt, 1); err != nil {
// Import hint
if _, err := exercice.AddHint(hint_title, hint_cnt, hint_cost); err != nil {
errs = append(errs, fmt.Sprintf("%q: unable to add hint %q: %s", path.Base(exercice.Path), hfile, err))
}
}