From aedf9f14f1cedb5e269148d9a98777cd82b03004 Mon Sep 17 00:00:00 2001 From: Andrii Kurdiumov Date: Sat, 20 Jun 2026 19:03:23 +0200 Subject: [PATCH] Fixes to make it work --- .gitignore | 2 ++ pixelflut/brain.py | 3 ++- pixelflut/pixelflut.py | 20 ++++++++++++++------ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index a674924..332fb82 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ pixelnuke/pixelnuke pixelwar/.* pixelwar/target +save/ +__pycache__/ diff --git a/pixelflut/brain.py b/pixelflut/brain.py index 027a128..bbd9db5 100644 --- a/pixelflut/brain.py +++ b/pixelflut/brain.py @@ -49,7 +49,7 @@ def on_connect(c, client): @on('KEYDOWN-c') def on_key_c(c): c.clear() - pixelflut.async(c.text, 5, 5, text, delay=0.1) + pixelflut.async2(c.text, 5, 5, text, delay=0.1) @on('KEYDOWN-s') def on_key_s(c): @@ -77,6 +77,7 @@ def on_text(canvas, client, x, y, *words): @on('COMMAND-SIZE') def on_size(canvas, client): client.send('SIZE %d %d' % canvas.get_size()) + #pass @on('COMMAND-QUIT') def on_quit(canvas, client): diff --git a/pixelflut/pixelflut.py b/pixelflut/pixelflut.py index caefe08..0ccb294 100755 --- a/pixelflut/pixelflut.py +++ b/pixelflut/pixelflut.py @@ -19,7 +19,7 @@ import os.path import logging log = logging.getLogger('pixelflut') -async = spawn +async2 = spawn class Client(object): pps = 1000 @@ -35,7 +35,8 @@ class Client(object): def send(self, line): with self.lock: if self.socket: - self.socket.sendall(line + '\n') + self.socket.sendall((line + '\n').encode()) + #self.socket.sendall(line) def nospam(self, line): self.send(line) @@ -75,12 +76,15 @@ class Client(object): class Canvas(object): size = 640, 480 - flags = pygame.RESIZABLE#|pygame.FULLSCREEN + flags = pygame.RESIZABLE|pygame.NOFRAME#|pygame.FULLSCREEN - def __init__(self): + def __init__(self,pos_x,pos_y): pygame.init() pygame.mixer.quit() self.set_title() + os.environ['SDL_VIDEO_WINDOW_POS'] = '%i,%i' % (pos_x,pos_y) + os.environ['SDL_VIDEO_CENTERED'] = '0' + self.screen = pygame.display.set_mode(self.size, self.flags) self.frames = 0 self.width = self.screen.get_width() @@ -192,6 +196,8 @@ class Canvas(object): def load_from(self, filename): img = pygame.image.load(filename).convert() self.screen.blit(img, (0,0)) + def move(self, x, y): + self.screen.move(x, y) def load_font(self, fname): ''' Load a font image with 16x16 sprites. ''' @@ -232,12 +238,14 @@ if __name__ == '__main__': help="specify hostname to run on") parser.add_option("-p", "--port", dest="portnum", default=1234, type="int", help="port number to run on") + parser.add_option("-x", "--delta-x", type="int", default=0) + parser.add_option("-y", "--delta-y", type="int", default=0) (options, args) = parser.parse_args() if len(args) != 1: parser.error("incorrect number of arguments") - canvas = Canvas() + canvas = Canvas(options.delta_x, options.delta_y) task = spawn(canvas.serve, options.hostname, options.portnum) brainfile = args[0] @@ -249,7 +257,7 @@ if __name__ == '__main__': canvas.fire('UNLOAD') canvas.events.clear() try: - execfile(brainfile, {'on':canvas.on, '__file__': brainfile}) + exec(open(brainfile).read(), {'on':canvas.on, '__file__': brainfile}) except: log.exception('Brain failed') continue