Skip to content
This repository has been archived by the owner on Nov 8, 2019. It is now read-only.

Commit

Permalink
more simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
tballmsft committed Sep 25, 2019
1 parent 2fab6e1 commit 7dc6b30
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
28 changes: 10 additions & 18 deletions blockstile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//% weight=1000 color="#442255" icon="\uf45c"
//% groups='["Tiles", "Events", "Conditions", "Actions"]'
//% groups='["Tiles", "Events", "Tests", "Actions"]'
//% blockGap=8
namespace TileWorld {

Expand Down Expand Up @@ -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);
Expand All @@ -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)
}
}
17 changes: 12 additions & 5 deletions tileworld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ enum TileDir {
Down
}

//% blockId=tiledir block="$dir"
function _tileDir(dir: TileDir): number {
return dir;
}

enum ResultSet {
//% block="has no"
Zero,
Expand All @@ -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
}

//%
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down

0 comments on commit 7dc6b30

Please sign in to comment.