mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 20:21:32 -06:00
introduce persistent data storage, which for now just caches rom -> server pairs
This commit is contained in:
24
Utils.py
24
Utils.py
@@ -9,7 +9,7 @@ import sys
|
||||
import typing
|
||||
import functools
|
||||
|
||||
from yaml import load
|
||||
from yaml import load, dump
|
||||
|
||||
try:
|
||||
from yaml import CLoader as Loader
|
||||
@@ -212,6 +212,28 @@ def get_location_name_from_address(address):
|
||||
return Regions.lookup_id_to_name.get(address, f'Unknown location (ID:{address})')
|
||||
|
||||
|
||||
def persistent_store(category, key, value):
|
||||
path = local_path("_persistent_storage.yaml")
|
||||
storage: dict = persistent_load()
|
||||
category = storage.setdefault(category, {})
|
||||
category[key] = value
|
||||
with open(path, "wt") as f:
|
||||
f.write(dump(storage))
|
||||
|
||||
|
||||
def persistent_load():
|
||||
path = local_path("_persistent_storage.yaml")
|
||||
storage: dict = {}
|
||||
if os.path.exists(path):
|
||||
try:
|
||||
with open(path, "r") as f:
|
||||
storage = parse_yaml(f.read())
|
||||
except Exception as e:
|
||||
import logging
|
||||
logging.debug(f"Could not read store: {e}")
|
||||
return storage
|
||||
|
||||
|
||||
class ReceivedItem(typing.NamedTuple):
|
||||
item: int
|
||||
location: int
|
||||
|
||||
Reference in New Issue
Block a user