Adding Portal Sound and Maximum Spawn protection

Adding Portal Sound and Maximum Spawn protection
This commit is contained in:
Alezia Kurdis 2025-01-16 22:19:10 -05:00 committed by GitHub
parent febb84e0f5
commit ec47320ee2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 72 additions and 34 deletions

View file

@ -38,8 +38,10 @@
var channel = "com.overte.places"; var channel = "com.overte.places";
var portalChannelName = "com.overte.places.portalRezzer"; var portalChannelName = "com.overte.places.portalRezzer";
var MAX_DISTANCE_TO_CONSIDER_PORTAL = 50.0; //in meters var MAX_DISTANCE_TO_CONSIDER_PORTAL = 100.0; //in meters
var PORTAL_DURATION_MILLISEC = 45000; //45 sec var PORTAL_DURATION_MILLISEC = 45000; //45 sec
var rezzerPortalCount = 0;
var MAX_REZZED_PORTAL = 15;
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
@ -587,6 +589,7 @@
} }
function generatePortal(position, url, name, placeID) { function generatePortal(position, url, name, placeID) {
if (rezzerPortalCount <= MAX_REZZED_PORTAL) {
var TOLERANCE_FACTOR = 1.1; var TOLERANCE_FACTOR = 1.1;
if (Vec3.distance(MyAvatar.position, position) < MAX_DISTANCE_TO_CONSIDER_PORTAL) { if (Vec3.distance(MyAvatar.position, position) < MAX_DISTANCE_TO_CONSIDER_PORTAL) {
var height = MyAvatar.userHeight * MyAvatar.scale * TOLERANCE_FACTOR; var height = MyAvatar.userHeight * MyAvatar.scale * TOLERANCE_FACTOR;
@ -614,12 +617,18 @@
"grabbable": false "grabbable": false
} }
}, "local"); }, "local");
rezzerPortalCount = rezzerPortalCount + 1;
Script.setTimeout(function () { Script.setTimeout(function () {
Entities.deleteEntity(portalID); Entities.deleteEntity(portalID);
rezzerPortalCount = rezzerPortalCount - 1;
if (rezzerPortalCount < 0) {
rezzerPortalCount = 0;
}
}, PORTAL_DURATION_MILLISEC); }, PORTAL_DURATION_MILLISEC);
} }
} }
}
function cleanup() { function cleanup() {

View file

@ -15,13 +15,17 @@
var portalURL = ""; var portalURL = "";
var portalName = ""; var portalName = "";
var TP_SOUND = SoundCache.getSound(ROOT + "sounds/teleportSound.mp3"); var TP_SOUND = SoundCache.getSound(ROOT + "sounds/teleportSound.mp3");
var PORTAL_SOUND = SoundCache.getSound(ROOT + "sounds/portalSound.mp3");
var portalInjector = Uuid.NONE;
var portalPosition;
this.preload = function(entityID) { this.preload = function(entityID) {
var properties = Entities.getEntityProperties(entityID, ["userData", "dimensions"]); var properties = Entities.getEntityProperties(entityID, ["userData", "dimensions", "position"]);
var userDataObj = JSON.parse(properties.userData); var userDataObj = JSON.parse(properties.userData);
portalURL = userDataObj.url; portalURL = userDataObj.url;
portalName = userDataObj.name; portalName = userDataObj.name;
portalPosition = properties.position;
var portalColor = getColorFromPlaceID(userDataObj.placeID); var portalColor = getColorFromPlaceID(userDataObj.placeID);
@ -116,6 +120,26 @@
"spinFinish": 0 "spinFinish": 0
},"local"); },"local");
if (PORTAL_SOUND.downloaded) {
playLoopSound();
} else {
PORTAL_SOUND.ready.connect(onSoundReady);
}
}
function onSoundReady() {
PORTAL_SOUND.ready.disconnect(onSoundReady);
playLoopSound();
}
function playLoopSound() {
var injectorOptions = {
"position": portalPosition,
"volume": 0.15,
"loop": true,
"localOnly": true
};
portalInjector = Audio.playSound(PORTAL_SOUND, injectorOptions);
} }
this.enterEntity = function(entityID) { this.enterEntity = function(entityID) {
@ -129,11 +153,16 @@
var timer = Script.setTimeout(function () { var timer = Script.setTimeout(function () {
Window.location = portalURL; Window.location = portalURL;
portalInjector.stop();
Entities.deleteEntity(entityID); Entities.deleteEntity(entityID);
}, 1000); }, 1000);
}; };
this.unload = function(entityID) {
portalInjector.stop();
};
function getColorFromPlaceID(placeID) { function getColorFromPlaceID(placeID) {
var idIntegerConstant = getStringScore(placeID); var idIntegerConstant = getStringScore(placeID);
var hue = (idIntegerConstant%360)/360; var hue = (idIntegerConstant%360)/360;

Binary file not shown.