AdamsLair / duality

a 2D Game Development Framework
https://adamslair.github.io/duality
MIT License
1.41k stars 290 forks source link

Parse math expression in textboxes #429

Open ChristianGreiner opened 7 years ago

ChristianGreiner commented 7 years ago

I would find it useful if you could perform calculation in text-fields in the editor.

For example: You want to center an image on the x-coordinate:
Just type in the textbox "423/2" and the result (211,5) gets stored in the property.

SirePi commented 7 years ago

Even better, have some (even hardcoded) variables that allow dynamic evaluation such as WindowWidth, WindowHeight, etc..

But I think this would require an extensive rewrite of the property

ilexp commented 7 years ago

Thought about this for a bit and I'm skeptical, because

If we limit it to pure math, i.e. only numbers and (add / subtract / multiply / divide / power) then the above points do not apply, but even then we would need to clearly define scope.

As far as I'm concerned I'd keep the scope as small as possible for maintenance reasons and make sure all of the code is in a static class that takes a string and returns a float - consciously limiting the system to simple math only, starting with the API choice.

One more thing to consider is whether we really want to open that topic, as every feature has the potential to raise new and more expectations. And this one could mean a lot of added complexity, so if we do it, we need to somehow make sure it doesn't raise the kind of expectation that would make this an open-ended topic.