newstyle DataPackage. Both versions in merged format for compatibility for now.

This commit is contained in:
Fabian Dill
2021-07-12 18:05:46 +02:00
parent 50a21fbd74
commit f456dba993
9 changed files with 60 additions and 38 deletions

View File

@@ -5,36 +5,34 @@ __all__ = {"lookup_any_item_id_to_name",
"lookup_any_location_id_to_name",
"network_data_package"}
# all of the below should be moved to AutoWorld functionality
from .alttp.Items import lookup_id_to_name as alttp
from .hk.Items import lookup_id_to_name as hk
from .factorio import Technologies
from .minecraft.Items import lookup_id_to_name as mc
lookup_any_item_id_to_name = {**alttp, **hk, **Technologies.lookup_id_to_name, **mc}
assert len(alttp) + len(hk) + len(Technologies.lookup_id_to_name) + len(mc) == len(lookup_any_item_id_to_name)
lookup_any_item_name_to_id = {name: id for id, name in lookup_any_item_id_to_name.items()}
# assert len(lookup_any_item_name_to_id) == len(lookup_any_item_id_to_name) # currently broken: Single Arrow
from .alttp import Regions
from .hk import Locations
from .minecraft import Locations as Advancements
lookup_any_location_id_to_name = {**Regions.lookup_id_to_name, **Locations.lookup_id_to_name,
**Technologies.lookup_id_to_name, **Advancements.lookup_id_to_name}
assert len(Regions.lookup_id_to_name) + len(Locations.lookup_id_to_name) + \
len(Technologies.lookup_id_to_name) + len(Advancements.lookup_id_to_name) == \
len(lookup_any_location_id_to_name)
lookup_any_location_name_to_id = {name: id for id, name in lookup_any_location_id_to_name.items()}
assert len(lookup_any_location_name_to_id) == len(lookup_any_location_id_to_name)
network_data_package = {"lookup_any_location_id_to_name": lookup_any_location_id_to_name,
"lookup_any_item_id_to_name": lookup_any_item_id_to_name,
"version": 9}
# end of TODO block
# import all submodules to trigger AutoWorldRegister
for file in os.scandir(os.path.dirname(__file__)):
if file.is_dir():
importlib.import_module(f".{file.name}", "worlds")
importlib.import_module(f".{file.name}", "worlds")
from .AutoWorld import AutoWorldRegister
lookup_any_item_id_to_name = {}
lookup_any_location_id_to_name = {}
games = {}
for world_name, world in AutoWorldRegister.world_types.items():
games[world_name] = {
"item_name_to_id" : world.item_name_to_id,
"location_name_to_id": world.location_name_to_id,
"version": world.data_version,
# seems clients don't actually want this. Keeping it here in case someone changes their mind.
# "item_name_groups": {name: tuple(items) for name, items in world.item_name_groups.items()}
}
lookup_any_item_id_to_name.update(world.item_id_to_name)
lookup_any_location_id_to_name.update(world.location_id_to_name)
network_data_package = {
"lookup_any_location_id_to_name": lookup_any_location_id_to_name, # legacy, to be removed
"lookup_any_item_id_to_name": lookup_any_item_id_to_name, # legacy, to be removed
"version": 10, # legacy, to be removed
"games": games,
}
import json
with open("datapackagegroups.json", "w") as f:
json.dump(network_data_package, f, indent=4)