Skip to content

Commit 8dae38a

Browse files
committed
(graphics) MapSprite and corresponding helpers
1 parent 833831a commit 8dae38a

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

agrf/graphics/helpers/map.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import grf
2+
from agrf.graphics import SCALE_TO_ZOOM
3+
from agrf.graphics.sprites.map import MapSprite
4+
5+
6+
def map_alternative_sprites(a, f, name, xofs=0, yofs=0):
7+
alts = []
8+
for scale in [1, 2, 4]:
9+
for bpp in [8, 32]:
10+
if (sa := a.get_sprite(zoom=SCALE_TO_ZOOM[scale], bpp=bpp)) is None:
11+
continue
12+
fs = MapSprite(
13+
sa, lambda x, scale=scale, bpp=bpp: f(x, scale, bpp), name, xofs=xofs * scale, yofs=yofs * scale
14+
)
15+
alts.append(fs)
16+
17+
return grf.AlternativeSprites(*alts)

agrf/graphics/sprites/map.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import grf
2+
from agrf.graphics import LayeredImage
3+
from agrf.graphics.spritesheet import LazyAlternativeSprites
4+
5+
6+
THIS_FILE = grf.PythonFile(__file__)
7+
8+
9+
class MapSprite(grf.Sprite):
10+
def __init__(self, a, f, name, xofs=0, yofs=0):
11+
super().__init__(a.w, a.h, zoom=a.zoom, xofs=a.xofs + xofs, yofs=a.yofs + yofs, bpp=a.bpp, crop=a.crop)
12+
self.a = a
13+
self.f = f
14+
self._fname = name
15+
16+
def get_fingerprint(self):
17+
return {"a": self.a.get_fingerprint(), "name": self._fname}
18+
19+
def get_resource_files(self):
20+
return self.a.get_resource_files() + (THIS_FILE,)
21+
22+
def get_data_layers(self, context):
23+
timer = context.start_timer()
24+
fa = self.f(LayeredImage.from_sprite(self.a).copy())
25+
timer.count_composing()
26+
27+
return fa.w, fa.h, fa.rgb, fa.alpha, fa.mask

0 commit comments

Comments
 (0)