automated snapshot

This commit is contained in:
sumi
2025-12-15 01:41:05 -06:00
parent 049656fed3
commit e664862048
2 changed files with 8 additions and 7 deletions

View File

@@ -175,11 +175,7 @@ func main() {
rl.EndMode2D()
if rl.IsKeyDown(rl.KeySpace) {
img := rl.LoadImageFromScreen()
defer rl.UnloadImage(img)
if _, err := storage.Save(img); err != nil {
if _, err := storage.Save(); err != nil {
log.Printf("Error saving snapshot: %v\n", err)
}
}

View File

@@ -35,6 +35,7 @@ func NewStorage(snapshotsDir string) (*Storage, error) {
snapshotsDir: snapshotsDir,
gen: gen,
db: db,
log: log,
}
return &s, nil
}
@@ -84,16 +85,20 @@ func initSchema(db *sql.DB) error {
return tx.Commit()
}
func (s *Storage) Save(img *rl.Image) (string, error) {
func (s *Storage) Save() (string, error) {
id, _ := s.gen.Next()
kid := ids.Base62Encode(id)
path := filepath.Join(s.snapshotsDir, kid)
os.MkdirAll(path, 0755)
snapshotPng := filepath.Join(path, fmt.Sprintf("%s.png", kid))
img := rl.LoadImageFromScreen()
defer rl.UnloadImage(img)
snapshotPng := filepath.Join(path, fmt.Sprintf("%s.png", kid))
rl.ExportImage(*img, snapshotPng)
s.log.Printf("Checking git status...\n")
hash, branch, committed, err := CommitAllIfDirty(s.repoRoot, "automated snapshot", s.log)
if err != nil {