TODO: - verify spells description and attributes - update json.schema - advance on #1
160 lines
No EOL
3.9 KiB
Markdown
160 lines
No EOL
3.9 KiB
Markdown
# Notes
|
|
Pour transformer le json d'origine, on itérera sur le fichier pour le scinder en deux
|
|
on utilise le tools ici : https://jsoneditoronline.org/#right=cloud.f0a19b92543d4c7fa1bdb58a913707e8&left=local.xoliwi
|
|
|
|
##### Pour avoir le json en francais:
|
|
*Cette version de la fonction query utilise une récursion pour explorer les sous-objets de chaque objet dans la liste data. La fonction checkKey transforme les clés se terminant par "_fr" en supprimant cette terminaison, et elle vérifie si la clé contient un nombre avant de traiter ses sous-objets. Si la clé ne contient pas de nombre, la fonction ne traite pas les sous-objets de cette clé.*
|
|
```js
|
|
function query(data) {
|
|
function checkKey(obj) {
|
|
obj = _.mapKeys(obj, (value, key) => {
|
|
|
|
if (_.endsWith(key, "_fr") ) {
|
|
return key.slice(0, -3);
|
|
}
|
|
return key;
|
|
});
|
|
for (const [key, value] of Object.entries(obj)) {
|
|
if (_.isObject(value) && isNaN(value) ) {
|
|
obj[key] = checkKey(value);
|
|
}
|
|
}
|
|
return _.pickBy(obj, (value, key) => !_.endsWith(key, "_en"));
|
|
}
|
|
|
|
return _.chain(data)
|
|
.map(obj => checkKey(obj))
|
|
.value();
|
|
}
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
##### Pour deplacer les classes dans un objet "classes"
|
|
```js
|
|
function query(data) {
|
|
return _.chain(data)
|
|
.map(item => {
|
|
const {
|
|
bard = "",
|
|
cleric = "",
|
|
druid = "",
|
|
paladin = "",
|
|
ranger = "",
|
|
scholar = "",
|
|
sorcerer = "",
|
|
warlock = "",
|
|
wizard = "",
|
|
...rest
|
|
} = item;
|
|
return {
|
|
...rest,
|
|
classes: {
|
|
bard,
|
|
cleric,
|
|
druid,
|
|
paladin,
|
|
ranger,
|
|
scholar,
|
|
sorcerer,
|
|
warlock,
|
|
wizard
|
|
}
|
|
};
|
|
})
|
|
.value();
|
|
}
|
|
```
|
|
|
|
|
|
##### pour renommer les components :
|
|
```js
|
|
function query(data) {
|
|
return _.chain(data)
|
|
.map(obj => {
|
|
// Renommer les clés spécifiées
|
|
obj = _.mapKeys(obj, (value, key) => {
|
|
switch(key) {
|
|
case "composite_oral":
|
|
return "v";
|
|
case "composite_moves":
|
|
return "s";
|
|
case "composite_material":
|
|
return "m";
|
|
case "material_components_fr":
|
|
return "m_fr";
|
|
case "material_components_en":
|
|
return "m_en";
|
|
case "composite_material_destroyed":
|
|
return "m_destroyed"
|
|
default:
|
|
return key;
|
|
}
|
|
});
|
|
return obj;
|
|
})
|
|
.value();
|
|
}
|
|
```
|
|
|
|
##### Pour deplacer les components dans un objet "components"
|
|
```js
|
|
function query(data) {
|
|
return _.chain(data)
|
|
.map(item => {
|
|
const {
|
|
m_destroyed = "",
|
|
v = "",
|
|
s= "",
|
|
m= "",
|
|
m_fr= "",
|
|
m_en= "",
|
|
...rest
|
|
} = item;
|
|
return {
|
|
...rest,
|
|
components: {
|
|
m_destroyed,
|
|
v,
|
|
s,
|
|
m,
|
|
m_fr,
|
|
m_en,
|
|
}
|
|
};
|
|
})
|
|
.value();
|
|
}
|
|
```
|
|
|
|
##### Pour ajouter recid et source
|
|
```js
|
|
function query(data) {
|
|
return _.chain(data)
|
|
.map((item, index) => _.merge({ recid: index }, item))
|
|
.map((item, index) => _.merge({ source: "GRI01" }, item))
|
|
.value();
|
|
}
|
|
```
|
|
|
|
##### Pour transformer les clé 0/1 en true/false
|
|
```js
|
|
function query(data) {
|
|
return _.chain(data)
|
|
.map((item) => ({
|
|
...item,
|
|
composite_material_destroyed: item.composite_material_destroyed = "x"? true : false,
|
|
composite_oral: item.composite_oral == 1? true : false,
|
|
has_higher_level_details: item.has_higher_level_details == 1? true : false,
|
|
ritual: item.ritual == 1? true : false,
|
|
dragons_exclusive: item.dragons_exclusive == 1? true : false,
|
|
composite_moves: item.composite_moves == 1? true : false,
|
|
composite_material: item.composite_material == 1? true : false,
|
|
corrupted: item.corrupted == 1? true : false,
|
|
concentration: item.concentration == 1? true : false,
|
|
}))
|
|
.value();
|
|
}
|
|
``` |