[pypy-svn] r28732 - in pypy/dist/pypy/translator/js/proxy: . testme testme/static/javascript testme/templates
ericvrp at codespeak.net
ericvrp at codespeak.net
Tue Jun 13 08:34:31 CEST 2006
Author: ericvrp
Date: Tue Jun 13 08:34:20 2006
New Revision: 28732
Modified:
pypy/dist/pypy/translator/js/proxy/dev.cfg
pypy/dist/pypy/translator/js/proxy/testme/servermessage.py
pypy/dist/pypy/translator/js/proxy/testme/static/javascript/bnb.js
pypy/dist/pypy/translator/js/proxy/testme/templates/bnb.kid
Log:
added more packet types and made tje javascript show the loaded pictures
Modified: pypy/dist/pypy/translator/js/proxy/dev.cfg
==============================================================================
--- pypy/dist/pypy/translator/js/proxy/dev.cfg (original)
+++ pypy/dist/pypy/translator/js/proxy/dev.cfg Tue Jun 13 08:34:20 2006
@@ -25,14 +25,14 @@
# SERVER
# Some server parameters that you may want to tweak
-# server.socketPort=8080
+server.socketPort=8080
# Disable the debug output at the end on pages.
# logDebugInfoFilter.on = False
-server.environment="development"
+server.environment="production" #"development"
autoreload.package="testme"
-autoreload.on = False
+#autoreload.on = False
sessionFilter.on = True
sessionFilter.storageType = "Ram"
Modified: pypy/dist/pypy/translator/js/proxy/testme/servermessage.py
==============================================================================
--- pypy/dist/pypy/translator/js/proxy/testme/servermessage.py (original)
+++ pypy/dist/pypy/translator/js/proxy/testme/servermessage.py Tue Jun 13 08:34:20 2006
@@ -15,10 +15,13 @@
#proxy messages
-PMSG_PING = "ping"
+PMSG_PING = "ping" #server wants to hear from client
+PMSG_PONG = "pong" #server responds to client's ping
PMSG_DEF_PLAYFIELD = "def_playfield"
PMSG_DEF_ICON = "def_icon"
+PMSG_PLAYER_ICON = "player_icon"
PMSG_PLAYER_JOIN = "player_join"
+PMSG_DEF_KEY = "def_key"
# convert server messages to proxy messages in json format
@@ -37,34 +40,18 @@
log("UNKNOWN MESSAGE:%s" % str(values))
return dict(type='unknown', values=values)
- #UNKNOWN MESSAGE:('k', 'right', 0, 0, 1, 2, 3) #def_key
- #UNKNOWN MESSAGE:('k', 'left', 1, 4, 5, 6, 7)
- #UNKNOWN MESSAGE:('k', 'jump', 2, 8, 9, 10, 11)
- #UNKNOWN MESSAGE:('k', 'fire', 3, 12, 13, 14, 15)
- #UNKNOWN MESSAGE:('k', '-right', 4)
- #UNKNOWN MESSAGE:('k', '-left', 5)
- #UNKNOWN MESSAGE:('k', '-jump', 6)
- #UNKNOWN MESSAGE:('k', '-fire', 7)
- #UNKNOWN MESSAGE:('i', 0, 16) #player_icon
- #UNKNOWN MESSAGE:('i', 1, 17)
- #UNKNOWN MESSAGE:('i', 2, 18)
- #UNKNOWN MESSAGE:('i', 3, 19)
- #UNKNOWN MESSAGE:('i', 4, 20)
- #UNKNOWN MESSAGE:('i', 5, 21)
- #UNKNOWN MESSAGE:('i', 6, 22)
- #UNKNOWN MESSAGE:('i', 7, 23)
- #UNKNOWN MESSAGE:('i', 8, 24)
- #UNKNOWN MESSAGE:('i', 9, 25)
- #UNKNOWN MESSAGE:('G',) #pong
-
#server message handlers...
def broadcast_port(self, *values):
log('MESSAGE (IGNORE):broadcast_port %s' % str(values))
- def ping(self):
- log('MESSAGE:ping')
+ def ping(self, *rest):
+ log('MESSAGE:ping udpsockcounter=%s' % rest)
return dict(type=PMSG_PING)
+ def pong(self):
+ log('MESSAGE:pong')
+ return dict(type=PMSG_PONG)
+
def def_playfield(self, width, height, backcolor, FnDesc):
log('MESSAGE:def_playfield width=%s, height=%s, backcolor=%s, FnDesc=%s' %\
(width, height, backcolor, FnDesc))
@@ -100,16 +87,40 @@
filename = 'static/images/icon%d.gif' % code
return dict(type=PMSG_DEF_ICON, code=code, filename=filename, width=w, height=h)
+ def player_icon(self, player_id, code):
+ log('MESSAGE:player_icon player_id=%d, code=%d' % (player_id, code))
+ return dict(type=PMSG_PLAYER_ICON, player_id=player_id, code=code)
+
def player_join(self, player_id, client_is_self):
log('MESSAGE:player_join player_id=%d, client_is_self=%d' % (player_id, client_is_self))
return dict(type=PMSG_PLAYER_JOIN, player_id=player_id, client_is_self=client_is_self)
-
+
+ #UNKNOWN MESSAGE:('k', 'right', 0, 0, 1, 2, 3) #def_key
+ #UNKNOWN MESSAGE:('k', 'left', 1, 4, 5, 6, 7)
+ #UNKNOWN MESSAGE:('k', 'jump', 2, 8, 9, 10, 11)
+ #UNKNOWN MESSAGE:('k', 'fire', 3, 12, 13, 14, 15)
+ #UNKNOWN MESSAGE:('k', '-right', 4)
+ #UNKNOWN MESSAGE:('k', '-left', 5)
+ #UNKNOWN MESSAGE:('k', '-jump', 6)
+ #UNKNOWN MESSAGE:('k', '-fire', 7)
+
+ def def_key(self, keyname, num, *rest):
+'''
+ for keyname, icolist, fn in game.FnKeys:
+ self.msgl.append(message(MSG_DEF_KEY, keyname, num,
+ *[ico.code for ico in icolist]))
+'''
+ return dict(type=PMSG_DEF_KEY)
+
MESSAGES = {
MSG_BROADCAST_PORT : broadcast_port,
MSG_PING : ping,
MSG_DEF_PLAYFIELD : def_playfield,
MSG_DEF_BITMAP : def_bitmap,
MSG_DEF_ICON : def_icon,
+ MSG_PLAYER_ICON : player_icon,
MSG_PLAYER_JOIN : player_join,
+ MSG_PONG : pong,
+ MSG_DEF_KEY : def_key,
}
Modified: pypy/dist/pypy/translator/js/proxy/testme/static/javascript/bnb.js
==============================================================================
--- pypy/dist/pypy/translator/js/proxy/testme/static/javascript/bnb.js (original)
+++ pypy/dist/pypy/translator/js/proxy/testme/static/javascript/bnb.js Tue Jun 13 08:34:20 2006
@@ -1,20 +1,42 @@
-//note: we assume Mochikit is already included
+function BnB() { //entrypoint to be called by body.onLoad
+ // init global data
+ playfield = DIV({'bgcolor':'red', 'width':42, 'height':42}); //updated with def_playfield
+ icon = {};
+ x = 0; y = 0; //for filling the playfield with loaded icons
+ doc = currentDocument();
+ body = doc.body;
+ sendToServer();
+}
+
+function BnBColorToHexString(c) {
+ var r = c; //XXX should do the correct masking here
+ var g = c;
+ var b = c;
+ return Color.fromRGB(r,g,b).toHexString();
+}
function sendToServer() { //XXX for now, just get (proxy) server data
loadJSONDoc('send').addCallback(
function (json_doc) {
- var messages = json_doc.messages;
- for (var i in messages) {
- var message = messages[i];
- var s = message.type;
- if (message.type == 'def_icon') { //code, filename, width, height
- s += ', filename=' + message.filename;
- }
- document.body.firstChild.nodeValue = s;
+ for (var i in json_doc.messages) {
+ var msg = json_doc.messages[i];
+ if (msg.type == 'def_playfield') { //XXX refactor to helper functions
+ var bgcolor = BnBColorToHexString(msg.backcolor);
+ updateNodeAttributes(playfield,
+ {'bgcolor':bgcolor, 'width':msg.width, 'height':msg.height});
+ replaceChildNodes(body, playfield);
+ body.setAttribute('bgcolor', bgcolor); //XXX hack!
+ } else if (msg.type == 'def_icon') {
+ if (!(msg.code in icon)) {
+ icon[msg.code] = new Image();
+ icon[msg.code].src = msg.filename
+ var img = IMG({'src':icon[msg.code].src,
+ 'width':msg.width, 'height':msg.height});
+ appendChildNodes(playfield, img);
+ }
+ }
}
- callLater(0.01, sendToServer); //again...
+ sendToServer();
}
);
}
-
-callLater(0.01, sendToServer);
Modified: pypy/dist/pypy/translator/js/proxy/testme/templates/bnb.kid
==============================================================================
--- pypy/dist/pypy/translator/js/proxy/testme/templates/bnb.kid (original)
+++ pypy/dist/pypy/translator/js/proxy/testme/templates/bnb.kid Tue Jun 13 08:34:20 2006
@@ -6,6 +6,6 @@
<title>
BnB - the game
</title>
- <body>
+ <body onLoad="BnB()">
</body>
</html>
More information about the Pypy-commit
mailing list