Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map editor cannot save to xml #271

Open
dangillet opened this issue Jun 15, 2016 · 1 comment
Open

Map editor cannot save to xml #271

dangillet opened this issue Jun 15, 2016 · 1 comment
Labels

Comments

@dangillet
Copy link
Contributor

It was found out that the map editor found in tools\editor.py cannot save correctly to xml a map if the xml contains other elements than rectmap. A workaround was to include such elements using the requires tag.

dangillet added a commit that referenced this issue Jun 15, 2016
Refactored Resource into 2 classes : XMLResource and TMXResource.
Start some unit testing to help in refactoring.
@dangillet
Copy link
Contributor Author

I propose a temporary solution working towards a better implementation. See my branch https://github.com/los-cocos/cocos/tree/tile_editor

Digging in the problem raised many questions. Do we want to be able to load a .tmx file and be able to save it to *.xml ? It's quite a challenge to do so. Do we want to be able to change the resource in any way we can think of and still be able to save as XML representation ?

At the moment, the editor sole purpose is to edit the RectMapLayer. We add or remove Tiles in the map. The RectMapLayer can save itself correctly to xml. So I decided to only update the rectmap tag in the original xml file with whatever RectMapLayer._as_xml method is providing. Any other tags like tileset, image, imagealtas, ... are left unchanged.

I have also changed a bit the way the code was structured. I found it strange that the load_tiles function would instantiate a Resource object but then parse itself the XML file to give it to the Resource file. I thought all this logic should go in the Resource class. Recognizing that there are difference behaviours between XML and TMX files, I decided to make an Abstract Base Class Resource and derive two classes XMLResource and TMXresource to implement the different behaviours.

I've made some unit tests while I was making the changes. See file utest/test_p_resource_tiles.py. As per naming convention, I used the _p_ to show that those unit tests are to be used with py.test. They are certainly not exhaustive, but helped me during the refactoring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants