sync: randomize imports: themes order, MCQ and UCQ choices
This commit is contained in:
parent
614003a7cd
commit
abd7fc6bef
@ -46,6 +46,7 @@ type ExerciceFlagMCQChoice struct {
|
||||
type ExerciceFlagMCQ struct {
|
||||
Label string `toml:",omitempty"`
|
||||
Choice []ExerciceFlagMCQChoice
|
||||
NoShuffle bool
|
||||
}
|
||||
|
||||
// ExerciceFlagUCQChoice holds a choice for an UCQ flag.
|
||||
@ -65,6 +66,7 @@ type ExerciceFlagUCQ struct {
|
||||
Choices_Cost int64 `toml:",omitempty"`
|
||||
Choice []ExerciceFlagUCQChoice
|
||||
LockedFile []ExerciceUnlockFile `toml:"unlock_file,omitempty"`
|
||||
NoShuffle bool
|
||||
}
|
||||
|
||||
// ExerciceParams contains values parsed from defines.txt.
|
||||
|
@ -2,6 +2,7 @@ package sync
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"path"
|
||||
"unicode"
|
||||
|
||||
@ -93,6 +94,13 @@ func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
|
||||
|
||||
// Import choices
|
||||
hasOne := false
|
||||
|
||||
if !flag.NoShuffle {
|
||||
rand.Shuffle(len(flag.Choice), func(i, j int) {
|
||||
flag.Choice[i], flag.Choice[j] = flag.Choice[j], flag.Choice[i]
|
||||
})
|
||||
}
|
||||
|
||||
for cid, choice := range flag.Choice {
|
||||
if len(choice.Label) == 0 {
|
||||
choice.Label = choice.Value
|
||||
@ -121,6 +129,13 @@ func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
|
||||
} else {
|
||||
hasOne := false
|
||||
isJustified := false
|
||||
|
||||
if !quest.NoShuffle {
|
||||
rand.Shuffle(len(quest.Choice), func(i, j int) {
|
||||
quest.Choice[i], quest.Choice[j] = quest.Choice[j], quest.Choice[i]
|
||||
})
|
||||
}
|
||||
|
||||
for cid, choice := range quest.Choice {
|
||||
var val bool
|
||||
var justify string
|
||||
|
@ -2,6 +2,7 @@ package sync
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
@ -54,6 +55,10 @@ func SyncThemes(i Importer) []string {
|
||||
if themes, err := getThemes(i); err != nil {
|
||||
errs = append(errs, err.Error())
|
||||
} else {
|
||||
rand.Shuffle(len(themes), func(i, j int) {
|
||||
themes[i], themes[j] = themes[j], themes[i]
|
||||
})
|
||||
|
||||
for _, tdir := range themes {
|
||||
var authors []string
|
||||
var intro string
|
||||
|
Loading…
Reference in New Issue
Block a user