def hook(self): main = 'race/{}.race'.format(self.race) sub = 'race/{}.{}.sub.race'.format(self.race, self.subrace) mainjf = iface.JSONInterface(main) if (self.subrace): subjf = iface.JSONInterface(sub) self.core = c.Race(iface.LinkedInterface(mainjf, subjf), str(self)) else: # For the sake of having a consistent API it needs to be a LinkedInterface self.core = c.Race(iface.LinkedInterface(mainjf), str(self))
def get_feature_links(self): rv = collections.OrderedDict() main = 'race/{}.race'.format(self.race) sub = 'race/{}.{}.sub.race'.format(self.race, self.subrace) mainjf = iface.JSONInterface(main) for name in (mainjf.get('/features') or []): rv[name] = main + '/features/' + name if (self.subrace): subjf = iface.JSONInterface(sub) for name in (subjf.get('/features') or []): rv[name] = sub + '/features/' + name return rv
def startup_end(self): name = self.levelgain['Character Name?'] cl = self.levelgain['Class to gain a level in?'] path = 'character/' + h.clean(name) + '.character' if (os.path.exists(iface.JSONInterface.OBJECTSPATH + path)): self.record = iface.JSONInterface(path) else: gui.ErrorMessage('A character with that name was not found.') clpath = 'class/' + h.clean(cl) + '.class' if (not os.path.exists(iface.JSONInterface.OBJECTSPATH + path)): gui.ErrorMessage('A class with that name was not found.') self.character = c.Character(self.record) pattern = r'\s*([a-zA-Z\']+)\s*(\(([a-zA-Z\'\s]+)\))?' desc_ = re.match(pattern, cl).groups() desc = [str(item) for item in desc_ if item is not None] # desc should be a class and possibly a subclass name (rec, level) = self.character.classes.level_up(*desc) self.core = FeaturesAtLevel(self.f, rec.record, level) # Set new number of hit dice size = rec.hit_dice hdpath = '/HP/HD/' + size + '/maxnumber' hdn = self.character.get(hdpath) self.character.set(hdpath, hdn + 1) # Set new number of hit points conmod = h.modifier(self.character.get('/abilities/Constitution')) if (self.levelgain['Average or roll for HP?'] == 'average'): gain = r.roll(size, 'average') + .5 elif (self.levelgain['Average or roll for HP?'] == 'roll'): gain = r.roll(size) current = self.character.get('/HP/max') self.character.set('/HP/max', current + gain + conmod) self.draw_static() self.container.deiconify()
def startup_end(self): name = self.charactername['Character Name?'] path = 'character/' + h.clean(name) + '.character' if (os.path.exists(iface.JSONInterface.OBJECTSPATH + path)): self.record = iface.JSONInterface(path) else: gui.ErrorMessage('A character with that name was not found.') self.character = c.Character(self.record) self.core = ConditionsDisplay(self.f, self.character) self.draw_static() self.container.deiconify()
def startup_end(self): name = self.charactername['Character Name?'] path = iface.JSONInterface.OBJECTSPATH + 'character/' + name + '.character' if (os.path.exists(path)): jf = iface.JSONInterface('character/' + name + '.character') else: raise FileNotFoundError character = c.Character(jf) self.core = Attacks(self.f, character) self.draw_static() self.container.deiconify()
def startup_end(self): name = self.charactername['Character Name?'] path = 'character/' + name + '.character' if (os.path.exists(iface.JSONInterface.OBJECTSPATH + path)): self.record = iface.JSONInterface(path) else: raise FileNotFoundError self.character = c.Character(self.record) self.core = FeaturesDisplay(self.f, self.character) self.draw_static() self.container.deiconify()
def startup_finish(self): name = self.charactername['Character Name?'] path = iface.JSONInterface.OBJECTSPATH + 'character/' + name + '.character' if (os.path.exists(path)): self.record = iface.JSONInterface(path) else: raise FileNotFoundError self.corehandler = c.HPhandler(self.record) self.hpdisplay = HitPointDisplay(self.f, self.corehandler) self.draw_static() self.container.deiconify()
def __init__(self, container, character, output, adv, dis): gui.Section.__init__(self, container) self.person = character self.display = output self.adv = adv self.dis = dis sk = iface.JSONInterface('skill/SKILLS.skill') self.skillmap = sk.get('/') self.buttons = [tk.Button(self.f, text=n, command=lambda x=n: self.roll_check(x)) for n in sorted(self.skillmap)] self.draw_static()
def load_file(self): base = iface.JSONInterface.OBJECTSPATH # filename = 'monster/' + h.clean(self.filequery.get().casefold()) + '.monster' filename = self.filename # if (os.path.isfile(base + filename)): if (os.path.isfile(filename)): interface = iface.JSONInterface(filename, isabsolute=True) self.data.update(interface.get('/')) # self.data.update({'average': self.av.get()}) av = messagebox.askyesno(message='Take average HP?') self.data.update({'average': av}) self.finish(fromfile=True) else: gui.ErrorMessage('That file does not exist. Check your spelling.')
def __init__(self, container): gui.Section.__init__(self, container) sk = iface.JSONInterface('skill/SKILLS.skill') self.skillmap = sk.get('/') self.proficiencies = [tk.StringVar() for n in self.skillmap] self.buttons = [ tk.Checkbutton(self.f, text=n, variable=self.proficiencies[i], onvalue=n, offvalue='') for (i, n) in enumerate(sorted(self.skillmap)) ] self.draw_static()
def hook(self): main = 'class/{}.class' sub = 'class/{}.{}.sub.class' super_ = 'class/{}.super.class' for (C, S, L) in zip(self._classes, self._subclasses, self.levels): C = h.clean(C) S = h.clean(S) file_ = main.format(C) subfile_ = sub.format(C, S) mainclass = iface.JSONInterface(file_) try: subclass = iface.JSONInterface(subfile_) subclassfound = True except FileNotFoundError: subclassfound = False superclasses = [ iface.JSONInterface(super_.format(name)) for name in mainclass.get('/superclass') ] if (subclassfound and subclass.get('/superclass')): superclasses.extend([ iface.JSONInterface(super_.format(name)) for name in subclass.get('/superclass') ]) if (subclassfound): jf = iface.LinkedInterface(*superclasses, mainclass, subclass) # self.classes.update( # {str(mainclass): iface.LinkedInterface(*superclasses, # mainclass, # subclass)}) else: jf = iface.LinkedInterface(*superclasses, mainclass) # self.classes.update( # {str(mainclass): iface.LinkedInterface(*superclasses, # mainclass)}) self.classes.update({C: c.Class(jf, L)})
def begin_end(self): name = self.charactername['Character name?'] filename = 'character/{}.character'.format(h.clean(name)) self.record = iface.JSONInterface(filename) self.character = c.Character(self.record) self.numbers = NumberDisplay(self.f, self.character) self.handler = SpellSection(self.f, self.record, self.character, self.numbers, self.effects) self.prepare = tk.Button(self.excessblock, text='Prepare a spell', command=self.detail.prepare_start) self.unprepare = tk.Button(self.excessblock, text='Unprepare a spell', command=self.detail.unprepare_start) self.container.deiconify() self.draw_static()
def register_change(self, var): Chooser.register_change(self, var) self.subclassname = var.get() if (self.subclassname): # Add the subclass and display extra options clm = re.search('(\w+)\.class', self.fullpath) self.classname = clm.group(1) name = 'class/{}.{}.sub.class'.format(h.clean(self.classname), h.clean(self.subclassname)) if (os.path.isfile(iface.JSONInterface.OBJECTSPATH + name)): self.clear_subframe() rec = iface.JSONInterface(name) lvm = re.search('/(\d+)/.*$', self.fullpath) lv = int(lvm.group(1)) self.subclassfeatures = FeaturesAtLevel(self.subfeatures, rec, lv) self.draw_dynamic() else: raise FileNotFoundError(name)
def startup_finish(self): name = self.charactername['Character Name?'] path = iface.JSONInterface.OBJECTSPATH + 'character/' + name + '.character' if (os.path.exists(path)): self.record = iface.JSONInterface(path) else: raise FileNotFoundError self.handler = c.Inventory(self.record) self.buttons = [] for item in self.handler: self.buttons.append( tk.Button(self.buttonframe, text=item.name, command=lambda x=item: self.display.toggle_equip(x))) if (item.equipped): self.display.equip(item) self.draw_static() self.container.deiconify()
def startup_end(self): name = self.charactername['Character Name?'] path = 'character/' + h.clean(name) + '.character' if (os.path.exists(iface.JSONInterface.OBJECTSPATH + path)): self.record = iface.JSONInterface(path) else: gui.ErrorMessage('A character with that name was not found.') print(iface.JSONInterface.OBJECTSPATH + path) raise FileNotFoundError self.character = c.Character(self.record) self.container.title(str(self.character)) self.settingmenu = Settings(self.container, self.character) self.container.config(menu=self.settingmenu.core) ###### # Front page self.info = Information(self.frontpage, self.character) self.HP = hp.module(self.frontpage, self.character) self.roller = dice.module(self.frontpage, self.character) self.abils = abilities.module(self.frontpage, self.character) ###### # Attacks self.attacktop = tk.Frame(self.attackpage) self.attacks = attacks.module(self.attacktop, self.character) self.conditions = conditions.module(self.attacktop, self.character) self.equipment = equipment.module(self.attackpage, self.character) ###### # Features self.features = features.module(self.featurespage, self.character) self.resources = resources.module(self.featurespage, self.character) self.featureroller = dice.module(self.featurespage, self.character) ###### # Inventory self.inventory = inventory.module(self.inventorypage, self.character) ###### # Spells self.spells = spells.module(self.spellspage, self.character) ###### self.container.deiconify() self.draw_static()
# roll_pattern = '(\d+d\d+)\s?\+?\s?\d*' # # roll_pattern = '(\d+d\d+)' # damage_roll_pattern = roll_pattern + ' (\w+) damage' # saving_throw_pattern = '(Strength|Dexterity|Constitution|Intelligence|Wisdom|Charisma) saving throw' # attack_flag_pattern = 'spell attack' component_pattern = '(V)?(S)?(M)?(gp)?' # In the end, needs to set: # /damage to damage dice # /attacks to expected number of attacks # for f in os.scandir('../objects/spell/'): print(f.name) jf = iface.JSONInterface('spell/' + f.name) # eff = jf.get('/effect') # attackroll = re.search(attack_flag_pattern, eff) is not None # if (attackroll): # jf.set('/attack_roll', attackroll) # else: # save = re.search(saving_throw_pattern, eff) # if (save is not None): # jf.set('/save', save.group(1)) # damageroll = re.search(damage_roll_pattern, eff) # if (damageroll is not None): # jf.set('/damage', damageroll.group(1)) # jf.set('/damage_type', damageroll.group(2)) # else: # roll = re.search(roll_pattern, eff) # if roll:
import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)) + '/../libraries') import interface as iface import classes as c import ClassMap as cm iface.JSONInterface.OBJECTSPATH = '../objects/' cleric = iface.JSONInterface('class/Cleric.class') all = iface.JSONInterface('class/ALL.super.class') caster = iface.JSONInterface('class/CASTER.super.class') combined = all + caster + cleric print(combined.get('ALL/proficiency/0/0')) print(combined.get('/proficiency/0/0')) print(combined.get('CASTER/slots/full/12')) print(combined.get('/slots/full/12')) jf = iface.JSONInterface('character/Calan.character') classes = cm.ClassMap(jf.get('/level')) print(classes.sum()) for n, cl, lv in classes: print(cl) Calan = c.Character(jf)
def class_features(self, var): classname = var.get() path = 'class/' + h.clean(classname) + '.class' classjf = iface.JSONInterface(path) self.classfeatures = FeaturesAtLevel(self.featuresframe, classjf, 1) self.draw_dynamic()