refactor: add equipment registry

This commit is contained in:
2026-06-04 19:46:09 +08:00
parent 6c109708b8
commit 53b9f48f7d
3 changed files with 55 additions and 8 deletions
+22
View File
@@ -0,0 +1,22 @@
from functools import cache
from pathlib import Path
from database.connect import BACKEND_DIR
class EquipmentRegistry:
def __init__(self, equipment_cls):
self.equipment_cls = equipment_cls
@cache
def get(self, version: str = '0'):
normalized = version or '0'
if not self._version_exists(normalized):
if normalized == '0':
return self.equipment_cls(normalized)
return self.get('0')
return self.equipment_cls(normalized)
def _version_exists(self, version: str) -> bool:
db_path = Path(BACKEND_DIR) / 'dataFiles' / f'dcalc_{version}.db'
return db_path.exists()