1 | #!/usr/bin/env python |
---|
2 | # -*- coding: utf-8 -*- |
---|
3 | # |
---|
4 | # Puzzlebox - Brainstorms - Client Interface - Pygame - Local |
---|
5 | # |
---|
6 | # Copyright Puzzlebox Productions, LLC (2010) |
---|
7 | # |
---|
8 | # This code is released under the GNU Pulic License (GPL) version 2 |
---|
9 | # For more information please refer to http://www.gnu.org/copyleft/gpl.html |
---|
10 | # |
---|
11 | # Last Update: 2010.06.28 |
---|
12 | # |
---|
13 | ##################################################################### |
---|
14 | |
---|
15 | import os, sys |
---|
16 | |
---|
17 | import pygame |
---|
18 | #import pygame.font |
---|
19 | import pygame.image |
---|
20 | import pygame.locals |
---|
21 | |
---|
22 | from twisted.internet import reactor, protocol, defer |
---|
23 | |
---|
24 | import puzzlebox_brainstorms_configuration as configuration |
---|
25 | import puzzlebox_brainstorms_client_interface_pygame as client_interface |
---|
26 | import puzzlebox_brainstorms_network_server_twisted as server |
---|
27 | #import puzzlebox_logger |
---|
28 | |
---|
29 | ##################################################################### |
---|
30 | # Globals |
---|
31 | ##################################################################### |
---|
32 | |
---|
33 | DEBUG = 1 |
---|
34 | |
---|
35 | SERVER_INTERFACE = configuration.BRAINSTORMS_SERVER_INTERFACE |
---|
36 | SERVER_HOST = configuration.BRAINSTORMS_SERVER_HOST |
---|
37 | SERVER_PORT = configuration.BRAINSTORMS_SERVER_PORT |
---|
38 | |
---|
39 | DISPLAY_WINDOW_X_COORDINATE = configuration.CLIENT_PYGAME_DISPLAY_WINDOW_X_COORDINATE |
---|
40 | DISPLAY_WINDOW_Y_COORDINATE = configuration.CLIENT_PYGAME_DISPLAY_WINDOW_Y_COORDINATE |
---|
41 | DISPLAY_WINDOW_X_DIMENSION = configuration.CLIENT_PYGAME_DISPLAY_WINDOW_X_DIMENSION |
---|
42 | DISPLAY_WINDOW_Y_DIMENSION = configuration.CLIENT_PYGAME_DISPLAY_WINDOW_Y_DIMENSION |
---|
43 | |
---|
44 | WINDOW_BACKGROUND_COLOR = configuration.CLIENT_PYGAME_WINDOW_BACKGROUND_COLOR |
---|
45 | |
---|
46 | ##################################################################### |
---|
47 | # Classes |
---|
48 | ##################################################################### |
---|
49 | |
---|
50 | ##################################################################### |
---|
51 | # Functions |
---|
52 | ##################################################################### |
---|
53 | |
---|
54 | ##################################################################### |
---|
55 | # Main |
---|
56 | ##################################################################### |
---|
57 | |
---|
58 | if __name__ == '__main__': |
---|
59 | |
---|
60 | #log = puzzlebox_logger.puzzlebox_logger(logfile='puzzlebox') |
---|
61 | log = None |
---|
62 | |
---|
63 | |
---|
64 | # Collect default settings and command line parameters |
---|
65 | server_interface = SERVER_INTERFACE |
---|
66 | server_host = SERVER_HOST |
---|
67 | server_port = SERVER_PORT |
---|
68 | display_window_x_coordinate = DISPLAY_WINDOW_X_COORDINATE |
---|
69 | display_window_y_coordinate = DISPLAY_WINDOW_Y_COORDINATE |
---|
70 | display_window_x_dimension = DISPLAY_WINDOW_X_DIMENSION |
---|
71 | display_window_y_dimension = DISPLAY_WINDOW_Y_DIMENSION |
---|
72 | window_background_color = WINDOW_BACKGROUND_COLOR |
---|
73 | |
---|
74 | |
---|
75 | for each in sys.argv: |
---|
76 | |
---|
77 | if each.startswith("--interface="): |
---|
78 | server_interface = each[ len("--interface="): ] |
---|
79 | if each.startswith("--host="): |
---|
80 | server_host = each[ len("--host="): ] |
---|
81 | if each.startswith("--port="): |
---|
82 | server_port = each[ len("--port="): ] |
---|
83 | |
---|
84 | |
---|
85 | # Window Defaults |
---|
86 | try: |
---|
87 | display_window_x_coordinate = string.atoi(sys.argv[-4]) |
---|
88 | display_window_y_coordinate = string.atoi(sys.argv[-3]) |
---|
89 | display_window_x_dimension = string.atoi(sys.argv[-2]) |
---|
90 | display_window_y_dimension = string.atoi(sys.argv[-1]) |
---|
91 | except: |
---|
92 | if DEBUG > 1: |
---|
93 | print "Using default display coordinates" |
---|
94 | |
---|
95 | |
---|
96 | embedded_server = server.puzzlebox_brainstorms_network_server_twisted(log, DEBUG=DEBUG) |
---|
97 | |
---|
98 | if DEBUG: |
---|
99 | print "--> [Server] Initializing server on %s:%i" % \ |
---|
100 | (server_interface, server_port) |
---|
101 | |
---|
102 | reactor.listenTCP(interface=server_interface, port=server_port, factory=embedded_server) |
---|
103 | |
---|
104 | |
---|
105 | interface = client_interface.puzzlebox_brainstorms_client_interface_pygame( \ |
---|
106 | log, \ |
---|
107 | display_window_x_coordinate, \ |
---|
108 | display_window_y_coordinate, \ |
---|
109 | display_window_x_dimension, \ |
---|
110 | display_window_y_dimension, \ |
---|
111 | window_background_color, \ |
---|
112 | DEBUG=DEBUG) |
---|
113 | |
---|
114 | reactor.callWhenRunning(interface.check_events) |
---|
115 | |
---|
116 | |
---|
117 | reactor.run() |
---|
118 | |
---|