Skip to content

Commit

Permalink
Bg-Char realtionship update 2
Browse files Browse the repository at this point in the history
- last commit b5a660b
- 加入了“Narrative”即“叙述者”的分类
- 将原本的CharacterInfoProxyComm提炼成CharacterInfoIndirectProxy供复用
  • Loading branch information
sctop committed Jan 20, 2024
1 parent 31333d3 commit a55926e
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions data_model/actual_data/character.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def to_json(self, no_used_by: bool = True):
return d


class CharacterInfoProxyComm:
class CharacterInfoIndirectProxy:
"""
这个类干的东西基本上就是:接管原对象的 `used_by.register` 方法,然后把背景数据的filetype改一下实现特殊注册。
"""
Expand All @@ -135,10 +135,21 @@ def __init__(self, real_obj: "NpcInfo" or "StudentInfo"):
def used_by(self):
return self._used_by_handler

def register(self, file_loader: FileLoader, count_increase=True):
self.used_by.register(file_loader, count_increase)

def __getattr__(self, item):
return getattr(self.real_obj, item)


class CharacterInfoProxyComm(CharacterInfoIndirectProxy):
pass


class CharacterInfoProxyNarrative(CharacterInfoIndirectProxy):
pass


class CharacterInfo(FileLoader, InterpageMixin, UsedByRegisterMixin, RelatedToRegisterMixin):
_instance = {}

Expand All @@ -147,16 +158,21 @@ def get_instance(cls, instance_id):
def return_instance(instance):
if is_comm:
return CharacterInfoProxyComm(instance)
elif is_narrative:
return CharacterInfoProxyNarrative(instance)
return instance

instance_id = instance_id.upper()
is_comm = False
is_comm, is_narrative = False, False

# 考虑是不是comm特殊例
if instance_id.endswith("(COMM)") or instance_id.endswith("_COMM"):
# 清除特殊标记
instance_id = instance_id.replace("_COMM", "").replace("(COMM)", "")
is_comm = True
elif instance_id.endswith("(NARR)") or instance_id.endswith("_NARR"):
instance_id = instance_id.replace("_NARR", "").replace("(NARR)", "")
is_narrative = True

try:
# If it's a student
Expand Down Expand Up @@ -484,8 +500,13 @@ def to_json(self):

if isinstance(i, CharacterInfoProxyComm):
temp["is_comm"] = True
temp["is_narrative"] = False
elif isinstance(i, CharacterInfoProxyNarrative):
temp["is_comm"] = False
temp["is_narrative"] = True
else:
temp["is_comm"] = False
temp["is_narrative"] = False

t.append(temp)

Expand Down

0 comments on commit a55926e

Please sign in to comment.