mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 07:47:30 +02:00
This also works
This commit is contained in:
parent
022a47d3ec
commit
8044b33d65
10 changed files with 1 additions and 1862 deletions
|
@ -114,7 +114,7 @@ QUrl expandScriptUrl(const QUrl& rawScriptURL) {
|
|||
url = QUrl::fromLocalFile(fileInfo.canonicalFilePath());
|
||||
|
||||
QUrl defaultScriptsLoc = PathUtils::defaultScriptsLocation();
|
||||
if (!defaultScriptsLoc.isParentOf(url) /*&& defaultScriptsLoc != url*/) {
|
||||
if (!defaultScriptsLoc.isParentOf(url) && defaultScriptsLoc != url) {
|
||||
qCWarning(scriptengine) << "Script.include() ignoring file path"
|
||||
<< "-- outside of standard libraries: "
|
||||
<< url.path()
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
"use strict";
|
||||
//
|
||||
// backbutton.js
|
||||
// scripts/system/+android
|
||||
//
|
||||
// Created by Gabriel Calero & Cristian Duarte on Apr 06, 2018
|
||||
// Copyright 2018 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() { // BEGIN LOCAL_SCOPE
|
||||
|
||||
var actionbar;
|
||||
var backButton;
|
||||
|
||||
var logEnabled = true;
|
||||
|
||||
function printd(str) {
|
||||
if (logEnabled)
|
||||
print("[actionbar.js] " + str);
|
||||
}
|
||||
|
||||
function init() {
|
||||
actionbar = new QmlFragment({
|
||||
qml: "hifi/ActionBar.qml"
|
||||
});
|
||||
backButton = actionbar.addButton({
|
||||
icon: "icons/+android_interface/backward.svg",
|
||||
activeIcon: "icons/+android_interface/backward.svg",
|
||||
text: "",
|
||||
bgOpacity: 0.0,
|
||||
hoverBgOpacity: 0.0,
|
||||
activeBgOpacity: 0.0
|
||||
});
|
||||
|
||||
backButton.entered.connect(onBackPressed);
|
||||
backButton.clicked.connect(onBackClicked);
|
||||
}
|
||||
|
||||
function onBackPressed() {
|
||||
Controller.triggerHapticPulseOnDevice(Controller.findDevice("TouchscreenVirtualPad"), 0.1, 40.0, 0);
|
||||
}
|
||||
|
||||
function onBackClicked() {
|
||||
Window.openAndroidActivity("Home", false);
|
||||
}
|
||||
|
||||
|
||||
Script.scriptEnding.connect(function() {
|
||||
if(backButton) {
|
||||
backButton.entered.disconnect(onBackPressed);
|
||||
backButton.clicked.disconnect(onBackClicked);
|
||||
}
|
||||
});
|
||||
|
||||
init();
|
||||
|
||||
}()); // END LOCAL_SCOPE
|
|
@ -1,71 +0,0 @@
|
|||
"use strict";
|
||||
//
|
||||
// audio.js
|
||||
// scripts/system/
|
||||
//
|
||||
// Created by Gabriel Calero & Cristian Duarte on Jan 16, 2018
|
||||
// Copyright 2018 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() { // BEGIN LOCAL_SCOPE
|
||||
|
||||
var audiobar;
|
||||
var audioButton;
|
||||
|
||||
var logEnabled = false;
|
||||
|
||||
function printd(str) {
|
||||
if (logEnabled)
|
||||
print("[audio.js] " + str);
|
||||
}
|
||||
|
||||
function init() {
|
||||
audiobar = new QmlFragment({
|
||||
qml: "hifi/AudioBar.qml"
|
||||
});
|
||||
|
||||
audioButton = audiobar.addButton({
|
||||
icon: "icons/mic-unmute-a.svg",
|
||||
activeIcon: "icons/mic-mute-a.svg",
|
||||
text: "",
|
||||
bgOpacity: 0.0,
|
||||
hoverBgOpacity: 0.0,
|
||||
activeHoverBgOpacity: 0.0,
|
||||
activeBgOpacity: 0.0
|
||||
});
|
||||
|
||||
onMuteToggled();
|
||||
|
||||
audioButton.clicked.connect(onMuteClicked);
|
||||
audioButton.entered.connect(onMutePressed);
|
||||
Audio.mutedChanged.connect(onMuteToggled);
|
||||
}
|
||||
|
||||
function onMuteClicked() {
|
||||
Audio.muted = !Audio.muted;
|
||||
}
|
||||
|
||||
function onMutePressed() {
|
||||
Controller.triggerHapticPulseOnDevice(Controller.findDevice("TouchscreenVirtualPad"), 0.1, 40.0, 0);
|
||||
}
|
||||
|
||||
function onMuteToggled() {
|
||||
printd("On Mute Toggled");
|
||||
audioButton.isActive = Audio.muted; // Menu.isOptionChecked("Mute Microphone")
|
||||
printd("Audio button is active: " + audioButton.isActive);
|
||||
}
|
||||
|
||||
Script.scriptEnding.connect(function () {
|
||||
if(audioButton) {
|
||||
audioButton.clicked.disconnect(onMuteClicked);
|
||||
audioButton.entered.disconnect(onMutePressed);
|
||||
Audio.mutedChanged.connect(onMuteToggled);
|
||||
}
|
||||
});
|
||||
|
||||
init();
|
||||
|
||||
}()); // END LOCAL_SCOPE
|
|
@ -1,108 +0,0 @@
|
|||
"use strict";
|
||||
//
|
||||
// clickWeb.js
|
||||
// scripts/system/+android
|
||||
//
|
||||
// Created by Gabriel Calero & Cristian Duarte on Jun 22, 2018
|
||||
// Copyright 2018 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() { // BEGIN LOCAL_SCOPE
|
||||
|
||||
var logEnabled = false;
|
||||
var touchOverlayID;
|
||||
var touchEntityID;
|
||||
|
||||
function printd(str) {
|
||||
if (logEnabled)
|
||||
print("[clickWeb.js] " + str);
|
||||
}
|
||||
|
||||
function intersectsWebOverlay(intersection) {
|
||||
return intersection && intersection.intersects && intersection.overlayID &&
|
||||
Overlays.getOverlayType(intersection.overlayID) == "web3d";
|
||||
}
|
||||
|
||||
function intersectsWebEntity(intersection) {
|
||||
if (intersection && intersection.intersects && intersection.entityID) {
|
||||
var properties = Entities.getEntityProperties(intersection.entityID, ["type", "sourceUrl"]);
|
||||
return properties.type && properties.type == "Web" && properties.sourceUrl;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function findRayIntersection(pickRay) {
|
||||
// Check 3D overlays and entities. Argument is an object with origin and direction.
|
||||
var overlayRayIntersection = Overlays.findRayIntersection(pickRay);
|
||||
var entityRayIntersection = Entities.findRayIntersection(pickRay, true);
|
||||
var isOverlayInters = intersectsWebOverlay(overlayRayIntersection);
|
||||
var isEntityInters = intersectsWebEntity(entityRayIntersection);
|
||||
if (isOverlayInters &&
|
||||
(!isEntityInters ||
|
||||
overlayRayIntersection.distance < entityRayIntersection.distance)) {
|
||||
return { type: 'overlay', obj: overlayRayIntersection };
|
||||
} else if (isEntityInters &&
|
||||
(!isOverlayInters ||
|
||||
entityRayIntersection.distance < overlayRayIntersection.distance)) {
|
||||
return { type: 'entity', obj: entityRayIntersection };
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function touchBegin(event) {
|
||||
var intersection = findRayIntersection(Camera.computePickRay(event.x, event.y));
|
||||
if (intersection && intersection.type == 'overlay') {
|
||||
touchOverlayID = intersection.obj.overlayID;
|
||||
touchEntityID = null;
|
||||
} else if (intersection && intersection.type == 'entity') {
|
||||
touchEntityID = intersection.obj.entityID;
|
||||
touchOverlayID = null;
|
||||
}
|
||||
}
|
||||
|
||||
function touchEnd(event) {
|
||||
var intersection = findRayIntersection(Camera.computePickRay(event.x, event.y));
|
||||
if (intersection && intersection.type == 'overlay' && touchOverlayID == intersection.obj.overlayID) {
|
||||
var propertiesToGet = {};
|
||||
propertiesToGet[overlayID] = ['url'];
|
||||
var properties = Overlays.getOverlaysProperties(propertiesToGet);
|
||||
if (properties[overlayID].url) {
|
||||
Window.openUrl(properties[overlayID].url);
|
||||
}
|
||||
} else if (intersection && intersection.type == 'entity' && touchEntityID == intersection.obj.entityID) {
|
||||
var properties = Entities.getEntityProperties(touchEntityID, ["sourceUrl"]);
|
||||
if (properties.sourceUrl) {
|
||||
Window.openUrl(properties.sourceUrl);
|
||||
}
|
||||
}
|
||||
|
||||
touchOverlayID = null;
|
||||
touchEntityID = null;
|
||||
}
|
||||
|
||||
function ending() {
|
||||
Controller.touchBeginEvent.disconnect(touchBegin);
|
||||
Controller.touchEndEvent.disconnect(touchEnd);
|
||||
}
|
||||
|
||||
function init() {
|
||||
Controller.touchBeginEvent.connect(touchBegin);
|
||||
Controller.touchEndEvent.connect(touchEnd);
|
||||
|
||||
Script.scriptEnding.connect(function () {
|
||||
ending();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: init,
|
||||
ending: ending
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
}()); // END LOCAL_SCOPE
|
|
@ -1,167 +0,0 @@
|
|||
"use strict";
|
||||
//
|
||||
// displayNames.js
|
||||
// scripts/system/
|
||||
//
|
||||
// Created by Cristian Duarte & Gabriel Calero on May 3, 2018
|
||||
// Copyright 2018 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() { // BEGIN LOCAL_SCOPE
|
||||
|
||||
var MAX_DISTANCE_PX = 20; // Should we use dp instead?
|
||||
var UNKNOWN_NAME = "Unknown";
|
||||
var METERS_ABOVE_HEAD = 0.4;
|
||||
|
||||
var TEXT_LINE_HEIGHT = .1;
|
||||
var TEXT_MARGIN = 0.025;
|
||||
|
||||
var HIDE_MS = 10000;
|
||||
|
||||
var currentTouchToAnalyze = null;
|
||||
|
||||
var currentlyShownAvatar = {
|
||||
avatarID: null,
|
||||
avatar: null,
|
||||
overlay: null
|
||||
};
|
||||
|
||||
var logEnabled = false;
|
||||
|
||||
var hideTimer = null;
|
||||
|
||||
function printd(str) {
|
||||
if (logEnabled) {
|
||||
print("[displayNames.js] " + str);
|
||||
}
|
||||
}
|
||||
|
||||
function clearOverlay() {
|
||||
currentlyShownAvatar.avatar = null;
|
||||
if (currentlyShownAvatar.overlay) {
|
||||
Overlays.editOverlay(currentlyShownAvatar.overlay, {visible: false});
|
||||
}
|
||||
}
|
||||
|
||||
function touchedAvatar(avatarID, avatarData) {
|
||||
printd("[AVATARNAME] touchEnd FOUND " + JSON.stringify(avatarData));
|
||||
|
||||
if (hideTimer) {
|
||||
Script.clearTimeout(hideTimer);
|
||||
}
|
||||
|
||||
// Case: touching an already selected avatar
|
||||
if (currentlyShownAvatar.avatar && currentlyShownAvatar.avatarID == avatarID) {
|
||||
clearOverlay();
|
||||
return;
|
||||
}
|
||||
|
||||
// Save currently selected avatar
|
||||
currentlyShownAvatar.avatarID = avatarID;
|
||||
currentlyShownAvatar.avatar = avatarData;
|
||||
|
||||
if (currentlyShownAvatar.overlay == null) {
|
||||
var over = Overlays.addOverlay("text3d", {
|
||||
lineHeight: TEXT_LINE_HEIGHT,
|
||||
color: { red: 255, green: 255, blue: 255},
|
||||
backgroundColor: {red: 0, green: 0, blue: 0},
|
||||
leftMargin: TEXT_MARGIN,
|
||||
topMargin: TEXT_MARGIN,
|
||||
rightMargin: TEXT_MARGIN,
|
||||
bottomMargin: TEXT_MARGIN,
|
||||
alpha: 0.6,
|
||||
solid: true,
|
||||
isFacingAvatar: true,
|
||||
visible: false
|
||||
});
|
||||
currentlyShownAvatar.overlay = over;
|
||||
}
|
||||
|
||||
var nameToShow = avatarData.displayName ? avatarData.displayName :
|
||||
(avatarData.sessionDisplayName ? avatarData.sessionDisplayName : UNKNOWN_NAME);
|
||||
var textSize = Overlays.textSize(currentlyShownAvatar.overlay, nameToShow);
|
||||
|
||||
Overlays.editOverlay(currentlyShownAvatar.overlay, {
|
||||
dimensions: {
|
||||
x: textSize.width + 2 * TEXT_MARGIN,
|
||||
y: TEXT_LINE_HEIGHT + 2 * TEXT_MARGIN
|
||||
},
|
||||
localPosition: { x: 0, y: METERS_ABOVE_HEAD, z: 0 },
|
||||
text: nameToShow,
|
||||
parentID: avatarData.sessionUUID,
|
||||
parentJointIndex: avatarData.getJointIndex("Head"),
|
||||
visible: true
|
||||
});
|
||||
|
||||
hideTimer = Script.setTimeout(function() {
|
||||
clearOverlay();
|
||||
}, HIDE_MS);
|
||||
}
|
||||
|
||||
function touchBegin(event) {
|
||||
currentTouchToAnalyze = event;
|
||||
}
|
||||
|
||||
function touchEnd(event) {
|
||||
if (Vec3.distance({x: event.x, y: event.y }, {x: currentTouchToAnalyze.x, y: currentTouchToAnalyze.y}) > MAX_DISTANCE_PX) {
|
||||
printd("[AVATARNAME] touchEnd moved too much");
|
||||
currentTouchToAnalyze = null;
|
||||
return;
|
||||
}
|
||||
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
var avatarRay = AvatarManager.findRayIntersection(pickRay, [], [MyAvatar.sessionUUID])
|
||||
|
||||
if (avatarRay.intersects) {
|
||||
touchedAvatar(avatarRay.avatarID, AvatarManager.getAvatar(avatarRay.avatarID));
|
||||
} else {
|
||||
printd("[AVATARNAME] touchEnd released outside the avatar");
|
||||
}
|
||||
|
||||
currentTouchToAnalyze = null;
|
||||
}
|
||||
|
||||
var runAtLeastOnce = false;
|
||||
|
||||
function ending() {
|
||||
if (!runAtLeastOnce) {
|
||||
return;
|
||||
}
|
||||
|
||||
Controller.touchBeginEvent.disconnect(touchBegin);
|
||||
Controller.touchEndEvent.disconnect(touchEnd);
|
||||
Controller.mousePressEvent.disconnect(touchBegin);
|
||||
Controller.mouseReleaseEvent.disconnect(touchEnd);
|
||||
|
||||
if (currentlyShownAvatar.overlay) {
|
||||
Overlays.deleteOverlay(currentlyShownAvatar.overlay);
|
||||
currentlyShownAvatar.overlay = null;
|
||||
}
|
||||
if (currentlyShownAvatar.avatar) {
|
||||
currentlyShownAvatar.avatar = null;
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
Controller.touchBeginEvent.connect(touchBegin);
|
||||
Controller.touchEndEvent.connect(touchEnd);
|
||||
Controller.mousePressEvent.connect(touchBegin);
|
||||
Controller.mouseReleaseEvent.connect(touchEnd);
|
||||
|
||||
Script.scriptEnding.connect(function () {
|
||||
ending();
|
||||
});
|
||||
|
||||
runAtLeastOnce = true;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: init,
|
||||
ending: ending
|
||||
}
|
||||
|
||||
//init(); // Enable to use in desktop as a standalone
|
||||
|
||||
}()); // END LOCAL_SCOPE
|
|
@ -1,124 +0,0 @@
|
|||
"use strict";
|
||||
//
|
||||
// modes.js
|
||||
// scripts/system/
|
||||
//
|
||||
// Created by Gabriel Calero & Cristian Duarte on Jan 23, 2018
|
||||
// Copyright 2018 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() { // BEGIN LOCAL_SCOPE
|
||||
|
||||
var modeButton;
|
||||
var currentMode;
|
||||
var barQml;
|
||||
|
||||
var SETTING_CURRENT_MODE_KEY = 'Android/Mode';
|
||||
var MODE_VR = "VR", MODE_RADAR = "RADAR", MODE_MY_VIEW = "MY VIEW";
|
||||
var DEFAULT_MODE = MODE_MY_VIEW;
|
||||
var nextMode = {};
|
||||
nextMode[MODE_RADAR]=MODE_MY_VIEW;
|
||||
nextMode[MODE_MY_VIEW]=MODE_RADAR;
|
||||
var modeLabel = {};
|
||||
modeLabel[MODE_RADAR]="TOP VIEW";
|
||||
modeLabel[MODE_MY_VIEW]="MY VIEW";
|
||||
|
||||
var logEnabled = false;
|
||||
var radar = Script.require('./radar.js');
|
||||
var uniqueColor = Script.require('./uniqueColor.js');
|
||||
var displayNames = Script.require('./displayNames.js');
|
||||
var clickWeb = Script.require('./clickWeb.js');
|
||||
|
||||
function printd(str) {
|
||||
if (logEnabled) {
|
||||
print("[modes.js] " + str);
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
radar.setUniqueColor(uniqueColor);
|
||||
radar.init();
|
||||
|
||||
barQml = new QmlFragment({
|
||||
qml: "hifi/modesbar.qml"
|
||||
});
|
||||
modeButton = barQml.addButton({
|
||||
icon: "icons/myview-a.svg",
|
||||
activeBgOpacity: 0.0,
|
||||
hoverBgOpacity: 0.0,
|
||||
activeHoverBgOpacity: 0.0,
|
||||
text: "MODE",
|
||||
height:240,
|
||||
bottomMargin: 16,
|
||||
textSize: 38,
|
||||
fontFamily: "Raleway",
|
||||
fontBold: true
|
||||
|
||||
});
|
||||
|
||||
switchToMode(getCurrentModeSetting());
|
||||
|
||||
modeButton.entered.connect(modeButtonPressed);
|
||||
modeButton.clicked.connect(modeButtonClicked);
|
||||
}
|
||||
|
||||
function shutdown() {
|
||||
modeButton.entered.disconnect(modeButtonPressed);
|
||||
modeButton.clicked.disconnect(modeButtonClicked);
|
||||
}
|
||||
|
||||
function modeButtonPressed() {
|
||||
Controller.triggerHapticPulseOnDevice(Controller.findDevice("TouchscreenVirtualPad"), 0.1, 40.0, 0);
|
||||
}
|
||||
|
||||
function modeButtonClicked() {
|
||||
switchToMode(nextMode[currentMode]);
|
||||
}
|
||||
|
||||
function saveCurrentModeSetting(mode) {
|
||||
Settings.setValue(SETTING_CURRENT_MODE_KEY, mode);
|
||||
}
|
||||
|
||||
function getCurrentModeSetting(mode) {
|
||||
return Settings.getValue(SETTING_CURRENT_MODE_KEY, DEFAULT_MODE);
|
||||
}
|
||||
|
||||
function switchToMode(newMode) {
|
||||
// before leaving radar mode
|
||||
if (currentMode == MODE_RADAR) {
|
||||
radar.endRadarMode();
|
||||
}
|
||||
currentMode = newMode;
|
||||
modeButton.text = modeLabel[currentMode];
|
||||
|
||||
saveCurrentModeSetting(currentMode);
|
||||
|
||||
if (currentMode == MODE_RADAR) {
|
||||
radar.startRadarMode();
|
||||
displayNames.ending();
|
||||
clickWeb.ending();
|
||||
} else if (currentMode == MODE_MY_VIEW) {
|
||||
// nothing to do yet
|
||||
displayNames.init();
|
||||
clickWeb.init();
|
||||
} else {
|
||||
printd("Unknown view mode " + currentMode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function sendToQml(o) {
|
||||
if(barQml) {
|
||||
barQml.sendToQml(o);
|
||||
}
|
||||
}
|
||||
|
||||
Script.scriptEnding.connect(function () {
|
||||
shutdown();
|
||||
});
|
||||
|
||||
init();
|
||||
|
||||
}()); // END LOCAL_SCOPE
|
File diff suppressed because it is too large
Load diff
|
@ -1,39 +0,0 @@
|
|||
"use strict";
|
||||
//
|
||||
// stats.js
|
||||
// scripts/system/
|
||||
//
|
||||
// Created by Sam Gondelman on 3/14/18
|
||||
// Copyright 2018 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() { // BEGIN LOCAL_SCOPE
|
||||
|
||||
var statsbar;
|
||||
var statsButton;
|
||||
|
||||
function init() {
|
||||
statsbar = new QmlFragment({
|
||||
qml: "hifi/StatsBar.qml"
|
||||
});
|
||||
|
||||
statsButton = statsbar.addButton({
|
||||
icon: "icons/stats.svg",
|
||||
activeIcon: "icons/stats.svg",
|
||||
textSize: 45,
|
||||
bgOpacity: 0.0,
|
||||
activeBgOpacity: 0.0,
|
||||
bgColor: "#FFFFFF",
|
||||
text: "STATS"
|
||||
});
|
||||
statsButton.clicked.connect(function() {
|
||||
Menu.triggerOption("Show Statistics");
|
||||
});
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
}()); // END LOCAL_SCOPE
|
|
@ -1,22 +0,0 @@
|
|||
"use strict";
|
||||
//
|
||||
// touchscreenvirtualpad.js
|
||||
// scripts/system/
|
||||
//
|
||||
// Created by Gabriel Calero & Cristian Duarte on Jan 16, 2018
|
||||
// Copyright 2018 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() { // BEGIN LOCAL_SCOPE
|
||||
|
||||
function init() {
|
||||
Controller.setVPadEnabled(true);
|
||||
Controller.setVPadHidden(false);
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
}()); // END LOCAL_SCOPE
|
|
@ -1,54 +0,0 @@
|
|||
"use strict";
|
||||
//
|
||||
// uniqueColor.js
|
||||
// scripts/system/
|
||||
//
|
||||
// Created by Gabriel Calero & Cristian Duarte on 17 Oct 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
|
||||
//
|
||||
|
||||
var colorsMap = {};
|
||||
var colorsCount = 0;
|
||||
// 'red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'magenta'
|
||||
var baseColors = [ '#EB3345', '#F0851F', '#FFCD29', '#94C338', '#11A6C5', '#294C9F', '#C01D84' ];
|
||||
|
||||
function getNextColor(n) {
|
||||
var N = baseColors.length;
|
||||
/*if (n < baseColors.length) {
|
||||
return baseColors[n];
|
||||
} else {
|
||||
var baseColor = baseColors[n % N];
|
||||
var d = (n / N) % 10;
|
||||
var c2 = "" + Qt.lighter(baseColor, 1 + d / 10);
|
||||
return c2;
|
||||
}*/
|
||||
return baseColors[n%N];
|
||||
}
|
||||
|
||||
function getColorForId(uuid) {
|
||||
if (colorsMap == undefined) {
|
||||
colorsMap = {};
|
||||
}
|
||||
if (!colorsMap.hasOwnProperty(uuid)) {
|
||||
colorsMap[uuid] = getNextColor(colorsCount);
|
||||
colorsCount = colorsCount + 1;
|
||||
}
|
||||
return colorsMap[uuid];
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getColor: function(id) {
|
||||
return getColorForId(id);
|
||||
},
|
||||
convertHexToRGB: function(hex) {
|
||||
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
||||
return result ? {
|
||||
red: parseInt(result[1], 16),
|
||||
green: parseInt(result[2], 16),
|
||||
blue: parseInt(result[3], 16)
|
||||
} : null;
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue