Skip to content

Commit

Permalink
make yaml_output dump all player options as csv
Browse files Browse the repository at this point in the history
  • Loading branch information
alwaysintreble committed Jul 17, 2024
1 parent a35da3b commit 72e3e88
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No
multiworld.sprite_pool = args.sprite_pool.copy()

multiworld.set_options(args)
if args.yaml_output:
from Options import dump_player_options
dump_player_options(multiworld)
multiworld.set_item_links()
multiworld.state = CollectionState(multiworld)
logger.info('Archipelago Version %s - Seed: %s\n', __version__, multiworld.seed)
Expand Down
35 changes: 33 additions & 2 deletions Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
import random
import typing
import enum
from collections import defaultdict
from copy import deepcopy
from dataclasses import dataclass

from schema import And, Optional, Or, Schema
from typing_extensions import Self

from Utils import get_fuzzy_results, is_iterable_except_str
from Utils import get_fuzzy_results, is_iterable_except_str, output_path

if typing.TYPE_CHECKING:
from BaseClasses import PlandoOptions
from BaseClasses import MultiWorld, PlandoOptions
from worlds.AutoWorld import World
import pathlib

Expand Down Expand Up @@ -1488,6 +1489,36 @@ def yaml_dump_scalar(scalar) -> str:
f.write(res)


def dump_player_options(multiworld: MultiWorld) -> None:
from csv import DictWriter

game_players = defaultdict(list)
for player, game in multiworld.game.items():
game_players[game].append(player)
game_players = dict(sorted(game_players.items()))

output = []
all_options = set()
for game, players in game_players.items():
for player in players:
world = multiworld.worlds[player]
player_output = {
"name": multiworld.get_player_name(player),
"game": multiworld.game[player],
}
output.append(player_output)
for option_key, option in world.options_dataclass.type_hints.items():
display_name = getattr(option, "display_name", option_key)
player_output[display_name] = getattr(world.options, option_key).current_option_name
all_options.add(display_name)

with open(output_path(f"generate_{multiworld.seed_name}.csv"), mode="w") as file:
fields = ["name", "game", *sorted(all_options)]
writer = DictWriter(file, fields)
writer.writeheader()
writer.writerows(output)


if __name__ == "__main__":

from worlds.alttp.Options import Logic
Expand Down

0 comments on commit 72e3e88

Please sign in to comment.