mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 19:59:28 +02:00
Cleanup string in bow to only use 1 entity
This commit is contained in:
parent
c06a3a3a11
commit
09dd68ae37
1 changed files with 75 additions and 94 deletions
169
bow/bow/bow.js
169
bow/bow/bow.js
|
@ -106,6 +106,7 @@
|
||||||
aiming: false,
|
aiming: false,
|
||||||
arrowTipPosition: null,
|
arrowTipPosition: null,
|
||||||
preNotchString: null,
|
preNotchString: null,
|
||||||
|
stringID: null,
|
||||||
arrow: null,
|
arrow: null,
|
||||||
stringData: {
|
stringData: {
|
||||||
currentColor: {
|
currentColor: {
|
||||||
|
@ -125,13 +126,7 @@
|
||||||
this.arrowNotchSound = SoundCache.getSound(NOTCH_ARROW_SOUND_URL);
|
this.arrowNotchSound = SoundCache.getSound(NOTCH_ARROW_SOUND_URL);
|
||||||
var userData = Entities.getEntityProperties(this.entityID, ["userData"]).userData;
|
var userData = Entities.getEntityProperties(this.entityID, ["userData"]).userData;
|
||||||
this.userData = JSON.parse(userData);
|
this.userData = JSON.parse(userData);
|
||||||
var children = Entities.getChildrenIDs(this.entityID);
|
this.stringID = null;
|
||||||
children.forEach(function(childID) {
|
|
||||||
var childName = Entities.getEntityProperties(childID, ["name"]).name;
|
|
||||||
if (childName == "Hifi-Bow-Pre-Notch-String") {
|
|
||||||
this.preNotchString = children[0];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
unload: function() {
|
unload: function() {
|
||||||
|
@ -152,21 +147,8 @@
|
||||||
var data = getEntityCustomData('grabbableKey', this.entityID, {});
|
var data = getEntityCustomData('grabbableKey', this.entityID, {});
|
||||||
data.grabbable = false;
|
data.grabbable = false;
|
||||||
setEntityCustomData('grabbableKey', this.entityID, data);
|
setEntityCustomData('grabbableKey', this.entityID, data);
|
||||||
Entities.editEntity(_this.entityID, {
|
|
||||||
collidesWith: ""
|
|
||||||
});
|
|
||||||
|
|
||||||
//make sure the string is ready
|
this.initString();
|
||||||
if (!this.preNotchString) {
|
|
||||||
this.createPreNotchString();
|
|
||||||
}
|
|
||||||
var preNotchStringProps = Entities.getEntityProperties(this.preNotchString);
|
|
||||||
if (!preNotchStringProps || preNotchStringProps.name != "Hifi-Bow-Pre-Notch-String") {
|
|
||||||
this.createPreNotchString();
|
|
||||||
}
|
|
||||||
Entities.editEntity(this.preNotchString, {
|
|
||||||
visible: true
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
continueEquip: function(entityID, args) {
|
continueEquip: function(entityID, args) {
|
||||||
this.deltaTime = checkInterval();
|
this.deltaTime = checkInterval();
|
||||||
|
@ -184,17 +166,27 @@
|
||||||
this.checkStringHand();
|
this.checkStringHand();
|
||||||
},
|
},
|
||||||
releaseEquip: function(entityID, args) {
|
releaseEquip: function(entityID, args) {
|
||||||
Messages.sendMessage('Hifi-Hand-Disabler', "none");
|
Messages.sendLocalMessage('Hifi-Hand-Disabler', "none");
|
||||||
|
|
||||||
this.stringDrawn = false;
|
this.stringDrawn = false;
|
||||||
this.deleteStrings();
|
|
||||||
|
|
||||||
var data = getEntityCustomData('grabbableKey', this.entityID, {});
|
var data = getEntityCustomData('grabbableKey', this.entityID, {});
|
||||||
data.grabbable = true;
|
data.grabbable = true;
|
||||||
setEntityCustomData('grabbableKey', this.entityID, data);
|
setEntityCustomData('grabbableKey', this.entityID, data);
|
||||||
Entities.deleteEntity(this.arrow);
|
Entities.deleteEntity(this.arrow);
|
||||||
Entities.editEntity(_this.entityID, {
|
this.resetStringToIdlePosition();
|
||||||
collidesWith: "static,dynamic,kinematic,otherAvatar,myAvatar"
|
this.destroyArrow();
|
||||||
|
},
|
||||||
|
|
||||||
|
destroyArrow: function() {
|
||||||
|
var children = Entities.getChildrenIDs(this.entityID);
|
||||||
|
children.forEach(function(childID) {
|
||||||
|
var childName = Entities.getEntityProperties(childID, ["name"]).name;
|
||||||
|
if (childName == ARROW_NAME) {
|
||||||
|
Entities.deleteEntity(childID);
|
||||||
|
// Continue iterating through children in case we've ended up in
|
||||||
|
// a bad state where there are multiple arrows.
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -202,7 +194,7 @@
|
||||||
this.playArrowNotchSound();
|
this.playArrowNotchSound();
|
||||||
|
|
||||||
var arrow = Entities.addEntity({
|
var arrow = Entities.addEntity({
|
||||||
name: 'Hifi-Arrow',
|
name: ARROW_NAME,
|
||||||
type: 'Model',
|
type: 'Model',
|
||||||
modelURL: ARROW_MODEL_URL,
|
modelURL: ARROW_MODEL_URL,
|
||||||
shapeType: 'compound',
|
shapeType: 'compound',
|
||||||
|
@ -252,60 +244,51 @@
|
||||||
return arrow;
|
return arrow;
|
||||||
},
|
},
|
||||||
|
|
||||||
createPreNotchString: function() {
|
initString: function() {
|
||||||
this.preNotchString = Entities.addEntity({
|
// Check for existence of string
|
||||||
"collisionless": 1,
|
var children = Entities.getChildrenIDs(this.entityID);
|
||||||
"dimensions": { "x": 5, "y": 5, "z": 5 },
|
children.forEach(function(childID) {
|
||||||
"ignoreForCollisions": 1,
|
var childName = Entities.getEntityProperties(childID, ["name"]).name;
|
||||||
"linePoints": [ { "x": 0, "y": 0, "z": 0 }, { "x": 0, "y": -1.2, "z": 0 } ],
|
if (childName == STRING_NAME) {
|
||||||
"lineWidth": 5,
|
this.stringID = childID;
|
||||||
"name": "Hifi-Bow-Pre-Notch-String",
|
}
|
||||||
"parentID": this.entityID,
|
});
|
||||||
"localPosition": { "x": 0, "y": 0.6, "z": 0.1 },
|
|
||||||
"localRotation": { "w": 1, "x": 0, "y": 0, "z": 0 },
|
// If thie string wasn't found, create it
|
||||||
"type": "Line",
|
if (this.stringID === null) {
|
||||||
"userData": "{\"grabbableKey\":{\"grabbable\":false}}"
|
this.stringID = Entities.addEntity({
|
||||||
|
collisionless: true,
|
||||||
|
dimensions: { "x": 5, "y": 5, "z": 5 },
|
||||||
|
ignoreForCollisions: 1,
|
||||||
|
linePoints: [ { "x": 0, "y": 0, "z": 0 }, { "x": 0, "y": -1.2, "z": 0 } ],
|
||||||
|
lineWidth: 5,
|
||||||
|
name: STRING_NAME,
|
||||||
|
parentID: this.entityID,
|
||||||
|
localPosition: { "x": 0, "y": 0.6, "z": 0.1 },
|
||||||
|
localRotation: { "w": 1, "x": 0, "y": 0, "z": 0 },
|
||||||
|
type: 'Line',
|
||||||
|
userData: JSON.stringify({
|
||||||
|
grabbableKey: {
|
||||||
|
grabbable: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.resetStringToIdlePosition();
|
||||||
|
},
|
||||||
|
|
||||||
|
// This resets the string to a straight line
|
||||||
|
resetStringToIdlePosition: function() {
|
||||||
|
Entities.editEntity(this.stringID, {
|
||||||
|
linePoints: [ { "x": 0, "y": 0, "z": 0 }, { "x": 0, "y": -1.2, "z": 0 } ],
|
||||||
|
lineWidth: 5,
|
||||||
|
localPosition: { "x": 0, "y": 0.6, "z": 0.1 },
|
||||||
|
localRotation: { "w": 1, "x": 0, "y": 0, "z": 0 },
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
createStrings: function() {
|
updateString: function() {
|
||||||
if (!this.topString) {
|
|
||||||
this.createTopString();
|
|
||||||
Entities.editEntity(this.preNotchString, { visible: false });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
createTopString: function() {
|
|
||||||
var stringProperties = {
|
|
||||||
name: 'Hifi-Bow-Top-String',
|
|
||||||
type: 'Line',
|
|
||||||
position: Vec3.sum(this.bowProperties.position, TOP_NOTCH_OFFSET),
|
|
||||||
dimensions: LINE_DIMENSIONS,
|
|
||||||
dynamic: false,
|
|
||||||
collisionless: true,
|
|
||||||
lineWidth: 5,
|
|
||||||
color: this.stringData.currentColor,
|
|
||||||
userData: JSON.stringify({
|
|
||||||
grabbableKey: {
|
|
||||||
grabbable: false
|
|
||||||
}
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
this.topString = Entities.addEntity(stringProperties);
|
|
||||||
},
|
|
||||||
|
|
||||||
deleteStrings: function() {
|
|
||||||
if (this.topString) {
|
|
||||||
Entities.deleteEntity(this.topString);
|
|
||||||
this.topString = null;
|
|
||||||
Entities.editEntity(this.preNotchString, { visible: true });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
drawStrings: function() {
|
|
||||||
this.createStrings();
|
|
||||||
|
|
||||||
var upVector = Quat.getUp(this.bowProperties.rotation);
|
var upVector = Quat.getUp(this.bowProperties.rotation);
|
||||||
var upOffset = Vec3.multiply(upVector, TOP_NOTCH_OFFSET);
|
var upOffset = Vec3.multiply(upVector, TOP_NOTCH_OFFSET);
|
||||||
var downVector = Vec3.multiply(-1, Quat.getUp(this.bowProperties.rotation));
|
var downVector = Vec3.multiply(-1, Quat.getUp(this.bowProperties.rotation));
|
||||||
|
@ -317,11 +300,20 @@
|
||||||
var bottomStringPosition = Vec3.sum(this.bowProperties.position, downOffset);
|
var bottomStringPosition = Vec3.sum(this.bowProperties.position, downOffset);
|
||||||
this.bottomStringPosition = Vec3.sum(bottomStringPosition, backOffset);
|
this.bottomStringPosition = Vec3.sum(bottomStringPosition, backOffset);
|
||||||
|
|
||||||
var lineVectors = this.getLocalLineVectors();
|
var stringProps = Entities.getEntityProperties(this.stringID, ['position', 'rotation']);
|
||||||
|
var handPositionLocal = Vec3.subtract(this.arrowRearPosition, stringProps.position);
|
||||||
|
//handPositionLocal = Vec3.subtract(handPositionLocal, { x: 0, y: 0.6, z: 0 });
|
||||||
|
handPositionLocal = Vec3.multiplyQbyV(Quat.inverse(stringProps.rotation), handPositionLocal);
|
||||||
|
|
||||||
Entities.editEntity(this.topString, {
|
var linePoints = [
|
||||||
position: this.topStringPosition,
|
{ x: 0, y: 0, z: 0 },
|
||||||
linePoints: [{ x: 0, y: 0, z: 0 }, lineVectors[0], lineVectors[1]]
|
//{ x: 0, y: -0.6, z: 1 },
|
||||||
|
handPositionLocal,
|
||||||
|
{ x: 0, y: -1.2, z: 0 },
|
||||||
|
];
|
||||||
|
|
||||||
|
Entities.editEntity(this.stringID, {
|
||||||
|
linePoints: linePoints,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -511,19 +503,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
} // else if (shouldReleaseArrow === true) {
|
}
|
||||||
// they released without pulling back; just delete the arrow.
|
|
||||||
// Entities.deleteEntity(this.arrow);
|
|
||||||
// this.arrow = null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (shouldReleaseArrow === true) {
|
|
||||||
// //clear the strings back to only the single straight one
|
|
||||||
// Entities.editEntity(this.preNotchString, {
|
|
||||||
// visible: true
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
scaleArrowShotStrength: function(value) {
|
scaleArrowShotStrength: function(value) {
|
||||||
|
@ -566,6 +546,7 @@
|
||||||
|
|
||||||
this.stringPullInjector.options = audioProperties;
|
this.stringPullInjector.options = audioProperties;
|
||||||
},
|
},
|
||||||
|
|
||||||
scaleSoundVolume: function(value) {
|
scaleSoundVolume: function(value) {
|
||||||
var min1 = SHOT_SCALE.min1;
|
var min1 = SHOT_SCALE.min1;
|
||||||
var max1 = SHOT_SCALE.max1;
|
var max1 = SHOT_SCALE.max1;
|
||||||
|
|
Loading…
Reference in a new issue