overte/scripts/vr-edit/vr-edit.js

67 lines
1.7 KiB
JavaScript

"use strict";
//
// vr-edit.js
//
// Created by David Rowe on 27 Jun 2017.
// Copyright 2017 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
(function () {
var APP_NAME = "VR EDIT", // TODO: App name.
APP_ICON_INACTIVE = "icons/tablet-icons/edit-i.svg", // TODO: App icons.
APP_ICON_ACTIVE = "icons/tablet-icons/edit-a.svg",
tablet,
button,
isAppActive = false,
VR_EDIT_SETTING = "io.highfidelity.isVREditing"; // Note: This constant is duplicated in utils.js.
function onButtonClicked() {
isAppActive = !isAppActive;
Settings.setValue(VR_EDIT_SETTING, isAppActive);
button.editProperties({ isActive: isAppActive });
}
function setUp() {
Settings.setValue(VR_EDIT_SETTING, isAppActive);
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
if (!tablet) {
return;
}
// Tablet/toolbar button.
button = tablet.addButton({
icon: APP_ICON_INACTIVE,
activeIcon: APP_ICON_ACTIVE,
text: APP_NAME,
isActive: isAppActive
});
if (button) {
button.clicked.connect(onButtonClicked);
}
}
function tearDown() {
if (!tablet) {
return;
}
if (button) {
button.clicked.disconnect(onButtonClicked);
tablet.removeButton(button);
button = null;
}
tablet = null;
}
setUp();
Script.scriptEnding.connect(tearDown);
}());