Added tiler and some checks
This commit is contained in:
parent
60e4f610a1
commit
4a7f633a28
30
async-bot.py
30
async-bot.py
|
@ -69,10 +69,12 @@ class AsyncBotManager:
|
||||||
self.put_bit(index, l > 0)
|
self.put_bit(index, l > 0)
|
||||||
|
|
||||||
def put_pixel(self, x: int, y: int, val: bool):
|
def put_pixel(self, x: int, y: int, val: bool):
|
||||||
|
if x > 1000 or y > 1000:
|
||||||
|
return
|
||||||
self.put_bit(x + y * 1000, val)
|
self.put_bit(x + y * 1000, val)
|
||||||
|
|
||||||
def put_bit(self, index: int, value: bool):
|
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
|
self.difference[index] = value
|
||||||
|
|
||||||
def add_animation(
|
def add_animation(
|
||||||
|
@ -134,7 +136,15 @@ class AsyncBotManager:
|
||||||
async with AsyncSimpleClient(http_session=http) as sio:
|
async with AsyncSimpleClient(http_session=http) as sio:
|
||||||
await sio.connect(f"{self.base}/socket.io")
|
await sio.connect(f"{self.base}/socket.io")
|
||||||
while not self._shutdown:
|
while not self._shutdown:
|
||||||
|
try:
|
||||||
|
async with asyncio.timeout(10):
|
||||||
event, data = await sio.receive()
|
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":
|
if event == "full_state":
|
||||||
buffer = b64decode(data["full_state"].encode() + b"=")
|
buffer = b64decode(data["full_state"].encode() + b"=")
|
||||||
image = Image.frombytes("1", (1000, 1000), buffer)
|
image = Image.frombytes("1", (1000, 1000), buffer)
|
||||||
|
@ -161,7 +171,7 @@ class AsyncBotManager:
|
||||||
outgoing = self._written_boxes / (now - self._last_printout)
|
outgoing = self._written_boxes / (now - self._last_printout)
|
||||||
incoming = self._read_boxes / (now - self._last_printout)
|
incoming = self._read_boxes / (now - self._last_printout)
|
||||||
print()
|
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)}")
|
print(f"Alive workers: {len(self._active)}")
|
||||||
|
|
||||||
n_correct, n_wrong = 0, 0
|
n_correct, n_wrong = 0, 0
|
||||||
|
@ -253,7 +263,7 @@ async def amain() -> None:
|
||||||
for elem in settings["elements"]:
|
for elem in settings["elements"]:
|
||||||
if elem["type"] == "text":
|
if elem["type"] == "text":
|
||||||
mgr.put_text(elem["x"], elem["y"], elem["text"], elem.get("font", "default"), elem.get("size", 8))
|
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":
|
elif elem["type"] == "text_anim":
|
||||||
frames: list[Image.Image] = []
|
frames: list[Image.Image] = []
|
||||||
for text in elem["lines"]:
|
for text in elem["lines"]:
|
||||||
|
@ -261,9 +271,20 @@ async def amain() -> None:
|
||||||
mgr.add_animation(elem["x"], elem["y"], frames, elem["spf"])
|
mgr.add_animation(elem["x"], elem["y"], frames, elem["spf"])
|
||||||
for frame in frames:
|
for frame in frames:
|
||||||
frame.close()
|
frame.close()
|
||||||
|
print("ADD text animation", elem)
|
||||||
elif elem["type"] == "image":
|
elif elem["type"] == "image":
|
||||||
with Image.open(elem["path"]).convert("LA") as im:
|
with Image.open(elem["path"]).convert("LA") as im:
|
||||||
mgr.put_image(elem["x"], elem["y"], 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":
|
elif elem["type"] == "animation":
|
||||||
with Image.open(elem["path"]) as anim:
|
with Image.open(elem["path"]) as anim:
|
||||||
frames: list[Image.Image] = []
|
frames: list[Image.Image] = []
|
||||||
|
@ -272,6 +293,7 @@ async def amain() -> None:
|
||||||
mgr.add_animation(elem["x"], elem["y"], frames, elem["spf"])
|
mgr.add_animation(elem["x"], elem["y"], frames, elem["spf"])
|
||||||
for frame in frames:
|
for frame in frames:
|
||||||
frame.close()
|
frame.close()
|
||||||
|
print("ADD animation", elem)
|
||||||
elif elem["type"] == "rgb111":
|
elif elem["type"] == "rgb111":
|
||||||
ox, oy = elem["x"], elem["y"]
|
ox, oy = elem["x"], elem["y"]
|
||||||
with Image.open(elem["path"]).convert("RGBA") as im:
|
with Image.open(elem["path"]).convert("RGBA") as im:
|
||||||
|
@ -353,4 +375,4 @@ async def amain() -> None:
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
asyncio.run(amain())
|
asyncio.run(amain(), debug=True)
|
||||||
|
|
|
@ -13,6 +13,14 @@
|
||||||
"h": 10,
|
"h": 10,
|
||||||
"description": "Not ruining fun for normal users"
|
"description": "Not ruining fun for normal users"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "rect",
|
||||||
|
"x": 0,
|
||||||
|
"y": 20,
|
||||||
|
"w": 1000,
|
||||||
|
"h": 80,
|
||||||
|
"description": "The VOID"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "rect",
|
"type": "rect",
|
||||||
"x": 0,
|
"x": 0,
|
||||||
|
@ -50,9 +58,15 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "rgb565",
|
"type": "rgb565",
|
||||||
"path": "./pictures/niko.png",
|
"path": "./pictures/niko_standing.png",
|
||||||
"x": 48,
|
"x": 106,
|
||||||
"y": 48
|
"y": 132
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "rgb565",
|
||||||
|
"path": "./pictures/hello.png",
|
||||||
|
"x": 112,
|
||||||
|
"y": 203
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue