From 7889d58170b0cf46d9021f48a4bf7deb3f8868af Mon Sep 17 00:00:00 2001 From: hkc Date: Thu, 4 Jul 2024 17:02:05 +0300 Subject: [PATCH] Changed avoid logic to allow single pixels --- async-bot.py | 24 ++++++++++++++------ avoid_masks/noita.png | Bin 0 -> 26757 bytes avoid_masks/noita_black_outline_179x111.png | Bin 5456 -> 0 bytes settings.json | 2 +- 4 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 avoid_masks/noita.png delete mode 100644 avoid_masks/noita_black_outline_179x111.png diff --git a/async-bot.py b/async-bot.py index 155d281..b64ba83 100644 --- a/async-bot.py +++ b/async-bot.py @@ -19,7 +19,7 @@ class AsyncBotManager: self.difference: dict[int, bool] = {} self._last_update = 0 self._shutdown: bool = False - self.avoid: set[range] = set() + self.avoid: set[int] = set() def put_text(self, x: int, y: int, text: str): with Image.new("LA", (int(self.font.getlength(text) + 12), 16)) as im: @@ -40,7 +40,7 @@ class AsyncBotManager: self.put_index(index, l > 0) def put_index(self, index: int, value: bool): - if not any([index in avoid for avoid in self.avoid]): + if not index in self.avoid: self.difference[index] = value def add_avoid_rect(self, sx: int, sy: int, w: int, h: int): @@ -49,7 +49,10 @@ class AsyncBotManager: self.add_avoid_range(sx + ox, sx + w + ox) def add_avoid_range(self, start: int, stop: int, step: int = 1): - self.avoid.add(range(start, stop, step)) + self.avoid |= set(range(start, stop, step)) + + def add_avoid_index(self, *indices: int): + self.avoid |= set(indices) def get_difference_image(self) -> Image.Image: with Image.new("LA", (1000, 1000), 0) as im: @@ -60,10 +63,9 @@ class AsyncBotManager: def get_avoid_image(self) -> Image.Image: with Image.new("RGB", (1000, 1000), (0, 255, 0)) as im: - for rng in self.avoid: - for index in rng: - y, x = divmod(index, 1000) - im.putpixel((x, y), (255, 0, 0)) + for index in self.avoid: + y, x = divmod(index, 1000) + im.putpixel((x, y), (255, 0, 0)) return im.copy() async def listener(self): @@ -140,6 +142,14 @@ async def amain(): mgr.add_avoid_range( avoid["start"], avoid["stop"], avoid.get("step", 1) ) + elif avoid["type"] == "image": + with Image.open(avoid["path"]).convert("LA") as im: + assert im.width == 1000 and im.height == 1000 + for y in range(im.height): + for x in range(im.width): + l, a = im.getpixel((x, y)) # type: ignore + if a > 128: + mgr.add_avoid_index(x + y * 1000) for elem in settings["elements"]: if elem["type"] == "text": mgr.put_text(elem["x"], elem["y"], elem["text"]) diff --git a/avoid_masks/noita.png b/avoid_masks/noita.png new file mode 100644 index 0000000000000000000000000000000000000000..33fb84f3bbc0969262f8d8daa383b8dd6ce33150 GIT binary patch literal 26757 zcmeHPcUV))wogJr2kGrlB1NPmgisSHK|m=|1P&k|5JKn>NCHHV60smERTLEkMUHqx z5sx4iB*%gU57HD6P(Z45MNt%ZJ7^Mo_kG{H=e>8|cmK%t8~0>p&6>5={C;cC#BC0` zI&T#bR1gG#KqB^bHf|sg<1t^8zhSWgSBxkYF*<+djnJUK_*@vO-)W&## z>Y6$P%mV_NK>0us1w%j*z`Y145>&Yu+{tTK>e2=^=m+V;}03;czs~32ynjz z6f{tm0`8B25`N(OyuCnO3Q)$s`p23~#8ZjE@WgOx7<{X}lPl<(76{}E$gu9rMmQRY z!65Zb0gWiMAr@tVMH#~Njj=|iSbYo#0@|O?2a*TIECK~w%CQ&t$iDt@CIQeg=(|l! z-&k>BI>?F(v(AdkexT0t!%t>(dDqmX*Z2>HeAjuHIrc|=oxpc9zWcn=wbBm~bJ$|P z1(=8#Sm3Xf9*{MNpO=@97sk)W$0s1bFDNV}A}k~%EH5FsPD)8ZMOjHfQ4y|=)P$?* zswpaNG||#U=^Gjvs%T=&P0?mZ14A@Z30OctKv+mvPDDfwy)!nb4;vpne)6=fz2n8p&aUoP1A}jehDS!n#^24o|1kgY z)57O3i%h?mezLCbp8Y4k!~wq`P$&7Cn&=)6}Y`^x&#(?wr&xUJ2w zXyQ6QPa1&M3 z=NhecwMjD9RQ=2-Tv@{_`u)cFJLI%gg^y{bgOr?-avB2!tU~9E5tjFF1z$E= zy4HItG9Gb4zF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LB$V0o~n`pFX@MlbQ$wSCs~s)=mA^LbXn3oJg0ZQZhJXheN9Q z3PdEXp!kI~`=u5J+_d2=JkjN0mBr7C;`MVj1j16TAI@TDf})9zIx9&X zUG@+RG%B)0?fJQ4Yv90%d9Ulh?g0bJm`5=u1fcBQybwEWmwJJ9M(abG>ja90ysg%5 z0jL`ShwuEcR~|{X1DwrsMXq_w?MWZJvrku!hmHkIz+Um;Btcg{M(wA;^9t%MN7E70 zPUZIlIS&CvA#V)u@CEi3k>A8@?Kqs?M6Y6Grex0`%XzoKb^B#EMGXnEOb0_;_!Xtc zEgCHI1X4H*Wo~onmJr9Y%0AoqY||Mai0Hvz;0HG|+u1bZR=CmNz>l3ZxD^h$*y);E z;pPo)^5nAM--ZPvntO+VU&eM|{w@GFUvYOe+^05|1zZ+zS-@ohmjzrFa9O}*0ha|_ h7W}g;(1)z>xNDR_{FeHInLh(=Z|iJxWpm)3{{UwOb^8DS literal 0 HcmV?d00001 diff --git a/avoid_masks/noita_black_outline_179x111.png b/avoid_masks/noita_black_outline_179x111.png deleted file mode 100644 index 7358dcc8cac44395a17fffef53bbf11017474928..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5456 zcmeHLcT^Ku7axkiA{}IbRSZE`6w@ZO1R{_E1dXBu1gt}55=KZN2?P*O1l(10!CggB z*tJkp1Pg1&6$@nr6$>DsYeB(=uAqpOZxT@Pe0$D!Jm=g0oXO0*a_{fm`@8qO^Ilek z%nUR(v@-+%z?d7vo`Zd>ut#d3hrP@0KP$sNc1Q$Q$m0Q1u(AQ5rDXx=U?nZ=)?Ah~ z2|ZXf6J@bNxGWYAWbv&nr^3v1ef|(73^;RH-){Yub+6TgX%-&#i- zA75x&%B%MGsY1Uie7VYT&!qCRJ!dVQ7vv4Dd$hVqCteUhY3@9=-qCsbKx8 zpLdzhvJ4F4m8Cj7+J7!Nrz(8c{#M4Tv1gLgkb*~Uf$PrV^Kt%JE9}ngtO-~XUSu^E z?U*$<7&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45,7 +45,7 @@ }, { "type": "image", - "path": "./avoid_masks/noita_black_outline_179x111.png", + "path": "./avoid_masks/noita.png", "description": "Noita logo by Cr4xy" } ],