Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/Data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging
from typing import Literal

from .DataValidation import DataValidation, ValidationError
from .Helpers import load_data_file as helpers_load_data_file
from .Helpers import load_data_file as helpers_load_data_file, load_data_csv

from .hooks.Data import \
after_load_game_file, \
Expand All @@ -23,13 +24,20 @@ def convert_to_list(data, property_name: str) -> list:
class ManualFile:
filename: str
data_type: dict|list
filetype: Literal['json', 'csv']

def __init__(self, filename, data_type):
def __init__(self, filename, data_type, filetype='json'):
self.filename = filename
self.data_type = data_type
self.filetype = filetype

def load(self):
contents = helpers_load_data_file(self.filename)
if self.filetype == 'json':
contents = helpers_load_data_file(self.filename)
elif self.filetype == 'csv':
contents = load_data_csv(self.filename)
else:
raise ValueError(f"Unsupported filetype: {self.filetype}")

if not contents and type(contents) != self.data_type:
return self.data_type()
Expand All @@ -44,6 +52,9 @@ def load(self):
category_table = ManualFile('categories.json', dict).load() #dict
meta_table = ManualFile('meta.json', dict).load() #dict

item_table.extend(ManualFile('items.csv', list, 'csv').load()) #list
location_table.extend(ManualFile('locations.csv', list, 'csv').load()) #list

# Removal of schemas in root of tables
region_table.pop('$schema', '')
category_table.pop('$schema', '')
Expand Down
14 changes: 13 additions & 1 deletion src/Helpers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import csv
import os
import pkgutil
import json

from BaseClasses import MultiWorld, Item, Location
from BaseClasses import MultiWorld, Item
from typing import Optional, List, TYPE_CHECKING
from worlds.AutoWorld import World
from .hooks.Helpers import before_is_category_enabled, before_is_item_enabled, before_is_location_enabled
Expand All @@ -24,6 +25,17 @@ def load_data_file(*args) -> dict:

return filedata

def load_data_csv(*args) -> list[dict]:
fname = os.path.join("data", *args)

try:
lines = pkgutil.get_data(__name__, fname).decode().splitlines()
except:
lines = []
filedata = list(csv.DictReader(lines))

return filedata

def is_option_enabled(multiworld: MultiWorld, player: int, name: str) -> bool:
return get_option_value(multiworld, player, name) > 0

Expand Down
3 changes: 3 additions & 0 deletions src/Items.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@

item_table[key]["id"] = count
item_table[key]["progression"] = val["progression"] if "progression" in val else False
if isinstance(val.get("category", []), str):
item_table[key]["category"] = [val["category"]]

count += 1

for item in item_table:
Expand Down
5 changes: 4 additions & 1 deletion src/Locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@

location_table[key]["id"] = count

if not "region" in location_table[key]:
if "region" not in location_table[key]:
location_table[key]["region"] = "Manual" # all locations are in the same region for Manual

if isinstance(location_table[key].get("category", []), str):
location_table[key]["category"] = [location_table[key]["category"]]

count += 1

if not victory_names:
Expand Down
3 changes: 3 additions & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ def create_item(self, name: str) -> Item:
if "progression_skip_balancing" in item and item["progression_skip_balancing"]:
classification = ItemClassification.progression_skip_balancing

if "classification" in item:
classification = ItemClassification[item["classification"]]

item_object = ManualItem(name, classification,
self.item_name_to_id[name], player=self.player)

Expand Down
3 changes: 3 additions & 0 deletions src/data/categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
},
"Example Yaml-option category": {
"yaml_option": ["DLC_enabled"]
},
"Stage": {
"yaml_option": ["randomize_stages"]
}
}
4 changes: 4 additions & 0 deletions src/data/game.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
{
"items": ["Deadpool"],
"yaml_option": ["start_with_deadpool"]
},
{
"item_categories": ["Stage"],
"yaml_option": ["randomize_stages"]
}
],
"death_link": false
Expand Down
10 changes: 10 additions & 0 deletions src/data/items.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name,category,classification
Danger Room,Stage,progression
Shadowland,Stage,progression
S.H.I.E.L.D Air Show,Stage,progression
Asgard: Sea of Space,Stage,progression
Days of Future Past,Stage,progression
City that Never Sleeps,Stage,progression
Chaos at Tricell,Stage,progression
Demon Village Redux,Stage,progression
Bonne Wonderland,Stage,progression