comparison src/parpg/systems/scriptingsystem.py @ 191:c97e48257f51

script commands are stored in the System now instead of the the script object.
author KarstenBock@gmx.net
date Sun, 13 Nov 2011 13:37:24 +0100
parents 61d158ce6bc3
children 191f89a22303
comparison
equal deleted inserted replaced
190:a22e92090018 191:c97e48257f51
15 from collections import deque 15 from collections import deque
16 16
17 class Script(object): 17 class Script(object):
18 """Script object""" 18 """Script object"""
19 19
20 def __init__(self, condition, actions, commands): 20 def __init__(self, condition, actions, system):
21 """Constructor""" 21 """Constructor"""
22 assert(isinstance(actions, deque)) 22 assert(isinstance(actions, deque))
23 self.condition = condition 23 self.condition = condition
24 self.actions = actions 24 self.actions = actions
25 self.commands = commands 25 self.system = system
26 self.running = False 26 self.running = False
27 self.finished = False 27 self.finished = False
28 self.time = 0 28 self.time = 0
29 self.wait = 0 29 self.wait = 0
30 self.cur_action = None 30 self.cur_action = None
43 self.cur_action = action[0] 43 self.cur_action = action[0]
44 self.wait = action[1] 44 self.wait = action[1]
45 if len(action) >= 3: 45 if len(action) >= 3:
46 vals = action[3:] if len(action) > 3 else () 46 vals = action[3:] if len(action) > 3 else ()
47 command = action[2] 47 command = action[2]
48 self.commands[command](*vals, action=self.cur_action) 48 self.system.commands[command](
49 *vals,
50 action=self.cur_action
51 )
49 else: 52 else:
50 self.cur_action.execute() 53 self.cur_action.execute()
51 except IndexError: 54 except IndexError:
52 self.finished = True 55 self.finished = True
53 self.running = False 56 self.running = False
57 """ 60 """
58 System responsible for managing scripts attached to entities to define 61 System responsible for managing scripts attached to entities to define
59 their behavior. 62 their behavior.
60 """ 63 """
61 64
62 def __init__(self, funcs): 65 def __init__(self, funcs, commands):
63 """Constructor""" 66 """Constructor"""
64 self.funcs = funcs 67 self.funcs = funcs
65 self.vals = {} 68 self.vals = {}
66 self.scripts = [] 69 self.scripts = []
70 self.commands = commands
67 71
68 def step(self, dt): 72 def step(self, dt):
69 """Execute a time step for the system. Must be defined 73 """Execute a time step for the system. Must be defined
70 by all system classes. 74 by all system classes.
71 75