Scratch 3 runtime for J2ME devices.
0

Configure Feed

Select the types of activity you want to include in your feed.

S3ME / src / main / java / leap / s3me / scratch / blocks / EventBlocks.java
2.9 kB 73 lines
1package leap.s3me.scratch.blocks; 2 3import leap.s3me.Interpret; 4import leap.s3me.Pair; 5import leap.s3me.Scratch; 6import leap.s3me.scratch.Block; 7import leap.s3me.scratch.BlockChain; 8import leap.s3me.scratch.BlockExecutor; 9import leap.s3me.scratch.Input; 10import leap.s3me.scratch.Sprite; 11import leap.s3me.scratch.Value; 12 13public class EventBlocks { 14 public static class FlagClicked implements BlockExecutor.BlockHandler { 15 public int run(Block block, Sprite sprite, boolean[] withoutScreenRefresh, boolean fromRepeat) { 16 return BlockExecutor.RESULT_CONTINUE; 17 } 18 } 19 20 public static class WhenBackdropSwitchesTo implements BlockExecutor.BlockHandler { 21 public int run(Block block, Sprite sprite, boolean[] withoutScreenRefresh, boolean fromRepeat) { 22 return BlockExecutor.RESULT_CONTINUE; 23 } 24 } 25 26 public static class Broadcast implements BlockExecutor.BlockHandler { 27 public int run(Block block, Sprite sprite, boolean[] withoutScreenRefresh, boolean fromRepeat) { 28 Interpret.broadcastQueue.addElement(Scratch.getInputValue(block, "BROADCAST_INPUT", sprite).asString()); 29 return BlockExecutor.RESULT_CONTINUE; 30 } 31 } 32 33 public static class BroadcastAndWait implements BlockExecutor.BlockHandler { 34 public int run(Block block, Sprite sprite, boolean[] withoutScreenRefresh, boolean fromRepeat) { 35 if (block.repeatTimes != -1 && !fromRepeat) { 36 block.repeatTimes = -1; 37 } 38 39 if (block.repeatTimes == -1) { 40 block.repeatTimes = -10; 41 BlockExecutor.addToRepeatQueue(sprite, block); 42 block.broadcastsRun = BlockExecutor.runBroadcast(Scratch.getInputValue(block, "BROADCAST_INPUT", sprite).asString()); 43 } 44 45 boolean shouldEnd = true; 46 for (int i = 0; i < block.broadcastsRun.size(); i++) { 47 Pair pair = (Pair)block.broadcastsRun.elementAt(i); 48 Block blockPtr = (Block)pair.first; 49 Sprite spritePtr = (Sprite)pair.second; 50 51 if (!((BlockChain)spritePtr.blockChains.get(blockPtr.blockChainID)).blocksToRepeat.isEmpty()) { 52 shouldEnd = false; 53 break; 54 } 55 } 56 57 if (!shouldEnd) return BlockExecutor.RESULT_RETURN; 58 59 block.repeatTimes = -1; 60 BlockExecutor.removeFromRepeatQueue(sprite, block); 61 return BlockExecutor.RESULT_CONTINUE; 62 } 63 } 64 65 public static class WhenKeyPressed implements BlockExecutor.BlockHandler { 66 public int run(Block block, Sprite sprite, boolean[] withoutScreenRefresh, boolean fromRepeat) { 67 if (Input.isKeyPressed(Scratch.getFieldValue(block, "KEY_OPTION"))) { 68 return BlockExecutor.RESULT_CONTINUE; 69 } 70 return BlockExecutor.RESULT_RETURN; 71 } 72 } 73}