Showing the changes to scripts/tutorials/entity_scripts (4 of 64 files). Show all
Unified · Split
| @@ -32,7 +32,7 @@ · 31 unmodified lines | ||
| 32 | 32 | range: DEFAULT_RANGE, |
| 33 | 33 | maxVolume: DEFAULT_VOLUME, |
| 34 | 34 | disabled: true, |
| 35 | − grabbableKey: { wantsTrigger: true }, | |
| 35 | + grab: { triggerable: true } | |
| 36 | 36 | }; |
| 37 | 37 | |
| 38 | 38 | var soundURL = ""; |
| @@ -182,7 +182,7 @@ · 143 unmodified lines | ||
| 182 | 182 | entity = entityID; |
| 183 | 183 | _this = this; |
| 184 | 184 | |
| 185 | − var props = Entities.getEntityProperties(entity, [ "userData" ]); | |
| 185 | + var props = Entities.getEntityProperties(entity, [ "userData", "grab.triggerable" ]); | |
| 186 | 186 | var data = {}; |
| 187 | 187 | if (props.userData) { |
| 188 | 188 | data = JSON.parse(props.userData); |
| @@ -194,14 +194,15 @@ · 5 unmodified lines | ||
| 194 | 194 | changed = true; |
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | − if (!data.grabbableKey.wantsTrigger) { | |
| 198 | − data.grabbableKey.wantsTrigger = true; | |
| 199 | − changed = true; | |
| 200 | − } | |
| 201 | 197 | if (changed) { |
| 202 | 198 | debugPrint("applying default values to userData"); |
| 203 | 199 | Entities.editEntity(entity, { userData: JSON.stringify(data) }); |
| 204 | 200 | } |
| 201 | + | |
| 202 | + if (!props.grab.triggerable) { | |
| 203 | + Entities.editEntity(entity, { grab: { triggerable: true } }); | |
| 204 | + } | |
| 205 | + | |
| 205 | 206 | this._updateColor(data.disabled); |
| 206 | 207 | this.updateSettings(); |
| 207 | 208 | |
| @@ -52,32 +52,8 @@ · 51 unmodified lines | ||
| 52 | 52 | It will behave as the constructor |
| 53 | 53 | */ |
| 54 | 54 | preload: function(id) { |
| 55 | − /* | |
| 56 | − We will now override any existing userdata with the grabbable property. | |
| 57 | − Only retrieving userData | |
| 58 | − */ | |
| 59 | − var entityProperties = Entities.getEntityProperties(id, ['userData']); | |
| 60 | − var userData = { | |
| 61 | − grabbableKey: {} | |
| 62 | − }; | |
| 63 | − // Check if existing userData field exists. | |
| 64 | − if (entityProperties.userData && entityProperties.userData.length > 0) { | |
| 65 | − try { | |
| 66 | − userData = JSON.parse(entityProperties.userData); | |
| 67 | − if (!userData.grabbableKey) { | |
| 68 | − userData.grabbableKey = {}; // If by random change there is no grabbableKey in the userData. | |
| 69 | − } | |
| 70 | − } catch (e) { | |
| 71 | − // if user data is not valid json, we will simply overwrite it. | |
| 72 | − } | |
| 73 | − } | |
| 74 | − // Object must be triggerable inorder to bind releaseGrabEvent | |
| 75 | − userData.grabbableKey.grabbable = true; | |
| 76 | − | |
| 77 | 55 | // Apply the new properties to entity of id |
| 78 | − Entities.editEntity(id, { | |
| 79 | − userData: JSON.stringify(userData) | |
| 80 | − }); | |
| 56 | + Entities.editEntity(id, { grab: { grabbable: true } }); | |
| 81 | 57 | Script.scriptEnding.connect(function() { |
| 82 | 58 | Script.removeEventHandler(id, "releaseGrab", this.releaseGrab); |
| 83 | 59 | }); |
| @@ -62,11 +62,7 @@ · 61 unmodified lines | ||
| 62 | 62 | position: originalProps.position, |
| 63 | 63 | shapeType: originalProps.shapeType, |
| 64 | 64 | visible: true, |
| 65 | − userData:JSON.stringify({ | |
| 66 | − grabbableKey:{ | |
| 67 | − grabbable:false | |
| 68 | − } | |
| 69 | − }) | |
| 65 | + grab: { grabbable: false } | |
| 70 | 66 | }; |
| 71 | 67 | _this.copy = Entities.addEntity(props); |
| 72 | 68 | } |
| @@ -142,11 +142,7 @@ · 141 unmodified lines | ||
| 142 | 142 | position: originalProps.position, |
| 143 | 143 | shapeType: originalProps.shapeType, |
| 144 | 144 | visible: true, |
| 145 | − userData:JSON.stringify({ | |
| 146 | − grabbableKey:{ | |
| 147 | − grabbable:false | |
| 148 | − } | |
| 149 | − }) | |
| 145 | + grab: { grabbable: false } | |
| 150 | 146 | }; |
| 151 | 147 | _this.copy = Entities.addEntity(props); |
| 152 | 148 | } |