Various bug fixes

Most important bugfixes have to do with tilesets. The new feature that
paints nonexistent tiles wasn't working properly. A similar bug also
affected the Level Diagnostics Tool.