Exemplo n.º 1
0
def build_server(cls, i, ex, args):
    i.local_address = hive.property(cls, "local_address", "tuple")
    i.push_bind_address = hive.push_in(i.local_address)
    ex.bind_to = hive.antenna(i.push_bind_address)

    i.do_bind = hive.triggerable(cls.do_bind)
    hive.trigger(i.push_bind_address, i.do_bind)

    # Receiving connection
    i.connected_address = hive.property(cls, "connected_address", "tuple")
    i.push_connected_address = hive.push_out(i.connected_address)
    ex.on_client_connected = hive.output(i.push_connected_address)

    # Receiving connection
    i.disconnected_address = hive.property(cls, "disconnected_address",
                                           "tuple")
    i.push_disconnected_address = hive.push_out(i.disconnected_address)
    ex.on_client_disconnected = hive.output(i.push_disconnected_address)

    # Receiving
    i.from_address = hive.property(cls, "from_address", "tuple")
    i.pull_from_address = hive.pull_out(i.from_address)
    ex.from_address = hive.output(i.pull_from_address)

    i.received_data = hive.property(cls, "received_data", "bytes")
    i.push_received = hive.push_out(i.received_data)
    ex.on_received = hive.output(i.push_received)

    # Hive callbacks
    i.on_disconnected = hive.triggerfunc()
    i.on_connected = hive.triggerfunc()
    i.on_received = hive.triggerfunc()

    hive.trigger(i.on_received, i.push_received)
    hive.trigger(i.on_connected, i.push_connected_address)
    hive.trigger(i.on_disconnected, i.push_disconnected_address)

    # Sending
    i.to_address = hive.property(cls, "to_address", "tuple")
    i.pull_to_address = hive.pull_in(i.to_address)
    ex.to_address = hive.antenna(i.pull_to_address)

    i.outgoing_data = hive.property(cls, "outgoing_data", "bytes")
    i.push_outgoing_data = hive.push_in(i.outgoing_data)
    ex.send = hive.antenna(i.push_outgoing_data)

    i.do_send_data = hive.triggerable(cls.do_send)
    hive.trigger(i.push_outgoing_data, i.pull_to_address, pretrigger=True)
    hive.trigger(i.push_outgoing_data, i.do_send_data)

    i.synchronise_data = hive.triggerable(cls.synchronise)
    i.on_tick = OnTick()
    hive.connect(i.on_tick.on_tick, i.synchronise_data)
Exemplo n.º 2
0
def build_set(i, ex, args, meta_args):
    """Perform set operation on single sets"""

    i.set_ = hive.attribute('set', set())
    i.pull_set_ = hive.pull_out(i.set_)
    ex.set_out = hive.output(i.pull_set_)

    i.push_set_ = hive.push_in(i.set_)
    ex.set_ = hive.antenna(i.push_set_)

    # Pop item
    i.popped_item = hive.attribute(meta_args.data_type)
    i.pull_pop = hive.pull_out(i.popped_item)
    ex.pop = hive.output(i.pull_pop)

    def do_pop(self):
        self._popped_item = self._set_.pop()

    i.do_pop = hive.modifier(do_pop)
    hive.trigger(i.pull_pop, i.do_pop, pretrigger=True)

    # Add item
    i.to_add = hive.attribute(meta_args.data_type)
    i.push_to_add = hive.push_in(i.to_add)
    ex.add = hive.antenna(i.push_to_add)

    def to_add(self):
        self._set_.add(self._to_add)

    i.do_add = hive.modifier(to_add)
    hive.trigger(i.push_to_add, i.do_add)

    # Remove item
    i.to_remove = hive.attribute(meta_args.data_type)
    i.push_to_remove = hive.push_in(i.to_remove)
    ex.remove = hive.antenna(i.push_to_remove)

    def do_remove(self):
        self._set_.remove(self._to_remove)

    i.do_remove = hive.modifier(do_remove)
    hive.trigger(i.push_to_remove, i.do_remove)

    def do_clear(self):
        self._set_.clear()

    i.do_clear = hive.modifier(do_clear)
    ex.clear = hive.entry(i.do_clear)
Exemplo n.º 3
0
def build_convert(i, ex, args, meta_args):
    i.value_in = hive.variable(meta_args.from_data_type)
    i.value_out = hive.variable(meta_args.to_data_type)

    # For push in, push out
    if meta_args.mode == "push":
        i.ppin = hive.push_in(i.value_in)
        i.ppout = hive.push_out(i.value_out)

        hive.trigger(i.ppin, i.ppout)

    else:
        i.ppin = hive.pull_in(i.value_in)
        i.ppout = hive.pull_out(i.value_out)

        hive.trigger(i.ppout, i.ppin, pretrigger=True)

    ex.value_in = hive.antenna(i.ppin)
    ex.value_out = hive.output(i.ppout)

    # For casting (explicit conversion)
    if meta_args.conversion == "cast":
        to_base_type_name = hive.get_base_data_type(meta_args.to_data_type)
        value_cls = _type_map[to_base_type_name]

        def converter(self):
            self._value_out = value_cls(self._value_in)

        i.do_conversion = hive.modifier(converter)
        hive.trigger(i.ppout, i.do_conversion, pretrigger=True)

    # For duck typing, move value through
    else:
        i.move_value = hive.modifier(move_value)
        hive.trigger(i.ppin, i.move_value)
Exemplo n.º 4
0
def build_keyboard(cls, i, ex, args, meta_args):
    """Listen for keyboard event"""
    if meta_args.mode == 'single key':
        ex.on_event = hive.socket(cls.add_single_listener, identifier="event.add_handler")

        args.key = hive.parameter("str.keycode", "w")
        i.key = hive.property(cls, "key", "str.keycode", args.key)

        i.push_key = hive.push_in(i.key)
        ex.key = hive.antenna(i.push_key)

        i.on_key_changed = hive.triggerable(cls.change_listener_keys)
        hive.trigger(i.push_key, i.on_key_changed)

        i.on_pressed = hive.triggerfunc()
        ex.on_pressed = hive.hook(i.on_pressed)

        i.on_released = hive.triggerfunc()
        ex.on_released = hive.hook(i.on_released)

        i.is_pressed = hive.property(cls, "is_pressed", "bool")
        i.pull_is_pressed = hive.pull_out(i.is_pressed)
        ex.is_pressed = hive.output(i.pull_is_pressed)

    else:
        ex.on_event = hive.socket(cls.add_any_listener, identifier="event.add_handler")

        i.key_pressed = hive.property(cls, 'key_pressed', data_type='str.keycode')
        i.pull_key_pressed = hive.push_out(i.key_pressed)
        ex.key_pressed = hive.output(i.pull_key_pressed)

        i.key_released = hive.property(cls, 'key_released', data_type='str.keycode')
        i.pull_key_released = hive.push_out(i.key_released)
        ex.key_released = hive.output(i.pull_key_released)
Exemplo n.º 5
0
def build_instantiator(cls, i, ex, args, meta_args):
    """Instantiates a Hive class at runtime"""
    # If this is built now, then it won't perform matchmaking, so use meta hive
    bind_meta_class = hive.meta_hive("BindEnvironment", build_bind_environment, declare_build_environment,
                                     builder_cls=BindEnvironmentClass)
    #assert bind_meta_class._hive_object_class
    i.bind_meta_class = hive.property(cls, "bind_meta_class", "class", bind_meta_class)

    i.trig_instantiate = hive.triggerfunc(cls.instantiate)
    i.do_instantiate = hive.triggerable(i.trig_instantiate)

    i.hive_class = hive.property(cls, "hive_class", "class")
    i.pull_hive_class = hive.pull_in(i.hive_class)
    ex.hive_class = hive.antenna(i.pull_hive_class)

    ex.create = hive.entry(i.do_instantiate)

    hive.trigger(i.trig_instantiate, i.pull_hive_class, pretrigger=True)

    ex.process_id = hive.property(cls, "last_created_process_id", "int.process_id")
    i.pull_process_id = hive.pull_out(ex.process_id)
    ex.last_process_id = hive.output(i.pull_process_id)

    i.push_stop_process = hive.push_in(cls.stop_hive)
    ex.stop_process = hive.antenna(i.push_stop_process)

    # Bind class plugin
    ex.bind_on_created = hive.socket(cls.add_on_created, identifier="bind.on_created", policy=hive.MultipleOptional)
    ex.add_get_plugins = hive.socket(cls.add_get_plugins, identifier="bind.get_plugins", policy=hive.MultipleOptional)
    ex.add_get_config = hive.socket(cls.add_get_config, identifier="bind.get_config", policy=hive.MultipleOptional)

    # Bind instantiator
    if meta_args.bind_process == 'child':
        # Add startup and stop callbacks
        ex.on_stopped = hive.plugin(cls.stop_all_processes, identifier="on_stopped")
Exemplo n.º 6
0
def build_watch(cls, i, ex, args, meta_args):
    """Watch value and indicate when it is changed.

    Uses a tick callback.
    """
    args.start_value = hive.parameter(meta_args.data_type, None)
    i.value = hive.property(cls, "current_value", meta_args.data_type, args.start_value)

    if meta_args.mode == 'pull':
        i.value_in = hive.pull_in(i.value)

    else:
        i.value_in = hive.push_in(i.value)

    ex.value = hive.antenna(i.value_in)

    i.on_changed = hive.triggerfunc()
    ex.on_changed = hive.hook(i.on_changed)

    if meta_args.mode == 'pull':
        ex.get_add_handler = hive.socket(cls.set_add_handler, identifier="event.add_handler")

    else:
        i.compare_values = hive.triggerable(cls.compare_values)
        hive.trigger(i.value_in, i.compare_values)
Exemplo n.º 7
0
def build_attr(i, ex, args, meta_args):
    """Set/get attribute on object"""
    i.name = hive.attribute("str")
    i.value = hive.attribute(meta_args.attribute_type)
    i.object_ = hive.attribute(meta_args.object_type)

    i.pull_name = hive.pull_in(i.name)
    i.pull_object = hive.pull_in(i.object_)

    ex.object_ = hive.antenna(i.pull_object)
    ex.name = hive.antenna(i.pull_name)

    if meta_args.mode == "set":
        i.push_value = hive.push_in(i.value)
        ex.value = hive.antenna(i.push_value)

        i.do_set_attr = hive.modifier(do_setattr)

        hive.trigger(i.push_value, i.pull_object)
        hive.trigger(i.pull_object, i.pull_name)
        hive.trigger(i.pull_name, i.do_set_attr)

    else:
        i.pull_value = hive.pull_out(i.value)
        ex.value = hive.output(i.pull_value)

        i.do_get_attr = hive.modifier(do_getattr)

        hive.trigger(i.pull_value, i.pull_object, pretrigger=True)
        hive.trigger(i.pull_object, i.pull_name)
        hive.trigger(i.pull_name, i.do_get_attr)
Exemplo n.º 8
0
def build_unpack_tuple(i, ex, args, meta_args):
    """Unpack a tuple from individual inputs"""
    i.tuple_ = hive.attribute('tuple')
    i.push_tuple = hive.push_in(i.tuple_)
    ex.tuple_ = hive.antenna(i.push_tuple)

    for index, data_type in enumerate(meta_args.types):
        attr = hive.attribute(data_type)
        setattr(i, "attr_{}".format(index), attr)

        pull_out = hive.pull_out(attr)
        setattr(i, "pull_out_{}".format(index), pull_out)

        setattr(ex, "item_{}".format(index), hive.output(pull_out))

    def do_unpack_tuple(self):
        tuple_ = self._tuple_
        data_types = meta_args.types

        assert len(tuple_) == len(data_types)

        for index, item in enumerate(tuple_):
            setattr(self, "_attr_{}".format(index), item)

    i.do_unpack_tuple = hive.modifier(do_unpack_tuple)
    hive.trigger(i.push_tuple, i.do_unpack_tuple)
Exemplo n.º 9
0
def build_item(i, ex, args, meta_args):
    """Set/get item in object"""
    i.name = hive.attribute(meta_args.index_type)
    i.value = hive.attribute(meta_args.item_type)
    i.container_ = hive.attribute(meta_args.container_type)

    i.pull_name = hive.pull_in(i.name)
    i.pull_container = hive.pull_in(i.container_)

    ex.container_ = hive.antenna(i.pull_container)
    ex.name = hive.antenna(i.pull_name)

    if meta_args.mode == "set":
        i.push_value = hive.push_in(i.value)
        ex.value = hive.antenna(i.push_value)

        i.do_set_attr = hive.modifier(do_setitem)

        hive.trigger(i.push_value, i.pull_container)
        hive.trigger(i.pull_container, i.pull_name)
        hive.trigger(i.pull_name, i.do_set_attr)

    else:
        i.pull_value = hive.pull_out(i.value)
        ex.value = hive.output(i.pull_value)

        i.do_get_attr = hive.modifier(do_getitem)

        hive.trigger(i.pull_value, i.pull_container, pretrigger=True)
        hive.trigger(i.pull_container, i.pull_name)
        hive.trigger(i.pull_name, i.do_get_attr)
Exemplo n.º 10
0
def build_buffer(i, ex, args, meta_args):
    """Store the input value and output saved value.

    In pull mode, the trigger is used to update the internal value.
    In push mode, the trigger is used to output the internal value.

    Can be used to cache changing values
    """
    args.start_value = hive.parameter(meta_args.data_type, None)
    i.cached_value = hive.attribute(meta_args.data_type, args.start_value)

    if meta_args.mode == "push":
        i.push_value = hive.push_in(i.cached_value)
        ex.value = hive.antenna(i.push_value)

        i.push_cached_value = hive.push_out(i.cached_value)
        ex.cached_value = hive.output(i.push_cached_value)

        ex.output = hive.entry(i.push_cached_value)

    elif meta_args.mode == "pull":
        i.pull_value = hive.pull_in(i.cached_value)
        ex.value = hive.antenna(i.pull_value)

        i.pull_cached_value = hive.pull_out(i.cached_value)
        ex.cached_value = hive.output(i.pull_cached_value)

        ex.update_cache = hive.entry(i.pull_value)
Exemplo n.º 11
0
def build_bind(cls, i, ex, args, meta_args):
    if meta_args.forward_events == "none":
        return

    if meta_args.forward_events == "by_leader":
        i.event_leader = hive.property(cls, "leader", "tuple")
        i.pull_event_leader = hive.pull_in(i.event_leader)
        ex.event_leader = hive.antenna(i.pull_event_leader)

    i.push_pause_in = hive.push_in(cls.pause)
    ex.pause_events = hive.antenna(i.push_pause_in)

    i.push_resume_in = hive.push_in(cls.resume)
    ex.resume_events = hive.antenna(i.push_resume_in)

    ex.on_created = hive.plugin(cls.on_created, "bind.on_created")
Exemplo n.º 12
0
def build_print(i, ex, args):
    """Output object to Python stdout"""
    ex.value = hive.variable()
    i.value_in = hive.push_in(ex.value)
    ex.value_in = hive.antenna(i.value_in)

    i.func = hive.modifier(lambda self: print(self.value))

    hive.trigger(i.value_in, i.func)
Exemplo n.º 13
0
def build_struct(cls, i, ex, args):
    """Interface to Struct class"""
    i.tuple = hive.variable("tuple")
    i.pack_in = hive.push_in(i.tuple)
    ex.pack = hive.antenna(i.pack_in)

    i.bytes = hive.variable("bytes")
    i.unpack_out = hive.push_out(i.bytes)
    ex.unpack = hive.output(i.unpack_out)

    i.size_out = hive.pull_out(cls.size)
    ex.size = hive.output(i.size_out)
Exemplo n.º 14
0
def build_myhive(cls, i, ex, args):
    ex.a_ = hive.property(cls, "a", "int")
    ex.b_ = hive.property(cls, "b", "int")

    i.a_in = hive.push_in(ex.a_)
    i.b_in = hive.push_in(ex.b_)

    ex.a = hive.antenna(i.a_in)
    ex.b = hive.antenna(i.b_in)

    ex.c_ = hive.attribute()
    i.c_out = hive.push_out(ex.c_)
    ex.c = hive.output(i.c_out)

    # On triggered
    def on_triggered(this):
        this.c_ = this.a_ + this.b_
        this.c.push()

    i.on_triggered = hive.modifier(lambda this: setattr(this, 'c_', (this.a_ + this.b_)))
    ex.trigger = hive.entry(i.on_triggered)
Exemplo n.º 15
0
def build_chessboard(cls, i, ex, args):
    prop_move = h.property(cls, "prop_move", "str")  # TODO: make buffer
    i.make_move = h.push_in(prop_move)
    i.trig_make_move = h.triggerable(cls.trig_make_move)  # TODO: make modifier
    h.trigger(i.make_move, i.trig_make_move)

    ex.make_move = h.antenna(i.make_move)
    ex.do_make_move = cls.make_move
    ex.p_make_move = h.plugin(cls.make_move)
    ex.prop_move = prop_move
    ex.set_turn = h.socket(cls.set_turn)
    ex.add_moveprocessor = h.socket(cls.add_moveprocessor)
Exemplo n.º 16
0
def build_server(cls, i, ex, args):
    i.connect_address = hive.property(cls, "server_address", "tuple")
    i.push_connect = hive.push_in(i.connect_address)
    ex.connect_to = hive.antenna(i.push_connect)

    i.do_connect = hive.triggerable(cls.do_connect)
    hive.trigger(i.push_connect, i.do_connect)

    # Hive callbacks
    i.on_disconnected = hive.triggerfunc()
    i.on_connected = hive.triggerfunc()
    i.on_received = hive.triggerfunc()

    # Receiving connection
    ex.on_connected = hive.hook(i.on_connected)

    # Lost connection
    ex.on_disconnected = hive.hook(i.on_disconnected)

    # Receiving
    i.received_data = hive.property(cls, "received_data", "bytes")
    i.push_received = hive.push_out(i.received_data)
    ex.on_received = hive.output(i.push_received)

    hive.trigger(i.on_received, i.push_received)

    # Sending
    i.outgoing_data = hive.property(cls, "outgoing_data", "bytes")
    i.push_outgoing_data = hive.push_in(i.outgoing_data)
    ex.send = hive.antenna(i.push_outgoing_data)

    i.do_send_data = hive.triggerable(cls.do_send)
    hive.trigger(i.push_outgoing_data, i.do_send_data)

    i.synchronise_data = hive.triggerable(cls.synchronise)
    i.on_tick = OnTick()
    hive.connect(i.on_tick.on_tick, i.synchronise_data)
Exemplo n.º 17
0
def build_dictionary(cls, i, ex, args, meta_args):
    """Interface to dictionary object"""
    ex.dict = hive.property(cls, "dict", "dict")

    i.dict_in = hive.push_in(ex.dict)
    ex.dict_ = hive.antenna(i.dict_in)

    i.dict_out = hive.pull_out(ex.dict)
    ex.dict_out = hive.output(i.dict_out)

    i.key = hive.property(cls, "key", meta_args.key_data_type)
    i.value = hive.property(cls, "value", meta_args.data_type)

    # Setitem
    i.set_key_in = hive.pull_in(i.key)
    ex.set_key = hive.antenna(i.set_key_in)

    i.in_value = hive.push_in(i.value)
    ex.in_value = hive.antenna(i.in_value)

    i.set_value = hive.triggerable(cls.set_value)

    hive.trigger(i.in_value, i.set_key_in)
    hive.trigger(i.set_key_in, i.set_value)

    i.get_key_in = hive.pull_in(i.key)
    ex.get_key = hive.antenna(i.get_key_in)

    i.out_value = hive.pull_out(i.value)
    ex.out_value = hive.output(i.out_value)

    i.get_value = hive.triggerable(cls.get_value)

    # Before outputting, update key
    hive.trigger(i.out_value, i.get_key_in, pretrigger=True)
    hive.trigger(i.get_key_in, i.get_value)
Exemplo n.º 18
0
def build_input(i, ex, args):
    """Get input from Python stdin"""
    args.message = hive.parameter("str", "")
    ex.message = hive.attribute("str", args.message)

    i.message_in = hive.push_in(ex.message)
    ex.message_in = hive.antenna(i.message_in)

    ex.value = hive.attribute("str")
    i.value_out = hive.pull_out(ex.value)
    ex.value_out = hive.output(i.value_out)

    def get_input(self):
        self.value = input(self.message)

    i.get_input = hive.modifier(get_input)
    hive.trigger(i.value_out, i.get_input, pretrigger=True)
Exemplo n.º 19
0
def build_random(cls, i, ex, args):
    """HIVE interface to Python random module"""
    i.push_seed = hive.push_in(cls.set_seed)
    ex.seed = hive.antenna(i.push_seed)

    i.pull_random = hive.pull_out(cls.get_rand)
    ex.random = hive.output(i.pull_random)

    i.pull_bool = hive.pull_out(cls.get_bool)
    ex.bool = hive.output(i.pull_bool)

    # Randint
    i.randint_min = hive.property(cls, "randint_min", "int")
    i.randint_max = hive.property(cls, "randint_max", "int")
    i.randint_step = hive.property(cls, "randint_step", "int")

    i.pull_randint_min = hive.pull_in(i.randint_min)
    i.pull_randint_max = hive.pull_in(i.randint_max)
    i.pull_randint_step = hive.pull_in(i.randint_step)

    ex.int_min = hive.antenna(i.pull_randint_min)
    ex.int_max = hive.antenna(i.pull_randint_max)
    ex.int_step = hive.antenna(i.pull_randint_step)

    i.pull_int = hive.pull_out(cls.get_randrange)
    ex.int = hive.output(i.pull_int)

    hive.trigger(i.pull_int, i.pull_randint_max, pretrigger=True)
    hive.trigger(i.pull_int, i.pull_randint_min, pretrigger=True)
    hive.trigger(i.pull_int, i.pull_randint_step, pretrigger=True)

    # Randrange
    i.uniform_min = hive.property(cls, "uniform_min", "float")
    i.uniform_max = hive.property(cls, "uniform_max", "float")

    i.uniform_min_in = hive.pull_in(i.uniform_min)
    i.uniform_max_in = hive.pull_in(i.uniform_max)

    ex.uniform_min = hive.antenna(i.uniform_min_in)
    ex.uniform_max = hive.antenna(i.uniform_max_in)

    i.pull_uniform = hive.pull_out(cls.get_uniform)
    ex.uniform = hive.output(i.pull_uniform)

    hive.trigger(i.pull_uniform, i.uniform_max_in, pretrigger=True)
    hive.trigger(i.pull_uniform, i.uniform_min_in, pretrigger=True)
Exemplo n.º 20
0
def build_variable(i, ex, args, meta_args):
    """Simple value-holding hive"""
    args.start_value = hive.parameter(meta_args.data_type)
    ex.value = hive.variable(meta_args.data_type, args.start_value)

    i.pull_value = hive.pull_out(ex.value)
    ex.value_out = hive.output(i.pull_value)

    i.push_value = hive.push_in(ex.value)
    ex.value_in = hive.antenna(i.push_value)

    if meta_args.advanced:
        i.pre_output = hive.triggerfunc()
        ex.pre_output = hive.hook(i.pre_output)

        i.do_pre_output = hive.triggerable(i.pre_output)
        hive.trigger(i.pull_value, i.do_pre_output, pretrigger=True)
Exemplo n.º 21
0
def build_mouse(cls, i, ex, args):
    ex.on_event = hive.socket(cls.set_add_handler,
                              identifier="event.add_handler")
    i.on_tick = hive.triggerfunc()

    args.button = hive.parameter("str",
                                 "left",
                                 options={"left", "middle", "right"})
    i.button = hive.property(cls, "button", "str", args.button)

    i.push_button = hive.push_in(i.button)
    ex.button = hive.antenna(i.push_button)

    i.on_button_changed = hive.triggerable(cls.change_listener_buttons)
    hive.trigger(i.push_button, i.on_button_changed)

    i.on_pressed = hive.triggerfunc()
    ex.on_pressed = hive.hook(i.on_pressed)

    i.on_moved = hive.triggerfunc()
    ex.on_moved = hive.hook(i.on_moved)

    i.pos_x = hive.property(cls, "pos_x", "float")
    i.pull_x = hive.pull_out(i.pos_x)
    ex.x = hive.output(i.pull_x)

    i.pos_y = hive.property(cls, "pos_y", "float")
    i.pull_y = hive.pull_out(i.pos_y)
    ex.y = hive.output(i.pull_y)

    i.dx = hive.property(cls, "dx", "float")
    i.pull_dx = hive.pull_out(i.dx)
    ex.dx = hive.output(i.pull_dx)

    i.dy = hive.property(cls, "dy", "float")
    i.pull_dy = hive.pull_out(i.dy)
    ex.dy = hive.output(i.pull_dy)

    i.is_pressed = hive.property(cls, "is_pressed", "bool")
    i.pull_is_pressed = hive.pull_out(i.is_pressed)
    ex.is_pressed = hive.output(i.pull_is_pressed)
Exemplo n.º 22
0
def build_tag(cls, i, ex, args, meta_args):
    """Access to entity tag API"""
    if meta_args.bound:
        ex.get_bound = hive.socket(cls.set_get_entity_id, identifier="entity.get_bound")
        i.do_get_bound_entity_id = hive.triggerable(cls.get_entity_id)

    else:
        i.entity_id = hive.property(cls, "entity_id", "int.entity_id")
        i.pull_entity_id = hive.pull_in(i.entity_id)
        ex.entity_id = hive.antenna(i.pull_entity_id)
        i.do_get_bound_entity_id = hive.triggerable(i.pull_entity_id)

    i.tag_name = hive.property(cls, "tag_name", "str")
    i.tag_value = hive.property(cls, "tag_value", meta_args.data_type)

    i.pull_tag_name = hive.pull_in(i.tag_name)
    ex.name = hive.antenna(i.pull_tag_name)

    if meta_args.mode == 'get':
        ex.get_get_tag = hive.socket(cls.set_get_tag, identifier="entity.tag.get")

        i.pull_tag_value = hive.pull_out(i.tag_value)
        ex.value = hive.output(i.pull_tag_value)

        i.do_get_tag = hive.triggerable(cls.get_tag)

        hive.trigger(i.pull_tag_value, i.do_get_bound_entity_id)
        hive.trigger(i.pull_tag_value, i.pull_tag_name)
        hive.trigger(i.pull_tag_value, i.do_get_tag)

    else:
        ex.get_set_tag = hive.socket(cls.set_set_tag, identifier="entity.tag.set")

        i.push_tag_value = hive.push_in(i.tag_value)
        ex.value = hive.antenna(i.push_tag_value)

        i.do_get_tag = hive.triggerable(cls.get_tag)

        hive.trigger(i.push_tag_value, i.do_get_bound_entity_id)
        hive.trigger(i.push_tag_value, i.pull_tag_name)
        hive.trigger(i.push_tag_value, i.do_get_tag)
Exemplo n.º 23
0
def event_builder(cls, i, ex, args):
    ex.add_handler = hive.plugin(cls.add_handler,
                                 identifier="event.add_handler",
                                 export_to_parent=True)
    ex.remove_handler = hive.plugin(cls.remove_handler,
                                    identifier="event.remove_handler",
                                    export_to_parent=True)
    ex.read_event = hive.plugin(cls.handle_event,
                                identifier="event.process",
                                export_to_parent=True)

    # Send startup and stop events
    ex.on_stopped = hive.plugin(cls.on_stopped, identifier="on_stopped")
    ex.on_started = hive.plugin(cls.on_started, identifier="on_started")

    # Allow events to be pushed in
    i.event_in = hive.property(cls, 'pushed_event', 'tuple')
    i.push_event = hive.push_in(i.event_in)
    ex.event_in = hive.antenna(i.push_event)

    i.on_event_in = hive.triggerable(cls.on_event_in)
    hive.trigger(i.push_event, i.on_event_in)
Exemplo n.º 24
0
def build_visibility(cls, i, ex, args, meta_args):
    """Set/Get entity visibility"""

    if meta_args.bound:
        ex.get_bound_id = hive.socket(cls.set_get_entity_id, identifier="entity.get_bound")
        i.do_get_entity_id = hive.triggerable(cls.get_bound_entity)

    else:
        i.entity_id = hive.property(cls, "entity_id", "int.entity_id")
        i.do_get_entity_id = hive.pull_in(i.entity_id)
        ex.entity_id = hive.antenna(i.do_get_entity_id)

    if meta_args.mode == 'get':
        ex.get_get_visibility = hive.socket(cls.set_get_visibility, identifier="entity.visibility.get")
        i.pull_visibility = hive.pull_out(cls.get_visibility)
        ex.visibility = hive.output(i.pull_visibility)
        hive.trigger(i.pull_visibility, i.do_get_entity_id, pretrigger=True)

    else:
        ex.get_set_visibility = hive.socket(cls.set_set_visibility, identifier="entity.visibility.set")
        i.push_in_visibility = hive.push_in(cls.set_visibility)
        ex.visibility = hive.antenna(i.push_in_visibility)
        hive.trigger(i.push_in_visibility, i.do_get_entity_id, pretrigger=True)
Exemplo n.º 25
0
def build_parent(cls, i, ex, args, meta_args):
    """Set/Get entity parent"""
    ex.get_get_parent = hive.socket(cls.set_get_parent,
                                    identifier="entity.parent.get")
    ex.get_set_parent = hive.socket(cls.set_set_parent,
                                    identifier="entity.parent.set")

    i.parent_id = hive.property(cls, "parent_id", "int.entity_id")

    if meta_args.bound:
        ex.get_bound = hive.socket(cls.set_get_entity_id,
                                   identifier="entity.get_bound")
        i.do_get_bound_entity_id = hive.triggerable(cls.get_entity_id)

    else:
        i.entity_id = hive.property(cls, "entity_id", "int.entity_id")
        i.pull_entity_id = hive.pull_in(i.entity_id)
        ex.entity_id = hive.antenna(i.pull_entity_id)
        i.do_get_bound_entity_id = hive.triggerable(i.pull_entity_id)

    if meta_args.mode == "get":
        i.pull_parent_id = hive.pull_out(i.parent_id)
        ex.parent_id = hive.output(i.pull_parent_id)

        i.get_parent_id = hive.triggerable(cls.get_parent_id)
        hive.trigger(i.pull_parent_id,
                     i.do_get_bound_entity_id,
                     pretrigger=True)
        hive.trigger(i.pull_parent_id, i.get_parent_id, pretrigger=True)

    else:
        i.push_parent_id = hive.push_in(i.parent_id_id)
        ex.parent_id = hive.antenna(i.push_parent_id)

        i.set_parent = hive.triggerable(cls.set_parent)
        hive.trigger(i.push_parent_id, i.do_get_bound_entity_id)
        hive.trigger(i.push_parent_id, i.set_parent)
Exemplo n.º 26
0
def build_position(cls, i, ex, args, meta_args):
    """Access to entity position API"""
    coordinate_system = meta_args.coordinate_system

    i.position = hive.property(cls, "position", "vector")

    if meta_args.bound:
        ex.get_bound = hive.socket(cls.set_get_entity_id,
                                   identifier="entity.get_bound")
        i.do_get_entity_id = hive.triggerable(cls.do_get_entity_id)

    else:
        i.entity_id = hive.property(cls, "entity_id", "int.entity_id")
        i.pull_entity_id = hive.pull_in(i.entity_id)
        ex.entity_id = hive.antenna(i.pull_entity_id)

    if coordinate_system == 'relative':
        i.other_entity_id = hive.property(cls, "other_entity_id",
                                          "int.entity_id")
        i.pull_other_entity_id = hive.pull_in(i.other_entity_id)
        ex.other_entity_id = hive.antenna(i.pull_other_entity_id)

    if meta_args.mode == "get":
        i.pull_position = hive.pull_out(i.position)
        ex.position = hive.output(i.pull_position)

    else:
        i.push_position = hive.push_in(i.position)
        ex.position = hive.antenna(i.push_position)

    if meta_args.mode == "get":
        if coordinate_system == 'absolute':
            ex.get_get_position = hive.socket(
                cls.set_get_position,
                identifier="entity.position.get.absolute")
            i.do_get_position = hive.triggerable(cls.do_get_position)

        else:
            ex.get_get_position = hive.socket(
                cls.set_get_position,
                identifier="entity.position.get.relative")
            i.do_get_position = hive.triggerable(cls.do_get_relative_position)
            hive.trigger(i.pull_position,
                         i.pull_other_entity_id,
                         pretrigger=True)

        if meta_args.bound:
            hive.trigger(i.pull_position, i.do_get_entity_id, pretrigger=True)

        else:
            hive.trigger(i.pull_position, i.pull_entity_id, pretrigger=True)

        hive.trigger(i.pull_position, i.do_get_position, pretrigger=True)

    else:
        if coordinate_system == 'absolute':
            ex.get_set_position = hive.socket(
                cls.set_set_position,
                identifier="entity.position.set.absolute")
            i.do_set_position = hive.triggerable(cls.do_set_position)

        else:
            ex.get_set_position = hive.socket(
                cls.set_set_position,
                identifier="entity.position.set.relative")
            i.do_set_position = hive.triggerable(cls.do_set_relative_position)
            hive.trigger(i.push_position, i.pull_other_entity_id)

        if meta_args.bound:
            hive.trigger(i.push_position, i.do_get_entity_id)

        else:
            hive.trigger(i.push_position, i.pull_entity_id)

        hive.trigger(i.push_position, i.do_set_position)
Exemplo n.º 27
0
def build_list(i, ex, args, meta_args):
    """Interface to list container"""
    data_type = "list[{}]".format(meta_args.data_type or '?')
    i.list_ = hive.variable(data_type, list())
    i.pull_list_ = hive.pull_out(i.list_)
    ex.list_out = hive.output(i.pull_list_)

    i.push_list_ = hive.push_in(i.list_)
    ex.list_ = hive.antenna(i.push_list_)

    i.item = hive.variable(meta_args.data_type)

    # Pop item
    i.popped_item = hive.variable(meta_args.data_type)
    i.pull_pop = hive.pull_out(i.popped_item)
    ex.pop = hive.output(i.pull_pop)

    def do_pop(self):
        self._popped_item = self._list_.pop()

    i.do_pop = hive.modifier(do_pop)
    hive.trigger(i.pull_pop, i.do_pop, pretrigger=True)

    # Add item
    i.push_to_append = hive.push_in(i.item)
    ex.append = hive.antenna(i.push_to_append)

    def to_append(self):
        self._list_.append(self._item)

    i.do_append = hive.modifier(to_append)
    hive.trigger(i.push_to_append, i.do_append)

    # Remove item
    i.push_to_remove = hive.push_in(i.item)
    ex.remove = hive.antenna(i.push_to_remove)

    def do_remove(self):
        self._list_.remove(self._item)

    i.do_remove = hive.modifier(do_remove)
    hive.trigger(i.push_to_remove, i.do_remove)

    def do_clear(self):
        self._list_.clear()

    i.do_clear = hive.modifier(do_clear)
    ex.clear = hive.entry(i.do_clear)

    # Index
    i.index = hive.variable('int')

    # Getitem
    i.pull_getitem_index = hive.pull_in(i.index)
    ex.get_index = hive.antenna(i.pull_getitem_index)

    i.pull_getitem = hive.pull_out(i.item)
    ex.getitem = hive.output(i.pull_getitem)

    def do_getitem(self):
        self._item = self._list[self._index]

    i.do_getitem = hive.modifier(do_getitem)

    hive.trigger(i.pull_getitem, i.pull_getitem_index, pretrigger=True)
    hive.trigger(i.pull_getitem_index, i.do_getitem)

    # Setitem
    i.pull_setitem_index = hive.pull_in(i.item)
    ex.set_index = hive.antenna(i.pull_setitem_index)

    i.push_setitem = hive.push_in(i.item)
    ex.setitem = hive.antenna(i.push_setitem)

    def do_setitem(self):
        self._list[self._index] = self._item

    i.do_setitem = hive.modifier(do_setitem)

    hive.trigger(i.push_setitem, i.pull_setitem_index)
    hive.trigger(i.pull_setitem_index, i.do_setitem)
Exemplo n.º 28
0
def build_velocity(cls, i, ex, args, meta_args):
    """Access to entity velocity API"""
    coordinate_system = meta_args.coordinate_system

    i.velocity = hive.property(cls, "velocity", "vector")

    if meta_args.bound:
        ex.get_bound = hive.socket(cls.set_get_entity_id, identifier="entity.get_bound")
        i.do_get_entity_id = hive.triggerable(cls.do_get_entity_id)

    else:
        i.entity_id = hive.property(cls, "entity_id", "int.entity_id")
        i.pull_entity_id = hive.pull_in(i.entity_id)
        ex.entity_id = hive.antenna(i.pull_entity_id)

    if coordinate_system == 'relative':
        i.other_entity_id = hive.property(cls, "other_entity_id", "int.entity_id")
        i.pull_other_entity_id = hive.pull_in(i.other_entity_id)
        ex.other_entity_id = hive.antenna(i.pull_other_entity_id)

    if meta_args.mode == "get":
        i.pull_velocity = hive.pull_out(i.velocity)
        ex.velocity = hive.output(i.pull_velocity)

    else:
        i.push_velocity = hive.push_in(i.velocity)
        ex.velocity = hive.antenna(i.push_velocity)

    if meta_args.mode == "get":
        if coordinate_system == 'absolute':
            ex.get_get_velocity = hive.socket(cls.set_get_velocity, identifier="entity.linear_velocity.get")
            i.do_get_velocity = hive.triggerable(cls.do_get_velocity)

        else:
            ex.get_get_velocity = hive.socket(cls.set_get_velocity, identifier="entity.linear_velocity.get")
            i.do_get_velocity = hive.triggerable(cls.do_get_relative_velocity)
            hive.trigger(i.pull_velocity, i.pull_other_entity_id, pretrigger=True)

        if meta_args.bound:
            hive.trigger(i.pull_velocity, i.do_get_entity_id, pretrigger=True)

        else:
            hive.trigger(i.pull_velocity, i.pull_entity_id, pretrigger=True)

        hive.trigger(i.pull_velocity, i.do_get_velocity, pretrigger=True)

    else:
        if coordinate_system == 'absolute':
            ex.get_set_velocity = hive.socket(cls.set_set_velocity, identifier="entity.linear_velocity.set")
            i.do_set_velocity = hive.triggerable(cls.do_set_velocity)

        else:
            ex.get_set_velocity = hive.socket(cls.set_set_velocity, identifier="entity.linear_velocity.set")
            i.do_set_velocity = hive.triggerable(cls.do_set_relative_velocity)
            hive.trigger(i.push_velocity, i.pull_other_entity_id)

        if meta_args.bound:
            hive.trigger(i.push_velocity, i.do_get_entity_id)

        else:
            hive.trigger(i.push_velocity, i.pull_entity_id)

        hive.trigger(i.push_velocity, i.do_set_velocity)