Editing costume: svg costume cannot be changed to bitmap

Having an svg costume it is not possible to convert it to a bitmap by editing it. When closing the Paint Editor after converting the costume to a bitmap, the costume is not changed. However the sprite itself gets the new costume (you can see this by changing also the shape/color after converting to bitmap), but it cannot be referred to (after giving the sprite another costume one cannot get the just drawn bitmap costume back).

That's a bug indeed. This used to work but something broke it... I'll investigate when I get some time (sigh).

I just realized: also when editing a bitmap costume and changing it to SVG, the original costume will not be changed, but the new SVG costume will be added.

Actually it seems impossible to change a bitmap costume to a vector costume (or vice versa) "in place", since a new object (costume) is created. But removing the old object and adding the new one (actually inserting at the same index) should give the impression of editing/changing.

So there is an "addCostume" missing when converting from SVG to bitmap. And "removeCostume" is missing for both conversion directions.

I have created an issue on github.

I have a fix in my fork of Snap.

One of the problems was the asymmetric handling of bitmap and vector costumes. The vector costume was created by the bitmap editor when changing to vector type. But at this place the context of the editing (new sprite or new costume or edit existing costume) is not known. The existing callbacks only worked for some use cases.

So I decided to create all editor callbacks in the gui events, where the context is known. When the costume type is changed inside an editor, the callbacks are just forwarded to the new editor. To allow this, it was also necessary to generate the costume after editing (inside the callbacks from the data sent to the callback by the editor).

I plan to do some more refactorings before generating a pull request.

I hope my fix is useful. Can you have a look at my commits and give me feedback whether my solution is ok for you or what still needs to be done? Or do you still plan to come up with a fix by yourself?

Here are some questions from my side (as a start):

  • I have added a global (factory) function createCostume in objects.js. Would you rather make that a (static) member of Costume?
  • When creating a new costume from the wardrobe (WardrobeMor.prototype.paintNew), there is this check if ide (= this.parentThatIsA(IDE_Morph)) is not null. How could it happen that ide is null? And why is the sprite that shall wear the costume accessed via ide (ide.currentSprite), whereas the costume is added to the sprite that is accessed via the wardrobe (myself.sprite)? In which cases can they be different?
  • Each javascript file seems to have a version info at the beginning (e.g. modules.gui = '2019-August-08'). Who updates this and when?

Thank you for any hints. (Btw: I have taken the "solution" flag back, which I have set a bit too quick, I guess.)