fromJSON (json) {
        // Clear the current runtime
        this.clear();

        // Validate & parse
        if (typeof json !== 'string') {
            log.error('Failed to parse project. Non-string supplied to fromJSON.');
            return;
        }
        json = JSON.parse(json);
        if (typeof json !== 'object') {
            log.error('Failed to parse project. JSON supplied to fromJSON is not an object.');
            return;
        }

        // Establish version, deserialize, and load into runtime
        // @todo Support Scratch 1.4
        // @todo This is an extremely naïve / dangerous way of determining version.
        //       See `scratch-parser` for a more sophisticated validation
        //       methodology that should be adapted for use here
        let deserializer;
        if ((typeof json.meta !== 'undefined') && (typeof json.meta.semver !== 'undefined')) {
            deserializer = sb3;
        } else {
            deserializer = sb2;
        }

        return deserializer.deserialize(json, this.runtime)
            .then(({targets, extensions}) =>
                this.installTargets(targets, extensions, true));
    }
/**
     * Load a project from a Scratch JSON representation.
     * @param {string} json JSON string representing a project.
     * @returns {Promise} Promise that resolves after the project has loaded
     */
Load a project from a Scratch JSON representation.
@param {string} json JSON string representing a project.
@returns {Promise} Promise that resolves after the project has loaded
Load a project from a Scratch JSON representation . @param { string } json JSON string representing a project . @returns { Promise } Promise that resolves after the project has loaded
fromJSON (json) {
        this.clear();
        if (typeof json !== 'string') {
            log.error('Failed to parse project. Non-string supplied to fromJSON.');
            return;
        }
        json = JSON.parse(json);
        if (typeof json !== 'object') {
            log.error('Failed to parse project. JSON supplied to fromJSON is not an object.');
            return;
        }
        let deserializer;
        if ((typeof json.meta !== 'undefined') && (typeof json.meta.semver !== 'undefined')) {
            deserializer = sb3;
        } else {
            deserializer = sb2;
        }
        return deserializer.deserialize(json, this.runtime)
            .then(({targets, extensions}) =>
                this.installTargets(targets, extensions, true));
    }
fromJSON ( json ) { this . clear ( ) ; if ( typeof json !== 'string' ) { log . error ( 'Failed to parse project. Non-string supplied to fromJSON.' ) ; return ; } json = JSON . parse ( json ) ; if ( typeof json !== 'object' ) { log . error ( 'Failed to parse project. JSON supplied to fromJSON is not an object.' ) ; return ; } let deserializer ; if ( ( typeof json . meta !== 'undefined' ) && ( typeof json . meta . semver !== 'undefined' ) ) { deserializer = sb3 ; } else { deserializer = sb2 ; } return deserializer . deserialize ( json , this . runtime ) . then ( ( { targets , extensions } ) => this . installTargets ( targets , extensions , true ) ) ; }
Load a project from a Scratch JSON representation.
Load a project from a Scratch JSON representation .
// Clear the current runtime // Validate & parse // Establish version, deserialize, and load into runtime // @todo Support Scratch 1.4 // @todo This is an extremely naïve / dangerous way of determining version. //       See `scratch-parser` for a more sophisticated validation //       methodology that should be adapted for use here