Files
cultivation-world-simulator/src/classes/root.py
2025-09-10 22:55:31 +08:00

47 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
灵根
目前只有五行:金木水火土。
其实和EssenceType很类似
但是单独拿出来是因为,之后可能整特殊的复杂灵根
所以这里单独定义一个Root类用来描述灵根。
"""
from enum import Enum
from src.classes.essence import EssenceType
class Root(Enum):
"""
灵根
"""
GOLD = ""
WOOD = ""
WATER = ""
FIRE = ""
EARTH = ""
@classmethod
def from_str(cls, root_str: str) -> 'Root':
"""
从字符串创建Root实例
Args:
root_str: 灵根的字符串表示,如 "", "", "", "", ""
Returns:
对应的Root枚举值
Raises:
ValueError: 如果字符串不匹配任何已知的灵根类型
"""
for root in cls:
if root.value == root_str:
return root
raise ValueError(f"Unknown root type: {root_str}")
corres_essence_type = {
Root.GOLD: EssenceType.GOLD,
Root.WOOD: EssenceType.WOOD,
Root.WATER: EssenceType.WATER,
Root.FIRE: EssenceType.FIRE,
Root.EARTH: EssenceType.EARTH,
}