Skip to content

Commit be0d260

Browse files
committed
Add support for Tool scripts in PaperScript.
1 parent b80ba6f commit be0d260

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/util/PaperScript.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,19 @@ var PaperScript = new function() {
119119
// Use paper.extend() to create a paper scope within which the code is
120120
// evaluated.
121121
with (paper.extend()) {
122-
return eval(compile(code));
122+
// TODO: Only create tool if code contains reference to tool scripts!
123+
var tool = new Tool();
124+
var res = eval(compile(code));
125+
// TODO: Again, only do this if we actually detected a tool script:
126+
Base.each(['onEditOptions', 'onOptions', 'onSelect', 'onDeselect',
127+
'onReselect', 'onMouseDown', 'onMouseUp', 'onMouseDrag',
128+
'onMouseMove'], function(key) {
129+
try {
130+
tool[key] = eval(key);
131+
} catch (e) {
132+
}
133+
});
134+
return res;
123135
}
124136
}
125137

0 commit comments

Comments
 (0)