-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathdemo.js
More file actions
65 lines (55 loc) · 1.85 KB
/
Copy pathdemo.js
File metadata and controls
65 lines (55 loc) · 1.85 KB
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
import 'babel-polyfill';
import DanceParty from './src/p5.dance';
import jazzy_beats from './metadata/jazzy_beats';
import interpreted from 'raw-loader!./src/p5.dance.interpreted.js';
import injectInterpreted from './test/helpers/injectInterpreted';
const textareaCode = document.querySelector('#code');
const buttonRun = document.querySelector('#run');
const nativeAPI = (window.nativeAPI = new DanceParty({
onPuzzleComplete: () => {},
playSound: (url, callback, onEnded) =>
setTimeout(() => {
callback && callback();
}, 0),
onInit: () => {
document.querySelector('#run').style.display = 'inline';
runCode();
},
container: 'dance',
}));
// Note: We don't just declare
// async function runCode() {
// here because of a bug in Babel that tries to hoist the async function definition above
// the prerequisite polyfill import, above. This is fixed in Babel 7.
// See https://github.com/babel/babel/issues/5085 and https://github.com/babel/babel/issues/6956
const runCode = async function () {
await nativeAPI.ensureSpritesAreLoaded();
const {runUserSetup, runUserEvents, getCueList} = injectInterpreted(
nativeAPI,
interpreted,
textareaCode.value
);
// Setup event tracking.
nativeAPI.addCues(getCueList());
nativeAPI.onHandleEvents = currentFrameEvents =>
runUserEvents(currentFrameEvents);
runUserSetup();
nativeAPI.play(jazzy_beats);
};
textareaCode.value =
textareaCode.value ||
`var cat = makeNewDanceSprite("CAT", null, {x: 200, y: 200});
setBackgroundEffectWithPalette("disco_ball", "rand");
atTimestamp(2, "measures", function () {
changeMoveLR(cat, MOVES.ClapHigh, 1);
});
`;
document.querySelector('#run').addEventListener('click', () => {
if (buttonRun.innerText === 'Reset') {
buttonRun.innerText = 'Run!';
nativeAPI.reset();
} else {
buttonRun.innerText = 'Reset';
runCode();
}
});