Justified MCQ are back!
This commit is contained in:
parent
a28f108b8a
commit
960122dfb6
5 changed files with 44 additions and 20 deletions
|
@ -253,6 +253,7 @@ func buildKeyFlag(exercice *fic.Exercice, flag ExerciceFlag, flagline int, defau
|
|||
type importFlag struct {
|
||||
Line int
|
||||
Flag fic.Flag
|
||||
JustifyOf *fic.MCQ_entry
|
||||
Choices []*fic.FlagChoice
|
||||
FilesDeps []string
|
||||
FlagsDeps []int64
|
||||
|
@ -272,7 +273,7 @@ func iface2Number(input interface{}, output *string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// buildExerciceFlags read challenge.txt and extract all flags.
|
||||
// buildExerciceFlag read challenge.txt and extract all flags.
|
||||
func buildExerciceFlag(i Importer, exercice *fic.Exercice, flag ExerciceFlag, nline int, exceptions *CheckExceptions) (ret []importFlag, errs []error) {
|
||||
switch strings.ToLower(flag.Type) {
|
||||
case "":
|
||||
|
@ -395,10 +396,11 @@ func buildExerciceFlag(i Importer, exercice *fic.Exercice, flag ExerciceFlag, nl
|
|||
continue
|
||||
}
|
||||
|
||||
addedFlag.Entries = append(addedFlag.Entries, &fic.MCQ_entry{
|
||||
entry := &fic.MCQ_entry{
|
||||
Label: choice.Label,
|
||||
Response: val,
|
||||
})
|
||||
}
|
||||
addedFlag.Entries = append(addedFlag.Entries, entry)
|
||||
|
||||
if isJustified && choice.Raw != nil {
|
||||
addedFlag, choices, berrs := buildKeyFlag(exercice, choice.ExerciceFlag, nline+1, "Flag correspondant", exceptions)
|
||||
|
@ -407,9 +409,10 @@ func buildExerciceFlag(i Importer, exercice *fic.Exercice, flag ExerciceFlag, nl
|
|||
}
|
||||
if addedFlag != nil {
|
||||
ret = append(ret, importFlag{
|
||||
Line: nline + 1,
|
||||
Flag: *addedFlag,
|
||||
Choices: choices,
|
||||
Line: nline + 1,
|
||||
Flag: *addedFlag,
|
||||
JustifyOf: entry,
|
||||
Choices: choices,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -422,10 +425,10 @@ func buildExerciceFlag(i Importer, exercice *fic.Exercice, flag ExerciceFlag, nl
|
|||
}
|
||||
}
|
||||
|
||||
ret = append(ret, importFlag{
|
||||
ret = append([]importFlag{importFlag{
|
||||
Line: nline + 1,
|
||||
Flag: &addedFlag,
|
||||
})
|
||||
}}, ret...)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -548,6 +551,12 @@ func SyncExerciceFlags(i Importer, exercice *fic.Exercice, exceptions *CheckExce
|
|||
// Import flags
|
||||
for _, flagid := range flagids {
|
||||
if flag, ok := flags[flagid]; ok {
|
||||
if flag.JustifyOf != nil {
|
||||
if f, ok := flag.Flag.(*fic.FlagKey); ok {
|
||||
f.Label = fmt.Sprintf("%%%d%%%s", flag.JustifyOf.Id, f.Label)
|
||||
}
|
||||
}
|
||||
|
||||
if addedFlag, err := exercice.AddFlag(flag.Flag); err != nil {
|
||||
errs = append(errs, NewFlagError(exercice, nil, flag.Line, err))
|
||||
} else {
|
||||
|
|
Reference in a new issue