Witness: apworld support (#1885)

This commit is contained in:
NewSoupVi 2023-06-25 02:00:56 +02:00 committed by GitHub
parent 7a4e903906
commit 46b13e0b53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 157 additions and 136 deletions

View File

@ -1,6 +1,6 @@
import os import os
from .utils import define_new_region, parse_lambda, lazy from .utils import define_new_region, parse_lambda, lazy, get_logic_file, get_items
class StaticWitnessLogicObj: class StaticWitnessLogicObj:
@ -8,16 +8,12 @@ class StaticWitnessLogicObj:
""" """
Reads the logic file and does the initial population of data structures Reads the logic file and does the initial population of data structures
""" """
path = os.path.join(os.path.dirname(__file__), file_path) lines = get_logic_file(file_path)
with open(path, "r", encoding="utf-8") as file:
current_region = dict() current_region = dict()
counter = 0 counter = 0
for line in file.readlines(): for line in lines:
line = line.strip()
if line == "": if line == "":
continue continue
@ -166,13 +162,10 @@ class StaticWitnessLogic:
Parses currently defined items from WitnessItems.txt Parses currently defined items from WitnessItems.txt
""" """
path = os.path.join(os.path.dirname(__file__), "WitnessItems.txt") lines = get_items()
with open(path, "r", encoding="utf-8") as file:
current_set = self.ALL_SYMBOL_ITEMS current_set = self.ALL_SYMBOL_ITEMS
for line in file.readlines(): for line in lines:
line = line.strip()
if line == "Progression:": if line == "Progression:":
current_set = self.ALL_SYMBOL_ITEMS current_set = self.ALL_SYMBOL_ITEMS
continue continue

View File

@ -3,7 +3,7 @@ from Utils import cache_argsless
from itertools import accumulate from itertools import accumulate
from typing import * from typing import *
from fractions import Fraction from fractions import Fraction
from collections import Counter from pkgutil import get_data
def make_warning_string(any_j: bool, any_u: bool, any_d: bool, all_j: bool, all_u: bool, all_d: bool) -> str: def make_warning_string(any_j: bool, any_u: bool, any_d: bool, all_j: bool, all_u: bool, all_d: bool) -> str:
@ -142,10 +142,8 @@ class lazy(object):
def get_adjustment_file(adjustment_file): def get_adjustment_file(adjustment_file):
path = os.path.join(os.path.dirname(__file__), adjustment_file) data = get_data(__name__, adjustment_file).decode('utf-8')
return [line.strip() for line in data.split("\n")]
with open(path) as f:
return [line.strip() for line in f.readlines()]
@cache_argsless @cache_argsless
@ -226,3 +224,33 @@ def get_ep_no_mountain():
@cache_argsless @cache_argsless
def get_ep_no_videos(): def get_ep_no_videos():
return get_adjustment_file("settings/EP_Shuffle/EP_Videos.txt") return get_adjustment_file("settings/EP_Shuffle/EP_Videos.txt")
@cache_argsless
def get_sigma_normal_logic():
return get_adjustment_file("WitnessLogic.txt")
@cache_argsless
def get_sigma_expert_logic():
return get_adjustment_file("WitnessLogicExpert.txt")
@cache_argsless
def get_vanilla_logic():
return get_adjustment_file("WitnessLogicVanilla.txt")
@cache_argsless
def get_items():
return get_adjustment_file("WitnessItems.txt")
def get_logic_file(filepath: str):
if filepath == "WitnessLogic.txt":
return get_sigma_normal_logic()
if filepath == "WitnessLogicExpert.txt":
return get_sigma_expert_logic()
if filepath == "WitnessLogicVanilla.txt":
return get_vanilla_logic
return get_adjustment_file(filepath)