automated snapshot
This commit is contained in:
6
main.go
6
main.go
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user