rot.js
rot.js copied to clipboard
Add support to limit the amount of text lines drawn.
I've added support to the drawText function to limit the amount of text lines drawn, as well as to skip the first X lines to draw.
This to add scrollable textboxes to my game. Example: http://daid.github.io/NightmareRL/ Press "L" to get a message log, you'll have to walk around a bit to fill it so it contains more lines then the screen. Then you can scroll the text with the up&down keys. The drawing code with this patch simply becomes: https://github.com/daid/NightmareRL/blob/gh-pages/dialog.js#L100
Sounds reasonable. The amount of arguments for ROT.Display.prototype.drawText
is getting too large for my likings, though. Would you mind refactoring the code so that the signature would be
ROT.Display.prototype.drawText = function(x, y, text, options) {
var opts = { maxWidth: null, maxLines: null, skipLines: 0 };
if (typeof(options) == "number") { options = {maxWidth:options}; } // backwards compatibility
for (var p in options) { opts[p] = options[p]; }
/// ... code as is now
}
?
This would also allow some potential space for future improvements of drawText
(although I am personally not using it at all, rendering paragraph text via regular HTML instead).