comparison systems/scriptingsystem.py @ 161:d224bbce512a

Implemented loading scripts from files.
author KarstenBock@gmx.net
date Thu, 17 Nov 2011 20:36:08 +0100
parents 75c0b728ccf3
children ed24962cdf5e
comparison
equal deleted inserted replaced
160:75c0b728ccf3 161:d224bbce512a
80 80
81 def __init__(self, commands, actions): 81 def __init__(self, commands, actions):
82 """Constructor""" 82 """Constructor"""
83 self.funcs = {} 83 self.funcs = {}
84 self.vals = {} 84 self.vals = {}
85 self.scripts = {}
86 self.commands = commands 85 self.commands = commands
87 self.conditions = []
88 self.actions = actions 86 self.actions = actions
89 self.game_state = None 87 self.game_state = None
88 self.reset()
90 89
90 def reset(self):
91 """Resets the script and condition collections"""
92 self.scripts = {}
93 self.conditions = []
94
95
91 def step(self, dt): 96 def step(self, dt):
92 """Execute a time step for the system. Must be defined 97 """Execute a time step for the system. Must be defined
93 by all system classes. 98 by all system classes.
94 99
95 :param dt: Time since last step invocation 100 :param dt: Time since last step invocation
119 124
120 def setScript(self, name, actions): 125 def setScript(self, name, actions):
121 """Sets a script. 126 """Sets a script.
122 @param name: The name of the script 127 @param name: The name of the script
123 @param actions: What the script does 128 @param actions: What the script does
129 @type actions: deque or iterable
124 """ 130 """
131 if not(isinstance(actions, deque)):
132 actions = deque(actions)
125 self.scripts[name] = Script(actions, 133 self.scripts[name] = Script(actions,
126 self 134 self
127 ) 135 )
128 136
129 def addCondition(self, condition, script_name): 137 def addCondition(self, condition, script_name):