2007-08-22 07:52:33 +00:00
import sys , os
# genereate keys.h file
2008-09-25 14:04:02 +00:00
f = file ( " src/engine/e_keys.h " , " w " )
2007-08-22 07:52:33 +00:00
2008-10-23 16:18:33 +00:00
keynames = [ ]
2008-10-20 17:47:42 +00:00
for i in range ( 0 , 512 ) :
2008-10-23 16:18:33 +00:00
keynames + = [ " & %d " % i ]
2007-08-22 07:52:33 +00:00
print >> f , " #ifndef ENGINE_KEYS_H "
print >> f , " #define ENGINE_KEYS_H "
print >> f , ' /* AUTO GENERATED! DO NOT EDIT MANUALLY! */ '
print >> f , " enum "
print >> f , " { "
2008-10-20 17:47:42 +00:00
highestid = 0
for line in open ( " scripts/SDL_keysym.h " ) :
l = line . strip ( ) . split ( " = " )
if len ( l ) == 2 and " SDLK_ " in line :
key = l [ 0 ] . strip ( ) . replace ( " SDLK_ " , " KEY_ " )
value = int ( l [ 1 ] . split ( " , " ) [ 0 ] . strip ( ) )
print >> f , " \t %s = %d , " % ( key , value )
2008-10-23 16:18:33 +00:00
keynames [ value ] = key . replace ( " KEY_ " , " " ) . lower ( )
2008-10-20 17:47:42 +00:00
if value > highestid :
highestid = value
2008-10-23 16:18:33 +00:00
print >> f , " \t KEY_MOUSE_1 = %d , " % ( highestid + 1 ) ; keynames [ highestid + 1 ] = " mouse1 "
print >> f , " \t KEY_MOUSE_2 = %d , " % ( highestid + 2 ) ; keynames [ highestid + 2 ] = " mouse2 "
print >> f , " \t KEY_MOUSE_3 = %d , " % ( highestid + 3 ) ; keynames [ highestid + 3 ] = " mouse3 "
print >> f , " \t KEY_MOUSE_4 = %d , " % ( highestid + 4 ) ; keynames [ highestid + 4 ] = " mouse4 "
print >> f , " \t KEY_MOUSE_5 = %d , " % ( highestid + 5 ) ; keynames [ highestid + 5 ] = " mouse5 "
print >> f , " \t KEY_MOUSE_6 = %d , " % ( highestid + 6 ) ; keynames [ highestid + 6 ] = " mouse6 "
print >> f , " \t KEY_MOUSE_7 = %d , " % ( highestid + 7 ) ; keynames [ highestid + 7 ] = " mouse7 "
print >> f , " \t KEY_MOUSE_8 = %d , " % ( highestid + 8 ) ; keynames [ highestid + 8 ] = " mouse8 "
print >> f , " \t KEY_MOUSE_WHEEL_UP = %d , " % ( highestid + 9 ) ; keynames [ highestid + 9 ] = " mousewheelup "
print >> f , " \t KEY_MOUSE_WHEEL_DOWN = %d , " % ( highestid + 10 ) ; keynames [ highestid + 10 ] = " mousewheeldown "
2008-10-20 17:47:42 +00:00
print >> f , " \t KEY_LAST, "
2007-08-22 07:52:33 +00:00
print >> f , " }; "
print >> f , " "
print >> f , " #endif "
# generate keynames.c file
2008-09-25 14:04:02 +00:00
f = file ( " src/engine/e_keynames.c " , " w " )
2007-08-22 07:52:33 +00:00
print >> f , ' /* AUTO GENERATED! DO NOT EDIT MANUALLY! */ '
print >> f , ' '
print >> f , " #include <string.h> "
print >> f , " "
print >> f , " static const char key_strings[512][16] = "
print >> f , " { "
2008-10-23 16:18:33 +00:00
for n in keynames :
2008-10-20 17:47:42 +00:00
print >> f , ' \t " %s " , ' % n
2007-08-22 07:52:33 +00:00
print >> f , " }; "
print >> f , " "
print >> f , " const char *inp_key_name(int k) { if (k >= 0 && k < 512) return key_strings[k]; else return key_strings[0]; } "
print >> f , " int inp_key_code(const char *key_name) { int i; if (!strcmp(key_name, \" -?- \" )) return -1; else for (i = 0; i < 512; i++) if (!strcmp(key_strings[i], key_name)) return i; return -1; } "
print >> f , " "
f . close ( )