forked from Moddable-OpenSource/moddable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
67 lines (62 loc) · 1.53 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* Copyright (c) 2016-2022 Moddable Tech, Inc.
*
* This file is part of the Moddable SDK.
*
* This work is licensed under the
* Creative Commons Attribution 4.0 International License.
* To view a copy of this license, visit
* <http://creativecommons.org/licenses/by/4.0>
* or send a letter to Creative Commons, PO Box 1866,
* Mountain View, CA 94042, USA.
*
*/
import {} from "piu/MC";
import config from "mc/config";
class PhotoPortBehavior extends Behavior {
onCreate(port, data) {
this.data = data;
this.index = 0;
this.textures = [1, 2, 3, 4, 5].map(i => new Texture({ path: `${i}.png` }));
if (globalThis.device?.peripheral?.button?.A) {
new device.peripheral.button.A({
onPush() {
if (this.pressed) {
port.bubble("onTimeChanged", port);
port.stop();
port.time = 0;
port.start();
}
}
});
}
}
onDisplaying(port) {
port.interval = 5000;
port.start();
}
onTimeChanged(port) {
this.index += 1;
if (this.index >= this.textures.length)
this.index = 0;
port.invalidate();
}
onDraw(port) {
let texture = this.textures[this.index];
port.drawTexture(texture, "black", 0, 0, 0, 0, texture.width, texture.height);
}
}
const M5PaperApp = Application.template($ => ({
left: 0, right: 0, top: 0, bottom: 0,
contents: [
Port($, {
top: 0, bottom: 0, left: 0, right: 0,
Behavior: PhotoPortBehavior
})
]
}));
export default function() {
if (config.updateMode)
screen.configure({updateMode: config.updateMode});
return new M5PaperApp({});
}