Skip to content
Snippets Groups Projects

Resolve "Determine Counter Facing Direction"

Merged Fabian Heinrich requested to merge 68-determine-counter-facing-direction into main
Files
2
@@ -242,58 +242,62 @@ class Visualizer:
"""
for part in parts:
part_type = part["type"]
angle, angle_offset = 0, 0
draw_pos = pos.copy()
if orientation is not None:
angle_offset = calc_angle(orientation, [0, 1])
if "rotate_image" in part.keys():
if part["rotate_image"]:
angle = calc_angle(orientation, [0, 1])
else:
angle = angle_offset
match part_type:
case "image":
angle, angle_offset = 0, 0
if orientation is not None:
angle_offset = calc_angle(orientation, [0, 1])
if "rotate_image" in part.keys():
if part["rotate_image"]:
angle = calc_angle(orientation, [0, 1])
else:
angle = angle_offset
if "center_offset" in part:
d = pygame.math.Vector2(part["center_offset"]) * grid_size
d.rotate_ip(angle_offset)
pos = np.array(pos)
pos += np.array(d)
draw_pos += np.array(d)
self.draw_image(
screen,
part["path"],
part["size"] * scale * grid_size,
pos,
draw_pos,
rot_angle=angle,
)
case "rect":
if "center_offset" in part:
d = pygame.math.Vector2(part["center_offset"]) * grid_size
d.rotate_ip(angle_offset)
draw_pos += np.array(d)
height = part["height"] * grid_size
width = part["width"] * grid_size
color = part["color"]
if "center_offset" in part:
dx, dy = np.array(part["center_offset"]) * grid_size
rect = pygame.Rect(pos[0] + dx, pos[1] + dy, height, width)
pygame.draw.rect(screen, color, rect)
else:
rect = pygame.Rect(
pos[0] - (height / 2),
pos[1] - (width / 2),
height,
width,
)
rect = pygame.Rect(
draw_pos[0] - (height / 2),
draw_pos[1] - (width / 2),
height,
width,
)
pygame.draw.rect(screen, color, rect)
case "circle":
if "center_offset" in part:
d = pygame.math.Vector2(part["center_offset"]) * grid_size
d.rotate_ip(-angle_offset)
draw_pos += np.array(d)
radius = part["radius"] * grid_size
color = colors[part["color"]]
if "center_offset" in part:
pygame.draw.circle(
screen,
color,
np.array(pos)
+ (np.array(part["center_offset"]) * grid_size),
radius,
)
else:
pygame.draw.circle(screen, color, pos, radius)
pygame.draw.circle(
screen,
color,
draw_pos,
radius,
)
def draw_item(
self,
@@ -329,7 +333,7 @@ class Visualizer:
screen=screen,
grid_size=grid_size,
)
#
if "progress_percentage" in item and item["progress_percentage"] > 0.0:
self.draw_progress_bar(
screen, pos, item["progress_percentage"], grid_size=grid_size
@@ -414,6 +418,7 @@ class Visualizer:
pos=pos,
parts=parts,
grid_size=grid_size,
orientation=counter_dict["orientation"],
)
def draw_counter_occupier(
@@ -422,6 +427,7 @@ class Visualizer:
occupied_by: dict | list,
grid_size,
pos: npt.NDArray[float],
item_scale: float,
):
# Multiple plates on plate return:
if isinstance(occupied_by, list):
@@ -431,6 +437,7 @@ class Visualizer:
pos=np.abs([pos[0], pos[1] - (i * 3)]),
grid_size=grid_size,
item=o,
scale=item_scale,
)
# All other items:
else:
@@ -439,6 +446,7 @@ class Visualizer:
grid_size=grid_size,
item=occupied_by,
screen=screen,
scale=item_scale,
)
def draw_counters(self, screen: pygame, state, grid_size):
@@ -452,6 +460,7 @@ class Visualizer:
for counter in state["counters"]:
if counter["occupied_by"]:
item_pos = counter["pos"]
item_scale = 1.0
counter_type = counter["type"]
if counter_type.endswith("Dispenser"):
@@ -466,12 +475,15 @@ class Visualizer:
+ 180
)
item_pos += offset_vec
if "item_scale" in self.config["Dispenser"].keys():
item_scale = self.config["Dispenser"]["item_scale"]
self.draw_counter_occupier(
screen,
counter["occupied_by"],
grid_size,
np.array(item_pos) * grid_size,
item_scale,
)
if SHOW_COUNTER_CENTERS:
Loading