From 02cbd4cd68a92af523668be2d8d39888871bb840 Mon Sep 17 00:00:00 2001 From: Balint Morasz Date: Wed, 6 Sep 2023 21:52:19 +0200 Subject: [PATCH] pdf updates --- src/components/Helpers.tsx | 2 +- src/domain-models/karakter.ts | 116 +++++++++++++++- src/pages/CreateCharacter.tsx | 60 +-------- src/pdf/character.pdf.ts | 240 ++++++++++++++++++++++++++++++++++ 4 files changed, 360 insertions(+), 58 deletions(-) create mode 100644 src/pdf/character.pdf.ts diff --git a/src/components/Helpers.tsx b/src/components/Helpers.tsx index 86a01be..8efe09f 100644 --- a/src/components/Helpers.tsx +++ b/src/components/Helpers.tsx @@ -1,3 +1,3 @@ export function SignedNumberToText(val: number) : string { - return val > 0 ? '+'+val : val.toString() + return val === 0 ? " 0" : (val > 0 ? '+'+val : val.toString()) } diff --git a/src/domain-models/karakter.ts b/src/domain-models/karakter.ts index bb65393..223426e 100644 --- a/src/domain-models/karakter.ts +++ b/src/domain-models/karakter.ts @@ -1,7 +1,7 @@ import {Faj} from "./faj"; import {Osztaly} from "./osztaly"; -import {KarakterTulajdonsagok} from "./tulajdonsag"; -import {KarakterMasodlagosErtekek} from "./masodlagos_ertekek"; +import {KarakterTulajdonsagok, Modifier} from "./tulajdonsag"; +import {CalculateMasodlagosErtekek, KarakterMasodlagosErtekek} from "./masodlagos_ertekek"; export interface Karakter { Name: string @@ -9,4 +9,116 @@ export interface Karakter { Osztaly: Osztaly Tulajdonsagok: KarakterTulajdonsagok, MasodlagosErtekek: KarakterMasodlagosErtekek + HP: () => number + VO: () => number + Mozgas: () => number + Kezdemenyezes: () => number + KozelharciTB: () => number + CelzoTB: () => number + KitartasMentoAlap: () => number + ReflexMentoAlap: () => number + AkarateroMentoAlap: () => number +} + +export class KarakterClass implements Karakter { + + public Name : string + public Faj : Faj + public Osztaly : Osztaly + public Tulajdonsagok : KarakterTulajdonsagok + public MasodlagosErtekek : KarakterMasodlagosErtekek + + constructor(name: string, faj: Faj, osztaly: Osztaly, tulajdonsagok: KarakterTulajdonsagok) { + this.Name = name + this.Faj = faj + this.Osztaly = osztaly + this.Tulajdonsagok = tulajdonsagok + this.MasodlagosErtekek = CalculateMasodlagosErtekek(osztaly, tulajdonsagok) + } + + public HP = () => this.MasodlagosErtekek.HP + + public VO = () => this.MasodlagosErtekek.VO + + public Mozgas = () => this.Faj === Faj.Torpe ? 20 : 30 + + public Kezdemenyezes() : number { + return Modifier(this.Tulajdonsagok.t_ugy) + (this.Osztaly === Osztaly.Tolvaj ? 4 : 0) + } + + public TamadasBonusz() : number { + switch (this.Osztaly){ + case Osztaly.Barbar: + case Osztaly.Amazon: + case Osztaly.Ijasz: + case Osztaly.Kaloz: + case Osztaly.Harcos: + return 2; + case Osztaly.Pap: + case Osztaly.Tolvaj: + return 0; + case Osztaly.Varazslo: + case Osztaly.Illuzionista: + return 0; + } + } + + public KozelharciTB(): number { + const base = this.TamadasBonusz(); + if (this.Osztaly === Osztaly.Kaloz && this.Tulajdonsagok.t_ugy > this.Tulajdonsagok.t_ero) { + return base + Modifier(this.Tulajdonsagok.t_ugy) + } + return base + Modifier(this.Tulajdonsagok.t_ero) + } + public CelzoTB(): number { + return this.TamadasBonusz() + Modifier(this.Tulajdonsagok.t_ugy) + } + + public KitartasMentoAlap() : number { + switch (this.Osztaly){ + case Osztaly.Barbar: + case Osztaly.Amazon: + case Osztaly.Ijasz: + case Osztaly.Kaloz: + case Osztaly.Harcos: + case Osztaly.Pap: + return 2; + case Osztaly.Tolvaj: + case Osztaly.Varazslo: + case Osztaly.Illuzionista: + return 0; + } + } + + public ReflexMentoAlap() : number { + switch (this.Osztaly){ + case Osztaly.Tolvaj: + return 2; + case Osztaly.Barbar: + case Osztaly.Amazon: + case Osztaly.Ijasz: + case Osztaly.Kaloz: + case Osztaly.Harcos: + case Osztaly.Pap: + case Osztaly.Varazslo: + case Osztaly.Illuzionista: + return 0; + } + } + + public AkarateroMentoAlap() : number { + switch (this.Osztaly){ + case Osztaly.Pap: + case Osztaly.Varazslo: + case Osztaly.Illuzionista: + return 2; + case Osztaly.Tolvaj: + case Osztaly.Barbar: + case Osztaly.Amazon: + case Osztaly.Ijasz: + case Osztaly.Kaloz: + case Osztaly.Harcos: + return 0; + } + } } \ No newline at end of file diff --git a/src/pages/CreateCharacter.tsx b/src/pages/CreateCharacter.tsx index bd92e6f..5ef8e34 100644 --- a/src/pages/CreateCharacter.tsx +++ b/src/pages/CreateCharacter.tsx @@ -1,7 +1,7 @@ import React, {useState} from 'react'; import './CreateCharacter.css' -import {Faj, FajLabel} from "../domain-models/faj"; -import {Osztaly, OsztalyLabel} from "../domain-models/osztaly" +import {Faj} from "../domain-models/faj"; +import {Osztaly} from "../domain-models/osztaly" import FajSelector from "../components/FajSelector"; import Tulajdonsagok from "../components/Tulajdonsagok"; import OsztalySelector from "../components/OsztalySelector"; @@ -9,10 +9,9 @@ import KarakterKepzettsegek from "../components/KarakterKepzettsegek"; import {KarakterTulajdonsagok, Modifier} from "../domain-models/tulajdonsag"; import MasodlagosErtekek from "../components/MasodlagosErtekek"; import {AvailableKezpettsegList, KepzettsegId, TolvajKepzettsegList} from "../domain-models/kepzettsegek"; -import {PDFDocument, rgb, StandardFonts} from 'pdf-lib' -import download from 'downloadjs' import {CalculateMasodlagosErtekek} from "../domain-models/masodlagos_ertekek"; -import {Karakter} from "../domain-models/karakter"; +import {CreatePDF} from "../pdf/character.pdf"; +import {KarakterClass} from "../domain-models/karakter"; const tulajdonsagDefaults: KarakterTulajdonsagok = { t_ero: 10, @@ -37,49 +36,6 @@ function getNumberOfKepzettsegek(t_int: number, faj: Faj, max: number) { return numberOfKepzettseg; } -async function createPDF(karakter: Karakter) { - - const existingPdfBytes = await fetch('/km_karakterlap_hysteria_1.2.pdf').then(res => res.arrayBuffer()) - const pdfDoc = await PDFDocument.load(existingPdfBytes) - - const timesRomanFont = await pdfDoc.embedFont(StandardFonts.Helvetica) - - const page = pdfDoc.getPage(0) - const fontSize = 12 - page.drawText(karakter.Name, { - x: 60, - y: 710, - size: fontSize, - font: timesRomanFont, - color: rgb(0, 0, 0), - }) - page.drawText(OsztalyLabel(karakter.Osztaly), { - x: 60, - y: 672, - size: fontSize, - font: timesRomanFont, - color: rgb(0, 0, 0), - }) - page.drawText('1', { - x: 264, - y: 682, - size: fontSize * 3, - font: timesRomanFont, - color: rgb(0, 0, 0), - }) - page.drawText(FajLabel(karakter.Faj), { - x: 304, - y: 710, - size: fontSize, - font: timesRomanFont, - color: rgb(0, 0, 0), - }) - - - const pdfBytes = await pdfDoc.save(); - download(pdfBytes, "karakter.pdf", "application/pdf"); -} - function CreateCharacterPage() { let [name, changeName] = useState("Névtelen kalandozó") @@ -149,13 +105,7 @@ function CreateCharacterPage() {
- +
diff --git a/src/pdf/character.pdf.ts b/src/pdf/character.pdf.ts new file mode 100644 index 0000000..fb3607a --- /dev/null +++ b/src/pdf/character.pdf.ts @@ -0,0 +1,240 @@ +import {Karakter} from "../domain-models/karakter"; +import {PDFDocument, rgb, StandardFonts} from "pdf-lib"; +import {OsztalyLabel} from "../domain-models/osztaly"; +import {FajLabel} from "../domain-models/faj"; +import {SignedNumberToText} from "../components/Helpers"; +import {Modifier} from "../domain-models/tulajdonsag"; +import download from "downloadjs"; + +export async function CreatePDF(karakter: Karakter) { + + const existingPdfBytes = await fetch('/km_karakterlap_hysteria_1.2.pdf').then(res => res.arrayBuffer()) + const pdfDoc = await PDFDocument.load(existingPdfBytes) + + const timesRomanFont = await pdfDoc.embedFont(StandardFonts.Helvetica) + + const page = pdfDoc.getPage(0) + const fontSize = 12 + page.drawText(karakter.Name, { + x: 60, + y: 710, + size: fontSize, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(OsztalyLabel(karakter.Osztaly), { + x: 60, + y: 672, + size: fontSize, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText('1', { + x: 264, + y: 682, + size: fontSize * 3, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(FajLabel(karakter.Faj), { + x: 304, + y: 710, + size: fontSize, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(karakter.Tulajdonsagok.t_ero.toString(), { + x: 130, + y: 613, + size: fontSize * 2, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(SignedNumberToText(Modifier(karakter.Tulajdonsagok.t_ero)), { + x: 176, + y: 613, + size: fontSize * 2, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(karakter.Tulajdonsagok.t_ugy.toString(), { + x: 130, + y: 580, + size: fontSize * 2, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(SignedNumberToText(Modifier(karakter.Tulajdonsagok.t_ugy)), { + x: 176, + y: 580, + size: fontSize * 2, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(karakter.Tulajdonsagok.t_egs.toString(), { + x: 130, + y: 547, + size: fontSize * 2, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(SignedNumberToText(Modifier(karakter.Tulajdonsagok.t_egs)), { + x: 176, + y: 547, + size: fontSize * 2, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(karakter.Tulajdonsagok.t_int.toString(), { + x: 130, + y: 515, + size: fontSize * 2, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(SignedNumberToText(Modifier(karakter.Tulajdonsagok.t_int)), { + x: 176, + y: 515, + size: fontSize * 2, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(karakter.Tulajdonsagok.t_bol.toString(), { + x: 130, + y: 482, + size: fontSize * 2, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(SignedNumberToText(Modifier(karakter.Tulajdonsagok.t_bol)), { + x: 176, + y: 482, + size: fontSize * 2, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(karakter.Tulajdonsagok.t_kar.toString(), { + x: 130, + y: 449, + size: fontSize * 2, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(SignedNumberToText(Modifier(karakter.Tulajdonsagok.t_kar)), { + x: 176, + y: 449, + size: fontSize * 2, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + + page.drawText(karakter.Mozgas().toString(), { + x: 162, + y: 416, + size: fontSize * 2, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(SignedNumberToText(karakter.Kezdemenyezes()), { + x: 505, + y: 416, + size: fontSize * 2, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(karakter.HP().toString(), { + x: 318, + y: 517, + size: fontSize * 1.5, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(karakter.VO().toString(), { + x: 368, + y: 495, + size: fontSize * 3, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(SignedNumberToText(karakter.KozelharciTB()), { + x: 258, + y: 382, + size: fontSize * 2, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(SignedNumberToText(karakter.CelzoTB()), { + x: 347, + y: 382, + size: fontSize * 2, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + + page.drawText(SignedNumberToText(karakter.KitartasMentoAlap()), { + x: 435, + y: 613, + size: fontSize, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(SignedNumberToText(karakter.ReflexMentoAlap()), { + x: 435, + y: 580, + size: fontSize, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(SignedNumberToText(karakter.AkarateroMentoAlap()), { + x: 435, + y: 547, + size: fontSize, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(SignedNumberToText(Modifier(karakter.Tulajdonsagok.t_egs)), { + x: 475, + y: 613, + size: fontSize, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(SignedNumberToText(Modifier(karakter.Tulajdonsagok.t_ugy)), { + x: 475, + y: 580, + size: fontSize, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(SignedNumberToText(Modifier(karakter.Tulajdonsagok.t_bol)), { + x: 475, + y: 547, + size: fontSize, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(SignedNumberToText(karakter.KitartasMentoAlap() + Modifier(karakter.Tulajdonsagok.t_egs)), { + x: 515, + y: 613, + size: fontSize, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(SignedNumberToText(karakter.ReflexMentoAlap() + Modifier(karakter.Tulajdonsagok.t_ugy)), { + x: 515, + y: 580, + size: fontSize, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + page.drawText(SignedNumberToText(karakter.AkarateroMentoAlap() + Modifier(karakter.Tulajdonsagok.t_bol)), { + x: 515, + y: 547, + size: fontSize, + font: timesRomanFont, + color: rgb(0, 0, 0), + }) + + const pdfBytes = await pdfDoc.save(); + download(pdfBytes, karakter.Name + ".pdf", "application/pdf"); +}