STYLE: improved logging output

This commit is contained in:
zomo
2026-04-16 00:13:24 -05:00
parent 219423f2b3
commit e6329500b5
6 changed files with 138 additions and 23 deletions
+58 -18
View File
@@ -6,12 +6,14 @@ import (
"image"
"image/color"
"image/png"
"log"
"os"
"path"
"path/filepath"
"slices"
"strings"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"
)
//go:embed silence.wav
@@ -19,6 +21,18 @@ var SILENCE_WAV []byte
const FILEPERM = 0644
var styleRedtext = lipgloss.NewStyle().
Foreground(lipgloss.Color("9"))
var styleYellowtext = lipgloss.NewStyle().
Foreground(lipgloss.Color("11"))
var styleGreentext = lipgloss.NewStyle().
Foreground(lipgloss.Color("10"))
var padd = lipgloss.NewStyle().
PaddingLeft(4)
// only deletes DATA/NIGHT_* folders and the CF.ini file
// will not touch TITLE or any game files
// so this can be ran safely in your game's directory
@@ -61,7 +75,9 @@ func emptyOutData(outpath string) error {
if len(name) >= len(nightprefix) && name[:len(nightprefix)] == nightprefix {
nightpath := path.Join(datapath, entry.Name())
log.Printf("INFO: removing %s", nightpath)
log.Info(Renderf(styleRedtext, "removing %s", nightpath))
err = os.RemoveAll(nightpath)
if err != nil {
return err
@@ -82,7 +98,7 @@ func emptyOutCredits(outpath string) error {
return nil
}
log.Printf("INFO: removing %s", cfpath)
log.Info(Renderf(styleRedtext, "removing %s", cfpath))
return os.Remove(cfpath)
}
@@ -96,7 +112,7 @@ func emptyOutCF(outpath string) error {
return nil
}
log.Printf("INFO: removing %s", cfpath)
log.Info(Renderf(styleRedtext, "removing %s", cfpath))
return os.Remove(cfpath)
}
@@ -110,6 +126,7 @@ Splash2len=%d
`, splash1len, splash2len)
// loop through folders
log.Info("")
roomcredits := []string{}
for _, roomFolder := range roomFolders {
err := copyFolder(&roomFolder, outpath)
@@ -124,12 +141,12 @@ Splash2len=%d
}
roomcredits = append(roomcredits, roomFolder.Cfg.ToCredits())
log.Info("")
}
// save ini file
outini := filepath.Join(outpath, "CF.ini")
log.Println("INFO:")
log.Printf("INFO: Writing %s", outini)
log.Info(Renderf(styleGreentext, "Writing %s", outini))
if err := os.WriteFile(outini, []byte(inistr.String()), FILEPERM); err != nil {
return err
@@ -139,8 +156,7 @@ Splash2len=%d
creditsstring := strings.Join(roomcredits, "\n")
outcredits := filepath.Join(outpath, "credits.txt")
log.Println("INFO:")
log.Printf("INFO: Writing %s", outcredits)
log.Info(Renderf(styleGreentext, "Writing %s", outcredits))
return os.WriteFile(outcredits, []byte(creditsstring), FILEPERM)
}
@@ -148,18 +164,28 @@ Splash2len=%d
// doesn't error currently
func checkCredits(roomFolder *RoomFolder) error {
if roomFolder.Cfg.name == "" {
log.Println("WARNING: room config has no name, defaulting to folder name")
log.Warn(padd.Render(styleYellowtext.Render("room config has no name, defaulting to folder name")))
foldername := filepath.Base(roomFolder.Path)
roomFolder.Cfg.name = foldername
}
if roomFolder.Cfg.credits == "" {
log.Println("WARNING: room config has no credits")
log.Warn(padd.Render(styleYellowtext.Render("room config has no credits")))
}
return nil
}
var styleTextRoom = lipgloss.NewStyle().
Bold(true).
Padding(0, 1).
Background(lipgloss.Color("10")).
Foreground(lipgloss.Color("0"))
var styleTextCopy = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("10"))
func copyFolder(roomFolder *RoomFolder, outpath string) error {
nightdir := fmt.Sprintf("NIGHT_%d", roomFolder.Cfg.night)
roomdir := fmt.Sprintf("ROOM_%d", roomFolder.Cfg.room)
@@ -168,11 +194,26 @@ func copyFolder(roomFolder *RoomFolder, outpath string) error {
os.MkdirAll(roomoutpath, FILEPERM)
log.Println("INFO:")
log.Printf("INFO: Copying %s", roomFolder.Path)
log.Printf("INFO: to %s", roomoutpath)
// print room info
name := roomFolder.Cfg.name
if name == "" {
name = "MISSING NAME"
}
textRoom := Renderf(styleTextRoom, "Room - %s", name)
log.Info(textRoom)
textCopy1 := styleTextCopy.Render("Copying From")
textCopy2 := styleTextCopy.Render(" To")
textCopy1Comb := fmt.Sprintf("%s %s", textCopy1, roomFolder.Path)
textCopy2Comb := fmt.Sprintf("%s %s", textCopy2, roomoutpath)
log.Info(padd.Render(textCopy1Comb))
log.Info(padd.Render(textCopy2Comb))
if roomFolder.IsDefaultCfg {
log.Println("INFO: room.ini was not found, using default settings")
log.Info(padd.Render(styleYellowtext.Render("room.ini was not found, using default settings")))
}
entries, err := os.ReadDir(roomFolder.Path)
@@ -211,7 +252,7 @@ func copyFolder(roomFolder *RoomFolder, outpath string) error {
}
if len(extraRequiredImages) > 0 {
log.Printf("INFO: necessary optional images will use a transparent file: %v", extraRequiredImages)
log.Info(Renderf(padd, "necessary optional images will use a transparent file: %v", extraRequiredImages))
transparent := image.NewRGBA(image.Rectangle{image.Point{0, 0}, image.Point{1, 1}})
transparent.Set(0, 0, color.RGBA{0xff, 0xff, 0xff, 0x01})
@@ -237,15 +278,14 @@ func copyFolder(roomFolder *RoomFolder, outpath string) error {
// ensure layer_frames is 1 if it's not included
if strings.ToUpper(imagename) == "LAYER" && roomFolder.Cfg.layerFrames != 1 {
log.Printf( "WARNING: room was configured to have %d layer frames, but no LAYER image exists", roomFolder.Cfg.layerFrames)
log.Println("WARNING: setting layer_frames=1")
log.Warn(padd.Render(Renderf(styleYellowtext, "room was configured to have %d layer frames, but no LAYER image exists: setting layer_frames=1", roomFolder.Cfg.layerFrames)))
roomFolder.Cfg.layerFrames = 1
}
}
}
if len(extraRequiredAudio) > 0 {
log.Printf("INFO: necessary optional audios will use a silent file: %v", extraRequiredAudio)
log.Info(Renderf(padd, "necessary optional audios will use a silent file: %v", extraRequiredAudio))
for _, audioname := range extraRequiredAudio {
audiopath := path.Join(roomoutpath, audioname+".wav")