genshin-wiki/utils/text.py

21 lines
568 B
Python
Raw Normal View History

2023-04-15 05:09:56 +00:00
from utils.context import ContextManager
__all__ = ("Text",)
class Text(str):
def __new__(cls, string: str | int) -> "Text":
_id = None
if isinstance(string, str):
try:
_id = int(string)
except ValueError:
_id = None
elif isinstance(string, int):
_id = string
if _id is not None:
string = (
ContextManager().get_value("resource_manager").get_text(_id) or ""
).replace("\\n", "\n")
return str.__new__(cls, string)