diff --git a/extensions/Lily/LooksPlus.js b/extensions/Lily/LooksPlus.js index 291c008d8b..df18e449be 100644 --- a/extensions/Lily/LooksPlus.js +++ b/extensions/Lily/LooksPlus.js @@ -33,6 +33,8 @@ return util.runtime.getSpriteTargetByName(nameString); }; + const renderer = Scratch.vm.runtime.renderer; + class LooksPlus { getInfo() { return { @@ -380,7 +382,7 @@ const drawableID = target.drawableID; const layerOrder = target.getLayerOrder(); const newLayer = args.LAYER - layerOrder; - target.renderer.setDrawableOrder(drawableID, newLayer, "sprite", true); + renderer.setDrawableOrder(drawableID, newLayer, "sprite", true); } spriteLayerNumber(args, util) { @@ -442,7 +444,7 @@ snapshotStage(args, util) { return new Promise((resolve) => { - Scratch.vm.runtime.renderer.requestSnapshot((uri) => { + renderer.requestSnapshot((uri) => { resolve(uri); }); }); @@ -467,15 +469,18 @@ const contentType = args.TYPE; const content = args.CONTENT; if (contentType === "SVG") { - Scratch.vm.runtime.renderer.updateSVGSkin( - costume.skinId, - Scratch.Cast.toString(content) - ); + try { + renderer.updateSVGSkin( + costume.skinId, + Scratch.Cast.toString(content) + ); + renderer._allSkins[costume.skinId].differsFromAsset = true; + } catch (e) { + console.error(e); + } } else { console.error("Options other than SVG are currently unavailable"); - return; } - Scratch.vm.emitTargetsUpdate(); } restoreCostumeContent(args, util) { @@ -490,21 +495,30 @@ return; } - //This is here to ensure no changes are made to bitmap costumes, as changes are irreversible - //Check will be removed when it's possible to edit bitmap skins + // This is here to ensure no changes are made to bitmap costumes, as changes are irreversible + // Check will be removed when it's possible to edit bitmap skins const format = costume.asset.assetType.runtimeFormat; if (format !== "svg") { console.error("Costume is not vector"); return; } - const content = costume.asset.decodeText(); - const rotationCenterX = costume.rotationCenterX; - const rotationCenterY = costume.rotationCenterY; - util.target.renderer.updateSVGSkin(costume.skinId, content, [ - rotationCenterX, - rotationCenterY, - ]); + if (!renderer._allSkins[costume.skinId].differsFromAsset) { + return; + } + + try { + const content = costume.asset.decodeText(); + const rotationCenterX = costume.rotationCenterX; + const rotationCenterY = costume.rotationCenterY; + renderer.updateSVGSkin(costume.skinId, content, [ + rotationCenterX, + rotationCenterY, + ]); + renderer._allSkins[costume.skinId].differsFromAsset = false; + } catch (e) { + console.error(e); + } } costumeContent(args, util) { diff --git a/extensions/Lily/lmsutils.js b/extensions/Lily/lmsutils.js index db895742fe..d99c229878 100644 --- a/extensions/Lily/lmsutils.js +++ b/extensions/Lily/lmsutils.js @@ -1356,14 +1356,13 @@ setSpriteSVG(args, util) { try { - Scratch.vm.runtime.renderer.updateSVGSkin( - util.target.sprite.costumes[args.INPUTA - 1].skinId, - args.INPUTB - ); + const skinId = util.target.sprite.costumes[args.INPUTA - 1].skinId; + const renderer = Scratch.vm.runtime.renderer; + renderer.updateSVGSkin(skinId, Scratch.Cast.toString(args.INPUTB)); + renderer._allSkins[skinId].differsFromAsset = true; } catch (error) { - return; + console.error(error); } - Scratch.vm.emitTargetsUpdate(); } alertBlock(args) {