Added tiler and some checks

This commit is contained in:
Casey 2024-07-07 12:47:06 +03:00
parent 60e4f610a1
commit 4a7f633a28
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
2 changed files with 44 additions and 8 deletions

View File

@ -69,10 +69,12 @@ class AsyncBotManager:
self.put_bit(index, l > 0)
def put_pixel(self, x: int, y: int, val: bool):
if x > 1000 or y > 1000:
return
self.put_bit(x + y * 1000, val)
def put_bit(self, index: int, value: bool):
if index not in self.avoid:
if index not in self.avoid and index < 1000000:
self.difference[index] = value
def add_animation(
@ -134,7 +136,15 @@ class AsyncBotManager:
async with AsyncSimpleClient(http_session=http) as sio:
await sio.connect(f"{self.base}/socket.io")
while not self._shutdown:
try:
async with asyncio.timeout(10):
event, data = await sio.receive()
except TimeoutError:
print("Reading failed")
if not sio.connected:
print("Reconnecting")
await sio.connect(f"{self.base}/socket.io")
continue
if event == "full_state":
buffer = b64decode(data["full_state"].encode() + b"=")
image = Image.frombytes("1", (1000, 1000), buffer)
@ -161,7 +171,7 @@ class AsyncBotManager:
outgoing = self._written_boxes / (now - self._last_printout)
incoming = self._read_boxes / (now - self._last_printout)
print()
print(f"Incoming: {incoming:7.2f}/s Outgoing: {outgoing:7.2f}/s")
print(f"I/O: {incoming:7.2f}/s | {outgoing:7.2f}/s")
print(f"Alive workers: {len(self._active)}")
n_correct, n_wrong = 0, 0
@ -253,7 +263,7 @@ async def amain() -> None:
for elem in settings["elements"]:
if elem["type"] == "text":
mgr.put_text(elem["x"], elem["y"], elem["text"], elem.get("font", "default"), elem.get("size", 8))
print("ADD text", elem["x"], elem["y"], elem["text"])
print("ADD text", elem)
elif elem["type"] == "text_anim":
frames: list[Image.Image] = []
for text in elem["lines"]:
@ -261,9 +271,20 @@ async def amain() -> None:
mgr.add_animation(elem["x"], elem["y"], frames, elem["spf"])
for frame in frames:
frame.close()
print("ADD text animation", elem)
elif elem["type"] == "image":
with Image.open(elem["path"]).convert("LA") as im:
mgr.put_image(elem["x"], elem["y"], im)
print("ADD image", elem)
elif elem["type"] == "tile":
with Image.open(elem["path"]).convert("LA") as im:
for i in range(elem.get("ry", 1)):
for j in range(elem.get("rx", 1)):
x = elem["x"] + im.width * j
y = elem["y"] + im.height * i
mgr.put_image(x, y, im)
print("ADD tile", elem)
elif elem["type"] == "animation":
with Image.open(elem["path"]) as anim:
frames: list[Image.Image] = []
@ -272,6 +293,7 @@ async def amain() -> None:
mgr.add_animation(elem["x"], elem["y"], frames, elem["spf"])
for frame in frames:
frame.close()
print("ADD animation", elem)
elif elem["type"] == "rgb111":
ox, oy = elem["x"], elem["y"]
with Image.open(elem["path"]).convert("RGBA") as im:
@ -353,4 +375,4 @@ async def amain() -> None:
if __name__ == "__main__":
asyncio.run(amain())
asyncio.run(amain(), debug=True)

View File

@ -13,6 +13,14 @@
"h": 10,
"description": "Not ruining fun for normal users"
},
{
"type": "rect",
"x": 0,
"y": 20,
"w": 1000,
"h": 80,
"description": "The VOID"
},
{
"type": "rect",
"x": 0,
@ -50,9 +58,15 @@
},
{
"type": "rgb565",
"path": "./pictures/niko.png",
"x": 48,
"y": 48
"path": "./pictures/niko_standing.png",
"x": 106,
"y": 132
},
{
"type": "rgb565",
"path": "./pictures/hello.png",
"x": 112,
"y": 203
}
]
}