unmuddle saved state in Settings and userData

This commit is contained in:
Seth Alves 2016-01-29 17:38:24 -08:00
parent 464f74fc1b
commit 0c5c682887
2 changed files with 36 additions and 67 deletions

View file

@ -209,35 +209,6 @@ function AttachedEntitiesManager() {
grabbableData = getEntityCustomData('grabbableKey', entityID, {});
this.updateRelativeOffsets(entityID, props);
props = Entities.getEntityProperties(entityID); // refresh, because updateRelativeOffsets changed them
// if an entity is currently being held or equipped, its original properties are saved in
// the userData under "grabKey". Save with these original properties rather than the
// ones currently on the entity.
if (grabData.refCount > 0) {
if ("gravity" in grabData) {
props.gravity = grabData.gravity;
}
if ("collidesWith" in grabData) {
props.collidesWith = grabData.collidesWith;
}
if ("dynamic" in grabData) {
props.dynamic = grabData.dynamic;
}
if ("collisionless" in grabData) {
if ("invertSolidWhileHeld" in grabbableData && grabbableData.invertSolidWhileHeld) {
props.collisionless = !grabData.collisionless;
} else {
props.collisionless = grabData.collisionless;
}
}
// if ("parentID" in grabData) {
// props.parentID = grabData.parentID;
// }
// if ("parentJointIndex" in grabData) {
// props.parentJointIndex = grabData.parentJointIndex;
// }
}
this.scrubProperties(props);
saveData.push(props);
}
@ -253,12 +224,13 @@ function AttachedEntitiesManager() {
toScrub.forEach(function(propertyName) {
delete props[propertyName];
});
// if the userData has a grabKey, strip it out
// if the userData has a grabKey, clear old state
if ("userData" in props) {
try {
parsedUserData = JSON.parse(props.userData);
if ("grabKey" in parsedUserData) {
delete parsedUserData["grabKey"];
parsedUserData.grabKey.refCount = 0;
delete parsedUserData.grabKey["avatarId"];
props["userData"] = JSON.stringify(parsedUserData);
}
} catch (e) {

View file

@ -1589,9 +1589,10 @@ function MyController(hand) {
data["avatarId"] = MyAvatar.sessionUUID;
if (wasLoaded) {
data["refCount"] = 1;
data["avatarId"] = MyAvatar.sessionUUID;
} else {
data["refCount"] = data["refCount"] ? data["refCount"] + 1 : 1;
}
// zero gravity and set ignoreForCollisions in a way that lets us put them back, after all grabs are done
if (data["refCount"] == 1) {
this.isInitialGrab = true;
@ -1602,10 +1603,6 @@ function MyController(hand) {
data["parentID"] = wasLoaded ? NULL_UUID : grabbedProperties.parentID;
data["parentJointIndex"] = grabbedProperties.parentJointIndex;
if ("invertSolidWhileHeld" in grabbableData && grabbableData.invertSolidWhileHeld) {
data["collisionless"] = !data["collisionless"];
}
var whileHeldProperties = {
gravity: {
x: 0,
@ -1627,7 +1624,7 @@ function MyController(hand) {
// the collision mask hinges on who the physics simulation owner is.
Entities.editEntity(entityID, {"collidesWith": COLLIDES_WITH_WHILE_MULTI_GRABBED});
}
}
setEntityCustomData(GRAB_USER_DATA_KEY, entityID, data);
return data;
};