feat: 改进对象系统

This commit is contained in:
2026-01-01 20:18:18 +08:00
parent 52ef6c65d4
commit 238013ac46
39 changed files with 682 additions and 180 deletions

View File

@@ -5,7 +5,6 @@ from typing import TypedDict
import toml
from heurams.context import config_var
from heurams.services.logger import get_logger
from .electron import Electron
@@ -19,11 +18,13 @@ class AtomRegister_runtime(TypedDict):
min_rate: int # 最低评分
new_activation: bool # 新激活
class AtomRegister(TypedDict):
nucleon: Nucleon
electron: Electron
runtime: AtomRegister_runtime
class Atom:
"""
统一处理一系列对象的所有信息与持久化:
@@ -39,10 +40,10 @@ class Atom:
"new_activation": False,
}
def __init__(self, nucleon_obj = None, electron_obj = None, orbital_obj = None):
self.ident = nucleon_obj["ident"] # type: ignore
def __init__(self, nucleon_obj=None, electron_obj=None, orbital_obj=None):
self.ident = nucleon_obj["ident"] # type: ignore
self.registry: AtomRegister = { # type: ignore
"ident": nucleon_obj["ident"], # type: ignore
"ident": nucleon_obj["ident"], # type: ignore
"nucleon": nucleon_obj,
"electron": electron_obj,
"orbital": orbital_obj,
@@ -53,7 +54,7 @@ class Atom:
self.registry["runtime"]["new_activation"] = True
def init_runtime(self):
self.registry['runtime'] = AtomRegister_runtime(**self.default_runtime)
self.registry["runtime"] = AtomRegister_runtime(**self.default_runtime)
def minimize(self, rating):
"""效果等同于 self.registry['runtime']['min_rate'] = min(rating, self.registry['runtime']['min_rate'])
@@ -97,4 +98,4 @@ class Atom:
def __setitem__(self, key, value):
if key == "ident":
raise AttributeError("应为只读")
self.registry[key] = value
self.registry[key] = value