def class_out(cls): # インポート部分 from basemods import Holder classts = ('Param', 'Thing', 'Process', 'Event', 'Route', 'Role') Scenario.candi = [Holder.classt(c) for c in classts] return (Scenario.candi, 'クラスを選んでください', True)
def focus_out_obj_role(self): # インポート部分 from basemods import Holder from game import Game role_f = self.role_f() objrole_m_str = self.objrole_m_str() rtn = Game.dummy() # 受動ロールの設定 if objrole_m_str == '': if role_f in (2, 3): rtn = (Holder.master('Role').values(), 'Arbit', 'Role', 0) else: self.objrole = self.role_first else: self.objrole = Holder.master('Role', objrole_m_str) return rtn
def buildvalid(self): # インポート部分 from basemods import Holder from iotemp import Template # Param.name のテンプレート処理 - scala編 if self.gtarget not in Holder.master('Param').keys(): try: self.gtarget = Template.holder[self.group][Holder.classt('Param')][self.gtarget] except Exception: print('TEMPLATEERROR: Process.gtarget -{0}-'.format(self.name)) # Param.name のテンプレート処理 - scala編 if self.gsbj_param not in Holder.master('Param').keys(): try: self.gsbj_param = Template.holder[self.group][Holder.classt('Param')][self.gsbj_param] except Exception: print('TEMPLATEERROR: Process.gsbj_param -{0}-'.format(self.name)) # Param.name のテンプレート処理 - scala編 if self.gobj_param not in Holder.master('Param').keys(): try: self.gobj_param = Template.holder[self.group][Holder.classt('Param')][self.gobj_param] except Exception: print('TEMPLATEERROR: Process.gobj_param -{0}-'.format(self.name))
def buildvalid(self): # インポート部分 from basemods import Holder from iotemp import Template # Process.name のテンプレート処理 - scala編 if self.procs not in Holder.master('Process').keys(): try: self.procs = Template.holder[self.group][Holder.classt( 'Process')][self.procs] except Exception: print('TEMPLATEERROR: Event.procs') lis_role = list(self.role) for v in lis_role: # Role.name のテンプレート処理 - tuple編 if v not in Holder.master('Role').keys(): idx = lis_role.index(v) del lis_role[idx] try: tname1 = Template.holder[self.group][Holder.classt( 'Role')][v] except Exception: tname1 = '' print('TEMPLATEERROR: Event.role -{0}- v={1}, idx={2}'. format(self.name, v, idx)) lis_role.insert(idx, tname1) self.role = tuple(lis_role) lis_thing = list(self.thing) for v in lis_thing: # Thing.name のテンプレート処理 - tuple編 if v not in Holder.master('Thing').keys(): idx = lis_thing.index(v) del lis_thing[idx] try: tname2 = Template.holder[self.group][Holder.classt( 'Thing')][v] except Exception: tname2 = '' print('TEMPLATEERROR: Event.thing -{0}- v={1}, idx={2}'. format(self.name, v, idx)) lis_thing.insert(idx, tname2) self.thing = tuple(lis_thing) if len(self.role) != 2: raise TrpgError('引数 -{0}- のリストサイズが2ではありません'.format('role')) if len(self.thing) != 2: raise TrpgError('引数 -{0}- のリストサイズが2ではありません'.format('thing'))
def action_in(self, act): """ Request In """ # インポート部分 from basemods import Holder if act is None: act = self.getroutes()[0] self.act = act if type(act) is Holder.classt('Route'): return { 'curr_func': self.way_node, 'arg': (act, ), 'next_func': self.way_in } else: return { 'curr_func': self.focus_out_thing, 'arg': (), 'next_func': self.focus_in_thing }
def check_in(self, s_name, tmpl, desc, opted): # インポート部分 from basemods import Holder tmpls = tmpl.split('-') typet = tmpls[0] numbt = None if len(tmpls) > 1: numbt = int(tmpls[1]) # tuple 定数a, list 無制限=0, dict 無制限=0の場合 if numbt < 1 or 100 < numbt: numbt = 100 if typet == 'str': if s_name == 'name': if self.name != '': rtn = self.name else: rtn = opted # 更新の場合 if rtn in list(self.classt.master.keys()): self.existclss = self.classt.master[rtn] else: rtn = opted elif typet == 'int': try: rtn = int(opted) except ValueError as e: if Dice.checkdice(rtn) > 0: print('MESSAGE: ダイス形式で設定') rtn = opted else: print('Exception: {0}'.format(e)) rtn = 0 elif typet == 'bool': rtn = bool(opted) elif typet == 'tuple': self.tlis = list(opted) rtn = tuple(self.tlis) elif typet == 'list': self.tlis = list(opted) rtn = self.tlis elif typet == 'dict': keyt = opted valt = opted self.tlis.append((keyt, valt)) rtn = dict(self.tlis) else: rtn = opted tt = typet.split('.') classtnames = ('Param', 'Thing', 'Process', 'Event', 'Route', 'Role') if tt[0] in classtnames: s_classt = Holder.classt(tt[0]) if tt[1] == 'name': s_candi = list(s_classt.master.keys()) elif tt[1] == 'deed': gg = getmembers(s_classt, isfunction) s_candi = [g[0] for g in gg] if tt[1] == 'name' and rtn not in s_candi: t = Template(s_classt, self.group, rtn) print('グループ -{0}- > クラス -{1}- > テンプレート -{2}- を作成しました'.format(self.group, s_classt.__name__, rtn)) t.holdermap(self.group, s_classt, rtn) if self.existclss is not None: if rtn == '': default = getattr(self.existclss, s_name) if type(default) in (int, str, bool): rtn = default else: raise TrpgError('デフォルトを設定します') setattr(self.existclss, s_name, rtn)
def check_out(self, s_name, tmpl, desc): # インポート部分 from basemods import Holder def outputu(desc, typet, candi=list(), numbt=None): default = None try: if self.existclss is not None: default = getattr(self.existclss, s_name) # message = '{0}({1}): {2} (default: {3})'.format(desc, s_name, typet, default) # (型, 候補リスト, 繰り返し回数, 入力領域, デフォルト) return (typet, candi, numbt, list(), default) except TrpgError as e: raise e tmpls = tmpl.split('-') typet = tmpls[0] valut = '' numbt = None if len(tmpls) > 1: numbt = int(tmpls[1]) # tuple 定数a, list 無制限=0, dict 無制限=0の場合 if numbt < 1 or 100 < numbt: numbt = 100 valut = '-'.join(tmpls[2:]) if typet == 'str': if s_name == 'name': if self.name == '': print('UPDATE IN {0}'.format(list(self.classt.master.keys()))) return outputu(desc, typet) else: return outputu(desc, typet) elif typet == 'int': return outputu(desc, typet) elif typet == 'bool': return outputu(desc, typet) elif typet == 'tuple': return outputu(desc, 'tuple', self.check_out(s_name, valut, desc), numbt) elif typet == 'list': return outputu(desc, 'list', self.check_out(s_name, valut, desc), numbt) elif typet == 'dict': tt = valut.split(':') tt0 = self.check_out(s_name, tt[0], desc) tt1 = self.check_out(s_name, tt[1], desc) return outputu(desc, 'dict', (tt0, tt1), numbt) else: tt = typet.split('.') classtnames = ('Param', 'Thing', 'Process', 'Event', 'Route', 'Role') if tt[0] in classtnames: s_classt = Holder.classt(tt[0]) if tt[1] == 'name': s_candi = list(s_classt.master.keys()) elif tt[1] == 'deed': gg = getmembers(s_classt, isfunction) s_candi = [g[0] for g in gg] print('SELECT IN {0}'.format(s_candi)) return outputu(desc, typet, s_candi)
__package__ = 'trpg' print('__package__: {}, __name__: {}'.format(__package__, __name__)) Test() Game(['太郎']) while True: print('SELECT IN {0}'.format({0: 'wizard', 1: 'game'})) start = input('> ') # try: if start == '0': s_argdic = Scenario.argdic_first() while True: wiz_out = Holder.progr_out(s_argdic) if wiz_out[2] is None: break try: if not wiz_out[2]: # 自由に入力 if wiz_out[0] is None: raise TrpgError('選択肢しませんでした') print('UPDATE IN {0}'.format(wiz_out[0])) wiz_in = input('{0} > '.format(wiz_out[1])) else: # リストからの選択 s_candi = Arbit.input_out(wiz_out[0], 'Scenario', 'make')
def do(self, n): # インポート部分 from basemods import Holder return Holder.master('Process', self.procs).deed(self.sbj, self.obj, n)
def objthing_m(self): # インポート部分 from basemods import Holder return Holder.master('Thing', self.thing[1])
def getpropts(self): # インポート部分 from basemods import Holder return [Holder.master('Thing', i) for i in self.propts]
def obj_param(self): # インポート部分 from basemods import Holder return Holder.master('Param', self.gobj_param)
def target(self): # インポート部分 from basemods import Holder return Holder.master('Param', self.gtarget)