Ejemplo n.º 1
0
def parse_move_pieces(element: Element):
    pieces = selectorparser.parse(element.attrib['pieces'], selectorparser.piece)
    to = selectorparser.parse(element.attrib['to'], selectorparser.collection)
    copy = element.attrib.get("copy") == 'true'
    count = selectorparser.parse(element.attrib["count"], selectorparser.numeric) if "count" in element.attrib else None
    position = step_models.Positions[element.attrib.get("position")] if "position" in element.attrib else None
    return step_models.MovePieces(pieces, to, position, count, copy, element.sourceline)
Ejemplo n.º 2
0
def parse_player_select(element: Element):
    selector = parse_select(element)
    selector = step_models.PlayerSelect(selector,
                                        selectorparser.parse(element.attrib.get("min"), selectorparser.numeric),
                                        selectorparser.parse(element.attrib.get("max"), selectorparser.numeric),
                                        selectorparser.parse(element.attrib.get("player"), selectorparser.player),
                                        element.sourceline)
    return selector
Ejemplo n.º 3
0
def parse_repeat(element: Element):
    label = element.attrib.get("label")
    action = create_action(element)
    action_selector = selector_models.ValueSelector(action)
    if "over" in element.attrib:
        over = selectorparser.parse(element.attrib["over"], selectorparser.item)
        repeat = step_models.ForEachStep(over, action_selector, label, element.sourceline)
    elif "test" in element.attrib or "exists" in element.attrib:
        test = parse_comparison(element.attrib["test"]) \
            if "test" in element.attrib \
            else parse_exists(element.attrib["exists"])
        repeat = step_models.WhileStep(test, action_selector, element.sourceline)
    elif "count" in element.attrib:
        count = selectorparser.parse(element.attrib["count"], selectorparser.numeric)
        repeat = step_models.RepeatStep(count, action_selector, label, element.sourceline)
    else:
        raise BadGameXML("Repeat has no attribute to repeat over", element)
    return repeat
Ejemplo n.º 4
0
def parse_select(element: Element):
    return step_models.Select(selectorparser.parse(element.attrib["from"], selectorparser.item), element.get("label"), element.sourceline)
Ejemplo n.º 5
0
def parse_assign_attribute(element: Element):
    parts = selectorparser.attribute.parseString(element.attrib["attribute"])
    attr_name = parts[-1]
    attr = selectorparser.to_selector(parts[:-2])
    value = selectorparser.parse(element.attrib["value"], selectorparser.item)
    return step_models.AssignAttributeStep(attr, value, attr_name, element.sourceline)
Ejemplo n.º 6
0
def parse_perform(element: Element):
    action = selectorparser.parse(element.attrib["action"], selectorparser.action)
    return step_models.ActionStep(action, element.sourceline)
Ejemplo n.º 7
0
def parse_shuffle_collection(element: Element):
    return step_models.ShuffleCollection(selectorparser.parse(element.attrib["collection"], selectorparser.collection), element.sourceline)
Ejemplo n.º 8
0
def parse_give_turn(element: Element):
    return step_models.GiveTurnStep(selectorparser.parse(element.attrib["to"], selectorparser.player),
                                    selectorparser.parse(element.attrib["turn"], selectorparser.turn),
                                    element.sourceline)
Ejemplo n.º 9
0
def parse_end_game(element: Element):
    return step_models.EndGameStep(selectorparser.parse(element.attrib["winners"], selectorparser.player), element.sourceline)