FEAT: randomize room number

randomize room number when not set but the night number is set
This commit is contained in:
zomo
2026-07-01 23:48:36 -05:00
parent 262f3d59ec
commit ecf30a9044
4 changed files with 38 additions and 8 deletions
+25
View File
@@ -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 { func CheckDuplicateRooms(rooms []RoomFolder) error {
maxnight := 0 maxnight := 0
maxroom := 0 maxroom := 0
+1 -6
View File
@@ -68,8 +68,7 @@ func (r *RoomIni) ToCredits() string {
return fmt.Sprintf(`Night %d - Room %d: %s return fmt.Sprintf(`Night %d - Room %d: %s
By: %s By: %s
Links: %s Links: %s`,
`,
r.night, r.room, name, r.night, r.room, name,
credits, links, credits, links,
) )
@@ -137,10 +136,6 @@ func loadIniMeta(roomini *RoomIni, cfg *ini.File) error {
roomini.room = val roomini.room = val
} }
if roomini.night > 0 && roomini.room < 1 {
return fmt.Errorf("night is set but room is not set")
}
return nil return nil
} }
+1
View File
@@ -34,6 +34,7 @@ func mainErr() error {
} }
AssignExtraRooms(roomFolders, *roomPerNight) AssignExtraRooms(roomFolders, *roomPerNight)
AssignRandomNightRooms(roomFolders, *roomPerNight)
// only deletes DATA/NIGHT_* folders and the CF.ini file // only deletes DATA/NIGHT_* folders and the CF.ini file
err = EmptyOut(*outPath) err = EmptyOut(*outPath)
+11 -2
View File
@@ -10,6 +10,7 @@ import (
"path" "path"
"path/filepath" "path/filepath"
"slices" "slices"
"sort"
"strings" "strings"
"github.com/charmbracelet/lipgloss" "github.com/charmbracelet/lipgloss"
@@ -128,7 +129,15 @@ Splash2len=%d
// loop through folders // loop through folders
log.Info("") log.Info("")
roomcredits := []string{} 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) err := copyFolder(&roomFolder, outpath)
if err != nil { if err != nil {
return fmt.Errorf("error copying folder %s: %+v", roomFolder.Path, err) return fmt.Errorf("error copying folder %s: %+v", roomFolder.Path, err)
@@ -153,7 +162,7 @@ Splash2len=%d
} }
// save credits file // save credits file
creditsstring := strings.Join(roomcredits, "\n") creditsstring := strings.Join(roomcredits, "\n\n") + "\n"
outcredits := filepath.Join(outpath, "credits.txt") outcredits := filepath.Join(outpath, "credits.txt")
log.Info(Renderf(styleGreentext, "Writing %s", outcredits)) log.Info(Renderf(styleGreentext, "Writing %s", outcredits))