From c0a65d5c4cdb50a263dfb8fdf30be1d3db36cd7a Mon Sep 17 00:00:00 2001 From: Georgi Angelov Date: Thu, 10 Apr 2025 11:54:03 +0300 Subject: [PATCH] feat: track asset provenance when using the paint editor --- .../src/containers/paint-editor-wrapper.jsx | 13 +++++++++++-- packages/scratch-gui/src/lib/project-saver-hoc.jsx | 3 ++- packages/scratch-vm/src/virtual-machine.js | 8 ++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/scratch-gui/src/containers/paint-editor-wrapper.jsx b/packages/scratch-gui/src/containers/paint-editor-wrapper.jsx index b69b850826..7e8e181f9b 100644 --- a/packages/scratch-gui/src/containers/paint-editor-wrapper.jsx +++ b/packages/scratch-gui/src/containers/paint-editor-wrapper.jsx @@ -24,19 +24,28 @@ class PaintEditorWrapper extends React.Component { this.props.vm.renameCostume(this.props.selectedCostumeIndex, name); } handleUpdateImage (isVector, image, rotationCenterX, rotationCenterY) { + const currentCostume = this.props.vm.editingTarget.getCostumes()[this.props.selectedCostumeIndex]; + const currentAsset = currentCostume.asset; + + const provenance = currentAsset.clean ? currentAsset.assetId : currentAsset.provenance; + if (isVector) { this.props.vm.updateSvg( this.props.selectedCostumeIndex, image, rotationCenterX, - rotationCenterY); + rotationCenterY, + provenance, + ); } else { this.props.vm.updateBitmap( this.props.selectedCostumeIndex, image, rotationCenterX, rotationCenterY, - 2 /* bitmapResolution */); + 2 /* bitmapResolution */, + provenance, + ); } } render () { diff --git a/packages/scratch-gui/src/lib/project-saver-hoc.jsx b/packages/scratch-gui/src/lib/project-saver-hoc.jsx index 81cf9ab105..21e44fe099 100644 --- a/packages/scratch-gui/src/lib/project-saver-hoc.jsx +++ b/packages/scratch-gui/src/lib/project-saver-hoc.jsx @@ -236,7 +236,8 @@ const ProjectSaverHOC = function (WrappedComponent) { asset.assetType, asset.dataFormat, asset.data, - asset.assetId + asset.assetId, + { provenance: asset.provenance } ).then(response => { // Asset servers respond with {status: ok} for successful POSTs if (response.status !== 'ok') { diff --git a/packages/scratch-vm/src/virtual-machine.js b/packages/scratch-vm/src/virtual-machine.js index 64ad7934fe..aec43dddb6 100644 --- a/packages/scratch-vm/src/virtual-machine.js +++ b/packages/scratch-vm/src/virtual-machine.js @@ -891,8 +891,9 @@ class VirtualMachine extends EventEmitter { * @param {!number} rotationCenterY y of point about which the costume rotates, relative to its upper left corner * @param {!number} bitmapResolution 1 for bitmaps that have 1 pixel per unit of stage, * 2 for double-resolution bitmaps + * @param {?string} provenance - an assetId of an asset that this one was based on */ - updateBitmap (costumeIndex, bitmap, rotationCenterX, rotationCenterY, bitmapResolution) { + updateBitmap (costumeIndex, bitmap, rotationCenterX, rotationCenterY, bitmapResolution, provenance) { const costume = this.editingTarget.getCostumes()[costumeIndex]; if (!(costume && this.runtime && this.runtime.renderer)) return; if (costume && costume.broken) delete costume.broken; @@ -934,6 +935,7 @@ class VirtualMachine extends EventEmitter { null, // id true // generate md5 ); + costume.asset.setProvenance(provenance); costume.assetId = costume.asset.assetId; costume.md5 = `${costume.assetId}.${costume.dataFormat}`; this.emitTargetsUpdate(); @@ -951,8 +953,9 @@ class VirtualMachine extends EventEmitter { * @param {string} svg - new SVG for the renderer. * @param {number} rotationCenterX x of point about which the costume rotates, relative to its upper left corner * @param {number} rotationCenterY y of point about which the costume rotates, relative to its upper left corner + * @param {?string} provenance - an assetId of an asset that this one was based on */ - updateSvg (costumeIndex, svg, rotationCenterX, rotationCenterY) { + updateSvg (costumeIndex, svg, rotationCenterX, rotationCenterY, provenance) { const costume = this.editingTarget.getCostumes()[costumeIndex]; if (costume && costume.broken) delete costume.broken; if (costume && this.runtime && this.runtime.renderer) { @@ -973,6 +976,7 @@ class VirtualMachine extends EventEmitter { null, true // generate md5 ); + costume.asset.setProvenance(provenance); costume.assetId = costume.asset.assetId; costume.md5 = `${costume.assetId}.${costume.dataFormat}`; this.emitTargetsUpdate();