-
-
Save smoogipoo/e75eecd3dfad3470223dbb4638872922 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Transformable<T> | |
where T : Transformable<T> | |
{ | |
} | |
class TransformationContinuation<T> | |
where T : Transformable<T> | |
{ | |
T origin; | |
public TransformationContinuation(T origin) | |
{ | |
this.origin = origin; | |
} | |
public T Then() | |
{ | |
... // Delays? | |
return origin; | |
} | |
public TransformationContinuation<T> Then(Action action) | |
{ | |
... // Do something with action | |
return new TransformationContinuation<T>(origin); | |
} | |
public static implicit operator T(TransformationContinuation<T> continuation) => T; | |
} | |
class Drawable : Transformable<Drawable> | |
{ | |
public TransformationContinuation<Drawable> ScaleTo() | |
{ | |
... | |
return new TransformationContinuation<Drawable>(this); | |
} | |
public TransformationContinuation<Drawable> RotateTo() | |
{ | |
... | |
return new TransformationContinuation<Drawable>(this); | |
} | |
} | |
class Sprite : Drawable { } | |
usage: | |
1: | |
Drawable d; | |
d.ScaleTo().Then().RotateTo(); | |
2: | |
Drawable d; | |
d.ScaleTo().Then().RotateTo().ScaleTo().Then().ScaleTo(); | |
3: | |
Drawable d; | |
Sprite s; | |
d.ScaleTo().Then(_ => s.Alpha = 5).ScaleTo().Then().ScaleTo(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment