Skip to content

Commit

Permalink
Transitioning out when reverse is enabled in an incrementing effect c…
Browse files Browse the repository at this point in the history
…an now go at a different rate than coming in
  • Loading branch information
erodozer committed Jul 15, 2011
1 parent 9438a1e commit 3d7e5fe
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions src/Rockmeter.py
Expand Up @@ -434,34 +434,46 @@ def __init__(self, layer, section):
self.current = [] #the current value

#rate at which values will increment between start and end
self.rates = []
self.inRates = [] #incoming rates
self.outRates = [] #outgoing rates (if reverse is enabled)

#catches flickering between 2 values
self.counter = 0
self.countRate = 0

#how long it takes for the transition to take place
self.transitionTime = 512.0
self.transitionTimeOut = 512.0

#gets the rate at which time is passing, usable in finding the rates of things in
#terms of milliseconds instead of frames
def getTime(self):
t = self.transitionTime * (max(self.engine.clock.get_fps(), _minFPS)) / 1000.0
self.countRate = 1.0/t
return t
def getTime(self, time):
t = time * (max(self.engine.clock.get_fps(), _minFPS)) / 1000.0
self.countRate = 1.0/max(t, 1.0)
return max(t, 1.0)

#updates the rates at which values between start and end should change to reach
# the desired point
def updateRates(self):
try:
t = self.getTime()
t = self.getTime(self.transitionTime)
for i in range(len(self.start)):
if self.end[i] < self.start[i]:
self.rates[i] = (self.start[i] - self.end[i])/t
self.inRates[i] = (self.start[i] - self.end[i])/t
else:
self.rates[i] = (self.end[i] - self.start[i])/t
self.inRates[i] = (self.end[i] - self.start[i])/t
if self.reverse and not bool(eval(self.condition)):
t = self.getTime(self.transitionTimeOut)
for i in range(len(self.start)):
if self.end[i] < self.start[i]:
self.outRates[i] = (self.start[i] - self.end[i])/t
else:
self.outRates[i] = (self.end[i] - self.start[i])/t
except:
self.rates = [0 for i in range(len(self.start))]
#catches if rates have been declared or if they're proper size
# then tries updating them again now that they're proper
self.inRates = [0 for i in range(len(self.start))]
self.outRates = self.inRates[:]
self.updateRates()

#updates the values with the rates and returns the current saved value
Expand All @@ -472,12 +484,12 @@ def updateValues(self):
for i in range(len(self.start)):
if self.current[i] > self.end[i]:
if self.end[i] < self.start[i]:
self.current[i] -= self.rates[i]
self.current[i] -= self.inRates[i]
else:
self.current[i] = self.end[i]
elif self.current[i] < self.end[i]:
if self.end[i] > self.start[i]:
self.current[i] += self.rates[i]
self.current[i] += self.inRates[i]
else:
self.current[i] = self.end[i]
if self.counter >= self.transitionTime:
Expand All @@ -488,12 +500,12 @@ def updateValues(self):
for i in range(len(self.start)):
if self.current[i] > self.start[i]:
if self.end[i] > self.start[i]:
self.current[i] -= self.rates[i]
self.current[i] -= self.outRates[i]
else:
self.current[i] = self.start[i]
elif self.current[i] < self.start[i]:
if self.end[i] < self.start[i]:
self.current[i] += self.rates[i]
self.current[i] += self.outRates[i]
else:
self.current[i] = self.start[i]
if self.counter <= 0.0:
Expand Down Expand Up @@ -579,7 +591,8 @@ def __init__(self, layer, section):
self.reverse = bool(eval(self.getexpr("reverse", "True")))
self.condition = self.getexpr("condition", "True")
self.transitionTime = self.get("transitionTime", float, 512.0)

self.transitionTimeOut = self.get("transitionTimeOut", float, self.transitionTime)

def updateValues(self):
#reverse the processing for font layer handling
if isinstance(self.layer, FontLayer):
Expand Down Expand Up @@ -615,6 +628,7 @@ def __init__(self, layer, section):
self.inPixels = self.get("inPixels", str, "").split("|") #variables in terms of pixels

self.transitionTime = self.get("transitionTime", float, 512.0)
self.transitionTimeOut = self.get("transitionTimeOut", float, self.transitionTime)
self.condition = self.getexpr("condition", "True")
self.reverse = bool(eval(self.getexpr("reverse", "True")))

Expand Down Expand Up @@ -678,6 +692,7 @@ def __init__(self, layer, section):
self.current = self.start[:]

self.transitionTime = self.get("transitionTime", float, 512.0)
self.transitionTimeOut = self.get("transitionTimeOut", float, self.transitionTime)
self.condition = self.getexpr("condition", "True")
self.reverse = bool(eval(self.getexpr("reverse", "True")))

Expand Down

0 comments on commit 3d7e5fe

Please sign in to comment.