Nettoyage de data

* séparation de options, calc, ...
* extraction de méthodes pour clarifier ce qui est fait dans getData
* fix de la feuille: utiliser data.data
* fix d'Actor:  update({ data.data
This commit is contained in:
Vincent Vandemeulebrouck
2021-03-05 03:42:45 +01:00
parent 2cb7647fc4
commit 3ae461bb71
110 changed files with 600 additions and 433 deletions

48
dev-notes.md Normal file
View File

@@ -0,0 +1,48 @@
# Actor notes
> The Actor#getData default implementation gives you the following for use in sheet rendering:
```
actor -> the Actor instance
data -> a cloned copy of Actor#data
items -> a cloned copy of Actor#data#items
effects -> a cloned copy of Actor#data#effects
```
> if all you need is a safe copy of `Actor#data`, you'll be much better off by simply defining your own function and avoiding all the wasted work that the parent class does which will slow down your sheet
```js
getData(options) {
return {
data: foundry.utils.deepClone(this.object.data)
}
}
```
who knows, maybe you don't even need to copy your actor data, skip the copy and it's even faster:
```js
getData(options) {
return {
data: this.object.data
}
}
```
Atropos19/02/2021
There are two recommended ways to create owned items in 0.8.0:
```js
await Item.create(itemData, {parent: actor});
await actor.createEmbeddedDocuments("Item", itemDataArray);
```
You can update an embedded item in one of two ways:
```js
//Method 1:
const item = actor.items.get(itemId);
item.update(data);
//Method 2:
actor.updateEmbeddedDocuments("Item", [{_id: itemId, ...}]);
```