58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
(function(){
|
|
|
|
var _entityId;
|
|
var _foundId;
|
|
var currentProps;
|
|
var _userdataProperties;
|
|
var wantDebug = false;
|
|
|
|
function searchForElevator(elevatorName, position, searchRadius) {
|
|
print("lightName serching for:", lightName);
|
|
print("lightName position for:", position);
|
|
|
|
Entities.findEntities(position, searchRadius).forEach(function (entityID) {
|
|
print("entityId", entityID);
|
|
var properties = Entities.getEntityProperties(entityID);
|
|
print(JSON.stringify(properties));
|
|
print("props name", properties.name);
|
|
print("lightName", elevatorName);
|
|
|
|
if (properties.name === elevatorName) {
|
|
_foundId = entityID;
|
|
}
|
|
});
|
|
}
|
|
|
|
/*
|
|
userData = {
|
|
elevatorName: "Light-Test",
|
|
searchRadius: 50,
|
|
}
|
|
*/
|
|
|
|
function ElevatorClient(){
|
|
|
|
}
|
|
|
|
ElevatorClient.prototype = {
|
|
preload: function(id){
|
|
_entityId = id;
|
|
currentProps = Entities.getEntityProperties(id);
|
|
var userData = currentProps.userData;
|
|
_userdataProperties = JSON.parse(userData);
|
|
print("### entity ID", id);
|
|
searchForElevator(_userdataProperties.elevatorName, currentProps.position, _userdataProperties.searchRadius);
|
|
},
|
|
enterEntity: function(){
|
|
searchForElevator(_userdataProperties.elevatorName, currentProps.position, _userdataProperties.searchRadius);
|
|
Entities.callEntityServerMethod(_foundId, 'startElevator');
|
|
},
|
|
leaveEntity: function(){
|
|
Entities.callEntityServerMethod(_foundId, 'stopElevator');
|
|
}
|
|
}
|
|
|
|
return new ElevatorClient();
|
|
})
|
|
|
|
/* globals Script Entities Vec3 */
|