コード例 #1
0
ファイル: main.py プロジェクト: admalledd/event_engine
def main():
    '''
    1:start servers
    2:connect suits
    3:connect tiles
    4:connect arena
    
    5:choose gametype
    6:pass events to gametype code
        gametype code overrides code from normal play via the lazerserver calling (in order) gametype code, then default code (default normally only does heartbeats)
        gametype code inherits from abstract code from the entities.* overriding with its own functions
    '''
    #load plugins first, they may add new events.
    lib.pluginloader.load_plugins()
    entities.init()#starts network server
    logger.info("event tree:%s"%pprint.pformat(events.base.events))
    logger.info("listener tree:%s"%pprint.pformat(events.base.listeners))
    while True:
        try:

            event = events.base.get()
            events.handle_event(event)
        except KeyboardInterrupt:
            logger.info("server quit requested!")
            lib.pluginloader.unload_plugins()
            return
        except Exception as e:
            logger.critical("error handling event %s:\n%s"%(event.name,traceback.format_exc()))
コード例 #2
0
ファイル: game.py プロジェクト: klaplong/spacegame
    def run(self):
        '''
        Run the game.
        '''
        self.init()

        while self._running:
            for event in pygame.event.get():
                events.handle_event(event, self)
            self.step()
            self.render()
            pygame.display.flip()
            self._clock.tick(self._fps)

        self.cleanup()
コード例 #3
0
ファイル: server.py プロジェクト: Pathoschild/smapi-mod-dump
def on_message(msg_str):
    import events

    try:
        msg = json.loads(msg_str)
    except json.JSONDecodeError:
        log(f"Got invalid message from mod {msg_str}", level=1)
        return
    msg_type = msg["type"]
    msg_data = msg["data"]
    if msg_type == "RESPONSE":
        fut = mod_requests.pop(msg_data["id"], None)
        if fut:
            resp_value = msg_data["value"]
            resp_error = msg_data["error"]
            try:
                if resp_error is None:
                    fut.set_result(resp_value)
                else:
                    exception = Exception(resp_value)
                    fut.set_exception(exception)
            except asyncio.InvalidStateError:
                pass
    elif msg_type == "STREAM_MESSAGE":
        stream_id = msg_data["stream_id"]

        stream = streams.get(stream_id)
        if stream is None:
            send_message("STOP_STREAM", stream_id)
            return
        stream_value = msg_data["value"]
        stream_error = msg_data.get("error")
        if stream_error is not None:
            log(f"Stream {stream_id} error: {stream_value}")
            stream.close()
            return
        stream.set_value(stream_value)
        stream.latest_value = stream_value
        try:
            stream.future.set_result(None)
        except asyncio.InvalidStateError:
            pass
    elif msg_type == "EVENT":
        events.handle_event(msg_data)
    else:
        raise RuntimeError(f"Unhandled message type from mod: {msg_type}")
コード例 #4
0
ファイル: bot.py プロジェクト: blotter/python-bot
    def do_POST(self):
        print(self.headers)
        if not all(x in self.headers
                   for x in [CONTENT_TYPE, CONTENT_LEN, EVENT_TYPE]):
            return
        content_type = self.headers['content-type']
        content_len = int(self.headers['content-length'])
        event_type = self.headers['x-github-event']

        data = self.rfile.read(content_len)

        self.send_response(200)
        self.send_header('content-type', 'text/html')
        self.end_headers()
        self.wfile.write(bytes('OK', 'utf-8'))

        events.handle_event(irc, event_type, json.loads(data.decode()))
        return
コード例 #5
0
    def do_POST(self) -> None:
        if not all(x in self.headers
                   for x in [CONTENT_TYPE, CONTENT_LEN, EVENT_TYPE]):
            return
        content_type = self.headers["content-type"]
        content_len = int(self.headers["content-length"])
        event_type = self.headers["x-github-event"]

        if content_type != "application/json":
            self.send_error(400, "Bad Request", "Expected a JSON request")
            return

        data = self.rfile.read(content_len)
        if sys.version_info < (3, 6):
            data = data.decode()

        self.send_response(200)
        self.send_header("content-type", "text/html")
        self.end_headers()
        self.wfile.write(bytes("OK", "utf-8"))

        if irc is not None:
            events.handle_event(irc, event_type, json.loads(data))
コード例 #6
0
ファイル: running.py プロジェクト: immabird/Small-Games
import math
import sys

import pygame

import defaults as d
import events as e
import grid as g

# create the grid storage
d.grid = g.Grid()

while True:
    # handles event list
    for event in pygame.event.get():
        e.handle_event(event)

    # fills the background
    if d.clear_screen:
        d.screen.fill(d.background_color)

    # draws the grid
    if d.show_grid:
        d.grid.draw_grid()

    # draws the block in grid
    d.grid.draw_blocks()

    pygame.display.update()
    d.clock.tick(d.fps)