コード例 #1
0
def deserialize_cardboard_cubeable(cardboard_cubeable: serialization_model,
                                   inflator: Inflator) -> CardboardCubeable:
    if isinstance(cardboard_cubeable, str):
        return inflator.inflate(Cardboard, cardboard_cubeable)

    return CARDBOARD_LAP_NAME_MAP[cardboard_cubeable['type']].deserialize(
        cardboard_cubeable, inflator)
コード例 #2
0
ファイル: cubeupdate.py プロジェクト: guldfisk/magiccube
 def deserialize(cls, value: serialization_model,
                 inflator: Inflator) -> 'Serializeable':
     return cls(
         inflator.inflate(Printing, value['cubeable']) if value['type'] ==
         'Printing' else cls._cubeables_name_map[value['type']].deserialize(
             value['cubeable'],
             inflator,
         ))
コード例 #3
0
def deserialize_cardboard_cubeable_string(
        cardboard_cubeable: str, inflator: Inflator) -> CardboardCubeable:
    if cardboard_cubeable.startswith('{'):
        cardboard_cubeable = json.loads(cardboard_cubeable)
        return CARDBOARD_LAP_NAME_MAP[cardboard_cubeable['type']].deserialize(
            cardboard_cubeable, inflator)

    return inflator.inflate(Cardboard, cardboard_cubeable)
コード例 #4
0
 def deserialize(cls, value: serialization_model, inflator: Inflator) -> Pool:
     return Pool(
         inflator.inflate_all(Printing, value['printings']),
         (
             Deck.deserialize(_value, inflator)
             for _value in
             value.get('decks', ())
         ),
     )
コード例 #5
0
 def deserialize(cls, value: serialization_model,
                 inflator: Inflator) -> CubeDeltaOperation:
     return cls({
         cubeable: multiplicity
         for cubeable, multiplicity in itertools.chain((
             (inflator.inflate(Printing, printing), multiplicity)
             for printing, multiplicity in value.get('printings', [])
         ), ((Trap.deserialize(trap, inflator), multiplicity)
             for trap, multiplicity in value.get('traps', [])), (
                 (Ticket.deserialize(ticket, inflator), multiplicity)
                 for ticket, multiplicity in value.get('tickets', [])), (
                     (Purple.deserialize(purple, inflator), multiplicity)
                     for purple, multiplicity in value.get('purples', [])))
     })
コード例 #6
0
ファイル: printingtree.py プロジェクト: guldfisk/magiccube
    def deserialize(cls, value: serialization_model, inflator: Inflator) -> CardboardNode:
        return (
            CardboardAnyNode
            if value['type'] == CardboardAnyNode.__name__ else
            CardboardAllNode
        )(

            {
                (
                    inflator.inflate(Cardboard, child)
                    if isinstance(child, str) else
                    cls.deserialize(child, inflator)
                ):
                    multiplicity
                for child, multiplicity
                in value['options']
            }
        )
コード例 #7
0
ファイル: printingtree.py プロジェクト: guldfisk/magiccube
    def deserialize(cls, value: serialization_model, inflator: Inflator) -> PrintingNode:
        return (
            AnyNode
            if value['type'] == AnyNode.__name__ else
            AllNode
        )(

            {
                (
                    inflator.inflate(Printing, child)
                    if isinstance(child, int) else
                    cls.deserialize(child, inflator)
                ):
                    multiplicity
                for child, multiplicity
                in value['options']
            }
        )
コード例 #8
0
ファイル: cube.py プロジェクト: guldfisk/magiccube
 def deserialize(cls, value: serialization_model, inflator: Inflator) -> Cube:
     return cls(
         cubeables = itertools.chain(
             inflator.inflate_all(Printing, value['printings']),
             (
                 Trap.deserialize(trap, inflator)
                 for trap in
                 value.get('traps', ())
             ),
             (
                 Ticket.deserialize(ticket, inflator)
                 for ticket in
                 value.get('tickets', ())
             ),
             (
                 Purple.deserialize(purple, inflator)
                 for purple in
                 value.get('purples', ())
             ),
         )
     )
コード例 #9
0
ファイル: cubeupdate.py プロジェクト: guldfisk/magiccube
 def deserialize(cls, value: serialization_model,
                 inflator: Inflator) -> AddInfinite:
     return cls(inflator.inflate(Cardboard, value['cardboard']))
コード例 #10
0
ファイル: cubeupdate.py プロジェクト: guldfisk/magiccube
 def deserialize(cls, value: serialization_model,
                 inflator: Inflator) -> PrintingChange:
     return cls(
         inflator.inflate(Printing, value['before']),
         inflator.inflate(Printing, value['after']),
     )
コード例 #11
0
ファイル: cubeupdate.py プロジェクト: guldfisk/magiccube
 def deserialize(cls, value: serialization_model,
                 inflator: Inflator) -> 'Serializeable':
     return cls(
         ConstrainedNode.deserialize(value['before'], inflator),
         inflator.inflate_all(Printing, value['after']),
     )
コード例 #12
0
ファイル: ticket.py プロジェクト: guldfisk/magiccube
 def deserialize(cls, value: serialization_model,
                 inflator: Inflator) -> CardboardTicket:
     return cls(
         inflator.inflate_all(Cardboard, value['options']),
         value['name'],
     )
コード例 #13
0
ファイル: ticket.py プロジェクト: guldfisk/magiccube
 def deserialize(cls, value: serialization_model,
                 inflator: Inflator) -> Ticket:
     return cls(
         inflator.inflate_all(Printing, value['options']),
         value['name'],
     )
コード例 #14
0
 def deserialize(cls, value: serialization_model,
                 inflator: Inflator) -> PrintingSet:
     return cls(inflator.inflate_all(Printing, value['printings']))
コード例 #15
0
def deserialize_cardboard_node_child(node_child: t.Any,
                                     inflator: Inflator) -> CardboardNodeChild:
    if isinstance(node_child, str):
        return inflator.inflate(Cardboard, node_child)
    return CardboardNode.deserialize(node_child, inflator)
コード例 #16
0
 def deserialize(cls, value: serialization_model,
                 inflator: Inflator) -> CardboardSet:
     return cls(inflator.inflate_all(Cardboard, value['cardboards']))
コード例 #17
0
def deserialize_cubeable_string(cubeable: str, inflator: Inflator) -> Cubeable:
    if _PRINTING_ID_PATTERN.match(cubeable):
        return inflator.inflate(Printing, int(cubeable))
    else:
        cubeable = json.loads(cubeable)
        return LAP_NAME_MAP[cubeable['type']].deserialize(cubeable, inflator)
コード例 #18
0
def deserialize_cubeable(cubeable: serialization_model,
                         inflator: Inflator) -> Cubeable:
    return (inflator.inflate(Printing, cubeable) if isinstance(cubeable, int)
            else LAP_NAME_MAP[cubeable['type']].deserialize(
                cubeable, inflator))