forked from ArchipelagoMW/Archipelago
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
917 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import json | ||
import os | ||
import pkgutil | ||
|
||
# blatantly copied from the minecraft ap world because why not | ||
def load_data_file(*args) -> dict: | ||
fname = os.path.join("data", *args) | ||
|
||
try: | ||
filedata = json.loads(pkgutil.get_data(__name__, fname).decode()) | ||
except: | ||
filedata = [] | ||
|
||
return filedata | ||
|
||
game_table = load_data_file('game.json') | ||
item_table = load_data_file('items.json') | ||
#progressive_item_table = load_data_file('progressive_items.json') | ||
progressive_item_table = {} | ||
location_table = load_data_file('locations.json') | ||
region_table = load_data_file('regions.json') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from .Data import game_table | ||
|
||
game_name = "Manual_%s_%s" % (game_table["game"], game_table["player"]) | ||
filler_item_name = game_table["filler_item_name"] | ||
|
||
# Programmatically generate starting indexes for items and locations based upon the game name and player name to aim for non-colliding indexes | ||
starting_index = (ord(game_table["game"][:1]) * 1000000) + \ | ||
(ord(game_table["game"][1:2]) * 100000) + \ | ||
(ord(game_table["game"][2:3]) * 100000) + \ | ||
(ord(game_table["game"][3:4]) * 100000) + \ | ||
(ord(game_table["game"][4:5]) * 100000) + \ | ||
(ord(game_table["game"][-1:]) * 100000) + \ | ||
(ord(game_table["player"][:1]) * 10000) + \ | ||
(ord(game_table["player"][1:2]) * 10000) + \ | ||
(ord(game_table["player"][-1:]) * 1000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from BaseClasses import Item | ||
from .Data import item_table, progressive_item_table | ||
from .Game import filler_item_name, starting_index | ||
|
||
###################### | ||
# Generate item lookups | ||
###################### | ||
|
||
item_id_to_name = {} | ||
item_name_to_item = {} | ||
advancement_item_names = set() | ||
lastItemId = -1 | ||
|
||
count = starting_index | ||
|
||
# add the filler item to the list of items for lookup | ||
item_table.append({ | ||
"name": filler_item_name | ||
}) | ||
|
||
# add sequential generated ids to the lists | ||
for key, val in enumerate(item_table): | ||
item_table[key]["id"] = count | ||
item_table[key]["progression"] = val["progression"] if "progression" in val else False | ||
count += 1 | ||
|
||
for item in item_table: | ||
item_name = item["name"] | ||
item_id_to_name[item["id"]] = item_name | ||
item_name_to_item[item_name] = item | ||
if item["progression"]: | ||
advancement_item_names.add(item_name) | ||
|
||
if item["id"] != None: | ||
lastItemId = max(lastItemId, item["id"]) | ||
|
||
progressive_item_list = {} | ||
|
||
for item in progressive_item_table: | ||
progressiveName = progressive_item_table[item] | ||
if progressiveName not in progressive_item_list: | ||
progressive_item_list[progressiveName] = [] | ||
progressive_item_list[progressiveName].append(item) | ||
|
||
for progressiveItemName in progressive_item_list.keys(): | ||
lastItemId += 1 | ||
generatedItem = {} | ||
generatedItem["id"] = lastItemId | ||
generatedItem["name"] = progressiveItemName | ||
generatedItem["progression"] = item_name_to_item[progressive_item_list[progressiveItemName][0]]["progression"] | ||
item_name_to_item[progressiveItemName] = generatedItem | ||
item_id_to_name[lastItemId] = progressiveItemName | ||
|
||
item_id_to_name[None] = "__Victory__" | ||
item_name_to_id = {name: id for id, name in item_id_to_name.items()} | ||
|
||
###################### | ||
# Item classes | ||
###################### | ||
|
||
|
||
class ManualItem(Item): | ||
game = "Manual" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from BaseClasses import Location | ||
from .Data import location_table | ||
from .Game import starting_index | ||
|
||
###################### | ||
# Generate location lookups | ||
###################### | ||
|
||
count = starting_index + 500 # 500 each for items and locations | ||
custom_victory_location = {} | ||
victory_key = {} | ||
|
||
# add sequential generated ids to the lists | ||
for key, _ in enumerate(location_table): | ||
if "victory" in location_table[key] and location_table[key]["victory"]: | ||
custom_victory_location = location_table[key] | ||
victory_key = key # store the victory location to be removed later | ||
|
||
continue | ||
|
||
location_table[key]["id"] = count | ||
|
||
if not "region" in location_table[key]: | ||
location_table[key]["region"] = "Manual" # all locations are in the same region for Manual | ||
|
||
count += 1 | ||
|
||
if victory_key: | ||
location_table.pop(victory_key) | ||
|
||
# Add the game completion location, which will have the Victory item assigned to it automatically | ||
location_table.append({ | ||
"id": count + 1, | ||
"name": "__Manual Game Complete__", | ||
"region": custom_victory_location["region"] if "region" in custom_victory_location else "Manual", | ||
"requires": custom_victory_location["requires"] if "requires" in custom_victory_location else [] | ||
}) | ||
|
||
location_id_to_name = {} | ||
location_name_to_location = {} | ||
|
||
for item in location_table: | ||
location_id_to_name[item["id"]] = item["name"] | ||
location_name_to_location[item["name"]] = item | ||
|
||
# location_id_to_name[None] = "__Manual Game Complete__" | ||
location_name_to_id = {name: id for id, name in location_id_to_name.items()} | ||
|
||
###################### | ||
# Location classes | ||
###################### | ||
|
||
|
||
class ManualLocation(Location): | ||
game = "Manual" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from Options import FreeText | ||
from BaseClasses import MultiWorld | ||
from typing import Union | ||
|
||
manual_options = {} | ||
|
||
def is_option_enabled(world: MultiWorld, player: int, name: str) -> bool: | ||
return get_option_value(world, player, name) > 0 | ||
|
||
def get_option_value(world: MultiWorld, player: int, name: str) -> Union[int, dict]: | ||
option = getattr(world, name, None) | ||
if option == None: | ||
return 0 | ||
|
||
return option[player].value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from BaseClasses import Entrance, MultiWorld, Region | ||
from .Data import region_table | ||
from .Locations import ManualLocation | ||
from ..AutoWorld import World | ||
|
||
if not region_table: | ||
region_table = {} | ||
|
||
regionMap = { **region_table } | ||
regionMap["Manual"] = { | ||
"requires": [], | ||
"connects_to": region_table.keys() # the Manual region connects to all user-defined regions automatically | ||
} | ||
|
||
def create_regions(base: World, world: MultiWorld, player: int): | ||
# Create regions and assign locations to each region | ||
for region in regionMap: | ||
# if it's an empty or unusable region, skip it | ||
if not regionMap[region]: | ||
continue | ||
|
||
exit_array = None | ||
|
||
if "connects_to" in regionMap[region]: | ||
exit_array = regionMap[region]["connects_to"] | ||
|
||
if not exit_array: | ||
exit_array = None | ||
|
||
new_region = create_region(base, world, player, region, [ | ||
location["name"] for location in base.location_table if location["region"] == region | ||
], exit_array) | ||
world.regions += [new_region] | ||
|
||
menu = create_region(base, world, player, "Menu", None, ["Manual"]) | ||
world.regions += [menu] | ||
menuConn = world.get_entrance("MenuToManual", player) | ||
menuConn.connect(world.get_region("Manual", player)) | ||
|
||
# Link regions together | ||
for region in regionMap: | ||
if "connects_to" in regionMap[region]: | ||
for linkedRegion in regionMap[region]["connects_to"]: | ||
connection = world.get_entrance(getConnectionName(region, linkedRegion), player) | ||
connection.connect(world.get_region(linkedRegion, player)) | ||
|
||
def create_region(base: World, world: MultiWorld, player: int, name: str, locations=None, exits=None): | ||
ret = Region(name, player, world) | ||
|
||
if locations: | ||
for location in locations: | ||
loc_id = base.location_name_to_id.get(location, 0) | ||
locationObj = ManualLocation(player, location, loc_id, ret) | ||
ret.locations.append(locationObj) | ||
if exits: | ||
for exit in exits: | ||
ret.exits.append(Entrance(player, getConnectionName(name, exit), ret)) | ||
return ret | ||
|
||
def getConnectionName(entranceName: str, exitName: str): | ||
return entranceName + "To" + exitName |
Oops, something went wrong.