mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 08:29:33 +02:00
Fix updating of distance/high score
This commit is contained in:
parent
bb0ce67f6b
commit
14cdc5801e
1 changed files with 28 additions and 25 deletions
|
@ -2,9 +2,35 @@ print("Loading pitching");
|
||||||
//Script.include("../libraries/line.js");
|
//Script.include("../libraries/line.js");
|
||||||
Script.include("https://raw.githubusercontent.com/huffman/hifi/line-js/examples/libraries/line.js");
|
Script.include("https://raw.githubusercontent.com/huffman/hifi/line-js/examples/libraries/line.js");
|
||||||
|
|
||||||
|
// Return all entities with properties `properties` within radius `searchRadius`
|
||||||
|
function findEntities(properties, searchRadius) {
|
||||||
|
var entities = Entities.findEntities(MyAvatar.position, searchRadius);
|
||||||
|
var matchedEntities = [];
|
||||||
|
var keys = Object.keys(properties);
|
||||||
|
for (var i = 0; i < entities.length; ++i) {
|
||||||
|
var match = true;
|
||||||
|
var candidateProperties = Entities.getEntityProperties(entities[i], keys);
|
||||||
|
for (var key in properties) {
|
||||||
|
if (candidateProperties[key] != properties[key]) {
|
||||||
|
// This isn't a match, move to next entity
|
||||||
|
match = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (match) {
|
||||||
|
matchedEntities.push(entities[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return matchedEntities;
|
||||||
|
}
|
||||||
|
|
||||||
// These are hard-coded to the relevant entity IDs on the sport server
|
// These are hard-coded to the relevant entity IDs on the sport server
|
||||||
var DISTANCE_BILLBOARD_ENTITY_ID = "{faa88b15-5b85-408c-ae07-a31e5a5ca791}";
|
var DISTANCE_BILLBOARD_NAME = "CurrentScore";
|
||||||
var HIGH_SCORE_BILLBOARD_ENTITY_ID = "{5fe0daf5-3fc5-43e3-a4eb-81a8e840a52b}";
|
var HIGH_SCORE_BILLBOARD_NAME = "HighScore";
|
||||||
|
var DISTANCE_BILLBOARD_ENTITY_ID = findEntities({name: DISTANCE_BILLBOARD_NAME }, 1000)[0];
|
||||||
|
var HIGH_SCORE_BILLBOARD_ENTITY_ID = findEntities({name: HIGH_SCORE_BILLBOARD_NAME }, 1000)[0];
|
||||||
|
print("Distance: ", DISTANCE_BILLBOARD_ENTITY_ID)
|
||||||
|
|
||||||
var METERS_TO_FEET = 3.28084;
|
var METERS_TO_FEET = 3.28084;
|
||||||
|
|
||||||
|
@ -81,29 +107,6 @@ var DISTANCE_FROM_PLATE = PITCHING_MACHINE_PROPERTIES.position.z;
|
||||||
|
|
||||||
var PITCH_RATE = 5000;
|
var PITCH_RATE = 5000;
|
||||||
|
|
||||||
// Return all entities with properties `properties` within radius `searchRadius`
|
|
||||||
function findEntities(properties, searchRadius) {
|
|
||||||
var entities = Entities.findEntities(MyAvatar.position, searchRadius);
|
|
||||||
var matchedEntities = [];
|
|
||||||
var keys = Object.keys(properties);
|
|
||||||
for (var i = 0; i < entities.length; ++i) {
|
|
||||||
var match = true;
|
|
||||||
var candidateProperties = Entities.getEntityProperties(entities[i], keys);
|
|
||||||
for (var key in properties) {
|
|
||||||
if (candidateProperties[key] != properties[key]) {
|
|
||||||
// This isn't a match, move to next entity
|
|
||||||
match = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (match) {
|
|
||||||
matchedEntities.push(entities[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return matchedEntities;
|
|
||||||
}
|
|
||||||
|
|
||||||
getPitchingMachine = function() {
|
getPitchingMachine = function() {
|
||||||
// Search for pitching machine
|
// Search for pitching machine
|
||||||
var entities = findEntities({ name: PITCHING_MACHINE_PROPERTIES.name }, 1000);
|
var entities = findEntities({ name: PITCHING_MACHINE_PROPERTIES.name }, 1000);
|
||||||
|
|
Loading…
Reference in a new issue