ondras / rot.js

ROguelike Toolkit in JavaScript. Cool dungeon-related stuff, interactive manual, documentation, tests!
https://ondras.github.io/rot.js/hp/
BSD 3-Clause "New" or "Revised" License
2.33k stars 255 forks source link

Implement drawOver capability #192

Closed Slogo closed 3 years ago

Slogo commented 3 years ago

Implements a drawOver function within the Display class that will accept partial ch/fg/bg values and draw only the provided values "over" any existing draw information.

The use case for this is being able to draw a game state in a way similar to this for efficiency:

tiles.forEach(tile => display.draw(tile.x, tile.y, tile.ch, tile.fg, tile.bg));
entities.forEach(entity => display.drawOver(tile.x, tile.y, tile.ch, tile.fg, null));

So as a result you can draw an entity (like the player) on the map while preserving the map background and without having to do a lookup of what the background color is. Similarly if you are doing cloud or particle effects you can draw those over the map and entities without having to reach out to other data structures to look at what else should be in that same tile.

Slogo commented 3 years ago

@ondras I am not sure what the PR process here is regarding the build files. I have run make for this pull request which is why there are so many changes to the docs. I can submit the same PR without running make to keep the changes limited to just the adjusted files if that's preferable.

ondras commented 3 years ago

Hi @Slogo,

thanks for the PR! I think this feature makes sense so I'm gonna merge it. There is no explicit PR policy, but I would run make myself, so I suppose this is perfectly okay.