| Index: sky/sdk/example/game/lib/action.dart
|
| diff --git a/sky/sdk/example/game/lib/action.dart b/sky/sdk/example/game/lib/action.dart
|
| index 400bcd8b13dda63e1b84b1b01a66a540b89a1e7a..f0763c02c01bd09d23b335c1f60d7455d95d6dbd 100644
|
| --- a/sky/sdk/example/game/lib/action.dart
|
| +++ b/sky/sdk/example/game/lib/action.dart
|
| @@ -8,6 +8,8 @@ abstract class Action {
|
| void step(double dt);
|
| void update(double t) {
|
| }
|
| +
|
| + double get duration => 0.0;
|
| }
|
|
|
| abstract class ActionInterval extends Action {
|
| @@ -53,17 +55,93 @@ class ActionRepeat extends ActionInterval {
|
| }
|
| }
|
|
|
| -// TODO: Implement
|
| class ActionSequence extends ActionInterval {
|
| - final List<ActionInterval> actions;
|
| + Action _a;
|
| + Action _b;
|
| + double _split;
|
| +
|
| + ActionSequence(List<Action> actions) {
|
| + assert(actions.length >= 2);
|
| +
|
| + if (actions.length == 2) {
|
| + // Base case
|
| + _a = actions[0];
|
| + _b = actions[1];
|
| + } else {
|
| + _a = actions[0];
|
| + _b = new ActionSequence(actions.sublist(1));
|
| + }
|
| +
|
| + // Calculate split and duration
|
| + _duration = _a.duration + _b.duration;
|
| + if (_duration > 0) {
|
| + _split = _a.duration / _duration;
|
| + } else {
|
| + _split = 1.0;
|
| + }
|
| + }
|
|
|
| - ActionSequence(this.actions) {
|
| - for (Action action in actions) {
|
| - _duration += action._duration;
|
| + void update(double t) {
|
| + if (t < _split) {
|
| + // Play first action
|
| + double ta;
|
| + if (_split > 0.0) {
|
| + ta = (t / _split).clamp(0.0, 1.0);
|
| + } else {
|
| + ta = 1.0;
|
| + }
|
| + _a.update(ta);
|
| + } else if (t >= 1.0) {
|
| + // Make sure everything is finished
|
| + if (!_a._finished) _a.update(1.0);
|
| + if (!_b._finished) _b.update(1.0);
|
| + } else {
|
| + // Play second action, but first make sure the first has finished
|
| + if (!_a._finished) _a.update(1.0);
|
| + double tb;
|
| + if (_split < 1.0) {
|
| + tb = (1.0 - (1.0 - t) / (1.0 - _split)).clamp(0.0, 1.0);
|
| + } else {
|
| + tb = 1.0;
|
| + }
|
| + _b.update(tb);
|
| }
|
| }
|
| }
|
|
|
| +abstract class ActionInstant extends Action {
|
| +
|
| + void step(double dt) {
|
| + }
|
| +
|
| + void update(double t) {
|
| + fire();
|
| + _finished = true;
|
| + }
|
| +
|
| + void fire();
|
| +}
|
| +
|
| +class ActionCallFunction extends ActionInstant {
|
| + Function _function;
|
| +
|
| + ActionCallFunction(this._function);
|
| +
|
| + void fire() {
|
| + _function();
|
| + }
|
| +}
|
| +
|
| +class ActionRemoveFromParent extends ActionInstant {
|
| + Node _node;
|
| +
|
| + ActionRemoveFromParent(this._node);
|
| +
|
| + void fire() {
|
| + _node.removeFromParent();
|
| + }
|
| +}
|
| +
|
| class ActionRepeatForever extends Action {
|
| final ActionInterval action;
|
| double _elapsedInAction = 0.0;
|
| @@ -140,6 +218,7 @@ class ActionController {
|
| ActionController();
|
|
|
| void run(Action action) {
|
| + action.update(0.0);
|
| _actions.add(action);
|
| }
|
|
|
|
|