Minimise Document using Prototype

Quick question, I've got no idea what I'm doing so please excuse my ineptitude. Say I have a document, e.g. a wall:
{
"light": 20,
"sight": 20,
"sound": 20,
"move": 30,
"c": [
840,
201,
630,
201
],
"_id": "IHq9JaSNgKneTEsm",
"dir": 0,
"door": 0,
"ds": 0,
"threshold": {
"light": null,
"sight": null,
"sound": null,
"attenuation": false
},
"flags": {}
}
{
"light": 20,
"sight": 20,
"sound": 20,
"move": 30,
"c": [
840,
201,
630,
201
],
"_id": "IHq9JaSNgKneTEsm",
"dir": 0,
"door": 0,
"ds": 0,
"threshold": {
"light": null,
"sight": null,
"sound": null,
"attenuation": false
},
"flags": {}
}
But I want to minimise it down to only the changed data from the defaults. I can check the defaults in WallDocument.prototype.constructor._schema.fields There I see that light always has an initial value of 20 so we can remove that. We also bin off the _id as we know we'll get a new one. A simplified object for this example would then be:
{
"move": 30,
"c": [
840,
201,
630,
201
]
}
{
"move": 30,
"c": [
840,
201,
630,
201
]
}
Is there a trivial/simple way to use the wall prototype to reduce full data to just the non-default fields?
L
Lyra135d ago
Thanks @theripper93
Solution
L
Lyra135d ago
From a post elsewhere: foundry.utils.diffObject(WallDocument.prototype.constructor._schema.initial(),canvas.walls.placeables[0].document.toObject(), {inner: true})