Skip to content

Commit

Permalink
Use MipmapElement, see phetsims/chipper#1218
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Aug 16, 2024
1 parent fd3dbc7 commit 556af69
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions js/util/sceneryDeserialize.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright 2022-2024, University of Colorado Boulder

/**
* Deserializes a generalized object
* @deprecated
* Used by the scenery inspector
*
* @author Jonathan Olson <[email protected]>
*/
Expand All @@ -15,6 +14,7 @@ import { Shape } from '../../../kite/js/imports.js';
import IntentionalAny from '../../../phet-core/js/types/IntentionalAny.js';
import { Circle, Color, DOM, Gradient, Image, Line, LinearGradient, Mipmap, Node, Paint, Path, Pattern, RadialGradient, Rectangle, scenery, Text } from '../imports.js';
import TinyProperty from '../../../axon/js/TinyProperty.js';
import MipmapElement from '../../../phet-core/js/MipmapElement.js';

const sceneryDeserialize = ( value: { type: string; [ key: string ]: IntentionalAny } ): IntentionalAny => {
const nodeTypes = [
Expand Down Expand Up @@ -111,25 +111,7 @@ const sceneryDeserialize = ( value: { type: string; [ key: string ]: Intentional
}
else if ( setup.imageType === 'mipmapData' ) {
const mipmapData = setup.mipmapData.map( ( level: Mipmap[0] ) => {
const result: IntentionalAny = {
width: level.width,
height: level.height,
url: level.url
};
result.img = new window.Image();
result.img.src = level.url;
result.canvas = document.createElement( 'canvas' );
result.canvas.width = level.width;
result.canvas.height = level.height;
const context = result.canvas.getContext( '2d' );
// delayed loading like in mipmap plugin
result.updateCanvas = function() {
if ( result.img.complete && ( typeof result.img.naturalWidth === 'undefined' || result.img.naturalWidth > 0 ) ) {
context.drawImage( result.img, 0, 0 );
delete result.updateCanvas;
}
};
return result;
return new MipmapElement( level.width, level.height, level.url, false );
} );
node = new Image( mipmapData );
}
Expand Down

0 comments on commit 556af69

Please sign in to comment.