X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=new%2Fplomrogue%2Fmisc.py;h=93be672eea7f9acadb7c233c6a9b717a1e7cc550;hb=6121e33c4b9fc86ced316406143195fdd3af7a00;hp=2b8f762c3e7aec665cbc0bba6f284ac879f410f5;hpb=9317e573f0b65269172e762717567051027f9369;p=plomrogue2-experiments diff --git a/new/plomrogue/misc.py b/new/plomrogue/misc.py index 2b8f762..93be672 100755 --- a/new/plomrogue/misc.py +++ b/new/plomrogue/misc.py @@ -841,7 +841,12 @@ class Game: self.send_gamestate() def get_command(self, command_name): - from functools import partial + + def partial_with_attrs(f, *args, **kwargs): + from functools import partial + p = partial(f, *args, **kwargs) + p.__dict__.update(f.__dict__) + return p def cmd_TASK_colon(task_name, game, *args): game.world.get_player().set_task(task_name, args) @@ -860,7 +865,7 @@ class Game: if command_name[:len(task_prefix)] == task_prefix: task_name = command_name[len(task_prefix):] if task_name in self.tasks: - f = partial(task_command, task_name, self) + f = partial_with_attrs(task_command, task_name, self) task = self.tasks[task_name] if argtypes_prefix: f.argtypes = argtypes_prefix + ' ' + task.argtypes @@ -877,9 +882,7 @@ class Game: if command: return command if command_name in self.commands: - f = partial(self.commands[command_name], self) - if hasattr(self.commands[command_name], 'argtypes'): - f.argtypes = self.commands[command_name].argtypes + f = partial_with_attrs(self.commands[command_name], self) return f return None @@ -900,27 +903,3 @@ def quote(string): def stringify_yx(tuple_): """Transform tuple (y,x) into string 'Y:'+str(y)+',X:'+str(x).""" return 'Y:' + str(tuple_[0]) + ',X:' + str(tuple_[1]) - - - -if __name__ == "__main__": - import sys - import os - if len(sys.argv) != 2: - print('wrong number of arguments, expected one (game file)') - exit(1) - game_file_name = sys.argv[1] - game = Game(game_file_name) - if os.path.exists(game_file_name): - if not os.path.isfile(game_file_name): - print('game file name does not refer to a valid game file') - else: - with open(game_file_name, 'r') as f: - lines = f.readlines() - for i in range(len(lines)): - line = lines[i] - print("FILE INPUT LINE %5s: %s" % (i, line), end='') - game.io.handle_input(line, store=False) - else: - game.io.handle_input('GEN_WORLD Y:16,X:16 bar') - game.io.run_loop_with_server()