The Witness: Utils.cache_argsless -> functools.lru_cache (#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 <109771707+el-u@users.noreply.github.com>

---------

Co-authored-by: el-u <109771707+el-u@users.noreply.github.com>
This commit is contained in:
NewSoupVi 2023-06-28 02:23:50 +02:00 committed by GitHub
parent 332eab9569
commit 99656bf059
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 43 deletions

View File

@ -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 == "":
@ -115,7 +112,7 @@ class StaticWitnessLogicObj:
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()
@ -130,7 +127,7 @@ class StaticWitnessLogicObj:
self.ENTITY_ID_TO_NAME = dict()
self.read_logic_file(file_path)
self.read_logic_file(lines)
class StaticWitnessLogic:
@ -204,15 +201,15 @@ class StaticWitnessLogic:
@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()

View File

@ -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
@ -141,116 +140,87 @@ class lazy(object):
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)