Skip to content

Commit

Permalink
use new well.isOccupied() functions in example code
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonahss committed Jan 22, 2024
1 parent 4acdbae commit f9f26f6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 61 deletions.
13 changes: 10 additions & 3 deletions examples/memory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ let fs = require('fs/promises')
let path = require('path')
let { createCanvas } = require('canvas');

let { Plinth } = require('@wyldcard/drivers')
let { Plinth, CardNotPresentError } = require('@wyldcard/drivers')

// return the button press callback, associated with a well and button
function buttonPress(well) {
return async (chordedButtonPressEvent) => {
// do nothing if no card present
if (!well.isOccupied()) {
return
}

memoryTemplate = {
buttonPresses: [[],[],[],[],[]],
count: 0,
Expand Down Expand Up @@ -104,8 +109,10 @@ function eraseAll(plinth) {
let pixelsFormattedForWyldcard = formatPixelBuffer(pixels)

plinth.wells.forEach((well) => {
well.storeData({})
well.displayImage(pixelsFormattedForWyldcard)
if (well.isOccupied()) {
well.storeData({})
well.displayImage(pixelsFormattedForWyldcard)
}
})
}

Expand Down
9 changes: 8 additions & 1 deletion examples/simple-demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ async function main() {
})
}

main()
main()



// catch all exceptions for this demo
process.on('uncaughtException', (err) => {
console.error(err);
})
57 changes: 0 additions & 57 deletions examples/simple-demo/package-lock.json

This file was deleted.

6 changes: 6 additions & 0 deletions examples/tarot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ async function main() {
}

let turnFacedown = async (well) => {
if (!well.isOccupied()) { return }

well.storeData({ tarotCard: 'facedown' })

let cardBackPath = path.resolve('/', 'home', 'pi', 'Pictures', 'wyldcard', 'tarot-reliberate', 'back.png')
Expand All @@ -46,6 +48,8 @@ async function main() {
}

let turnFaceup = async (well) => {
if (!well.isOccupied()) { return }

well.storeData({ tarotCard: 'faceup' })

let imagePath = await drawCard()
Expand Down Expand Up @@ -79,6 +83,8 @@ async function main() {

// returns a button-press callback
let flipCard = (well) => {
if (!well.isOccupied()) { return }

let memory;

try {
Expand Down

0 comments on commit f9f26f6

Please sign in to comment.