Skip to content

Commit a26abe0

Browse files
authored
Zillion: Some Code Cleaning (#4780)
1 parent 199b6bd commit a26abe0

File tree

8 files changed

+37
-37
lines changed

8 files changed

+37
-37
lines changed

worlds/zillion/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ZillionWebWorld(WebWorld):
5959
"English",
6060
"setup_en.md",
6161
"setup/en",
62-
["beauxq"]
62+
["beauxq"],
6363
)]
6464

6565
option_groups = z_option_groups
@@ -365,7 +365,7 @@ def finalize_item_locations(self) -> GenData:
365365
z_loc.zz_loc.item = multi_item
366366
multi_items[z_loc.zz_loc.name] = (
367367
z_loc.item.name,
368-
self.multiworld.get_player_name(z_loc.item.player)
368+
self.multiworld.get_player_name(z_loc.item.player),
369369
)
370370
# debug_zz_loc_ids.sort()
371371
# for name, id_ in debug_zz_loc_ids.items():

worlds/zillion/client.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def run_gui(self) -> None:
147147

148148
class ZillionManager(GameManager):
149149
logging_pairs = [
150-
("Client", "Archipelago")
150+
("Client", "Archipelago"),
151151
]
152152
base_title = "Archipelago Zillion Client"
153153

@@ -282,7 +282,7 @@ def on_package(self, cmd: str, args: dict[str, Any]) -> None:
282282

283283
payload = {
284284
"cmd": "Get",
285-
"keys": [f"zillion-{self.auth}-doors"]
285+
"keys": [f"zillion-{self.auth}-doors"],
286286
}
287287
async_start(self.send_msgs([payload]))
288288
elif cmd == "Retrieved":
@@ -326,7 +326,7 @@ def process_from_game_queue(self) -> None:
326326
n_locations = len(self.missing_locations) + len(self.checked_locations) - 1 # -1 to ignore win
327327
logger.info(f"New Check: {loc_name} ({self.ap_local_count}/{n_locations})")
328328
async_start(self.send_msgs([
329-
{"cmd": "LocationChecks", "locations": [server_id]}
329+
{"cmd": "LocationChecks", "locations": [server_id]},
330330
]))
331331
else:
332332
# This will happen a lot in Zillion,
@@ -338,7 +338,7 @@ def process_from_game_queue(self) -> None:
338338
if not self.finished_game:
339339
async_start(self.send_msgs([
340340
{"cmd": "LocationChecks", "locations": [loc_name_to_id["J-6 bottom far left"]]},
341-
{"cmd": "StatusUpdate", "status": ClientStatus.CLIENT_GOAL}
341+
{"cmd": "StatusUpdate", "status": ClientStatus.CLIENT_GOAL},
342342
]))
343343
self.finished_game = True
344344
elif isinstance(event_from_game, events.DoorEventFromGame):
@@ -347,7 +347,7 @@ def process_from_game_queue(self) -> None:
347347
payload = {
348348
"cmd": "Set",
349349
"key": f"zillion-{self.auth}-doors",
350-
"operations": [{"operation": "replace", "value": doors_b64}]
350+
"operations": [{"operation": "replace", "value": doors_b64}],
351351
}
352352
async_start(self.send_msgs([payload]))
353353
elif isinstance(event_from_game, events.MapEventFromGame):
@@ -367,7 +367,7 @@ def process_items_received(self) -> None:
367367
# TODO: colors in this text, like sni client?
368368
logger.info(f"received {self.ap_id_to_name[ap_id]} from {from_name}")
369369
self.to_game.put_nowait(
370-
events.ItemEventToGame(zz_item_ids)
370+
events.ItemEventToGame(zz_item_ids),
371371
)
372372
self.next_item = len(self.items_received)
373373

@@ -398,7 +398,7 @@ async def zillion_sync_task(ctx: ZillionContext) -> None:
398398
logger.info("Start Zillion in RetroArch, then use the /sms command to connect to it.")
399399
await asyncio.wait((
400400
asyncio.create_task(ctx.look_for_retroarch.wait()),
401-
asyncio.create_task(ctx.exit_event.wait())
401+
asyncio.create_task(ctx.exit_event.wait()),
402402
), return_when=asyncio.FIRST_COMPLETED)
403403

404404
last_log = ""
@@ -443,7 +443,7 @@ def log_no_spam(msg: str) -> None:
443443
await asyncio.wait((
444444
asyncio.create_task(ctx.got_slot_data.wait()),
445445
asyncio.create_task(ctx.exit_event.wait()),
446-
asyncio.create_task(asyncio.sleep(6))
446+
asyncio.create_task(asyncio.sleep(6)),
447447
), return_when=asyncio.FIRST_COMPLETED) # to not spam connect packets
448448
else: # not correct seed name
449449
log_no_spam("incorrect seed - did you mix up roms?")
@@ -467,7 +467,7 @@ def log_no_spam(msg: str) -> None:
467467
await asyncio.wait((
468468
asyncio.create_task(ctx.got_room_info.wait()),
469469
asyncio.create_task(ctx.exit_event.wait()),
470-
asyncio.create_task(asyncio.sleep(6))
470+
asyncio.create_task(asyncio.sleep(6)),
471471
), return_when=asyncio.FIRST_COMPLETED)
472472
else: # no name found in game
473473
if not help_message_shown:

worlds/zillion/gen_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def to_json(self) -> str:
1919
jsonable = {
2020
"multi_items": self.multi_items,
2121
"zz_game": self.zz_game.to_jsonable(),
22-
"game_id": list(self.game_id)
22+
"game_id": list(self.game_id),
2323
}
2424
return json.dumps(jsonable)
2525

@@ -37,5 +37,5 @@ def from_json(gen_data_str: str) -> "GenData":
3737
return GenData(
3838
from_json["multi_items"],
3939
ZzGame.from_jsonable(from_json["zz_game"]),
40-
bytes(from_json["game_id"])
40+
bytes(from_json["game_id"]),
4141
)

worlds/zillion/id_maps.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343

4444
def make_id_to_others(start_char: Chars) -> tuple[
45-
dict[int, str], dict[int, int], dict[int, ZzItem]
45+
dict[int, str], dict[int, int], dict[int, ZzItem],
4646
]:
4747
""" returns id_to_name, id_to_zz_id, id_to_zz_item """
4848
id_to_name: dict[int, str] = {}
@@ -53,19 +53,19 @@ def make_id_to_others(start_char: Chars) -> tuple[
5353
name_to_zz_item = {
5454
"Apple": _zz_rescue_0,
5555
"Champ": _zz_rescue_1,
56-
"JJ": _zz_empty
56+
"JJ": _zz_empty,
5757
}
5858
elif start_char == "Apple":
5959
name_to_zz_item = {
6060
"Apple": _zz_empty,
6161
"Champ": _zz_rescue_1,
62-
"JJ": _zz_rescue_0
62+
"JJ": _zz_rescue_0,
6363
}
6464
else: # Champ
6565
name_to_zz_item = {
6666
"Apple": _zz_rescue_0,
6767
"Champ": _zz_empty,
68-
"JJ": _zz_rescue_1
68+
"JJ": _zz_rescue_1,
6969
}
7070

7171
for name, ap_id in item_name_to_id.items():
@@ -150,10 +150,10 @@ def get_slot_info(regions: Iterable[RegionData],
150150
rescues[str(i)] = {
151151
"start_char": ri.start_char,
152152
"room_code": ri.room_code,
153-
"mask": ri.mask
153+
"mask": ri.mask,
154154
}
155155
return {
156156
"start_char": start_char,
157157
"rescues": rescues,
158-
"loc_mem_to_id": loc_memory_to_loc_id
158+
"loc_mem_to_id": loc_memory_to_loc_id,
159159
}

worlds/zillion/logic.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ def set_randomizer_locs(cs: CollectionState, p: int, zz_r: Randomizer) -> int:
2525
z_world = cs.multiworld.worlds[p]
2626
assert isinstance(z_world, ZillionWorld)
2727

28-
_hash = p
28+
hash_ = p
2929
for z_loc in z_world.my_locations:
3030
zz_name = z_loc.zz_loc.name
3131
zz_item = z_loc.item.zz_item \
3232
if isinstance(z_loc.item, ZillionItem) and z_loc.item.player == p \
3333
else zz_empty
3434
zz_r.locations[zz_name].item = zz_item
35-
_hash += (hash(zz_name) * (z_loc.zz_loc.req.gun + 2)) ^ hash(zz_item)
36-
return _hash
35+
hash_ += (hash(zz_name) * (z_loc.zz_loc.req.gun + 2)) ^ hash(zz_item)
36+
return hash_
3737

3838

3939
def item_counts(cs: CollectionState, p: int) -> tuple[tuple[str, int], ...]:
@@ -67,11 +67,11 @@ def cs_to_zz_locs(self, cs: CollectionState) -> frozenset[Location]:
6767
returns frozenset of accessible zilliandomizer locations
6868
"""
6969
# caching this function because it would be slow
70-
_hash = set_randomizer_locs(cs, self._player, self._zz_r)
70+
hash_ = set_randomizer_locs(cs, self._player, self._zz_r)
7171
counts = item_counts(cs, self._player)
72-
_hash += hash(counts)
72+
hash_ += hash(counts)
7373

74-
cntr, locs = self._cache.get(_hash, _cache_miss)
74+
cntr, locs = self._cache.get(hash_, _cache_miss)
7575
if cntr == cs.prog_items[self._player]:
7676
# print("cache hit")
7777
return locs
@@ -90,6 +90,6 @@ def cs_to_zz_locs(self, cs: CollectionState) -> frozenset[Location]:
9090
tr = frozenset(self._zz_r.get_locations(have_req))
9191

9292
# save result in cache
93-
self._cache[_hash] = (cs.prog_items[self._player].copy(), tr)
93+
self._cache[hash_] = (cs.prog_items[self._player].copy(), tr)
9494

9595
return tr

worlds/zillion/options.py

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

77
from zilliandomizer.options import (
88
Options as ZzOptions, char_to_gun, char_to_jump, ID,
9-
VBLR as ZzVBLR, Chars, ItemCounts as ZzItemCounts
9+
VBLR as ZzVBLR, Chars, ItemCounts as ZzItemCounts,
1010
)
1111
from zilliandomizer.options.parsing import validate as zz_validate
1212

@@ -23,7 +23,7 @@ class ZillionContinues(NamedRange):
2323
display_name = "continues"
2424
special_range_names = {
2525
"vanilla": 3,
26-
"infinity": 21
26+
"infinity": 21,
2727
}
2828

2929

@@ -247,7 +247,7 @@ class ZillionStartingCards(NamedRange):
247247
range_end = 10
248248
display_name = "starting cards"
249249
special_range_names = {
250-
"vanilla": 0
250+
"vanilla": 0,
251251
}
252252

253253

@@ -315,8 +315,8 @@ class ZillionOptions(PerGameCommonOptions):
315315
z_option_groups = [
316316
OptionGroup("item counts", [
317317
ZillionIDCardCount, ZillionBreadCount, ZillionOpaOpaCount, ZillionZillionCount,
318-
ZillionFloppyDiskCount, ZillionScopeCount, ZillionRedIDCardCount
319-
])
318+
ZillionFloppyDiskCount, ZillionScopeCount, ZillionRedIDCardCount,
319+
]),
320320
]
321321

322322

@@ -361,7 +361,7 @@ def validate(options: ZillionOptions) -> tuple[ZzOptions, Counter[str]]:
361361
"Zillion": options.zillion_count,
362362
"Floppy Disk": options.floppy_disk_count,
363363
"Scope": options.scope_count,
364-
"Red ID Card": options.red_id_card_count
364+
"Red ID Card": options.red_id_card_count,
365365
})
366366
minimums = Counter({
367367
"ID Card": 0,
@@ -370,7 +370,7 @@ def validate(options: ZillionOptions) -> tuple[ZzOptions, Counter[str]]:
370370
"Zillion": guns_required,
371371
"Floppy Disk": floppy_req.value,
372372
"Scope": 0,
373-
"Red ID Card": 1
373+
"Red ID Card": 1,
374374
})
375375
for key in minimums:
376376
item_counts[key] = max(minimums[key], item_counts[key])
@@ -426,7 +426,7 @@ def validate(options: ZillionOptions) -> tuple[ZzOptions, Counter[str]]:
426426
bool(options.early_scope.value),
427427
True, # balance defense
428428
starting_cards.value,
429-
map_gen
429+
map_gen,
430430
)
431431
zz_validate(zz_op)
432432
return zz_op, item_counts

worlds/zillion/test/TestGoal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class TestGoalAppleStart(ZillionTestBase):
104104
"start_char": "Apple",
105105
"jump_levels": "balanced",
106106
"gun_levels": "low",
107-
"zillion_count": 5
107+
"zillion_count": 5,
108108
}
109109

110110
def test_guns_jj_first(self) -> None:
@@ -131,7 +131,7 @@ class TestGoalChampStart(ZillionTestBase):
131131
"jump_levels": "low",
132132
"gun_levels": "balanced",
133133
"opa_opa_count": 5,
134-
"opas_per_level": 1
134+
"opas_per_level": 1,
135135
}
136136

137137
def test_jump_jj_first(self) -> None:

worlds/zillion/test/TestOptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_vblr_ap_to_zz(self) -> None:
1818
""" all of the valid values for the AP options map to valid values for ZZ options """
1919
for option_name, vblr_class in (
2020
("jump_levels", ZillionJumpLevels),
21-
("gun_levels", ZillionGunLevels)
21+
("gun_levels", ZillionGunLevels),
2222
):
2323
for value in vblr_class.name_lookup.values():
2424
self.options = {option_name: value}

0 commit comments

Comments
 (0)