Esempio n. 1
0
    def getConfigData(self):
        reader = cp.ConfigParser()
        ini_name = './character/' + self.info.name.get() + '.ini'
        data = {'Attacks': {}}
        try:
            reader.read(ini_name)
        except (KeyError):
            errorWindow = tk.Toplevel()
            tk.Label(
                errorWindow,
                text=
                "There is no .ini file in the character directory\nwith name "
                + ini_name).pack()
            tk.Button(errorWindow,
                      command=errorWindow.destroy,
                      text="OK").pack()
            return None

        for sp in reader['Spells']:
            args = dnd.readConfig(reader['Spells'][sp])
            args[-1] = args[-1].replace('$', '\n')
            data['Attacks'][sp] = dnd.spell(*args)
        for wep in reader['Weapons']:
            args = dnd.readConfig(reader['Weapons'][wep])
            args[-1] = args[-1].replace('$', '\n')
            data['Attacks'][wep] = dnd.weapon(*args)
        for ab in ['str', 'dex', 'con', 'int', 'wis', 'cha']:
            data[ab] = reader['Character'][ab]
        data['level'] = reader['Character']['level']
        data['caster level'] = reader['Character']['caster level']
        data['class'] = reader['Character']['class']
        data['max HP'] = reader['HP']['max hp']
        data['HP'] = reader['HP']['current hp']
        data['temp HP'] = reader['HP']['current temp hp']
        data['spell slots'] = reader['Spell Slots']['spell slots']
        self.characterdata['Attacks'] = data['Attacks']
        try:
            self.characterdata['spell slots'] = r.readList(data['spell slots'],
                                                           mode='int')
        except (SyntaxError):
            self.characterdata['spell slots'] = [0]
        return data