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
3232 range: DEFAULT_RANGE,
3333 maxVolume: DEFAULT_VOLUME,
3434 disabled: true,
35− grabbableKey: { wantsTrigger: true },
35+ grab: { triggerable: true }
3636 };
3737
3838 var soundURL = "";
@@ -182,7 +182,7 @@ · 143 unmodified lines
182182 entity = entityID;
183183 _this = this;
184184
185− var props = Entities.getEntityProperties(entity, [ "userData" ]);
185+ var props = Entities.getEntityProperties(entity, [ "userData", "grab.triggerable" ]);
186186 var data = {};
187187 if (props.userData) {
188188 data = JSON.parse(props.userData);
@@ -194,14 +194,15 @@ · 5 unmodified lines
194194 changed = true;
195195 }
196196 }
197− if (!data.grabbableKey.wantsTrigger) {
198− data.grabbableKey.wantsTrigger = true;
199− changed = true;
200− }
201197 if (changed) {
202198 debugPrint("applying default values to userData");
203199 Entities.editEntity(entity, { userData: JSON.stringify(data) });
204200 }
201+
202+ if (!props.grab.triggerable) {
203+ Entities.editEntity(entity, { grab: { triggerable: true } });
204+ }
205+
205206 this._updateColor(data.disabled);
206207 this.updateSettings();
207208
scripts/tutorials/entity_scripts/magneticBlock.js+1−25
@@ -52,32 +52,8 @@ · 51 unmodified lines
5252 It will behave as the constructor
5353 */
5454 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−
7755 // 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 } });
8157 Script.scriptEnding.connect(function() {
8258 Script.removeEventHandler(id, "releaseGrab", this.releaseGrab);
8359 });
scripts/tutorials/entity_scripts/springHold.js+1−5
@@ -62,11 +62,7 @@ · 61 unmodified lines
6262 position: originalProps.position,
6363 shapeType: originalProps.shapeType,
6464 visible: true,
65− userData:JSON.stringify({
66− grabbableKey:{
67− grabbable:false
68− }
69− })
65+ grab: { grabbable: false }
7066 };
7167 _this.copy = Entities.addEntity(props);
7268 }
scripts/tutorials/entity_scripts/touch.js+1−5
@@ -142,11 +142,7 @@ · 141 unmodified lines
142142 position: originalProps.position,
143143 shapeType: originalProps.shapeType,
144144 visible: true,
145− userData:JSON.stringify({
146− grabbableKey:{
147− grabbable:false
148− }
149− })
145+ grab: { grabbable: false }
150146 };
151147 _this.copy = Entities.addEntity(props);
152148 }

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