content/hifi-content/rebecca/Trivia/podium style/triviaProtectionZone.js
2022-02-14 02:04:11 +01:00

82 lines
2.6 KiB
JavaScript

//
// triviaProtectedZone.js
//
// Created by Rebecca Stankus on 08/31/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() {
var DELETE_OVERLAY_MS = 1000;
var _this;
var disqualifiedPosition;
var doNotEnterOverlay;
var TriviaZone = function() {
_this = this;
};
TriviaZone.prototype = {
preload: function(entityID) {
_this.entityID = entityID;
Entities.getChildrenIDs(_this.entityID).forEach(function(child) {
var properties = Entities.getEntityProperties(child, ['name', 'position']);
if (properties.name === "Trivia Zone Out Marker") {
disqualifiedPosition = properties.position;
disqualifiedPosition.y ++;
}
});
},
enterEntity: function() {
MyAvatar.position = disqualifiedPosition;
_this.createOverlay();
},
getPositionInFrontOfAvatar: function() {
var direction = Quat.getFront(MyAvatar.orientation);
var distance = 5;
var position = Vec3.sum(MyAvatar.position, Vec3.multiply(direction, distance));
position.y += 0.5;
return position;
},
createOverlay: function() {
doNotEnterOverlay = Overlays.addOverlay("text3d", {
textColor: { red: 0, blue: 0, green: 0 },
color: { red: 255, blue: 255, green: 255 },
dimensions: { x: 1.2, y: 0.7, z: 0.01 },
lineHeight: 0.2,
text: "Please wait to\nenter until the\nnext round.",
position: _this.getPositionInFrontOfAvatar(),
isFacingAvatar: true,
leftMargin: 0.01,
topMargin: 0.01,
rightMargin: 0.01,
bottomMargin: 0.01,
alpha: 0.7
});
Script.setTimeout(function() {
if (doNotEnterOverlay) {
Overlays.deleteOverlay(doNotEnterOverlay);
}
}, DELETE_OVERLAY_MS);
},
leaveEntity: function() {
if (doNotEnterOverlay) {
Overlays.deleteOverlay(doNotEnterOverlay);
}
},
unload: function() {
_this.leaveEntity();
}
};
return new TriviaZone;
});