Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templetize Simple Tweens using Nim's Templates/Macros #2

Open
EriKWDev opened this issue Apr 3, 2021 · 1 comment
Open

Templetize Simple Tweens using Nim's Templates/Macros #2

EriKWDev opened this issue Apr 3, 2021 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers Hacktoberfest help wanted Extra attention is needed

Comments

@EriKWDev
Copy link
Owner

EriKWDev commented Apr 3, 2021

I tried doing a simpleSingleValueTween template here, but when I did some testing later it seemed like it really didn't work as I expected. Currently, a lot of tweens follow a very copy-paste-ey pattern which seems ideal for a template, but I currently don't know enough about the system to get it to work.

Anyone with more experience in Nim or time to get it to function properly are welcome to Fix the issue :)

This is what my attempt looked like:

template simpleSingleValueTween*(target: typed, startValue: typed, endValue: typed, valueName: untyped) =
  var interpolators: seq[proc(t: float)]

  let interpolator = proc(t: float) =
    target.valueName = interpolate(startValue, endValue, t)

  interpolators.add(interpolator)

  target.valueName = endValue

  result = newTween(interpolators)

but it seemed like the untyped valueName didn't quite work. It would also be nice to support multiple valueNames in a vararg[untyped] kind-of way, but that would require a macro.

@EriKWDev EriKWDev added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Apr 6, 2021
@EriKWDev
Copy link
Owner Author

The relevant file in the project is src/nanim/animation/animations.nim (https://github.com/EriKWDev/nanim/blob/fea656276374bbbb673b87245f0503f56fe707ec/src/nanim/animation/animations.nim)

All those animations are very copy-paste-y and would benefit enormously from template or macro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers Hacktoberfest help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant