mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-28 22:30:40 -04:00
Get Asset
and AssetType
from storage instance
This commit is contained in:
parent
f8c898fc43
commit
c750f53c81
5 changed files with 7 additions and 11 deletions
|
@ -1,4 +1,3 @@
|
|||
const AssetType = require('scratch-storage').AssetType;
|
||||
const log = require('../util/log');
|
||||
|
||||
/**
|
||||
|
@ -19,7 +18,7 @@ const loadCostume = function (md5ext, costume, runtime) {
|
|||
return Promise.resolve(costume);
|
||||
}
|
||||
|
||||
|
||||
const AssetType = runtime.storage.AssetType;
|
||||
const idParts = md5ext.split('.');
|
||||
const md5 = idParts[0];
|
||||
const ext = idParts[1].toUpperCase();
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
const AssetType = require('scratch-storage').AssetType;
|
||||
const log = require('../util/log');
|
||||
|
||||
/**
|
||||
|
@ -20,7 +19,7 @@ const loadSound = function (sound, runtime) {
|
|||
}
|
||||
const idParts = sound.md5.split('.');
|
||||
const md5 = idParts[0];
|
||||
return runtime.storage.load(AssetType.Sound, md5).then(soundAsset => {
|
||||
return runtime.storage.load(runtime.storage.AssetType.Sound, md5).then(soundAsset => {
|
||||
sound.data = soundAsset.data;
|
||||
return runtime.audioEngine.decodeSound(sound).then(() => sound);
|
||||
});
|
||||
|
|
|
@ -47,7 +47,7 @@ window.onload = function () {
|
|||
Scratch.vm = vm;
|
||||
|
||||
const storage = new Scratch.Storage();
|
||||
const AssetType = Scratch.Storage.AssetType;
|
||||
const AssetType = storage.AssetType;
|
||||
storage.addWebSource([AssetType.Project], getProjectUrl);
|
||||
storage.addWebSource([AssetType.ImageVector, AssetType.ImageBitmap, AssetType.Sound], getAssetUrl);
|
||||
vm.attachStorage(storage);
|
||||
|
|
|
@ -2,7 +2,6 @@ const EventEmitter = require('events');
|
|||
|
||||
const log = require('./util/log');
|
||||
const Runtime = require('./engine/runtime');
|
||||
const ScratchStorage = require('scratch-storage');
|
||||
const sb2import = require('./import/sb2import');
|
||||
const StringUtil = require('./util/string-util');
|
||||
|
||||
|
@ -11,8 +10,6 @@ const loadSound = require('./import/load-sound.js');
|
|||
|
||||
const RESERVED_NAMES = ['_mouse_', '_stage_', '_edge_', '_myself_', '_random_'];
|
||||
|
||||
const AssetType = ScratchStorage.AssetType;
|
||||
|
||||
/**
|
||||
* Handles connections between blocks, stage, and extensions.
|
||||
* @constructor
|
||||
|
@ -170,12 +167,13 @@ class VirtualMachine extends EventEmitter {
|
|||
* @param {string} id - the ID of the project to download, as a string.
|
||||
*/
|
||||
downloadProjectId (id) {
|
||||
if (!this.runtime.storage) {
|
||||
const storage = this.runtime.storage;
|
||||
if (!storage) {
|
||||
log.error('No storage module present; cannot load project: ', id);
|
||||
return;
|
||||
}
|
||||
const vm = this;
|
||||
const promise = this.runtime.storage.load(AssetType.Project, id);
|
||||
const promise = storage.load(storage.AssetType.Project, id);
|
||||
promise.then(projectAsset => {
|
||||
vm.loadProject(projectAsset.decodeText());
|
||||
});
|
||||
|
|
2
test/fixtures/attach-test-storage.js
vendored
2
test/fixtures/attach-test-storage.js
vendored
|
@ -38,7 +38,7 @@ var getAssetUrl = function (asset) {
|
|||
*/
|
||||
var attachTestStorage = function (vm) {
|
||||
var storage = new ScratchStorage();
|
||||
var AssetType = ScratchStorage.AssetType;
|
||||
var AssetType = storage.AssetType;
|
||||
storage.addWebSource([AssetType.Project], getProjectUrl);
|
||||
storage.addWebSource([AssetType.ImageVector, AssetType.ImageBitmap, AssetType.Sound], getAssetUrl);
|
||||
vm.attachStorage(storage);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue