Skip to content

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

@EriKWDev

Description

@EriKWDev

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions