Esempio n. 1
0
def test_build_proto():
    attr_ref = AttributeRef(
        entity_id=24,
        component="Sprite2D",
    )
    encoded = attr_ref.SerializeToString()
    restored = AttributeRef()
    restored.ParseFromString(encoded)
    assert attr_ref == restored
Esempio n. 2
0
 def set_attr(self, name: str, value: Any):
     value = GraphNode.wrap(value)
     attr_ref = AttributeRef(
         entity_id=self._entity_id,
         component=self._name,
         attribute=name,
     )
     # ignore attribute self assignments (ie component.attr = component.attr)
     if (value.node.WhichOneof("op") == "retrieve_op"
             and value.node.retrieve_op.retrieve_attr.SerializeToString()
             == attr_ref.SerializeToString()):
         return
     # record the attribute set/mutate operation as output graph node
     set_op = GraphNode(node=Node(mutate_op=Node.Mutate(
         mutate_attr=attr_ref,
         to_node=value.node,
     )))
     self._outputs[to_str_attr(attr_ref)] = set_op
     # preserve order of execution in _outputs by moving set operation record to end
     self._outputs.move_to_end(to_str_attr(attr_ref))