diff --git a/module/actor/export-scriptarium/export-scriptarium.js b/module/actor/export-scriptarium/export-scriptarium.js index 5cf6b165..55b6dba2 100644 --- a/module/actor/export-scriptarium/export-scriptarium.js +++ b/module/actor/export-scriptarium/export-scriptarium.js @@ -25,10 +25,17 @@ export class ExportScriptarium { condition: (target) => game.user.isGM && OptionsAvancees.isUsing(EXPORT_CSV_SCRIPTARIUM) && this.$getActors(actorDirectory, target).length > 0, - callback: target => this.exportActors(this.$getActors(actorDirectory, target)) + callback: target => this.exportActors(this.$getActors(actorDirectory, target), this.$getTargetName(actorDirectory, target)) }) } - + $getTargetName(actorDirectory, target) { + const li = target.closest(".directory-item") + const folderId = li.data("folderId") + const actorId = li.data("documentId") + return actorId + ? game.actors.get(actorId).name + : actorDirectory.folders.find(it => it.id == folderId).name + } $getActors(actorDirectory, target) { const li = target.closest(".directory-item") const folderId = li.data("folderId") @@ -41,14 +48,13 @@ export class ExportScriptarium { return actors.filter(it => it.type == ACTOR_TYPES.personnage) } - exportActors(actors) { - console.log(LOG_HEAD + 'exportActors', actors) + exportActors(actors, targetName) { + const eol = '\n\r' const header = Misc.join(this.getHeaderLine(), ';') - console.log(header) - actors.forEach(actor => { - const actorLine = Misc.join(this.getActorLine(actor), ';') - console.log(actorLine) - }) + const actorLines = actors.map(actor => Misc.join(this.getActorLine(actor), ';')) + const data = Misc.join([header, ...actorLines], eol) + const filename = `scriptatium-${targetName?.slugify()}.csv`; + saveDataToFile(data, "text/csv", `${filename}`); } getHeaderLine() { @@ -69,5 +75,4 @@ export class ExportScriptarium { } return it } - }