ursina_event.py 1.7 KB
Newer Older
三月三net's avatar
三月三net 已提交
1
# -*- coding:utf-8 -*-
三月三net's avatar
三月三net 已提交
2 3
# title           :ursina天体运行模拟器事件传递
# description     :ursina天体运行模拟器事件传递
三月三net's avatar
三月三net 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# author          :Python超人
# date            :2023-02-11
# link            :https://gitcode.net/pythoncr/
# python_version  :3.8
# ==============================================================================
# pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com ursina


class UrsinaEvent:
    """

    """

    @staticmethod
    def init():
        if hasattr(UrsinaEvent, "on_reset_funcs"):
            return
        UrsinaEvent.on_reset_funcs = []
三月三net's avatar
三月三net 已提交
22
        UrsinaEvent.on_searching_bodies_funcs = []
三月三net's avatar
三月三net 已提交
23 24 25 26 27
        UrsinaEvent.on_application_run_callback = []

    @staticmethod
    def on_application_run_callback_subscription(fun):
        UrsinaEvent.on_application_run_callback.append(fun)
三月三net's avatar
三月三net 已提交
28 29 30 31

    @staticmethod
    def on_searching_bodies_subscription(subscription_name, fun):
        UrsinaEvent.on_searching_bodies_funcs.append((subscription_name, fun))
三月三net's avatar
三月三net 已提交
32 33 34 35 36 37 38 39 40 41

    @staticmethod
    def on_reset_subscription(fun):
        UrsinaEvent.on_reset_funcs.append(fun)

    @staticmethod
    def on_reset():
        for f in UrsinaEvent.on_reset_funcs:
            f()

三月三net's avatar
三月三net 已提交
42 43 44 45 46 47 48 49
    @staticmethod
    def on_application_run():
        if len(UrsinaEvent.on_application_run_callback) == 0:
            return
        for f in UrsinaEvent.on_application_run_callback:
            f()
        UrsinaEvent.on_application_run_callback.clear()

三月三net's avatar
三月三net 已提交
50 51 52 53 54 55 56
    @staticmethod
    def on_searching_bodies(**kwargs):
        results = []
        for subscription_name, fun in UrsinaEvent.on_searching_bodies_funcs:
            results.append((subscription_name, fun(**kwargs)))
        return results

三月三net's avatar
三月三net 已提交
57 58

UrsinaEvent.init()