/usr/share/games/castle-combat/scripts/config.py is in castle-combat 0.8.1.dfsg.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | from pygame.locals import *
conf = None
class Keys:
def __init__(self):
self.up = self.down = self.left = self.right = None
self.button = (None, None)
class PlayerConfig:
instances = []
def __init__(self, player_id):
self.keys = Keys()
if player_id == -1:
# dummy config
return
PlayerConfig.instances.append(self)
if player_id == 0:
self.keys.up = K_UP
self.keys.down = K_DOWN
self.keys.left = K_LEFT
self.keys.right = K_RIGHT
self.keys.button = [K_RETURN, K_RSHIFT]
elif player_id == 1:
self.keys.up = K_e
self.keys.down = K_d
self.keys.left = K_s
self.keys.right = K_f
self.keys.button = [K_a, K_q]
elif player_id == 2:
self.keys.up = K_KP8
self.keys.down = K_KP5
self.keys.left = K_KP4
self.keys.right = K_KP6
self.keys.button = [K_KP1, K_KP2]
elif player_id == 3:
self.keys.up = K_i
self.keys.down = K_k
self.keys.left = K_j
self.keys.right = K_l
self.keys.button = [K_h, K_y]
def assign():
i = 0
from game import game
for player in game.players:
if player.local:
print "assign config", i, "to player", player.player_id
config = PlayerConfig.instances[i]
i += 1
else:
config = PlayerConfig(-1)
player.set_config(config)
assign = staticmethod(assign)
class Config:
server = 'localhost'
total_players = 2
local_players = 2
ai_players = 1
fullscreen = True
sound = True
def open_config_file(mode):
import os
if os.name == 'posix':
file = open(os.path.join(os.getenv('HOME'), ".castle-combat.config"), mode)
else:
file = open("castle-combat.config", mode)
return file
def save():
conf.player_configs = PlayerConfig.instances
conf.version = 1
file = open_config_file('w')
import pickle
pickle.dump(conf, file)
def load():
global conf
try:
file = open_config_file('r')
import pickle
conf = pickle.load(file)
try:
if conf.version != 1:
raise Exception, "Unknown config file version."
except AttributeError:
print "Updating config file from alpha version"
PlayerConfig.instances = conf.player_configs
except IOError:
print "Could not load user's config file, loading defaults."
for i in range(4):
PlayerConfig(i)
conf = Config()
|