Skip to content

Instantly share code, notes, and snippets.

@willblaschko
Created April 13, 2019 23:13
Show Gist options
  • Save willblaschko/44b0a399084367271af1b2ab55704042 to your computer and use it in GitHub Desktop.
Save willblaschko/44b0a399084367271af1b2ab55704042 to your computer and use it in GitHub Desktop.
Falling Blocks - an APL Tetris Clone (Voice Control)
...
{
"type": "Video",
"position": "absolute",
"top": "0dp",
"left": "0dp",
"source": "<my file>",
"id": "counter",
"autoplay": "false",
"onPlay": [{
"type": "SendEvent",
"arguments": [
"counter"
]
}]
}
...
"grid": {
"values": [
[2, 0, 2, 1, 2, 1, 1, 2, 1, 0],
[0, 2, 0, 1, 0, 2, 0, 0, 0, 1],
[1, 2, 0, 2, 1, 0, 1, 1, 2, 0],
[1, 2, 0, 0, 0, 1, 1, 2, 2, 0],
[2, 1, 2, 0, 2, 1, 1, 2, 0, 2],
[2, 2, 1, 2, 0, 0, 0, 1, 2, 0],
[2, 1, 1, 0, 1, 0, 0, 2, 1, 2],
[1, 1, 2, 2, 1, 2, 0, 2, 2, 0],
[0, 1, 0, 2, 2, 0, 0, 0, 1, 2],
[0, 1, 1, 1, 1, 1, 1, 1, 2, 1],
[2, 1, 2, 2, 0, 2, 0, 1, 0, 2],
[2, 1, 2, 1, 0, 1, 2, 1, 1, 2],
[2, 0, 1, 2, 0, 0, 0, 1, 1, 2],
[0, 1, 2, 1, 2, 0, 0, 1, 2, 0],
[1, 2, 1, 2, 1, 1, 2, 0, 1, 2]
]
}
...
{
"name": "CommandIntent",
"slots": [{
"name": "DIRECTION_A",
"type": "DIRECTIONS"
},
{
"name": "DIRECTION_B",
"type": "DIRECTIONS"
},
{
"name": "DIRECTION_C",
"type": "DIRECTIONS"
},
{
"name": "DIRECTION_D",
"type": "DIRECTIONS"
},
{
"name": "DIRECTION_E",
"type": "DIRECTIONS"
},
{
"name": "DIRECTION_F",
"type": "DIRECTIONS"
},
{
"name": "DIRECTION_G",
"type": "DIRECTIONS"
},
{
"name": "DIRECTION_H",
"type": "DIRECTIONS"
},
{
"name": "DIRECTION_I",
"type": "DIRECTIONS"
},
{
"name": "DIRECTION_J",
"type": "DIRECTIONS"
}
],
"samples": [
"go {DIRECTION_A}",
"{DIRECTION_A} {DIRECTION_B}",
"{DIRECTION_A} {DIRECTION_B} {DIRECTION_C}",
"{DIRECTION_A} {DIRECTION_B} {DIRECTION_C} {DIRECTION_D}",
"{DIRECTION_A} {DIRECTION_B} {DIRECTION_C} {DIRECTION_D} {DIRECTION_E}",
"{DIRECTION_A} {DIRECTION_B} {DIRECTION_C} {DIRECTION_D} {DIRECTION_E} {DIRECTION_F}",
"{DIRECTION_A} {DIRECTION_B} {DIRECTION_C} {DIRECTION_D} {DIRECTION_E} {DIRECTION_F} {DIRECTION_G}",
"{DIRECTION_A} {DIRECTION_B} {DIRECTION_C} {DIRECTION_D} {DIRECTION_E} {DIRECTION_F} {DIRECTION_G} {DIRECTION_H}",
"{DIRECTION_A} {DIRECTION_B} {DIRECTION_C} {DIRECTION_D} {DIRECTION_E} {DIRECTION_F} {DIRECTION_G} {DIRECTION_H} {DIRECTION_I}",
"{DIRECTION_A} {DIRECTION_B} {DIRECTION_C} {DIRECTION_D} {DIRECTION_E} {DIRECTION_F} {DIRECTION_G} {DIRECTION_H} {DIRECTION_I} {DIRECTION_J}"
]
}, {
"name": "CommandOnlyIntent",
"slots": [{
"name": "DIRECTION_A",
"type": "DIRECTIONS"
}],
"samples": [
"{DIRECTION_A}"
]
}
...
const EventHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === "Alexa.Presentation.APL.UserEvent";
},
async handle(handlerInput) {
const args = handlerInput.requestEnvelope.request.arguments;
const parameter = args[0];
if (parameter === "counter") {
let persistentAttributes = await handlerInput.attributesManager.getPersistentAttributes();
if (persistentAttributes.states && persistentAttributes.states.length > 1) {
persistentAttributes.states.shift();
}
handlerInput.attributesManager.setPersistentAttributes(persistentAttributes);
await handlerInput.attributesManager.savePersistentAttributes();
return handlerInput.responseBuilder.getResponse();
}
}
};
"layouts": {
"Tile": {
"type": "Container",
"parameters": [{
"name": "name",
"type": "string"
},
{
"name": "page",
"type": "integer"
}
],
"items": [
{
"type": "Pager",
"width": "8.33vh",
"height": "100%",
"id": "${name}",
"data": "${payload.game.colors}",
"initialPage": "${page}",
"items": [{
"type": "Frame",
"id": "${index}",
"width": "100%",
"height": "100%",
"backgroundColor": "${data}",
}
]
}
]
}
},
...
"mainTemplate": {
"parameters": [
"payload"
],
"items": [{
"type": "Container",
"width": "100vw",
"height": "100vh",
"justifyContent": "center",
"alignItems": "center",
"direction": "row",
"items": [{
"type": "Container",
"width": "100%",
"height": "100%",
"data": "${payload.grid.values}",
"justifyContent": "center",
"alignItems": "center",
"items": [{
"type": "Container",
"direction": "row",
"width": "100vw",
"height": "8.33vh",
"data": "${data}",
"bind": [{
"name": "parentIndex",
"value": "${index}"
}],
"items": [{
"type": "Tile",
"name": "${parentIndex+'.'+index}",
"page": "${payload.grid.values[parentIndex][index]}"
}]
}]
}]
}]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment