CR. Run through Lint ECMAScript 5 standard

Meaning all const are out, non-variable definitions are out, etc
This commit is contained in:
Menithal 2017-03-06 21:07:16 +02:00
parent 04d3bf0c38
commit d50a0e33a9
2 changed files with 41 additions and 28 deletions

View file

@ -11,21 +11,23 @@
// Makes the entity the script is bound to connect to nearby, similarly sized entities, like a magnet.
(function() {
const SNAPSOUND_SOURCE = SoundCache.getSound(Script.resolvePath("../../system/assets/sounds/entitySnap.wav?xrs"));
const RANGE_MULTIPLER = 1.5;
const MAX_SCALE = 2;
const MIN_SCALE = 0.5;
var SNAPSOUND_SOURCE = SoundCache.getSound(Script.resolvePath("../../system/assets/sounds/entitySnap.wav?xrs"));
var RANGE_MULTIPLER = 1.5;
var MAX_SCALE = 2;
var MIN_SCALE = 0.5;
// Helper for detecting nearby objects near entityProperties, with the scale calculated by the dimensions of the object.
function findEntitiesInRange(entityProperties) {
var dimensions = entityProperties.dimensions;
return Entities.findEntities(entityProperties.position, ((dimensions.x + dimensions.y + dimensions.z) / 3) * RANGE_MULTIPLER);
// Average of the dimensions instead of full value.
return Entities.findEntities(entityProperties.position,
((dimensions.x + dimensions.y + dimensions.z) / 3) * RANGE_MULTIPLER);
}
function getNearestValidEntityProperties(releasedProperties) {
var entities = findEntitiesInRange(releasedProperties);
var nearestEntity = null;
var nearest = 9999999999999;
var nearest = Number.MAX_SAFE_INTEGER;
var releaseSize = Vec3.length(releasedProperties.dimensions);
entities.forEach(function(entityId) {
if (entityId !== releasedProperties.id) {
@ -38,27 +40,30 @@
nearest = distance;
}
}
})
});
return nearestEntity;
}
// Create the 'class'
function MagneticBlock() {}
// Bind pre-emptive events
MagneticBlock.prototype = {
// When script is bound to an entity, preload is the first callback called with the entityID. It will behave as the constructor
/*
When script is bound to an entity, preload is the first callback called with the entityID.
It will behave as the constructor
*/
preload: function(id) {
/*
We will now override any existing userdata with the grabbable property.
Only retrieving userData
*/
var val = Entities.getEntityProperties(id, ['userData'])
var entity = Entities.getEntityProperties(id, ['userData']);
var userData = {
grabbableKey: {}
};
// Check if existing userData field exists.
if (val.userData && val.userData.length > 0) {
if (entity.userData && entity.userData.length > 0) {
try {
userData = JSON.parse(val.userData);
userData = JSON.parse(entity.userData);
if (!userData.grabbableKey) {
userData.grabbableKey = {}; // If by random change there is no grabbableKey in the userData.
}
@ -75,7 +80,7 @@
});
Script.scriptEnding.connect(function() {
Script.removeEventHandler(id, "releaseGrab", this.releaseGrab);
})
});
},
releaseGrab: function(entityId) {
// Release grab is called with entityId,
@ -102,7 +107,7 @@
x: 0,
y: 0,
z: 0
}
};
if (abs.x >= abs.y && abs.x >= abs.z) {
newRelative.x = target.dimensions.x / 2 + released.dimensions.x / 2;
if (relativeDifference.x < 0) {
@ -138,9 +143,9 @@
y: 0.5,
z: 0.5
}
})
});
}
}
}
};
return new MagneticBlock();
})
});

View file

@ -12,19 +12,20 @@
(function() {
const MAX_RGB_COMPONENT_VALUE = 256 / 2; // Limit the values to half the maximum.
const MIN_COLOR_VALUE = 127;
const SIZE = 0.3;
const LIFETIME = 600;
var MAX_RGB_COMPONENT_VALUE = 256 / 2; // Limit the values to half the maximum.
var MIN_COLOR_VALUE = 127;
var SIZE = 0.3;
var LIFETIME = 600;
var VERTICAL_OFFSET = -0.25;
var ROWS = 3;
var COLUMNS = 3;
// Random Pastel Generator based on Piper's script
function newColor() {
color = {
return {
red: randomPastelRGBComponent(),
green: randomPastelRGBComponent(),
blue: randomPastelRGBComponent()
};
return color;
}
// Helper functions.
function randomPastelRGBComponent() {
@ -34,9 +35,9 @@
var SCRIPT_URL = Script.resolvePath("./entity_scripts/magneticBlock.js");
var frontVector = Quat.getFront(MyAvatar.orientation);
frontVector.y -=.25;
for(var x =0; x < 3; x++) {
for (var y = 0; y < 3; y++) {
frontVector.y += VERTICAL_OFFSET;
for (var x = 0; x < COLUMNS; x++) {
for (var y = 0; y < ROWS; y++) {
var frontOffset = {
x: 0,
@ -46,13 +47,20 @@
Entities.addEntity({
type: "Box",
name: "MagneticBlock-" + y +'-' + x,
name: "MagneticBlock-" + y + '-' + x,
dimensions: {
x: SIZE,
y: SIZE,
z: SIZE
},
userData: JSON.stringify({grabbableKey: { cloneable: true, grabbable: true, cloneLifetime : LIFETIME, cloneLimit: 9999}}),
userData: JSON.stringify({
grabbableKey: {
cloneable: true,
grabbable: true,
cloneLifetime: LIFETIME,
cloneLimit: 9999
}
}),
position: Vec3.sum(MyAvatar.position, Vec3.sum(frontOffset, frontVector)),
color: newColor(),
script: SCRIPT_URL