encodeScene function
- Scene scene
Encodes scene into a JSON-serializable map.
Implementation
Map<String, dynamic> encodeScene(Scene scene) {
_ensureFiniteDouble(scene.camera.offset.dx, 'camera.offsetX');
_ensureFiniteDouble(scene.camera.offset.dy, 'camera.offsetY');
_ensureFiniteColor(scene.background.color, 'background.color');
_ensureFiniteGrid(scene.background.grid, 'background.grid');
_ensureFinitePalette(scene.palette, 'palette');
return <String, dynamic>{
'schemaVersion': schemaVersionWrite,
'camera': {
'offsetX': scene.camera.offset.dx,
'offsetY': scene.camera.offset.dy,
},
'background': {
'color': _colorToHex(scene.background.color),
'grid': {
'enabled': scene.background.grid.isEnabled,
'cellSize': scene.background.grid.cellSize,
'color': _colorToHex(scene.background.grid.color),
},
},
'palette': {
'penColors': scene.palette.penColors.map(_colorToHex).toList(),
'backgroundColors': scene.palette.backgroundColors
.map(_colorToHex)
.toList(),
'gridSizes': scene.palette.gridSizes,
},
'layers': scene.layers.map(_encodeLayer).toList(),
};
}