From 7dc6b304c5945ad1d7c8a4e42fc5c5d0d315f801 Mon Sep 17 00:00:00 2001 From: Tom Ball Date: Wed, 25 Sep 2019 13:41:22 -0700 Subject: [PATCH] more simplification --- blockstile.ts | 28 ++++++++++------------------ tileworld.ts | 17 ++++++++++++----- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/blockstile.ts b/blockstile.ts index a0a8fff..f44eebe 100644 --- a/blockstile.ts +++ b/blockstile.ts @@ -1,5 +1,5 @@ //% weight=1000 color="#442255" icon="\uf45c" -//% groups='["Tiles", "Events", "Conditions", "Actions"]' +//% groups='["Tiles", "Events", "Tests", "Actions"]' //% blockGap=8 namespace TileWorld { @@ -76,7 +76,7 @@ namespace TileWorld { * @param body code to execute */ //% group="Events" color="#444488" - //% blockId=TWontilestationary block="on $tile of kind $kind=spritekind at rest" + //% blockId=TWontilestationary block="on change around $kind=spritekind at $tile" //% blockAllowMultiple=1 draggableParameters="reporter" export function onTileStationary(kind: number, h: (tile: TileSprite) => void) { myWorld.onTileStationary(kind, h); @@ -98,32 +98,24 @@ namespace TileWorld { * @param body code to execute */ //% group="Events" color="#444488" - //% blockId=TWontiletransition block="enter $tile of kind $kind=spritekind" + //% blockId=TWontiletransition block="on $kind=spritekind moved into $tile" //% blockAllowMultiple=1 draggableParameters="reporter" export function onTileTransition(kind: number, h: (tile: TileSprite) => void) { myWorld.onTileTransition(kind, h) } - // checks /** * Check if a direction is one of several values. */ - //% group="Conditions" color="#448844" - //% blockId=TWisoneof block="test %dir=variables_get(direction) one of %c1 %c2" - //% inlineInputMode=inline - export function isOneOf(dir: number, c1: TileDir, c2: TileDir = 0xff) { - myWorld.isOneOf(dir, c1, c2) - } - - /** - * Check if a direction is not one of several values. - */ - //% group="Conditions" color="#448844" - //% blockId=TWisnotoneof block="test %dir=variables_get(direction) not one of %c1 %c2" + //% group="Tests" color="#448844" + //% blockId=TWisoneof block="test %dir=variables_get(direction) $cmp %c1 %c2" //% inlineInputMode=inline - export function isNotOneOf(dir: number, c1: TileDir, c2: TileDir = 0xff) { - myWorld.isNotOneOf(dir, c1, c2) + export function isOneOf(dir: number, cmp: Testing = Testing.OneOf, c1: TileDir, c2: TileDir) { + if (cmp == Testing.OneOf) + myWorld.isOneOf(dir, c1, c2) + else + myWorld.isNotOneOf(dir, c1, c2) } } \ No newline at end of file diff --git a/tileworld.ts b/tileworld.ts index 1bcf62c..9bb89e7 100644 --- a/tileworld.ts +++ b/tileworld.ts @@ -12,6 +12,11 @@ enum TileDir { Down } +//% blockId=tiledir block="$dir" +function _tileDir(dir: TileDir): number { + return dir; +} + enum ResultSet { //% block="has no" Zero, @@ -21,9 +26,11 @@ enum ResultSet { MoreThanOne, } -//% blockId=tiledir block="$dir" -function _tileDir(dir: TileDir): number { - return dir; +enum Testing { + //% block="one of" + OneOf, + //% block="not one of" + NotOneOf } //% @@ -67,7 +74,7 @@ namespace TileWorld { // conditions //% blockId=TWhascode block="test $this(tile) $dir=tiledir $dir2=tiledir $size $code=colorindexpicker" - //% group="Conditions" color="#448844" inlineInputMode=inline + //% group="Tests" color="#448844" inlineInputMode=inline hasCode(code: number, dir: number = TileDir.None, dir2: number = TileDir.None, size: ResultSet = ResultSet.Zero) { if (size == ResultSet.ExactlyOne) this.parent.check(this.parent.containsAt(code, this, dir, dir2)) @@ -77,7 +84,7 @@ namespace TileWorld { this.parent.check(false) } //% blockId=TWhaskind block="test $this(tile) $dir=tiledir $dir2=tiledir $size $kind=spritekind" - //% group="Conditions" color="#448844" inlineInputMode=inline + //% group="Tests" color="#448844" inlineInputMode=inline hasKind(kind: number, dir: number = TileDir.None, dir2: number = TileDir.None, size: ResultSet = ResultSet.Zero) { if (size == ResultSet.ExactlyOne) this.parent.check(this.parent.containsAt(kind, this, dir, dir2))