feat: base html sheet
This commit is contained in:
73
src/main.ts
73
src/main.ts
@@ -4,13 +4,7 @@ import { Row } from './elements/row';
|
||||
import { Image } from './elements/image';
|
||||
import { Box } from './elements/box';
|
||||
import { Util } from './util';
|
||||
import {
|
||||
i18nLocalize,
|
||||
isGM,
|
||||
LABEL_SIZE,
|
||||
MARGINS,
|
||||
TEXT_SIZE,
|
||||
} from './constants';
|
||||
import { i18nLocalize, isGM, MARGINS } from './constants';
|
||||
import { ItemData } from '@league-of-foundry-developers/foundry-vtt-types/src/foundry/common/data/data.mjs';
|
||||
import { LabelledValues } from './elements/labelled-values';
|
||||
import { Text } from './elements/text';
|
||||
@@ -18,30 +12,39 @@ import { Texts } from './elements/texts';
|
||||
import { Column } from './elements/column';
|
||||
import { Separator } from './elements/separator';
|
||||
import { Blank } from './elements/blank';
|
||||
import { AbstractBuilder } from './abstract-builder';
|
||||
import { HtmlBuilder } from './html-builder';
|
||||
|
||||
Hooks.on('getActorDirectoryEntryContext', async (_, options) => {
|
||||
options.push({
|
||||
name: i18nLocalize('WFRP4SHEETPRINT.export.pdf'),
|
||||
condition: isGM(),
|
||||
icon: '<i class="fas fa-file-pdf"></i>',
|
||||
callback: async (target) => {
|
||||
const actor: Actor & any = (<any>game).actors.get(
|
||||
target.attr('data-document-id')
|
||||
);
|
||||
await generatePdf(actor);
|
||||
options.push(
|
||||
{
|
||||
name: i18nLocalize('WFRP4SHEETPRINT.export.pdf'),
|
||||
condition: isGM(),
|
||||
icon: '<i class="fas fa-file-pdf"></i>',
|
||||
callback: async (target) => {
|
||||
const actor: Actor & any = (<any>game).actors.get(
|
||||
target.attr('data-document-id')
|
||||
);
|
||||
const docBuilder = new PdfBuilder({
|
||||
orientation: 'p',
|
||||
unit: 'mm',
|
||||
});
|
||||
await generate(actor, docBuilder);
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
name: i18nLocalize('WFRP4SHEETPRINT.export.html'),
|
||||
condition: isGM(),
|
||||
icon: '<i class="fas fa-file-code"></i>',
|
||||
callback: async (target) => {
|
||||
const actor: Actor & any = (<any>game).actors.get(
|
||||
target.attr('data-document-id')
|
||||
);
|
||||
await generateHtml(actor);
|
||||
const actor: Actor & any = (<any>game).actors.get(
|
||||
target.attr('data-document-id')
|
||||
);
|
||||
const docBuilder = new HtmlBuilder();
|
||||
await generate(actor, docBuilder);
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
Hooks.on(
|
||||
@@ -50,7 +53,11 @@ Hooks.on(
|
||||
const actor: Actor & any = app.actor;
|
||||
|
||||
addActorSheetActionButton(html, 'print', async () => {
|
||||
await generatePdf(actor);
|
||||
const docBuilder = new PdfBuilder({
|
||||
orientation: 'p',
|
||||
unit: 'mm',
|
||||
});
|
||||
await generate(actor, docBuilder);
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -71,11 +78,7 @@ function addActorSheetActionButton(
|
||||
title.after(button);
|
||||
}
|
||||
|
||||
async function generateHtml(actor: Actor & any) {
|
||||
console.dir(actor);
|
||||
}
|
||||
|
||||
async function generatePdf(actor: Actor & any) {
|
||||
async function generate(actor: Actor & any, docBuilder: AbstractBuilder) {
|
||||
const actorData = actor.data;
|
||||
// @ts-ignore
|
||||
const actorDetails = actorData.data.details;
|
||||
@@ -91,14 +94,6 @@ async function generatePdf(actor: Actor & any) {
|
||||
const careerData: ItemData = currentCareer?.data;
|
||||
const careerDetail: any = careerData?.data;
|
||||
|
||||
const docBuilder = new PdfBuilder({
|
||||
orientation: 'p',
|
||||
unit: 'mm',
|
||||
});
|
||||
|
||||
const labelledRowHeight =
|
||||
Util.getHeightFromPx(docBuilder.doc, TEXT_SIZE + LABEL_SIZE) + 1;
|
||||
|
||||
const skills = new LabelledValues(
|
||||
0,
|
||||
0,
|
||||
@@ -379,6 +374,8 @@ async function generatePdf(actor: Actor & any) {
|
||||
3
|
||||
);
|
||||
|
||||
const labelledRowHeight = docBuilder.getLabelledRowHeight();
|
||||
|
||||
const imageWidth = 25;
|
||||
const imageY = labelledRowHeight + MARGINS.top + 2;
|
||||
const actorImageElement =
|
||||
@@ -624,5 +621,5 @@ async function generatePdf(actor: Actor & any) {
|
||||
mutationM,
|
||||
]),
|
||||
]);
|
||||
docBuilder.doc.save(`${actor.name}.pdf`);
|
||||
docBuilder.save(`${actor.name}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user