Skip to content

Commit

Permalink
The Witness: Utils.cache_argsless -> functools.lru_cache (Archipelago…
Browse files Browse the repository at this point in the history
…MW#1897)

* Changed Utils.cache_argsless to functools.lru_cache

* Revmoed unused variable

* Removed remaining direct reference to a .txt outside utils

* Update worlds/witness/utils.py

Co-authored-by: el-u <[email protected]>

---------

Co-authored-by: el-u <[email protected]>
  • Loading branch information
NewSoupVi and el-u authored Jun 28, 2023
1 parent 332eab9 commit 99656bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 43 deletions.
19 changes: 8 additions & 11 deletions worlds/witness/static_logic.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import os

from .utils import define_new_region, parse_lambda, lazy, get_logic_file, get_items
from .utils import define_new_region, parse_lambda, lazy, get_items, get_sigma_normal_logic, get_sigma_expert_logic,\
get_vanilla_logic


class StaticWitnessLogicObj:
def read_logic_file(self, file_path="WitnessLogic.txt"):
def read_logic_file(self, lines):
"""
Reads the logic file and does the initial population of data structures
"""
lines = get_logic_file(file_path)

current_region = dict()
counter = 0

for line in lines:
if line == "":
Expand Down Expand Up @@ -115,7 +112,7 @@ def read_logic_file(self, file_path="WitnessLogic.txt"):

current_region["panels"].append(check_hex)

def __init__(self, file_path="WitnessLogic.txt"):
def __init__(self, lines=get_sigma_normal_logic()):
# All regions with a list of panels in them and the connections to other regions, before logic adjustments
self.ALL_REGIONS_BY_NAME = dict()
self.STATIC_CONNECTIONS_BY_REGION_NAME = dict()
Expand All @@ -130,7 +127,7 @@ def __init__(self, file_path="WitnessLogic.txt"):

self.ENTITY_ID_TO_NAME = dict()

self.read_logic_file(file_path)
self.read_logic_file(lines)


class StaticWitnessLogic:
Expand Down Expand Up @@ -204,15 +201,15 @@ def parse_items(self):

@lazy
def sigma_expert(self) -> StaticWitnessLogicObj:
return StaticWitnessLogicObj("WitnessLogicExpert.txt")
return StaticWitnessLogicObj(get_sigma_expert_logic())

@lazy
def sigma_normal(self) -> StaticWitnessLogicObj:
return StaticWitnessLogicObj("WitnessLogic.txt")
return StaticWitnessLogicObj(get_sigma_normal_logic())

@lazy
def vanilla(self) -> StaticWitnessLogicObj:
return StaticWitnessLogicObj("WitnessLogicVanilla.txt")
return StaticWitnessLogicObj(get_vanilla_logic())

def __init__(self):
self.parse_items()
Expand Down
34 changes: 2 additions & 32 deletions worlds/witness/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
from Utils import cache_argsless
from functools import lru_cache
from itertools import accumulate
from typing import *
from fractions import Fraction
Expand Down Expand Up @@ -141,116 +140,87 @@ def __get__(self, instance, class_):
return res


@lru_cache(maxsize=None)
def get_adjustment_file(adjustment_file):
data = get_data(__name__, adjustment_file).decode('utf-8')
return [line.strip() for line in data.split("\n")]


@cache_argsless
def get_disable_unrandomized_list():
return get_adjustment_file("settings/Disable_Unrandomized.txt")


@cache_argsless
def get_early_utm_list():
return get_adjustment_file("settings/Early_UTM.txt")


@cache_argsless
def get_symbol_shuffle_list():
return get_adjustment_file("settings/Symbol_Shuffle.txt")


@cache_argsless
def get_door_panel_shuffle_list():
return get_adjustment_file("settings/Door_Panel_Shuffle.txt")


@cache_argsless
def get_doors_simple_list():
return get_adjustment_file("settings/Doors_Simple.txt")


@cache_argsless
def get_doors_complex_list():
return get_adjustment_file("settings/Doors_Complex.txt")


@cache_argsless
def get_doors_max_list():
return get_adjustment_file("settings/Doors_Max.txt")


@cache_argsless
def get_laser_shuffle():
return get_adjustment_file("settings/Laser_Shuffle.txt")


@cache_argsless
def get_audio_logs():
return get_adjustment_file("settings/Audio_Logs.txt")


@cache_argsless
def get_ep_all_individual():
return get_adjustment_file("settings/EP_Shuffle/EP_All.txt")


@cache_argsless
def get_ep_obelisks():
return get_adjustment_file("settings/EP_Shuffle/EP_Sides.txt")


@cache_argsless
def get_ep_easy():
return get_adjustment_file("settings/EP_Shuffle/EP_Easy.txt")


@cache_argsless
def get_ep_no_eclipse():
return get_adjustment_file("settings/EP_Shuffle/EP_NoEclipse.txt")


@cache_argsless
def get_ep_no_caves():
return get_adjustment_file("settings/EP_Shuffle/EP_NoCavesEPs.txt")


@cache_argsless
def get_ep_no_mountain():
return get_adjustment_file("settings/EP_Shuffle/EP_NoMountainEPs.txt")


@cache_argsless
def get_ep_no_videos():
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)

0 comments on commit 99656bf

Please sign in to comment.