History

Move grab pseudo-properties (userData) into first-class EntityItemProperties.

Seth Alves committed 8 years ago

Commit 834699f1 parent 7c9464564 files · +1528 −739Browse files

Showing the changes to scripts/tutorials/entity_scripts (4 of 64 files). Show all

Unified · Split

4 files
  1. scripts/tutorials/entity_scripts/ambientSound.js +7 −6
  2. scripts/tutorials/entity_scripts/magneticBlock.js +1 −25
  3. scripts/tutorials/entity_scripts/springHold.js +1 −5
  4. scripts/tutorials/entity_scripts/touch.js +1 −5
scripts/tutorials/entity_scripts/ambientSound.js+7−6
@@ -32,7 +32,7 @@ · 31 unmodified lines
32 range: DEFAULT_RANGE,32 range: DEFAULT_RANGE,
33 maxVolume: DEFAULT_VOLUME,33 maxVolume: DEFAULT_VOLUME,
34 disabled: true,34 disabled: true,
35 grabbableKey: { wantsTrigger: true },35 grab: { triggerable: true }
36 };36 };
37 37
38 var soundURL = "";38 var soundURL = "";
@@ -182,7 +182,7 @@ · 143 unmodified lines
182 entity = entityID;182 entity = entityID;
183 _this = this;183 _this = this;
184 184
185 var props = Entities.getEntityProperties(entity, [ "userData" ]);185 var props = Entities.getEntityProperties(entity, [ "userData", "grab.triggerable" ]);
186 var data = {};186 var data = {};
187 if (props.userData) {187 if (props.userData) {
188 data = JSON.parse(props.userData);188 data = JSON.parse(props.userData);
@@ -194,14 +194,15 @@ · 5 unmodified lines
194 changed = true;194 changed = true;
195 }195 }
196 }196 }
197 if (!data.grabbableKey.wantsTrigger) {
198 data.grabbableKey.wantsTrigger = true;
199 changed = true;
200 }
201 if (changed) {197 if (changed) {
202 debugPrint("applying default values to userData");198 debugPrint("applying default values to userData");
203 Entities.editEntity(entity, { userData: JSON.stringify(data) });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 this._updateColor(data.disabled);206 this._updateColor(data.disabled);
206 this.updateSettings();207 this.updateSettings();
207 208
scripts/tutorials/entity_scripts/magneticBlock.js+1−25
@@ -52,32 +52,8 @@ · 51 unmodified lines
52 It will behave as the constructor52 It will behave as the constructor
53 */53 */
54 preload: function(id) {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 // Apply the new properties to entity of id55 // Apply the new properties to entity of id
78 Entities.editEntity(id, {56 Entities.editEntity(id, { grab: { grabbable: true } });
79 userData: JSON.stringify(userData)
80 });
81 Script.scriptEnding.connect(function() {57 Script.scriptEnding.connect(function() {
82 Script.removeEventHandler(id, "releaseGrab", this.releaseGrab);58 Script.removeEventHandler(id, "releaseGrab", this.releaseGrab);
83 });59 });
scripts/tutorials/entity_scripts/springHold.js+1−5
@@ -62,11 +62,7 @@ · 61 unmodified lines
62 position: originalProps.position,62 position: originalProps.position,
63 shapeType: originalProps.shapeType,63 shapeType: originalProps.shapeType,
64 visible: true,64 visible: true,
65 userData:JSON.stringify({65 grab: { grabbable: false }
66 grabbableKey:{
67 grabbable:false
68 }
69 })
70 };66 };
71 _this.copy = Entities.addEntity(props);67 _this.copy = Entities.addEntity(props);
72 }68 }
scripts/tutorials/entity_scripts/touch.js+1−5
@@ -142,11 +142,7 @@ · 141 unmodified lines
142 position: originalProps.position,142 position: originalProps.position,
143 shapeType: originalProps.shapeType,143 shapeType: originalProps.shapeType,
144 visible: true,144 visible: true,
145 userData:JSON.stringify({145 grab: { grabbable: false }
146 grabbableKey:{
147 grabbable:false
148 }
149 })
150 };146 };
151 _this.copy = Entities.addEntity(props);147 _this.copy = Entities.addEntity(props);
152 }148 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t