(function() { "use strict"; // Consts // ///////////////////////////////////////////////////////////////////////// var BUTTON_NAME = "DANCE", EVENT_BRIDGE_OPEN_MESSAGE = "eventBridgeOpen", UPDATE_UI = BUTTON_NAME + "_update_ui", TRY_DANCE = "try_dance", STOP_DANCE = "stop_dance", START_DANCING = "start_dancing", REMOVE_DANCE = "remove_dance", REMOVE_DANCE_FROM_MENU = "remove_dance_from_menu", ADD_DANCE = "add_dance", PREVIEW_DANCE = "preview_dance", PREVIEW_DANCE_STOP = "preview_dance_stop", UPDATE_DANCE_ARRAY = "update_dance_array", CURRENT_DANCE = "current_dance", TOGGLE_HMD = "toggle_hmd", EVENTBRIDGE_SETUP_DELAY = 10 ; // Components // ///////////////////////////////////////////////////////////////////////// Vue.component('current-dance', { props: { add_this_dance: { type: Boolean }, current_dance: { type: Boolean }, should_be_running: { type: Boolean }, dance_array: { type: Boolean }, add_dance_name: { type: String }, current_dance_name: { type: String }, toggle_hmd: {type: Boolean} }, methods: { startDancing(){ EventBridge.emitWebEvent(JSON.stringify({ type: START_DANCING })); }, stopDance(){ EventBridge.emitWebEvent(JSON.stringify({ type: STOP_DANCE })); }, toggleHMD(){ EventBridge.emitWebEvent(JSON.stringify({ type: TOGGLE_HMD })); } }, template: /*html*/`

Preview: Current: Choose dances below {{current_dance_name}} {{add_dance_name}}
` }) Vue.component('dance-list-item', { props: ['dance', 'index'], data: function() { return { clicked: false, maxEndFrame: this.dance.endFrame } }, methods: { removeDance(){ EventBridge.emitWebEvent(JSON.stringify({ type: REMOVE_DANCE, value: this.index })); }, onBlur(){ var sanitizedObject = Object.assign({}, this.dance, { startFrame: parseInt(Math.max(this.dance.startFrame, 0)), endFrame: parseInt(Math.min(this.dance.endFrame, this.maxEndFrame)), duration: parseInt(Math.max(1, this.dance.duration)), fps: parseInt(Math.min(this.dance.fps, 500)) }); EventBridge.emitWebEvent(JSON.stringify({ type: UPDATE_DANCE_ARRAY, value: { dance: sanitizedObject, index: this.index } })); }, onClicked(){ this.clicked = !this.clicked; } }, template: /*html*/`
{{dance.name}}
Start Frame
End Frame
Duration(ms)
Frames/Sec
` }) Vue.component('dance-list', { props: ['dances', 'should_be_running'], template: /*html*/`
` }) Vue.component('dance', { props: ['dance', 'index'], methods: { addDance(){ if (!this.dance.selected) { EventBridge.emitWebEvent(JSON.stringify({ type: ADD_DANCE, value: { dance: this.dance, index: this.index } })); } else { EventBridge.emitWebEvent(JSON.stringify({ type: REMOVE_DANCE_FROM_MENU, value: { dance: this.dance, index: this.index } })); } }, tryDance(){ EventBridge.emitWebEvent(JSON.stringify({ type: TRY_DANCE, value: this.dance })); }, previewDance(){ EventBridge.emitWebEvent(JSON.stringify({ type: PREVIEW_DANCE, value: this.dance })); }, previewDanceStop(){ EventBridge.emitWebEvent(JSON.stringify({ type: PREVIEW_DANCE_STOP, value: this.dance })); }, }, template: /*html*/` ` }) // App // ///////////////////////////////////////////////////////////////////////// var app = new Vue({ el: '#app', data: { dataStore: { ui: { currentDance: false, danceList: false } } } }); // Procedural // ///////////////////////////////////////////////////////////////////////// function onScriptEventReceived(message) { var data; try { data = JSON.parse(message); switch (data.type) { case UPDATE_UI: if (data.slice === CURRENT_DANCE) { app.dataStore.currentDance = data.value.currentDance; } else { app.dataStore = data.value; } break; default: } } catch (e) { console.log(e) return; } } function onLoad() { // Initial button active state is communicated via URL parameter. // isActive = location.search.replace("?active=", "") === "true"; setTimeout(function () { // Open the EventBridge to communicate with the main script. // Allow time for EventBridge to become ready. EventBridge.scriptEventReceived.connect(onScriptEventReceived); EventBridge.emitWebEvent(JSON.stringify({ type: EVENT_BRIDGE_OPEN_MESSAGE })); }, EVENTBRIDGE_SETUP_DELAY); } // Main // ///////////////////////////////////////////////////////////////////////// onLoad(); }());