Bunch of improvements for entity / img support.

* Add export / import.
* Fix issue where entity attributes were being copied to other characters.
* Fix issue where consecutive identical entities were being collapsed into one.
* Misc. refactoring / cleanup.