Skip to content

Commit

Permalink
Merge pull request #5 from Exempt-Medic/wargroove2
Browse files Browse the repository at this point in the history
Some Code Review Suggestions
  • Loading branch information
FlySniper authored Sep 2, 2024
2 parents 7def399 + 1540017 commit dbf8bcc
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 131 deletions.
6 changes: 3 additions & 3 deletions worlds/wargroove2/Items.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ItemData(NamedTuple):

}

item_id_name: {int, str} = {}
item_id_name: Dict[int, str] = {}
for name in item_table.keys():
id = item_table[name].code
if id is not None:
Expand All @@ -80,7 +80,7 @@ class ItemData(NamedTuple):
class CommanderData(NamedTuple):
name: str
internal_name: str
alt_name: str = None
alt_name: Optional[str] = None


faction_table: Dict[str, List[CommanderData]] = {
Expand Down Expand Up @@ -128,7 +128,7 @@ class CommanderData(NamedTuple):
class Wargroove2Item(Item):
game = "Wargroove 2"

def __init__(self, name, player: int = None):
def __init__(self, name, player):
item_data = item_table[name]
super(Wargroove2Item, self).__init__(
name,
Expand Down
161 changes: 81 additions & 80 deletions worlds/wargroove2/Levels.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions worlds/wargroove2/Locations.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from BaseClasses import Location
from typing import Dict
from typing import Dict, Optional

location_table: Dict[str, int] = {
location_table: Dict[str, Optional[int]] = {
"Humble Beginnings Rebirth: Talk to Nadia": 253001,
"Humble Beginnings Rebirth: Victory": 253002,
"Humble Beginnings Rebirth: Good Dog": 253003,
Expand Down
11 changes: 7 additions & 4 deletions worlds/wargroove2/Options.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import typing
from dataclasses import dataclass

from Options import Choice, Range, DeathLink, PerGameCommonOptions, StartInventoryPool
Expand Down Expand Up @@ -38,9 +37,13 @@ class LevelShuffleSeed(Range):

class CommanderChoice(Choice):
"""How the player's commander is selected for missions.
Locked Random: The player's commander is randomly predetermined for each level.
Unlockable Factions: The player starts with Mercival and can unlock playable factions.
Random Starting Faction: The player starts with a random starting faction and can unlock the rest.
- Locked Random: The player's commander is randomly predetermined for each level.
- Unlockable Factions: The player starts with Mercival and can unlock playable factions.
- Random Starting Faction: The player starts with a random starting faction and can unlock the rest.
When playing with unlockable factions, faction items are added to the pool."""
display_name = "Commander Choice"
option_locked_random = 0
Expand Down
11 changes: 7 additions & 4 deletions worlds/wargroove2/RegionFilter.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
from typing import List


class Wargroove2LogicFilter:
items: [str]
items: List[str]

def __init__(self, items: [str]):
def __init__(self, items: List[str]):
self.items = items

def has(self, item: str, player: int) -> bool:
return item in self.items

def has_all(self, items: [str], player: int) -> bool:
def has_all(self, items: List[str], player: int) -> bool:
for item in items:
if item not in self.items:
return False
return True

def has_any(self, items: [str], player: int) -> bool:
def has_any(self, items: List[str], player: int) -> bool:
for item in items:
if item in self.items:
return True
Expand Down
22 changes: 11 additions & 11 deletions worlds/wargroove2/Regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ def create_regions(world: "Wargroove2World") -> None:

# Define Level 1s
for level_num in range(0, 4):
next_level = level_num * 4 + 4 - level_num
next_level = level_num * 3 + 4
multiworld.regions += [level_list[level_num].define_region(region_names[level_num], multiworld, exits=[
region_names[next_level],
region_names[
next_level + 1],
region_names[
next_level + 2]])]
region_names[next_level + 1],
region_names[next_level + 2]
])]
# Define Level 2s
for level_num in range(4, 16):
next_level = level_num + 12
multiworld.regions += [level_list[level_num].define_region(region_names[level_num], multiworld,
exits=[region_names[next_level]])]
exits=[region_names[next_level]])]
# Define Level 3s
for level_num in range(16, 28):
final_level_name = FINAL_LEVEL_1
Expand All @@ -42,13 +41,14 @@ def create_regions(world: "Wargroove2World") -> None:
final_level_name = FINAL_LEVEL_3
elif level_num >= 19:
final_level_name = FINAL_LEVEL_2
multiworld.regions += [level_list[level_num].define_region(region_names[level_num], multiworld, exits=[final_level_name])]
multiworld.regions += [level_list[level_num].define_region(region_names[level_num], multiworld,
exits=[final_level_name])]

# Define Final Levels
multiworld.regions += [final_levels[0].define_region(FINAL_LEVEL_1, multiworld),
final_levels[1].define_region(FINAL_LEVEL_2, multiworld),
final_levels[2].define_region(FINAL_LEVEL_3, multiworld),
final_levels[3].define_region(FINAL_LEVEL_4, multiworld)]
final_levels[1].define_region(FINAL_LEVEL_2, multiworld),
final_levels[2].define_region(FINAL_LEVEL_3, multiworld),
final_levels[3].define_region(FINAL_LEVEL_4, multiworld)]

# # link up our regions with the entrances
world.get_entrance("Menu exits to Humble Beginnings Rebirth").connect(
Expand All @@ -63,7 +63,7 @@ def create_regions(world: "Wargroove2World") -> None:
world.get_region(region_names[3]))
# Define Levels 1-4
for level_num in range(0, 4):
next_level = level_num * 4 + 4 - level_num
next_level = level_num * 3 + 4
world.get_entrance(f"{region_names[level_num]} exits to {region_names[next_level]}").connect(
world.get_region(region_names[next_level]))
world.get_entrance(f"{region_names[level_num]} exits to {region_names[next_level + 1]}").connect(
Expand Down
30 changes: 15 additions & 15 deletions worlds/wargroove2/Rules.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
from typing import List

from BaseClasses import Region, Location
from .Levels import Wargroove2Level
from typing import TYPE_CHECKING
from worlds.AutoWorld import LogicMixin
if TYPE_CHECKING:
from . import Wargroove2World


class Wargroove2Logic(LogicMixin):
pass


def set_rules(multiworld, level_list: [Wargroove2Level],
first_level: Wargroove2Level,
final_levels: [Wargroove2Level],
player: int) -> None:
def set_rules(world: "Wargroove2World") -> None:
level_list = world.level_list
first_level = world.first_level
final_levels = world.final_levels
player = world.player

# Level 0
first_level.define_access_rules(multiworld)
first_level.define_access_rules(world)

# Levels 1-28 (Top 28 of the list)
for i in range(0, 28):
level_list[i].define_access_rules(multiworld)
level_list[i].define_access_rules(world)

# Final Levels (Top 4 of the list)
final_levels[0].define_access_rules(multiworld, lambda state: state.has_all({"Final North", "Final Center"}, player))
final_levels[1].define_access_rules(multiworld, lambda state: state.has_all({"Final East", "Final Center"}, player))
final_levels[2].define_access_rules(multiworld, lambda state: state.has_all({"Final South", "Final Center"}, player))
final_levels[3].define_access_rules(multiworld, lambda state: state.has_all({"Final West", "Final Center"}, player))

final_levels[0].define_access_rules(world, lambda state: state.has_all(["Final North", "Final Center"], player))
final_levels[1].define_access_rules(world, lambda state: state.has_all(["Final East", "Final Center"], player))
final_levels[2].define_access_rules(world, lambda state: state.has_all(["Final South", "Final Center"], player))
final_levels[3].define_access_rules(world, lambda state: state.has_all(["Final West", "Final Center"], player))
14 changes: 7 additions & 7 deletions worlds/wargroove2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ class Wargroove2World(World):
game = "Wargroove 2"
topology_present = True
web = Wargroove2Web()
level_list: [Wargroove2Level] = None
first_level: Wargroove2Level = None
final_levels: [Wargroove2Level] = None
level_list: typing.List[Wargroove2Level] = []
first_level: Wargroove2Level
final_levels: typing.List[Wargroove2Level] = []

item_name_to_id = {name: data.code for name, data in item_table.items()}
location_name_to_id = location_table
item_name_to_id = {name: data.code for name, data in item_table.items() if data.code is not None}
location_name_to_id = {name: code for name, code in location_table.items() if code is not None}

def _get_slot_data(self) -> typing.Dict[str, typing.Any]:
return {
Expand Down Expand Up @@ -150,10 +150,10 @@ def create_items(self) -> None:
self.get_location(final_level.victory_locations[0]).place_locked_item(victory)
# Placing victory event at final location
self.multiworld.completion_condition[self.player] = lambda state: \
state.has("Wargroove 2 Victory", self.player, self.options.final_levels)
state.has("Wargroove 2 Victory", self.player, self.options.final_levels.value)

def set_rules(self) -> None:
set_rules(self.multiworld, self.level_list, self.first_level, self.final_levels, self.player)
set_rules(self)

def create_item(self, name: str) -> Item:
return Wargroove2Item(name, self.player)
Expand Down
10 changes: 5 additions & 5 deletions worlds/wargroove2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
from typing import Tuple, List, Iterable, Dict

from settings import get_settings
from worlds.wargroove2 import Wargroove2World
from worlds.wargroove2.Items import item_table, faction_table, CommanderData, ItemData, item_id_name
from . import Wargroove2World
from .Items import item_table, faction_table, CommanderData, ItemData, item_id_name

import ModuleUpdate
from worlds.wargroove2.Levels import LEVEL_COUNT, FINAL_LEVEL_COUNT, region_names, get_level_table, FINAL_LEVEL_1, \
from .Levels import LEVEL_COUNT, FINAL_LEVEL_COUNT, region_names, get_level_table, FINAL_LEVEL_1, \
FINAL_LEVEL_2, FINAL_LEVEL_3, FINAL_LEVEL_4, get_final_levels
from worlds.wargroove2.Locations import location_table
from worlds.wargroove2.RegionFilter import Wargroove2LogicFilter
from .Locations import location_table
from .RegionFilter import Wargroove2LogicFilter

ModuleUpdate.update()

Expand Down

0 comments on commit dbf8bcc

Please sign in to comment.