paulofmandown / rotLove

Roguelike Toolkit in Love. A Love2D/lua port of rot.js
http://paulofmandown.github.io/rotLove/
Other
258 stars 25 forks source link

Add text module and tests #38

Closed airstruck closed 7 years ago

airstruck commented 7 years ago

Can be used by display classes to fix issue #22.

More or less a direct port. Only API difference is Text:measure returns height and width as two separate values instead of a table (more Lua-esque, more efficient, and the function's never used internally).

Again, uses colon instead of dot syntax for calling functions (which are all static; this shouldn't be instantiated). Might be better if Text and Color module used dot notation to look more like functions in a namespace and less like singleton objects. Thoughts?

paulofmandown commented 7 years ago

Might be better if Text and Color module used dot notation to look more like functions in a namespace and less like singleton objects. Thoughts?

I agree. Your argument for that makes a lot of sense

timothymtorres commented 7 years ago

This is a good idea. I actually do this with with the dice module. Functions that are to be used with the instance or metamethods get the colon operator where regular functions just get the dot.

airstruck commented 7 years ago

Dot notation should work fine for Color and Text. The RNG still needs to keep the colon, because it's really an instance of a class, which can be cloned, so it needs to work as a prototype for other instances... even if 99% of the time you only ever use the provided instance.

Color and Text don't need to be like that, they're basically namespaces full of static functions, and there are no associated instance objects, but maybe that distinction's not immediately obvious.

Maybe just a documentation issue; would need to be clear about what RNG is (a stateful object, like a singleton) vs. what Color and Text would be (stateless namespaces full of functions).

airstruck commented 7 years ago

Made Text static, this PR should be good to go. Will handle Color in a separate PR unless someone gets to it first.