nanim icon indicating copy to clipboard operation
nanim copied to clipboard

Templetize Simple Tweens using Nim's Templates/Macros

Open EriKWDev opened this issue 3 years ago • 1 comments

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 avatar Apr 03 '21 08:04 EriKWDev

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.

EriKWDev avatar Oct 16 '21 11:10 EriKWDev