How to use the d20.utils.simplify_expr_annotations 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
Note that any neutrals in the resistances will be explicitly ignored.

    :type damage_expr: d20.Expression
    :type resistances: Resistances
    :param always: If passed, damage is always this type in addition to whatever it's annotated as.
    :type always: set[str]
    :param transforms: a dict representing damage type transforms. If None is a key, all damage types become that.
    :type transforms: dict[str or None, str]
    """
    if always is None:
        always = set()
    if transforms is None:
        transforms = {}

    # simplify damage types
    d20.utils.simplify_expr_annotations(damage_expr.roll, ambig_inherit='left')

    # depth first visit expression nodes: if it has an annotation, add the appropriate binops and move to the next
    def do_visit(node):
        if node.annotation:
            # handle transforms
            if None in transforms:
                tokens = _resist_tokenize(transforms[None])
            else:
                tokens = []
                for t in _resist_tokenize(node.annotation.lower()):
                    tokens.extend(_resist_tokenize(transforms.get(t, t)))
            original_annotation = node.annotation
            dtype = f"{' '.join(always)} {' '.join(tokens)}".strip()
            node.annotation = f"[{dtype}]"

            # handle tree modification