mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-08-28 22:08:54 -04:00
JSON: Improve serialization and deserialization on objects other than Item.
Closes #392
This commit is contained in:
parent
75c40babc9
commit
56dd636f22
4 changed files with 78 additions and 30 deletions
|
@ -207,3 +207,37 @@ test('Color', function() {
|
|||
});
|
||||
testExportImportJSON(paper.project);
|
||||
});
|
||||
|
||||
test('Color#importJSON()', function() {
|
||||
var topLeft = [100, 100];
|
||||
var bottomRight = [200, 200];
|
||||
|
||||
var path = new Path.Rectangle({
|
||||
topLeft: topLeft,
|
||||
bottomRight: bottomRight,
|
||||
// Fill the path with a gradient of three color stops
|
||||
// that runs between the two points we defined earlier:
|
||||
fillColor: {
|
||||
gradient: {
|
||||
stops: ['yellow', 'red', 'blue']
|
||||
},
|
||||
origin: topLeft,
|
||||
destination: bottomRight
|
||||
}
|
||||
});
|
||||
|
||||
var json = path.fillColor.exportJSON(),
|
||||
id = path.fillColor.gradient._id,
|
||||
color = new Color(),
|
||||
str = '[["dictionary",{"#' + id + '":["Gradient",[[[1,1,0],0],[[1,0,0],0.5],[[0,0,1],1]],false]}],["Color","gradient",["#' + id + '"],[100,100],[200,200]]]';
|
||||
|
||||
equals(json, str);
|
||||
|
||||
equals(function() {
|
||||
return color.importJSON(json) === color;
|
||||
}, true);
|
||||
|
||||
equals(function() {
|
||||
return color.equals(path.fillColor);
|
||||
}, true);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue