pdf updates
This commit is contained in:
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<string>("Névtelen kalandozó")
|
||||
@@ -149,13 +105,7 @@ function CreateCharacterPage() {
|
||||
<MasodlagosErtekek ertekek={CalculateMasodlagosErtekek(osztaly, tulajdonsagok)} />
|
||||
|
||||
<div className='d-grid gap-2 m-5'>
|
||||
<button className='btn btn-danger btn-lg' type='button' onClick={async () => await createPDF({
|
||||
Name: name,
|
||||
Faj: faj,
|
||||
MasodlagosErtekek: CalculateMasodlagosErtekek(osztaly, tulajdonsagok),
|
||||
Osztaly: osztaly,
|
||||
Tulajdonsagok: tulajdonsagok
|
||||
})}>Létrehozás</button>
|
||||
<button className='btn btn-danger btn-lg' type='button' onClick={async () => await CreatePDF(new KarakterClass(name, faj, osztaly, tulajdonsagok))}>Létrehozás</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
Reference in New Issue
Block a user