class_name Motion ## The animation language (gameplay-plan.md §B6): things rush in, hold or drift slowly, then rush ## out. Every animation in the game takes its timing from here, so the speed setting (and the ## tests' instant switch, Card3D.instant) reach all of them. ## Multiplies every duration; 0 is instant. Set from the animation-speed setting. static var speed_scale := 1.0 static func instant() -> bool: return speed_scale <= 0.0 or Card3D.instant ## `t` seconds at the current speed. static func secs(t: float) -> float: return 0.0 if instant() else t * speed_scale ## Rush to `to`: a fast start and a soft landing. static func rush_in(tw: Tween, obj: Object, prop: NodePath, to: Variant, t: float) -> PropertyTweener: return tw.tween_property(obj, prop, to, secs(t)).set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_OUT) ## Drift slowly to `to`, easing at both ends: the hold between two rushes. static func drift(tw: Tween, obj: Object, prop: NodePath, to: Variant, t: float) -> PropertyTweener: return tw.tween_property(obj, prop, to, secs(t)).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN_OUT) ## Rush away to `to`: a slow start that snaps at the end. static func rush_out(tw: Tween, obj: Object, prop: NodePath, to: Variant, t: float) -> PropertyTweener: return tw.tween_property(obj, prop, to, secs(t)).set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_IN) ## The whole curve on one property: rush to `hold_a`, drift to `hold_b`, rush out to `to`. static func rush_hold_rush(tw: Tween, obj: Object, prop: NodePath, hold_a: Variant, hold_b: Variant, to: Variant, t_in := 0.18, t_hold := 0.45, t_out := 0.16) -> void: rush_in(tw, obj, prop, hold_a, t_in) drift(tw, obj, prop, hold_b, t_hold) rush_out(tw, obj, prop, to, t_out) ## The curve as a function, for things driven by hand (shaders, pop-ups): progress `u` (0–1) of an ## animation whose middle `hold` share is the drift. Returns how far along the path it is (0–1): ## it covers `reach` of the way during the rush in, and the rest in the rush out. static func curve(u: float, hold := 0.5, reach := 0.86) -> float: u = clampf(u, 0.0, 1.0) var a := (1.0 - hold) / 2.0 if u < a: var k := u / a return reach * (1.0 - pow(2.0, -10.0 * k)) / (1.0 - pow(2.0, -10.0)) if u < a + hold: var k := (u - a) / hold return reach + (1.0 - reach) * 0.25 * (0.5 - 0.5 * cos(PI * k)) var k := (u - a - hold) / a var from := reach + (1.0 - reach) * 0.25 return from + (1.0 - from) * pow(2.0, 10.0 * (k - 1.0)) ## How strong a streak behind something moving on the curve should be at progress `u`: high in ## the rushes, low in the hold. static func streak(u: float, hold := 0.5) -> float: u = clampf(u, 0.0, 1.0) var a := (1.0 - hold) / 2.0 if u < a: return 1.0 - u / a * 0.6 if u < a + hold: return 0.15 return 0.4 + 0.6 * (u - a - hold) / a