From 9815a2747006e16e91c87f5e755b91e42d12a3dc Mon Sep 17 00:00:00 2001 From: GarboMuffin Date: Thu, 4 Aug 2022 23:49:43 -0500 Subject: [PATCH] Remove references to original asset in packaged runtime mode --- src/import/load-costume.js | 9 +++ src/import/load-sound.js | 4 ++ test/integration/tw_packaged_runtime.js | 90 +++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 test/integration/tw_packaged_runtime.js diff --git a/src/import/load-costume.js b/src/import/load-costume.js index 4253d614..bb7119b6 100644 --- a/src/import/load-costume.js +++ b/src/import/load-costume.js @@ -46,6 +46,10 @@ const loadVector_ = function (costume, runtime, rotationCenter, optVersion) { costume.bitmapResolution = 1; } + if (runtime.isPackaged) { + costume.asset = null; + } + resolve(costume); }); }; @@ -321,6 +325,11 @@ const loadBitmap_ = function (costume, runtime, _rotationCenter) { costume.rotationCenterY = rotationCenter[1] * 2; costume.bitmapResolution = 2; } + + if (runtime.isPackaged) { + costume.asset = null; + } + return costume; }); }; diff --git a/src/import/load-sound.js b/src/import/load-sound.js index c7479539..1c9cb495 100644 --- a/src/import/load-sound.js +++ b/src/import/load-sound.js @@ -34,6 +34,10 @@ const loadSoundFromAsset = function (sound, soundAsset, runtime, soundBank) { soundBank.addSoundPlayer(soundPlayer); } + if (runtime.isPackaged) { + sound.asset = null; + } + return sound; }); }; diff --git a/test/integration/tw_packaged_runtime.js b/test/integration/tw_packaged_runtime.js new file mode 100644 index 00000000..fa878172 --- /dev/null +++ b/test/integration/tw_packaged_runtime.js @@ -0,0 +1,90 @@ +const {loadCostume} = require('../../src/import/load-costume'); +const {loadSound} = require('../../src/import/load-sound'); +const Runtime = require('../../src/engine/runtime'); +const makeTestStorage = require('../fixtures/make-test-storage'); +const FakeRenderer = require('../fixtures/fake-renderer'); +const FakeBitmapAdapter = require('../fixtures/fake-bitmap-adapter'); +const {test} = require('tap'); + +global.Image = function () { + const image = { + width: 10, + height: 10 + }; + setTimeout(() => { + if (image.onload) { + image.onload(); + } + }); + return image; +}; + +class FakeAudioEngine { + async decodeSoundPlayer () { + return { + id: 0, + buffer: { + sampleRate: 1, + length: 1 + } + }; + } +} + +test('load bitmap in packaged runtime', async t => { + const rt = new Runtime(); + rt.convertToPackagedRuntime(); + rt.attachRenderer(new FakeRenderer()); + rt.attachV2BitmapAdapter(new FakeBitmapAdapter()); + const storage = makeTestStorage(); + rt.attachStorage(storage); + const asset = new storage.Asset( + storage.AssetType.ImageBitmap, + null, + storage.DataFormat.PNG, + new ArrayBuffer(10), + true + ); + const costume = await loadCostume(`${asset.assetId}.png`, {asset}, rt); + t.equal(costume.asset, null); + t.end(); +}); + +test('load vector in packaged runtime', async t => { + const rt = new Runtime(); + rt.convertToPackagedRuntime(); + rt.attachRenderer(new FakeRenderer()); + const storage = makeTestStorage(); + rt.attachStorage(storage); + const asset = new storage.Asset( + storage.AssetType.ImageVector, + null, + storage.DataFormat.SVG, + new ArrayBuffer(10), + true + ); + const costume = await loadCostume(`${asset.assetId}.svg`, {asset}, rt); + t.equal(costume.asset, null); + t.end(); +}); + +test('load sound in packaged runtime', async t => { + const rt = new Runtime(); + rt.convertToPackagedRuntime(); + const storage = makeTestStorage(); + rt.attachStorage(storage); + rt.attachAudioEngine(new FakeAudioEngine()); + const asset = new storage.Asset( + storage.AssetType.Sound, + null, + storage.DataFormat.MP3, + new ArrayBuffer(10), + true + ); + const costume = await loadSound({ + asset, + md5: `${asset.assetId}.mp3` + }, rt, null); + t.equal(costume.asset, null); + t.end(); +});