Skip to content

Commit

Permalink
Merge branch 'prove' of github.com:CoderDojoTrento/botch-vm into prove
Browse files Browse the repository at this point in the history
  • Loading branch information
raffaelepojer committed Aug 18, 2020
2 parents 2377f01 + 30fa303 commit e87467c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/extensions/botch/botch-storage-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ class BotchStorageHelper extends Helper {

/**
* In-memory storage for Botch assets
* @type {Object.<AssetType, AssetIdMap>} Maps asset type to a map of asset ID to actual assets.
* @typedef {Object.<string, BuiltinAssetRecord>} AssetIdMap - Maps asset ID to asset.
*
* Maps asset type to a map of asset ID to actual assets.
* @type {Object.<AssetType, AssetIdMap>}
* Maps asset ID to asset.
* @typedef {Object.<string, BuiltinAssetRecord>} AssetIdMap
*/
this.assets = {};

Expand Down Expand Up @@ -179,7 +182,7 @@ class BotchStorageHelper extends Helper {
/**
* Returns a list with all the tags of the sprites
*
* @returns {[]} list
* @returns {object[]} list
* @since botch 0.1
*/
getAllTags () {
Expand Down
25 changes: 22 additions & 3 deletions src/extensions/botch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,27 @@ class Scratch3Botch {
log.log('Botch: on PROJECT_LOADED');
this.storage = this.runtime.storage;
if (!this.storageHelper){
this.storageHelper = new BotchStorageHelper(this.runtime.storage);
this.storage.addHelper(this.storageHelper);
// in some tests it is not defined ...
if (this.storage && this.storage.addHelper){
this.storageHelper = new BotchStorageHelper(this.runtime.storage);
this.storage.addHelper(this.storageHelper);
} else {
log.log('this.runtime.storage is not defined, skipping BotchStorageHelper initialization');
}

}
// this.testStoreSprite();
}));

log.log('Botch runtime:', runtime);
log.log('Botch custom storageHelper:', this.storageHelper);

window.BOTCH = this;
// browser detection arcana https://stackoverflow.com/a/41863502
if (this.window === this){
window.BOTCH = this; // browser
} else {
global.BOTCH = this; // node
}

// show the organism when stopped
this.runtime.on(Runtime.PROJECT_STOP_ALL, (() => {
Expand Down Expand Up @@ -796,6 +807,14 @@ class Scratch3Botch {
for (const cost of sprite.costumes){
// NOTE 1: in costumes 'md5' field also has '.svg' appended

// this way it will have inside the precious encodeDataURI method
cost.asset = new this.storage.Asset(
cost.asset.assetType,
cost.asset.assetId,
cost.asset.dataFormat,
cost.asset.data,
false
);
cost.md5ext = cost.md5;
// NOTE 2: in preloaded data there is no md5, only md5ext
delete cost.md5;
Expand Down

0 comments on commit e87467c

Please sign in to comment.