Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Commit

Permalink
finalized fadeClass. Implement ParMode class as potential argument fo…
Browse files Browse the repository at this point in the history
…r mode.
  • Loading branch information
AlphaMoonbaseBerlin committed Sep 22, 2022
1 parent 91382e7 commit 9c7ebd6
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 27 deletions.
Binary file modified Project.toe
Binary file not shown.
40 changes: 24 additions & 16 deletions modules/project/tweener/extTweener.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,39 @@
Name : extTweener
Author : Alpha Moonbase
Version : 0
Build : 10
Savetimestamp : 1660063257
Build : 12
Savetimestamp : 1663849167
Saveorigin : Project.toe
Saveversion : 2021.16410
Saveversion : 2022.28040
Info Header End'''

import fade
import tween_value

from typing import Union, Hashable


_type = type

class extTweener:

def __init__(self, ownerComp):
# The component to which this extension is attached
self.ownerComp = ownerComp
self.fades:dict = {}
self.Tweens:dict = {}

self.Exceptions = mod.tweener_exceptions

self.delay_script = "me.CreateTween( args[0], args[1], args[2], type = args[3], curve = args[4], id = args[5], mode = args[6], expression = args[7], delay = 0)"
self.callback = self.ownerComp.op('callbackManager')

def getFadeId(self, par):
return hash(par)

def FadeStep(self, step_in_ms = None):
fadesCopy = self.fades.copy()
fadesCopy = self.Tweens.copy()
for fade_id, tween_object in fadesCopy.items():
tween_object.Step(step_in_ms)
if tween_object.done: del self.fades[ fade_id ]
if tween_object.done: del self.Tweens[ fade_id ]


def AbsoluteTweens(self, list_of_tweens, curve = "s", time=1):
Expand Down Expand Up @@ -65,29 +67,35 @@ def RelativeTween(self, par, end, speed, curve = 's', delay = 0):
self.CreateTween(par, end, time, curve = curve, delay = delay)
return

def CreateTween(self,parameter, end:float, time:float, type:str = 'fade', curve:str = 's', id = '', mode = 'CONSTANT', expression = None, delay = 0):
def CreateTween(self,parameter,
end:float,
time:float,
type:str = 'fade',
curve:str = 's',
id:Hashable = '',
mode:Union[str, ParMode] = 'CONSTANT',
expression:str = None,
delay:float = 0.0):
if not isinstance( parameter, Par):
raise self.Exceptions.TargetIsNotParameter(f"Invalid Parameterobject {parameter}")

target_value = tween_value.tween_value_from_arguments( parameter, mode, expression, end )
start_value = tween_value.tween_value_from_parameter( parameter )

fade_class:fade.tween = getattr( fade, type, fade.startsnap )
debug("Creating fade for parameter", parameter)
debug("Got fade_class", fade_class)
fade_object = fade_class( parameter, time, start_value, target_value, interpolation = curve)
fade_object = fade_class( parameter, time, start_value, target_value, interpolation = curve)
fade_object.Delay( delay )
self.fades[self.getFadeId( parameter )] = fade_object
self.Tweens[id or self.getFadeId( parameter )] = fade_object


def StopFade(self,par):
del self.fades[self.getFadeId(par)]
del self.Tweens[self.getFadeId(par)]

def StopAllFades(self):
self.fades = {}
self.Tweens = {}

def ClearFades(self):
self.fades.clear()
self.Tweens.clear()

def PrintFades(self):
print(self.fades)
print(self.Tweens)
10 changes: 5 additions & 5 deletions modules/project/tweener/fade.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
Name : fade
Author : Alpha Moonbase
Version : 0
Build : 12
Savetimestamp : 1660059262
Build : 13
Savetimestamp : 1663850219
Saveorigin : Project.toe
Saveversion : 2021.16410
Saveversion : 2022.28040
Info Header End'''
import tween_value
import td, math
from dataclasses import dataclass

curves = op("curves")


@dataclass
class tween:
Expand Down Expand Up @@ -44,7 +44,7 @@ class fade( tween ):

def Step(self, stepsize = None):
self.increment_step(stepsize)

curves = op("curves_repo").Repo
curve_value = curves.GetValue( self.current_step, self.time, self.interpolation )
start_evaluated = self.start_value.eval()
target_evaluated = self.target_value.eval()
Expand Down
25 changes: 19 additions & 6 deletions modules/project/tweener/tween_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
Name : tween_value
Author : Alpha Moonbase
Version : 0
Build : 10
Savetimestamp : 1660064238
Build : 12
Savetimestamp : 1663849707
Saveorigin : Project.toe
Saveversion : 2021.16410
Saveversion : 2022.28040
Info Header End'''

import td
from functools import lru_cache
import tweener_exceptions
from typing import Union

class tween_value:
def eval(self):
pass
Expand All @@ -18,13 +22,14 @@ def assign_to_par(self, parameter):

class expression_value( tween_value ):
def __init__(self, parameter, expression_string):
self.expression_string = expression_string
self.expression_function = lambda : parameter.owner.evalExpression( expression_string )

def eval(self):
return self.expression_function()

def assign_to_par(self, parameter):
parameter.mode = "EXPRESSION"
parameter.mode = ParMode.EXPRESSION
parameter.expr = self.expression_string


Expand All @@ -38,11 +43,19 @@ def eval(self):
def assign_to_par(self, parameter):
parameter.val = self.eval()

par_modes = [parmode.name.upper() for parmode in ParMode._value2member_map_.values()]

@lru_cache(None)
def stringify_parmode( mode ):
if isinstance(mode, ParMode): return mode.name.upper()
if isinstance(mode, str) and mode.upper() in par_modes: return mode.upper()
raise tweener_exceptions.InvalidParMode

def tween_value_from_parameter( parameter:td.Par ):
if parameter.mode.name =="EXPRESSION": return expression_value( parameter, parameter.expr )
return static_value( parameter, parameter.eval() )

def tween_value_from_arguments( parameter:td.Par, mode:str, expression:str, value:any):
if mode.upper() =="EXPRESSION" and expression: return expression_value( parameter, expression )
def tween_value_from_arguments( parameter:td.Par, mode:Union[str, ParMode], expression:str, value:any):
if stringify_parmode(mode) =="EXPRESSION" and expression: return expression_value( parameter, expression )
return static_value( parameter, value )

Binary file added modules/release/tweener.tox
Binary file not shown.
Binary file added modules/suspects/project/tweener.tox
Binary file not shown.
Binary file added modules/suspects/project/tweener/curves.tox
Binary file not shown.

0 comments on commit 9c7ebd6

Please sign in to comment.