Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # import settings
- class NpcMeta(type):
- def __new__(cls, name, base, attrs, **kwargs):
- super_new = super().__new__
- parents = [b for b in base if isinstance(b, NpcMeta)]
- if not parents:
- return super_new(cls, name, base, attrs)
- module = attrs.pop('__module__')
- new_attrs = {'__module__': module}
- new_class = super_new(cls, name, base, new_attrs, **kwargs)
- attr_meta = attrs.pop('Meta', None)
- meta = attr_meta or getattr(new_class, 'Meta', None)
- base_meta = getattr(new_class, '_meta', None)
- for i in meta.__dict__.keys():
- if i.find("__"):
- if getattr(meta, i) in (None, []):
- setattr(meta, i, "%s.%s" % (name, i))
- print("*** Empty '%s' parameter in '%s'. Setting to '%s'" % (i, name, getattr(meta, i)))
- meta_args = {k : v for k, v in meta.__dict__.items() if k.find("__")}
- new_class._write(meta_args)
- return new_class
- def _write(cls, data):
- with open("npc.txt", "r+", encoding="utf-8") as f:
- tree = f"[{cls.__name__}]\n"
- for i, j in data.items():
- tree += f"{i} = {j}\n"
- f.write(tree)
- class NpcBase(metaclass=NpcMeta):
- def __init__(self, *args, **kwargs):
- cls = self.__class__
- # opts = self._meta
- super().__init__()
- class TestNpc(NpcBase):
- class Meta:
- npc_name = "Joe0"
- npc_health = None
- npc_fraction = "Cool fraction"
- npc_armor_name = "Cool Armor"
- npc_armor_health = 30
- npc_phrases = ["1", "2", "3"]
- npc_inventory = []
- class TestNpc1(NpcBase):
- class Meta:
- npc_name = "Joe1"
- npc_health = 100
- npc_fraction = "Cool fraction"
- npc_armor_name = "Cool Armor"
- npc_armor_health = 30
- npc_phrases = ["1", "2", "3"]
- npc_inventory = []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement