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

Commit

Permalink
simplify? block
Browse files Browse the repository at this point in the history
  • Loading branch information
tballmsft committed Sep 25, 2019
1 parent 84ce046 commit 7713df1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion blockstile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace TileWorld {
* @param body code to execute
*/
//% group="Events" color="#444488"
//% blockId=TWontilearrived block="on $tile of kind $kind=spritekind move $direction"
//% blockId=TWontilearrived block="on request of $kind=spritekind at $tile to move $direction"
//% blockAllowMultiple=1 draggableParameters="reporter"
export function onTileArrived(kind: number, h: (tile: TileSprite, direction: TileDir) => void) {
myWorld.onTileArrived(kind, h)
Expand Down
41 changes: 25 additions & 16 deletions tileworld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ enum TileDir {
Down
}

enum ResultSet {
//% block="has no"
Zero,
//% block="has one"
ExactlyOne,
//% block="has multiple"
MoreThanOne,
}

//% blockId=tiledir block="$dir"
function _tileDir(dir: TileDir): number {
return dir;
Expand Down Expand Up @@ -57,25 +66,25 @@ namespace TileWorld {
}
// conditions

//% blockId=TWhascode block="does $this(tile) have code $code=colorindexpicker at $dir=tiledir $dir2=tiledir"
//% group="Conditions" color="#448844" inlineInputMode=inline
hasCode(code: number, dir: number = TileDir.None, dir2: number = TileDir.None) {
this.parent.check(this.parent.containsAt(code, this, dir, dir2))
}
//% blockId=TWhaskind block="does %this(tile) have kind $kind=spritekind at %dir=tiledir %dir2=tiledir"
//% blockId=TWhascode block="$this(tile) $dir=tiledir $dir2=tiledir $size $code=colorindexpicker"
//% group="Conditions" color="#448844" inlineInputMode=inline
hasKind(kind: number, dir: number = TileDir.None, dir2: number = TileDir.None) {
this.parent.check(this.parent.containsAt(kind, this, dir, dir2))
}
//% blockId=TWhasnocode block="%this(tile) has no code %code=colorindexpicker at %dir=tiledir %dir2=tiledir"
//% group="Conditions" color="#448844" inlineInputMode=inline
hasNoCode(code: number, dir: number = TileDir.None, dir2: number = TileDir.None) {
this.parent.check(!this.parent.containsAt(code, this, dir, dir2))
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))
else if (size == ResultSet.Zero)
this.parent.check(!this.parent.containsAt(code, this, dir, dir2))
else
this.parent.check(false)
}
//% blockId=TWhasnokind block="%this(tile) has no kind $kind=spritekind at %dir=tiledir %dir2=tiledir"
//% blockId=TWhaskind block="$this(tile) $dir=tiledir $dir2=tiledir $size $kind=spritekind"
//% group="Conditions" color="#448844" inlineInputMode=inline
hasNoKind(kind: number, dir: number = TileDir.None, dir2: number = TileDir.None, dir3: number = TileDir.None) {
this.parent.check(!this.parent.containsAt(kind, this, dir, dir2))
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))
else if (size == ResultSet.Zero)
this.parent.check(!this.parent.containsAt(kind, this, dir, dir2))
else
this.parent.check(false)
}
//% blockId=TWhasmultiple block="does %this(tile) have multiple $code=colorindexpicker at %dir || %dir2 %dir3"
//% group="Conditions" color="#448844" inlineInputMode=inline
Expand Down

0 comments on commit 7713df1

Please sign in to comment.