This commit is contained in:
Auric Vente
2024-07-18 20:10:08 -06:00
parent 685f5bc686
commit fa1f5301ae
18 changed files with 1188 additions and 101 deletions

26
cromulant/storage.py Normal file
View File

@@ -0,0 +1,26 @@
import json
from typing import TYPE_CHECKING
from .config import Config
if TYPE_CHECKING:
from .ants import Ant
class Storage:
@staticmethod
def get_ants() -> None:
with Config.ants_json.open() as file:
return json.load(file)
@staticmethod
def save_ants(ants: list["Ant"]) -> None:
objs = [ant.to_dict() for ant in ants]
with Config.ants_json.open("w") as file:
json.dump(objs, file)
@staticmethod
def get_names() -> None:
with Config.names_json.open() as file:
return json.load(file)