Files
Grinch-AP/worlds/stardew_valley/scripts/update_data.py
Jérémie Bolduc af7d0dbf37 Stardew Valley: implement new game (#1455)
* Stardew Valley Archipelago implementation

* fix breaking changes

* - Added and Updated Documentation for the game

* Removed fun

* Remove entire idea of step, due to possible inconsistency with the main AP core

* Commented out the desired steps, fix renaming after rebase

* Fixed wording

* tests now passes on 3.8

* run flake8

* remove dependency so apworld work again

* remove dependency for real

* - Fix Formatting in the Game Page
- Removed disabled Option Descriptions for Entrance Randomizer
- Improved Game Page's description of the Arcade Machine buffs
- Trimmed down the text on the Options page for Arcade Machines, so that it is smaller

* - Removed blankspace

* remove player field

* remove None check in options

* document the scripts

* fix pytest warning

* use importlib.resources.files

* fix

* add version requirement to importlib_resources

* remove __init__.py from data folder

* increment data version

* let the __init__.py for 3.9

* use sorted() instead of list()

* replace frozenset from fish_data with tuples

* remove dependency on pytest

* - Add a bit of text to the guide to tell them about how to redeem some received items

* - Added a comment about which mod version to use

* change single quotes for double quotes

* Minimum client version both ways

* Changed version number to be more specific. The mod will handle deciding

---------

Co-authored-by: Alex Gilbert <alexgilbert@yahoo.com>
2023-02-27 01:19:15 +01:00

89 lines
3.4 KiB
Python

"""Update data script
This script can be used to assign new ids for the items and locations in the CSV file. It also regenerates the items
based on the resource packs.
To run the script, use `python -m worlds.stardew_valley.scripts.update_data` from the repository root.
"""
import csv
import itertools
from pathlib import Path
from typing import List
from worlds.stardew_valley import LocationData
from worlds.stardew_valley.items import load_item_csv, Group, ItemData, load_resource_pack_csv, friendship_pack
from worlds.stardew_valley.locations import load_location_csv
RESOURCE_PACK_CODE_OFFSET = 5000
script_folder = Path(__file__)
def write_item_csv(items: List[ItemData]):
with open((script_folder.parent.parent / "data/items.csv").resolve(), "w", newline="") as file:
writer = csv.DictWriter(file, ["id", "name", "classification", "groups"])
writer.writeheader()
for item in items:
item_dict = {
"id": item.code_without_offset,
"name": item.name,
"classification": item.classification.name,
"groups": ",".join(sorted(group.name for group in item.groups))
}
writer.writerow(item_dict)
def write_location_csv(locations: List[LocationData]):
with open((script_folder.parent.parent / "data/locations.csv").resolve(), "w", newline="") as file:
write = csv.DictWriter(file, ["id", "region", "name", "tags"])
write.writeheader()
for location in locations:
location_dict = {
"id": location.code_without_offset,
"name": location.name,
"region": location.region,
"tags": ",".join(sorted(group.name for group in location.tags))
}
write.writerow(location_dict)
if __name__ == "__main__":
loaded_items = load_item_csv()
item_counter = itertools.count(max(item.code_without_offset
for item in loaded_items
if Group.RESOURCE_PACK not in item.groups
and item.code_without_offset is not None) + 1)
items_to_write = []
for item in loaded_items:
if item.has_any_group(Group.RESOURCE_PACK, Group.FRIENDSHIP_PACK):
continue
if item.code_without_offset is None:
items_to_write.append(ItemData(next(item_counter), item.name, item.classification, item.groups))
continue
items_to_write.append(item)
all_resource_packs = load_resource_pack_csv() + [friendship_pack]
resource_pack_counter = itertools.count(RESOURCE_PACK_CODE_OFFSET)
items_to_write.extend(
item for resource_pack in all_resource_packs for item in resource_pack.as_item_data(resource_pack_counter))
write_item_csv(items_to_write)
loaded_locations = load_location_csv()
location_counter = itertools.count(max(location.code_without_offset
for location in loaded_locations
if location.code_without_offset is not None) + 1)
locations_to_write = []
for location in loaded_locations:
if location.code_without_offset is None:
locations_to_write.append(
LocationData(next(location_counter), location.region, location.name, location.tags))
continue
locations_to_write.append(location)
write_location_csv(locations_to_write)