FEAT: randomize room number
randomize room number when not set but the night number is set
This commit is contained in:
@@ -32,6 +32,31 @@ func AssignExtraRooms(rooms []RoomFolder, roomsPerNight int) {
|
||||
}
|
||||
}
|
||||
|
||||
func AssignRandomNightRooms(rooms []RoomFolder, roomsPerNight int) {
|
||||
latestrooms := make(map[int]int)
|
||||
|
||||
for _, r := range rooms {
|
||||
if latestroom, ok := latestrooms[r.Cfg.night]; !ok {
|
||||
latestrooms[r.Cfg.night] = r.Cfg.room
|
||||
} else if r.Cfg.room > latestroom {
|
||||
latestrooms[r.Cfg.night] = r.Cfg.room
|
||||
}
|
||||
}
|
||||
|
||||
for i, r := range rooms {
|
||||
if r.Cfg.night <= 0 || r.Cfg.room > 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
if latestrooms[r.Cfg.night] < 0 {
|
||||
latestrooms[r.Cfg.night] = 0
|
||||
}
|
||||
|
||||
latestrooms[r.Cfg.night]++
|
||||
rooms[i].Cfg.room = latestrooms[r.Cfg.night]
|
||||
}
|
||||
}
|
||||
|
||||
func CheckDuplicateRooms(rooms []RoomFolder) error {
|
||||
maxnight := 0
|
||||
maxroom := 0
|
||||
|
||||
@@ -68,8 +68,7 @@ func (r *RoomIni) ToCredits() string {
|
||||
|
||||
return fmt.Sprintf(`Night %d - Room %d: %s
|
||||
By: %s
|
||||
Links: %s
|
||||
`,
|
||||
Links: %s`,
|
||||
r.night, r.room, name,
|
||||
credits, links,
|
||||
)
|
||||
@@ -137,10 +136,6 @@ func loadIniMeta(roomini *RoomIni, cfg *ini.File) error {
|
||||
roomini.room = val
|
||||
}
|
||||
|
||||
if roomini.night > 0 && roomini.room < 1 {
|
||||
return fmt.Errorf("night is set but room is not set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ func mainErr() error {
|
||||
}
|
||||
|
||||
AssignExtraRooms(roomFolders, *roomPerNight)
|
||||
AssignRandomNightRooms(roomFolders, *roomPerNight)
|
||||
|
||||
// only deletes DATA/NIGHT_* folders and the CF.ini file
|
||||
err = EmptyOut(*outPath)
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"path"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
@@ -128,7 +129,15 @@ Splash2len=%d
|
||||
// loop through folders
|
||||
log.Info("")
|
||||
roomcredits := []string{}
|
||||
for _, roomFolder := range roomFolders {
|
||||
|
||||
sortedRoomFolders := make([]RoomFolder, len(roomFolders))
|
||||
copy(sortedRoomFolders, roomFolders)
|
||||
|
||||
sort.Slice(sortedRoomFolders, func(i, j int) bool {
|
||||
return sortedRoomFolders[i].Cfg.night < sortedRoomFolders[j].Cfg.night || (sortedRoomFolders[i].Cfg.night == sortedRoomFolders[j].Cfg.night && sortedRoomFolders[i].Cfg.room < sortedRoomFolders[j].Cfg.room)
|
||||
})
|
||||
|
||||
for _, roomFolder := range sortedRoomFolders {
|
||||
err := copyFolder(&roomFolder, outpath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error copying folder %s: %+v", roomFolder.Path, err)
|
||||
@@ -153,7 +162,7 @@ Splash2len=%d
|
||||
}
|
||||
|
||||
// save credits file
|
||||
creditsstring := strings.Join(roomcredits, "\n")
|
||||
creditsstring := strings.Join(roomcredits, "\n\n") + "\n"
|
||||
|
||||
outcredits := filepath.Join(outpath, "credits.txt")
|
||||
log.Info(Renderf(styleGreentext, "Writing %s", outcredits))
|
||||
|
||||
Reference in New Issue
Block a user