How to use the d20.Literal function in d20

To help you get started, we’ve selected a few d20 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github avrae / avrae / cogs5e / models / sheet / resistance.py View on Github external
# handle tree modification
            ann = set(tokens) | always

            if any(n.applies_to(ann) for n in resistances.neutral):  # neutral overrides all
                return node

            if any(v.applies_to(ann) for v in resistances.vuln):
                node = d20.BinOp(d20.Parenthetical(node), '*', d20.Literal(2))

            if original_annotation.startswith('[^') or original_annotation.endswith('^]'):
                node.annotation = original_annotation
                # break here - don't handle resist/immune
                return node

            if any(r.applies_to(ann) for r in resistances.resist):
                node = d20.BinOp(d20.Parenthetical(node), '/', d20.Literal(2))

            if any(im.applies_to(ann) for im in resistances.immune):
                node = d20.BinOp(d20.Parenthetical(node), '*', d20.Literal(0))

            return node

        for i, child in enumerate(node.children):
            replacement = do_visit(child)
            if replacement and replacement is not child:
                node.set_child(i, replacement)
        return None
github avrae / avrae / cogs5e / models / sheet / resistance.py View on Github external
if any(n.applies_to(ann) for n in resistances.neutral):  # neutral overrides all
                return node

            if any(v.applies_to(ann) for v in resistances.vuln):
                node = d20.BinOp(d20.Parenthetical(node), '*', d20.Literal(2))

            if original_annotation.startswith('[^') or original_annotation.endswith('^]'):
                node.annotation = original_annotation
                # break here - don't handle resist/immune
                return node

            if any(r.applies_to(ann) for r in resistances.resist):
                node = d20.BinOp(d20.Parenthetical(node), '/', d20.Literal(2))

            if any(im.applies_to(ann) for im in resistances.immune):
                node = d20.BinOp(d20.Parenthetical(node), '*', d20.Literal(0))

            return node

        for i, child in enumerate(node.children):
            replacement = do_visit(child)
            if replacement and replacement is not child:
                node.set_child(i, replacement)
        return None