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

Commit

Permalink
auto populate variables
Browse files Browse the repository at this point in the history
  • Loading branch information
tballmsft committed Sep 23, 2019
1 parent 2e156b4 commit cd554b3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
30 changes: 15 additions & 15 deletions blockstile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,30 @@ 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 $sprite of kind $kind=spritekind at rest"
//% blockAllowMultiple=1 draggableParameters="reporter"
export function onTileStationary(kind: number, h: (tile: TileSprite) => void) {
export function onTileStationary(kind: number, h: (sprite: TileSprite) => void) {
myWorld.onTileStationary(kind, h);
}
/**
* Act on a sprite that has moved to center of tile
* @param body code to execute
*/
//% group="Events" color="#444488"
//% blockId=TWontilearrived block="on $tile of kind $kind=spritekind arrived"
//% blockId=TWontilearrived block="on $sprite of kind $kind=spritekind arrived"
//% blockAllowMultiple=1 draggableParameters="reporter"
export function onTileArrived(kind: number, h: (tile: TileSprite, direction: TileDir) => void) {
export function onTileArrived(kind: number, h: (sprite: TileSprite, direction: TileDir) => void) {
myWorld.onTileArrived(kind, h)
}
/**
* Act on a sprite that has just moved into new tile
* @param body code to execute
*/
//% group="Events" color="#444488"
//% blockId=TWontiletransition block="on $tile of kind $kind=spritekind transition"
//% blockId=TWontiletransition block="on $sprite of kind $kind=spritekind transition"
//% blockAllowMultiple=1 draggableParameters="reporter"
export function onTileTransition(code: number, h: (tile: TileSprite, col: number, row: number) => void) {
myWorld.onTileTransition(code, h)
export function onTileTransition(kind: number, h: (sprite: TileSprite, col: number, row: number) => void) {
myWorld.onTileTransition(kind, h)
}

// checks
Expand All @@ -103,18 +103,18 @@ namespace TileWorld {
* Check if a direction is one of several values.
*/
//% group="Conditions" color="#448844"
//% blockId=TWisoneof block="is %d one of %c1 %c2 || %c3"
//% inlineInputMode=inline
export function isOneOf(d: number, c1: TileDir, c2: TileDir = 0xff, c3: TileDir = 0xff) {
myWorld.isOneOf(d, c1, c2, c3)
//% blockId=TWisoneof block="is %dir=variables_get(direction) one of %c1 %c2 || %c3"
//% inlineInputMode=inline direction.shadow=tiledir
export function isOneOf(dir: number, c1: TileDir, c2: TileDir = 0xff, c3: TileDir = 0xff) {
myWorld.isOneOf(dir, c1, c2, c3)
}
/**
* Check if a direction is not one of several values.
*/
//% group="Conditions" color="#448844"
//% blockId=TWisnotoneof block="is %d not one of %c1 %c2 || %c3"
//% inlineInputMode=inline
export function isNotOneOf(d: number, c1: TileDir, c2: TileDir = 0xff, c3: TileDir = 0xff) {
myWorld.isNotOneOf(d, c1, c2, c3)
//% blockId=TWisnotoneof block="is %dir=variables_get(direction) not one of %c1 %c2 || %c3"
//% inlineInputMode=inline direction.shadow=tiledir
export function isNotOneOf(dir: number, c1: TileDir, c2: TileDir = 0xff, c3: TileDir = 0xff) {
myWorld.isNotOneOf(dir, c1, c2, c3)
}
}
24 changes: 14 additions & 10 deletions tileworld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,36 @@ namespace TileWorld {
this.onStationary = undefined;
this.onTransition = undefined;
}
//% blockId=TWsettilecode block="set code at %tile(tile) to %code"
//% group="Actions" color="#88CC44"
setCode(code: number) {
this.parent.setCode(this, code)
}
// conditions

// block
has(code: number, dir: TileDir = TileDir.None, dir2: TileDir = TileDir.None, dir3: TileDir = TileDir.None) {
this.parent.check(this.parent.containsAt(code, this, dir, dir2, dir3))
}
// block
hasNo(code: number, dir: TileDir = TileDir.None, dir2: TileDir = TileDir.None, dir3: TileDir = TileDir.None) {
this.parent.check(!this.parent.containsAt(code, this, dir, dir2, dir3))
}
// block
hasMultiple(code: number, dir: TileDir = TileDir.None, dir2: TileDir = TileDir.None, dir3: TileDir = TileDir.None) {
this.parent.check(this.parent.hasMultiple(code, this, dir, dir2, dir3))
}

// actions

// block
get(code: number, dir: TileDir = TileDir.None, dir2: TileDir = TileDir.None, dir3: TileDir = TileDir.None) {
return this.parent.getSprite(code, this, dir, dir2, dir3)
}
// block
hasNo(code: number, dir: TileDir = TileDir.None, dir2: TileDir = TileDir.None, dir3: TileDir = TileDir.None) {
this.parent.check(!this.parent.containsAt(code, this, dir, dir2, dir3))
}
//% blockId=TWsettilecode block="set tile at %this(sprite) to %code=colorindexpicker"
//% group="Actions" color="#88CC44"
setCode(code: number) {
this.parent.setCode(this, code)
}
// block
remove() {
this.parent.removeSprite(this)
}
}
// request sprite to move in specified direction
// block
moveOne(dir: TileDir) {
Expand Down

0 comments on commit cd554b3

Please sign in to comment.