mirror of
https://github.com/scratchfoundation/scratch-flash.git
synced 2024-11-24 08:28:16 -05:00
Merge pull request #630 from LLK/actionjson
Use actionjson for JSON decoding
This commit is contained in:
commit
6ae4b816c6
10 changed files with 70 additions and 39 deletions
|
@ -20,6 +20,7 @@
|
|||
<mxmlc file="${SRC_DIR}/Scratch.as" output="${DEPLOY_DIR}/ScratchFor10.2.swf"
|
||||
target-player="10.2" swf-version="11" debug="false">
|
||||
<source-path path-element="${SRC_DIR}" />
|
||||
<library-path file="${LIBS_DIR}/actionjson.swc" />
|
||||
<library-path file="${LIBS_DIR}/blooddy_crypto.swc" />
|
||||
<library-path file="${FLEX_HOME}/frameworks/libs/framework.swc" />
|
||||
<static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
|
||||
|
@ -33,6 +34,7 @@
|
|||
<mxmlc file="${SRC_DIR}/Scratch.as" output="${DEPLOY_DIR}/Scratch.swf"
|
||||
target-player="11.4" swf-version="17" debug="false">
|
||||
<source-path path-element="${SRC_DIR}" />
|
||||
<library-path file="${LIBS_DIR}/actionjson.swc" />
|
||||
<library-path file="${LIBS_DIR}/blooddy_crypto.swc" />
|
||||
<library-path file="${FLEX_HOME}/frameworks/libs/framework.swc" />
|
||||
<static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
|
||||
|
|
BIN
libs/actionjson.swc
Normal file
BIN
libs/actionjson.swc
Normal file
Binary file not shown.
|
@ -25,9 +25,13 @@
|
|||
// is independent of the internal representation and is easy to convert to/from JSON.
|
||||
|
||||
package blocks {
|
||||
import scratch.*;
|
||||
import util.*;
|
||||
import translation.*;
|
||||
import com.brokenfunction.json.decodeJson;
|
||||
|
||||
import scratch.*;
|
||||
|
||||
import translation.*;
|
||||
|
||||
import util.*;
|
||||
|
||||
public class BlockIO {
|
||||
|
||||
|
@ -36,7 +40,7 @@ public class BlockIO {
|
|||
}
|
||||
|
||||
public static function stringToStack(s:String, forStage:Boolean = false):Block {
|
||||
return arrayToStack(util.JSON.parse(s) as Array, forStage);
|
||||
return arrayToStack(decodeJson(s, true) as Array, forStage);
|
||||
}
|
||||
|
||||
public static function stackToArray(b:Block):Array {
|
||||
|
|
|
@ -24,16 +24,20 @@
|
|||
// socket-based communications with local and server-based extension helper applications.
|
||||
|
||||
package extensions {
|
||||
import flash.errors.IllegalOperationError;
|
||||
import flash.events.*;
|
||||
import flash.net.*;
|
||||
import flash.utils.Dictionary;
|
||||
import flash.utils.getTimer;
|
||||
import blocks.Block;
|
||||
import interpreter.*;
|
||||
import uiwidgets.DialogBox;
|
||||
import uiwidgets.IndicatorLight;
|
||||
import util.*;
|
||||
import blocks.Block;
|
||||
|
||||
import com.brokenfunction.json.decodeJson;
|
||||
|
||||
import flash.errors.IllegalOperationError;
|
||||
import flash.events.*;
|
||||
import flash.net.*;
|
||||
import flash.utils.Dictionary;
|
||||
import flash.utils.getTimer;
|
||||
|
||||
import interpreter.*;
|
||||
|
||||
import uiwidgets.DialogBox;
|
||||
import uiwidgets.IndicatorLight;
|
||||
|
||||
public class ExtensionManager {
|
||||
|
||||
|
@ -506,7 +510,7 @@ public class ExtensionManager {
|
|||
function completeHandler(e:Event):void {
|
||||
var specsObj:Object;
|
||||
try {
|
||||
specsObj = util.JSON.parse(loader.data);
|
||||
specsObj = decodeJson(loader.data, true);
|
||||
} catch(e:*) {}
|
||||
if (!specsObj) return;
|
||||
// use the block specs and (optionally) menu returned by the helper app
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
// A variable is a name-value pair.
|
||||
|
||||
package interpreter {
|
||||
import util.JSON;
|
||||
import util.JSON;
|
||||
|
||||
public class Variable {
|
||||
|
||||
|
|
|
@ -18,18 +18,27 @@
|
|||
*/
|
||||
|
||||
package ui.media {
|
||||
import assets.Resources;
|
||||
|
||||
import com.brokenfunction.json.decodeJson;
|
||||
|
||||
import extensions.ScratchExtension;
|
||||
|
||||
import flash.display.*;
|
||||
import flash.events.*;
|
||||
import flash.media.Sound;
|
||||
import flash.net.*;
|
||||
import flash.text.*;
|
||||
import flash.utils.*;
|
||||
import assets.Resources;
|
||||
import extensions.ScratchExtension;
|
||||
|
||||
import scratch.*;
|
||||
|
||||
import sound.mp3.MP3Loader;
|
||||
|
||||
import translation.Translator;
|
||||
|
||||
import uiwidgets.*;
|
||||
|
||||
import util.*;
|
||||
|
||||
public class MediaLibrary extends Sprite {
|
||||
|
@ -287,7 +296,7 @@ spriteFeaturesFilter.visible = false; // disable features filter for now
|
|||
function gotLibraryData(data:ByteArray):void {
|
||||
if (!data) return; // failure
|
||||
var s:String = data.readUTFBytes(data.length);
|
||||
libraryCache = util.JSON.parse(stripComments(s)) as Array;
|
||||
libraryCache = decodeJson(s, true) as Array; // TODO: consider async with JsonDecoderAsync
|
||||
collectEntries();
|
||||
}
|
||||
function collectEntries():void {
|
||||
|
|
|
@ -24,19 +24,26 @@
|
|||
// a name, thumbnail, and a line of information for the media object it represents.
|
||||
|
||||
package ui.media {
|
||||
import flash.display.*;
|
||||
import flash.events.MouseEvent;
|
||||
import flash.net.URLLoader;
|
||||
import flash.text.*;
|
||||
import flash.utils.ByteArray;
|
||||
import assets.Resources;
|
||||
import scratch.*;
|
||||
import sound.ScratchSoundPlayer;
|
||||
import sound.mp3.MP3SoundPlayer;
|
||||
import svgutils.SVGImporter;
|
||||
import translation.Translator;
|
||||
import uiwidgets.*;
|
||||
import util.*;
|
||||
import assets.Resources;
|
||||
|
||||
import com.brokenfunction.json.decodeJson;
|
||||
|
||||
import flash.display.*;
|
||||
import flash.events.MouseEvent;
|
||||
import flash.net.URLLoader;
|
||||
import flash.text.*;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
import scratch.*;
|
||||
|
||||
import sound.ScratchSoundPlayer;
|
||||
import sound.mp3.MP3SoundPlayer;
|
||||
|
||||
import svgutils.SVGImporter;
|
||||
|
||||
import translation.Translator;
|
||||
|
||||
import uiwidgets.*;
|
||||
|
||||
public class MediaLibraryItem extends Sprite {
|
||||
|
||||
|
@ -147,7 +154,7 @@ public class MediaLibraryItem extends Sprite {
|
|||
function gotJSONData(data:String):void {
|
||||
var md5:String;
|
||||
if (data) {
|
||||
var sprObj:Object = util.JSON.parse(data);
|
||||
var sprObj:Object = decodeJson(data, true);
|
||||
spriteCache[spriteMD5] = data;
|
||||
dbObj.scriptCount = (sprObj.scripts is Array) ? sprObj.scripts.length : 0;
|
||||
dbObj.costumeCount = (sprObj.costumes is Array) ? sprObj.costumes.length : 0;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package uiwidgets {
|
||||
import blocks.*;
|
||||
|
||||
import com.brokenfunction.json.decodeJson;
|
||||
|
||||
import flash.display.*;
|
||||
import flash.events.*;
|
||||
import flash.geom.*;
|
||||
|
@ -93,7 +95,7 @@ public class BlockColorEditor extends Sprite {
|
|||
}
|
||||
function fileLoaded(event:Event):void {
|
||||
var data:ByteArray = FileReference(event.target).data;
|
||||
var colors:Object = util.JSON.parse(data.toString());
|
||||
var colors:Object = decodeJson(data, true);
|
||||
for (var k:String in colors) {
|
||||
setCategoryColor(k, colors[k]);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
// of separate elements.
|
||||
|
||||
package util {
|
||||
import com.brokenfunction.json.decodeJson;
|
||||
|
||||
import flash.display.*;
|
||||
import flash.events.*;
|
||||
import flash.net.URLLoader;
|
||||
|
@ -153,7 +155,7 @@ public class ProjectIO {
|
|||
if (fName.slice(-5) == '.json') jsonData = contents.readUTFBytes(contents.length);
|
||||
}
|
||||
if (jsonData == null) return null;
|
||||
var jsonObj:Object = util.JSON.parse(jsonData);
|
||||
var jsonObj:Object = decodeJson(jsonData, true);
|
||||
if (jsonObj['children']) { // project JSON
|
||||
var proj:ScratchStage = new ScratchStage();
|
||||
proj.readJSON(jsonObj);
|
||||
|
@ -165,7 +167,7 @@ public class ProjectIO {
|
|||
if (jsonObj['direction'] != null) { // sprite JSON
|
||||
var sprite:ScratchSprite = new ScratchSprite();
|
||||
sprite.readJSON(jsonObj);
|
||||
sprite.instantiateFromJSON(app.stagePane)
|
||||
sprite.instantiateFromJSON(app.stagePane);
|
||||
installImagesAndSounds([sprite]);
|
||||
return sprite;
|
||||
}
|
||||
|
@ -296,7 +298,7 @@ public class ProjectIO {
|
|||
}
|
||||
}
|
||||
projectData.position = 0;
|
||||
var projObject:Object = util.JSON.parse(projectData.readUTFBytes(projectData.length));
|
||||
var projObject:Object = decodeJson(projectData, true);
|
||||
var proj:ScratchStage = new ScratchStage();
|
||||
proj.readJSON(projObject);
|
||||
var assetsToFetch:Array = collectAssetsToFetch(proj.allObjects());
|
||||
|
@ -369,7 +371,7 @@ public class ProjectIO {
|
|||
// Fetch a sprite with the md5 hash.
|
||||
function jsonReceived(data:ByteArray):void {
|
||||
if (!data) return;
|
||||
spr.readJSON(util.JSON.parse(data.readUTFBytes(data.length)));
|
||||
spr.readJSON(decodeJson(data, true));
|
||||
spr.instantiateFromJSON(app.stagePane);
|
||||
fetchSpriteAssets([spr], assetsReceived);
|
||||
}
|
||||
|
|
|
@ -48,7 +48,8 @@ function compile(src, dest, callback, lib_paths, extra_args) {
|
|||
|
||||
var src = path.join(src_dir, 'Scratch.as');
|
||||
var libs = [
|
||||
path.join(libs_dir, 'blooddy_crypto.swc')
|
||||
path.join(libs_dir, 'blooddy_crypto.swc'),
|
||||
path.join(libs_dir, 'actionjson.swc')
|
||||
];
|
||||
|
||||
function compileWith3D(callback) {
|
||||
|
|
Loading…
Reference in a new issue