Skip to content

Commit

Permalink
lichen-community-systemsgh-3: Adds support for composite events.
Browse files Browse the repository at this point in the history
  • Loading branch information
colinbdclark committed May 29, 2017
1 parent 6965667 commit afa5786
Show file tree
Hide file tree
Showing 4 changed files with 483 additions and 9 deletions.
26 changes: 18 additions & 8 deletions src/js/phet-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fluid.defaults("phetosc.converter", {

bundleParameters: true,

addressTemplate: "/%phetioID/%eventType/%event/",
addressTemplate: "/%phetioID/%eventType/%event",

jsToOSCTypes: {
"number": "d",
Expand All @@ -41,7 +41,7 @@ phetosc.converter.visitPhETEvents = function (phetEvent, options, packets, event
eventVisitor(phetEvent, options, packets);

fluid.each(phetEvent.children, function (childEvent) {
phetosc.converter.visitPhETEvents(childEvent, packets, eventVisitor);
phetosc.converter.visitPhETEvents(childEvent, options, packets, eventVisitor);
});
};

Expand Down Expand Up @@ -80,6 +80,13 @@ phetosc.converter.messageAddressPrefix = function (phetEvent, options) {
};

phetosc.converter.objectToMessages = function (obj, addressPrefix, options, packets) {
if (!obj || Object.keys(obj) < 1) {
// TODO: Rearrange argument order?
phetosc.converter.toMessage(undefined, addressPrefix, undefined, options, packets);
return;
}

addressPrefix = addressPrefix + "/";
fluid.each(obj, function (val, key) {
phetosc.converter.parameterToMessages(val, key, addressPrefix, options, packets);
});
Expand All @@ -96,22 +103,25 @@ phetosc.converter.parameterToMessages = function (val, key, addressPrefix, optio
parameterType = typeof val;

if (parameterType === "object") {
return phetosc.converter.objectToMessages(val, address + "/", options, packets);
return phetosc.converter.objectToMessages(val, address, options, packets);
} else {
return phetosc.converter.primitiveToMessage(val, address, parameterType, options, packets);
return phetosc.converter.toMessage(val, address, parameterType, options, packets);
}
};

phetosc.converter.primitiveToMessage = function (val, address, parameterType, options, packets) {
phetosc.converter.toMessage = function (val, address, parameterType, options, packets) {
var message = {
address: address,
args: [
address: address
};

if (val !== undefined) {
message.args = [
{
type: phetosc.converter.oscTypeForJSType(parameterType, options.jsToOSCTypes),
value: val
}
]
};
}

packets.push(message);
};
Expand Down
282 changes: 282 additions & 0 deletions tests/data/osc/osc-composite-event-drag-ended-bundled.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
[
{
"packets": [
{
"address": "/buildAnAtom.atomScreen.view.nucleons_9.inputListener/user/dragEnded"
}
]
},
{
"packets": [
{
"address": "/buildAnAtom.atomScreen.model.protons_9.userControlledProperty/model/changed/oldValue",
"args": [
{
"type": "b",
"value": true
}
]
},
{
"address": "/buildAnAtom.atomScreen.model.protons_9.userControlledProperty/model/changed/newValue",
"args": [
{
"type": "b",
"value": false
}
]
}
]
},
{
"packets": [
{
"address": "/buildAnAtom.atomScreen.model.particleAtom.protonCountProperty/model/changed/oldValue",
"args": [
{
"type": "d",
"value": 0
}
]
},
{
"address": "/buildAnAtom.atomScreen.model.particleAtom.protonCountProperty/model/changed/newValue",
"args": [
{
"type": "d",
"value": 1
}
]
}
]
},
{
"packets": [
{
"address": "/buildAnAtom.atomScreen.model.particleAtom.chargeProperty/model/changed/oldValue",
"args": [
{
"type": "d",
"value": 0
}
]
},
{
"address": "/buildAnAtom.atomScreen.model.particleAtom.chargeProperty/model/changed/newValue",
"args": [
{
"type": "d",
"value": 1
}
]
}
]
},
{
"packets": [
{
"address": "/buildAnAtom.atomScreen.view.chargeMeter.readoutText/model/textChanged/oldText",
"args": [
{
"type": "s",
"value": "0"
}
]
},
{
"address": "/buildAnAtom.atomScreen.view.chargeMeter.readoutText/model/textChanged/newText",
"args": [
{
"type": "s",
"value": "+1"
}
]
}
]
},
{
"packets": [
{
"address": "/buildAnAtom.atomScreen.model.particleAtom.massNumberProperty/model/changed/oldValue",
"args": [
{
"type": "d",
"value": 0
}
]
},
{
"address": "/buildAnAtom.atomScreen.model.particleAtom.massNumberProperty/model/changed/newValue",
"args": [
{
"type": "d",
"value": 1
}
]
}
]
},
{
"packets": [
{
"address": "/buildAnAtom.atomScreen.view.massNumberDisplay.numericalText/model/textChanged/oldText",
"args": [
{
"type": "s",
"value": "0"
}
]
},
{
"address": "/buildAnAtom.atomScreen.view.massNumberDisplay.numericalText/model/textChanged/newText",
"args": [
{
"type": "s",
"value": "1"
}
]
}
]
},
{
"packets": [
{
"address": "/buildAnAtom.atomScreen.model.particleAtom.particleCountProperty/model/changed/oldValue",
"args": [
{
"type": "d",
"value": 0
}
]
},
{
"address": "/buildAnAtom.atomScreen.model.particleAtom.particleCountProperty/model/changed/newValue",
"args": [
{
"type": "d",
"value": 1
}
]
}
]
},
{
"packets": [
{
"address": "/buildAnAtom.atomScreen.view.atomNode.elementName/model/textChanged/oldText",
"args": [
{
"type": "s",
"value": ""
}
]
},
{
"address": "/buildAnAtom.atomScreen.view.atomNode.elementName/model/textChanged/newText",
"args": [
{
"type": "s",
"value": "‪Hydrogen‬"
}
]
}
]
},
{
"packets": [
{
"address": "/buildAnAtom.atomScreen.view.atomNode.ionIndicator/model/textChanged/oldText",
"args": [
{
"type": "s",
"value": ""
}
]
},
{
"address": "/buildAnAtom.atomScreen.view.atomNode.ionIndicator/model/textChanged/newText",
"args": [
{
"type": "s",
"value": "‪+ Ion‬"
}
]
}
]
},
{
"packets": [
{
"address": "/buildAnAtom.atomScreen.view.atomNode.stabilityIndicator/model/textChanged/oldText",
"args": [
{
"type": "s",
"value": ""
}
]
},
{
"address": "/buildAnAtom.atomScreen.view.atomNode.stabilityIndicator/model/textChanged/newText",
"args": [
{
"type": "s",
"value": "‪Stable‬"
}
]
}
]
},
{
"packets": [
{
"address": "/buildAnAtom.atomScreen.model.particleAtom.protons/model/itemAdded/item",
"args": [
{
"type": "s",
"value": "TParticle"
}
]
}
]
},
{
"packets": [
{
"address":"/buildAnAtom.atomScreen.model.protons_9.destinationProperty/model/changed/oldValue/x",
"args": [
{
"type": "d",
"value": -9.20000000000003
}
]
},
{
"address":"/buildAnAtom.atomScreen.model.protons_9.destinationProperty/model/changed/oldValue/y",
"args": [
{
"type": "d",
"value": -41.360000000000014
}
]
},
{
"address":"/buildAnAtom.atomScreen.model.protons_9.destinationProperty/model/changed/newValue/x",
"args": [
{
"type": "d",
"value": 0
}
]
},
{
"address":"/buildAnAtom.atomScreen.model.protons_9.destinationProperty/model/changed/newValue/y",
"args": [
{
"type": "d",
"value": 0
}
]
}
]
}
]
Loading

0 comments on commit afa5786

Please sign in to comment.