Esempio n. 1
0
    def parse(sheet):
        dice = []
        row = 1
        while row < sheet.nrows:
            name = sheet.cell(rowx=row, colx=0).value
            try:
                color = ColorReader.read_color(
                    sheet.cell(rowx=row, colx=1).value)
                size = read_float(sheet.cell(rowx=row, colx=2).value)
            except ValueError as e:
                raise ValueError(str(e) + " (while reading " + name +
                                 ")") from None
            sides = sheet.cell(rowx=row, colx=3).value

            customContent = None
            if sheet.cell(rowx=row, colx=4).value:
                customContent = [
                    sheet.cell(rowx=row, colx=4).value,
                    sheet.cell(rowx=row, colx=5).value,
                    sheet.cell(rowx=row, colx=6).value,
                    sheet.cell(rowx=row, colx=7).value,
                    sheet.cell(rowx=row, colx=8).value,
                    sheet.cell(rowx=row, colx=9).value,
                ]

            try:
                dice.append(Die(name, color, size, sides, customContent))
            except ValueError as e:
                raise ValueError(str(e) + " (while reading " + name +
                                 ")") from None
            row += 1
        return dice
Esempio n. 2
0
 def _parseSimpleToken(sheet, row):
     entity = sheet.cell(rowx=row, colx=1).value
     name = sheet.cell(rowx=row, colx=0).value
     color = ColorReader.read_color(sheet.cell(rowx=row, colx=2).value)
     try:
         size = read_float(sheet.cell(rowx=row, colx=3).value)
     except ValueError as e:
         raise ValueError(str(e) + " (while reading " + name +
                          ")") from None
     return Token(name, entity, color, size)
Esempio n. 3
0
 def _parseToken(sheet, row):
     entity = sheet.cell(rowx=row, colx=1).value
     name = sheet.cell(rowx=row, colx=0).value
     bg_color = ColorReader.read_color(sheet.cell(rowx=row, colx=2).value)
     text_color = ColorReader.read_color(sheet.cell(rowx=row, colx=4).value)
     content = sheet.cell(rowx=row, colx=5).value
     try:
         size = read_float(sheet.cell(rowx=row, colx=3).value)
         # for some reason, custom tokens of size 1 are HUGE.
         # shrinking them down so they scale more logically with other stuff.
         size = size / 5
     except ValueError as e:
         raise ValueError(str(e) + " (while reading " + name +
                          ")") from None
     return ContentToken(name, entity, bg_color, text_color, content, size)
Esempio n. 4
0
    def parse(self, sheet):
        bags = []
        row = 1
        while row < sheet.nrows:
            name = sheet.cell(rowx=row, colx=0).value
            type = read_fromlist(
                sheet.cell(rowx=row, colx=1).value, ('bag', 'infinite-bag'))
            color = ColorReader.read_color(sheet.cell(rowx=row, colx=2).value)
            size = read_float(sheet.cell(rowx=row, colx=3).value)

            bag = Bag(name, size, color) if type == 'bag' else InfiniteBag(
                name, size, color)
            contentNum = 0
            while contentNum < (sheet.ncols - 4):
                content = read_content(
                    sheet.cell(rowx=row, colx=contentNum + 4).value)
                for key, item in enumerate(content):
                    bag.addContent(item[0], self.findType(item[1]))
                contentNum += 1

            bags.append(bag)
            row += 1
        return bags
Esempio n. 5
0
 def runFloatTests(self):
     assert read_float("1.5") == 1.5
     assert read_float("1.0") == 1
     assert read_float("3") == 3
     self.ensureNotAllowed(read_float, "abc", "Text is not supported")
     self.ensureNotAllowed(read_float, "", "Blank is not supported")