Skip to content

Commit f9f26f6

Browse files
committed
use new well.isOccupied() functions in example code
1 parent 4acdbae commit f9f26f6

File tree

4 files changed

+24
-61
lines changed

4 files changed

+24
-61
lines changed

examples/memory/index.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ let fs = require('fs/promises')
22
let path = require('path')
33
let { createCanvas } = require('canvas');
44

5-
let { Plinth } = require('@wyldcard/drivers')
5+
let { Plinth, CardNotPresentError } = require('@wyldcard/drivers')
66

77
// return the button press callback, associated with a well and button
88
function buttonPress(well) {
99
return async (chordedButtonPressEvent) => {
10+
// do nothing if no card present
11+
if (!well.isOccupied()) {
12+
return
13+
}
14+
1015
memoryTemplate = {
1116
buttonPresses: [[],[],[],[],[]],
1217
count: 0,
@@ -104,8 +109,10 @@ function eraseAll(plinth) {
104109
let pixelsFormattedForWyldcard = formatPixelBuffer(pixels)
105110

106111
plinth.wells.forEach((well) => {
107-
well.storeData({})
108-
well.displayImage(pixelsFormattedForWyldcard)
112+
if (well.isOccupied()) {
113+
well.storeData({})
114+
well.displayImage(pixelsFormattedForWyldcard)
115+
}
109116
})
110117
}
111118

examples/simple-demo/index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,11 @@ async function main() {
2828
})
2929
}
3030

31-
main()
31+
main()
32+
33+
34+
35+
// catch all exceptions for this demo
36+
process.on('uncaughtException', (err) => {
37+
console.error(err);
38+
})

examples/simple-demo/package-lock.json

-57
This file was deleted.

examples/tarot/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ async function main() {
3737
}
3838

3939
let turnFacedown = async (well) => {
40+
if (!well.isOccupied()) { return }
41+
4042
well.storeData({ tarotCard: 'facedown' })
4143

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

4850
let turnFaceup = async (well) => {
51+
if (!well.isOccupied()) { return }
52+
4953
well.storeData({ tarotCard: 'faceup' })
5054

5155
let imagePath = await drawCard()
@@ -79,6 +83,8 @@ async function main() {
7983

8084
// returns a button-press callback
8185
let flipCard = (well) => {
86+
if (!well.isOccupied()) { return }
87+
8288
let memory;
8389

8490
try {

0 commit comments

Comments
 (0)