Skip to content

Commit b79f872

Browse files
committed
..
1 parent 03b6272 commit b79f872

File tree

4 files changed

+27
-32
lines changed

4 files changed

+27
-32
lines changed

agrf/graphics/cv/foundation.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_left_part(left_parts, r, c, solid, scale):
3434

3535

3636
def make_foundation_subimage(
37-
img: LayeredImage, scale, left_parts, right_parts, s_shareground, cut_inside, zshift, solid
37+
img: LayeredImage, scale, left_parts, right_parts, y_limit, cut_inside, zshift, solid
3838
) -> LayeredImage:
3939
if img.alpha is not None:
4040
r = np.arange(img.h)[:, np.newaxis] + img.yofs + 0.5 + zshift * scale
@@ -51,8 +51,7 @@ def make_foundation_subimage(
5151
# FIXME
5252
pass
5353

54-
if not s_shareground:
55-
alphamask *= (1 - (r * 2 - c > 48 * scale) * (r * 2 + c > 48 * scale)).astype(np.uint8)
54+
alphamask *= (1 - (r * 2 - c > y_limit * scale) * (r * 2 + c > y_limit * scale)).astype(np.uint8)
5655

5756
alpha = img.alpha * alphamask
5857
else:
@@ -62,14 +61,12 @@ def make_foundation_subimage(
6261

6362

6463
def make_foundation(
65-
solid: LayeredImage, ground: LayeredImage, scale, left_parts, right_parts, s_shareground, cut_inside, zshift
64+
solid: LayeredImage, ground: LayeredImage, scale, left_parts, right_parts, y_limit, cut_inside, zshift
6665
) -> LayeredImage:
6766
if solid is not None:
68-
solid = make_foundation_subimage(solid, scale, left_parts, right_parts, s_shareground, cut_inside, zshift, True)
67+
solid = make_foundation_subimage(solid, scale, left_parts, right_parts, y_limit, cut_inside, zshift, True)
6968
if ground is not None:
70-
ground = make_foundation_subimage(
71-
ground, scale, left_parts, right_parts, s_shareground, cut_inside, zshift, False
72-
)
69+
ground = make_foundation_subimage(ground, scale, left_parts, right_parts, y_limit, cut_inside, zshift, False)
7370
if solid is not None and ground is not None:
7471
return ground.copy().blend_over(solid)
7572
return solid or ground

agrf/graphics/cv/foundation_test.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_make_foundation_subimage_basic_left_side():
1414
base = _full_alpha_image()
1515
# part (6, 0) targets the left side (c <= 0) when scale=4 and xofs=0
1616
out = make_foundation_subimage(
17-
base, scale=4, left_parts=6, right_parts=None, s_shareground=True, cut_inside=False, zshift=0, solid=True
17+
base, scale=4, left_parts=6, right_parts=None, y_limit=64, cut_inside=False, zshift=0, solid=True
1818
)
1919
assert out.alpha is not None
2020
# Left-most column should be non-zero
@@ -28,7 +28,7 @@ def test_make_foundation_subimage_alpha_none_passthrough():
2828
rgb = np.zeros((8, 8, 3), dtype=np.uint8)
2929
base = LayeredImage(0, 0, 8, 8, rgb, None, None)
3030
out = make_foundation_subimage(
31-
base, scale=4, left_parts=6, right_parts=None, s_shareground=True, cut_inside=False, zshift=0, solid=True
31+
base, scale=4, left_parts=6, right_parts=None, y_limit=64, cut_inside=False, zshift=0, solid=True
3232
)
3333
assert out.alpha is None
3434

@@ -37,26 +37,19 @@ def test_make_foundation_passthrough_single_input():
3737
base = _full_alpha_image()
3838
# Only solid provided
3939
expected_solid = make_foundation_subimage(
40-
base.copy(), scale=4, left_parts=6, right_parts=None, s_shareground=True, cut_inside=False, zshift=0, solid=True
40+
base.copy(), scale=4, left_parts=6, right_parts=None, y_limit=64, cut_inside=False, zshift=0, solid=True
4141
)
4242
out_solid = make_foundation(
43-
base, None, scale=4, left_parts=6, right_parts=None, s_shareground=True, cut_inside=False, zshift=0
43+
base, None, scale=4, left_parts=6, right_parts=None, y_limit=64, cut_inside=False, zshift=0
4444
)
4545
assert np.array_equal(out_solid.alpha, expected_solid.alpha)
4646

4747
# Only ground provided
4848
expected_ground = make_foundation_subimage(
49-
base.copy(),
50-
scale=4,
51-
left_parts=6,
52-
right_parts=None,
53-
s_shareground=True,
54-
cut_inside=False,
55-
zshift=0,
56-
solid=False,
49+
base.copy(), scale=4, left_parts=6, right_parts=None, y_limit=64, cut_inside=False, zshift=0, solid=False
5750
)
5851
out_ground = make_foundation(
59-
None, base, scale=4, left_parts=6, right_parts=None, s_shareground=True, cut_inside=False, zshift=0
52+
None, base, scale=4, left_parts=6, right_parts=None, y_limit=64, cut_inside=False, zshift=0
6053
)
6154
assert np.array_equal(out_ground.alpha, expected_ground.alpha)
6255

@@ -66,10 +59,10 @@ def test_make_foundation_subimage_zshift_reduces_coverage_for_part0():
6659
base = _full_alpha_image()
6760
base.yofs = 120
6861
out0 = make_foundation_subimage(
69-
base, scale=4, left_parts=6, right_parts=None, s_shareground=True, cut_inside=False, zshift=0, solid=True
62+
base, scale=4, left_parts=6, right_parts=None, y_limit=64, cut_inside=False, zshift=0, solid=True
7063
)
7164
out1 = make_foundation_subimage(
72-
base, scale=4, left_parts=6, right_parts=None, s_shareground=True, cut_inside=False, zshift=2, solid=True
65+
base, scale=4, left_parts=6, right_parts=None, y_limit=64, cut_inside=False, zshift=2, solid=True
7366
)
7467
sum0 = int(out0.alpha.sum())
7568
sum1 = int(out1.alpha.sum())

agrf/graphics/sprites/foundation.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99

1010
class FoundationSprite(grf.Sprite):
11-
def __init__(
12-
self, solid_sprite, ground_sprite, left_parts, right_parts, s_shareground, cut_inside, zshift, zoffset
13-
):
11+
def __init__(self, solid_sprite, ground_sprite, left_parts, right_parts, y_limit, cut_inside, zshift, zoffset):
1412
representative = ground_sprite or solid_sprite
1513
super().__init__(
1614
representative.w,
@@ -25,7 +23,7 @@ def __init__(
2523
self.ground_sprite = ground_sprite
2624
self.left_parts = left_parts
2725
self.right_parts = right_parts
28-
self.s_shareground = s_shareground
26+
self.y_limit = y_limit
2927
self.cut_inside = cut_inside
3028
self.zshift = zshift
3129
self.zoffset = zoffset
@@ -36,7 +34,7 @@ def get_fingerprint(self):
3634
"ground_sprite": self.ground_sprite.get_fingerprint() if self.ground_sprite is not None else None,
3735
"left_parts": self.left_parts,
3836
"right_parts": self.right_parts,
39-
"s_shareground": self.s_shareground,
37+
"y_limit": self.y_limit,
4038
"cut_inside": self.cut_inside,
4139
"zshift": self.zshift,
4240
"zoffset": self.zoffset,
@@ -59,7 +57,7 @@ def get_data_layers(self, context):
5957
ZOOM_TO_SCALE[(self.solid_sprite or self.ground_sprite).zoom],
6058
self.left_parts,
6159
self.right_parts,
62-
self.s_shareground,
60+
self.y_limit,
6361
self.cut_inside,
6462
self.zshift,
6563
)

agrf/lib/building/foundation.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ def get_sprite_conf(self, style, i):
104104
("extended", 9): (5, 7),
105105
}[style, i]
106106

107+
if (left is not None and (left & 1)) or (right is not None and (right & 1)):
108+
y_limit = 48
109+
else:
110+
y_limit = 64
111+
if self.s_shareground:
112+
y_limit += 16
113+
107114
if left is not None:
108115
left = (left & 3) + (left & 6) * 2
109116
if self.nw_clip:
@@ -118,13 +125,13 @@ def get_sprite_conf(self, style, i):
118125
if self.se_shareground:
119126
right = right & 12
120127

121-
return left, right
128+
return left, right, y_limit
122129

123130
def make_foundations_subset(self, subset):
124131
# sprite.voxel.render() # FIXME agrf cannot correctly track dependencies here
125132
ret = []
126133
for style, i in subset:
127-
l, r = self.get_sprite_conf(style, i)
134+
l, r, y_limit = self.get_sprite_conf(style, i)
128135
alts = []
129136
for scale in [1, 2, 4]:
130137
for bpp in [32]:
@@ -143,7 +150,7 @@ def make_foundations_subset(self, subset):
143150
g,
144151
l,
145152
r,
146-
self.s_shareground,
153+
y_limit,
147154
self.cut_inside,
148155
zshift=self.zshift,
149156
zoffset=(8 if style == "ground" else 0),

0 commit comments

Comments
 (0)