mirror of
https://github.com/Dadido3/noita-mapcap.git
synced 2024-11-22 21:17:33 +00:00
David Vogel
c9d2a37903
- Update to go 1.19 for new atomic types - Use atomic for StitchedImage query counter - Make sure that we don't copy any tile objects
49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
// Copyright (c) 2019-2022 David Vogel
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"path/filepath"
|
|
)
|
|
|
|
type ImageTiles []ImageTile
|
|
|
|
// LoadImageTiles "loads" all images in the directory at the given path.
|
|
func LoadImageTiles(path string, scaleDivider int) (ImageTiles, error) {
|
|
if scaleDivider < 1 {
|
|
return nil, fmt.Errorf("invalid scale of %v", scaleDivider)
|
|
}
|
|
|
|
var imageTiles ImageTiles
|
|
|
|
files, err := filepath.Glob(filepath.Join(path, "*.png"))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
for _, file := range files {
|
|
imageTile, err := NewImageTile(file, scaleDivider)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
imageTiles = append(imageTiles, imageTile)
|
|
}
|
|
|
|
return imageTiles, nil
|
|
}
|
|
|
|
// InvalidateAboveY invalidates all cached images that have no pixel at the given y coordinate or below.
|
|
func (it ImageTiles) InvalidateAboveY(y int) {
|
|
for i := range it {
|
|
tile := &it[i] // Need to copy a reference.
|
|
if tile.Bounds().Max.Y <= y {
|
|
tile.Invalidate()
|
|
}
|
|
}
|
|
}
|