automated snapshot
This commit is contained in:
6
main.go
6
main.go
@@ -175,11 +175,7 @@ func main() {
|
|||||||
rl.EndMode2D()
|
rl.EndMode2D()
|
||||||
|
|
||||||
if rl.IsKeyDown(rl.KeySpace) {
|
if rl.IsKeyDown(rl.KeySpace) {
|
||||||
|
if _, err := storage.Save(); err != nil {
|
||||||
img := rl.LoadImageFromScreen()
|
|
||||||
defer rl.UnloadImage(img)
|
|
||||||
|
|
||||||
if _, err := storage.Save(img); err != nil {
|
|
||||||
log.Printf("Error saving snapshot: %v\n", err)
|
log.Printf("Error saving snapshot: %v\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ func NewStorage(snapshotsDir string) (*Storage, error) {
|
|||||||
snapshotsDir: snapshotsDir,
|
snapshotsDir: snapshotsDir,
|
||||||
gen: gen,
|
gen: gen,
|
||||||
db: db,
|
db: db,
|
||||||
|
log: log,
|
||||||
}
|
}
|
||||||
return &s, nil
|
return &s, nil
|
||||||
}
|
}
|
||||||
@@ -84,16 +85,20 @@ func initSchema(db *sql.DB) error {
|
|||||||
return tx.Commit()
|
return tx.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) Save(img *rl.Image) (string, error) {
|
func (s *Storage) Save() (string, error) {
|
||||||
id, _ := s.gen.Next()
|
id, _ := s.gen.Next()
|
||||||
kid := ids.Base62Encode(id)
|
kid := ids.Base62Encode(id)
|
||||||
path := filepath.Join(s.snapshotsDir, kid)
|
path := filepath.Join(s.snapshotsDir, kid)
|
||||||
os.MkdirAll(path, 0755)
|
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)
|
rl.ExportImage(*img, snapshotPng)
|
||||||
|
|
||||||
|
s.log.Printf("Checking git status...\n")
|
||||||
|
|
||||||
hash, branch, committed, err := CommitAllIfDirty(s.repoRoot, "automated snapshot", s.log)
|
hash, branch, committed, err := CommitAllIfDirty(s.repoRoot, "automated snapshot", s.log)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user