fix: optimize separator + missing css

This commit is contained in:
Matthieu CAILLEAUX
2021-10-19 01:43:48 +02:00
parent e28eb3cd12
commit b35284768e
10 changed files with 274 additions and 182 deletions

View File

@@ -14,10 +14,12 @@ build:
- npm ci - npm ci
- npm run build - npm run build
- mkdir -p dist/lang - mkdir -p dist/lang
- mkdir -p dist/styles
- cp lang/* dist/lang/ - cp lang/* dist/lang/
- cp styles/* dist/styles/
- cp module.json dist - cp module.json dist
- cd dist - cd dist
- zip wfrp4e-actor-sheet-print.zip -r *.* elements lang -x ".*" - zip wfrp4e-actor-sheet-print.zip -r *.* elements lang styles -x ".*"
artifacts: artifacts:
name: wfrp4e-actor-sheet-print name: wfrp4e-actor-sheet-print
when: on_success when: on_success
@@ -33,10 +35,12 @@ build_beta:
- npm ci - npm ci
- npm run build - npm run build
- mkdir -p dist/lang - mkdir -p dist/lang
- mkdir -p dist/styles
- cp lang/* dist/lang/ - cp lang/* dist/lang/
- cp styles/* dist/styles/
- cp module-beta.json dist/module.json - cp module-beta.json dist/module.json
- cd dist - cd dist
- zip wfrp4e-actor-sheet-print.zip -r *.* elements lang -x ".*" - zip wfrp4e-actor-sheet-print.zip -r *.* elements lang styles -x ".*"
artifacts: artifacts:
name: wfrp4e-actor-sheet-print name: wfrp4e-actor-sheet-print
when: on_success when: on_success

View File

@@ -2,7 +2,7 @@
"name": "wfrp4e-actor-sheet-print-beta", "name": "wfrp4e-actor-sheet-print-beta",
"title": "[WFRP4] Actor Sheet Print BETA version", "title": "[WFRP4] Actor Sheet Print BETA version",
"description": "Functions to print actor sheet", "description": "Functions to print actor sheet",
"version": "1.0.0", "version": "1.0.1",
"minimumCoreVersion": "0.8.0", "minimumCoreVersion": "0.8.0",
"compatibleCoreVersion": "0.8.9", "compatibleCoreVersion": "0.8.9",
"author": "Skeroujvapluvit", "author": "Skeroujvapluvit",
@@ -21,7 +21,7 @@
"path": "lang/fr.json" "path": "lang/fr.json"
} }
], ],
"styles": [], "styles": ["./styles/main.css"],
"url": "https://github.com/mcailleaux/WFRP4-FoundryVTT-wfrp4e-actor-sheet-print/tree/dist-beta", "url": "https://github.com/mcailleaux/WFRP4-FoundryVTT-wfrp4e-actor-sheet-print/tree/dist-beta",
"download": "https://github.com/mcailleaux/WFRP4-FoundryVTT-wfrp4e-actor-sheet-print/blob/dist-beta/dist/wfrp4e-actor-sheet-print.zip?raw=true", "download": "https://github.com/mcailleaux/WFRP4-FoundryVTT-wfrp4e-actor-sheet-print/blob/dist-beta/dist/wfrp4e-actor-sheet-print.zip?raw=true",
"manifest": "https://raw.githubusercontent.com/mcailleaux/WFRP4-FoundryVTT-wfrp4e-actor-sheet-print/dist-beta/module-beta.json", "manifest": "https://raw.githubusercontent.com/mcailleaux/WFRP4-FoundryVTT-wfrp4e-actor-sheet-print/dist-beta/module-beta.json",

View File

@@ -2,7 +2,7 @@
"name": "wfrp4e-actor-sheet-print", "name": "wfrp4e-actor-sheet-print",
"title": "[WFRP4] Actor Sheet Print", "title": "[WFRP4] Actor Sheet Print",
"description": "Functions to print actor sheet", "description": "Functions to print actor sheet",
"version": "1.0.0", "version": "1.0.1",
"minimumCoreVersion": "0.8.0", "minimumCoreVersion": "0.8.0",
"compatibleCoreVersion": "0.8.9", "compatibleCoreVersion": "0.8.9",
"author": "Skeroujvapluvit", "author": "Skeroujvapluvit",
@@ -21,7 +21,7 @@
"path": "lang/fr.json" "path": "lang/fr.json"
} }
], ],
"styles": [], "styles": ["./styles/main.css"],
"url": "https://github.com/mcailleaux/WFRP4-FoundryVTT-wfrp4e-actor-sheet-print", "url": "https://github.com/mcailleaux/WFRP4-FoundryVTT-wfrp4e-actor-sheet-print",
"download": "https://github.com/mcailleaux/WFRP4-FoundryVTT-wfrp4e-actor-sheet-print/blob/dist/dist/wfrp4e-actor-sheet-print.zip?raw=true", "download": "https://github.com/mcailleaux/WFRP4-FoundryVTT-wfrp4e-actor-sheet-print/blob/dist/dist/wfrp4e-actor-sheet-print.zip?raw=true",
"manifest": "https://raw.githubusercontent.com/mcailleaux/WFRP4-FoundryVTT-wfrp4e-actor-sheet-print/dist/module.json", "manifest": "https://raw.githubusercontent.com/mcailleaux/WFRP4-FoundryVTT-wfrp4e-actor-sheet-print/dist/module.json",

View File

@@ -1,4 +1,6 @@
npm run build npm run build
mkdir -p ./dist/lang mkdir -p ./dist/lang
mkdir -p ./dist/styles
cp ./lang/* ./dist/lang/ cp ./lang/* ./dist/lang/
cp ./styles/* ./dist/styles/
cp module.json ./dist/module.json cp module.json ./dist/module.json

View File

@@ -18,7 +18,9 @@ export class Column extends AbstractElement {
element.x = Math.max(element.x, this.x); element.x = Math.max(element.x, this.x);
element.y = currentY; element.y = currentY;
element.prepareRender(doc); element.prepareRender(doc);
currentY += element.getHeight(doc) + 2; const elementHeight = element.getHeight(doc);
currentY +=
elementHeight > 0 ? element.getHeight(doc) + 2 : elementHeight;
} }
return doc; return doc;
} }
@@ -53,4 +55,8 @@ export class Column extends AbstractElement {
} }
return elements; return elements;
} }
public isEmpty(): boolean {
return this.elements.length === 0;
}
} }

View File

@@ -25,50 +25,52 @@ export class LabelledValues extends Row {
const labelPercent = 100 - valuePercent; const labelPercent = 100 - valuePercent;
const widthPercent = [labelPercent, valuePercent]; const widthPercent = [labelPercent, valuePercent];
let currentIndex = 0; let currentIndex = 0;
if (this.nbrOfCol > 1) { if (labelledValues.length > 0) {
const nbrPerCol = Math.floor(labelledValues.length / this.nbrOfCol); if (this.nbrOfCol > 1) {
const rest = labelledValues.length - nbrPerCol * this.nbrOfCol; const nbrPerCol = Math.floor(labelledValues.length / this.nbrOfCol);
const nbrPerCols = [ const rest = labelledValues.length - nbrPerCol * this.nbrOfCol;
rest > 0 ? nbrPerCol + 1 : nbrPerCol, const nbrPerCols = [
rest > 1 ? nbrPerCol + 1 : nbrPerCol, rest > 0 ? nbrPerCol + 1 : nbrPerCol,
rest > 2 ? nbrPerCol + 1 : nbrPerCol, rest > 1 ? nbrPerCol + 1 : nbrPerCol,
]; rest > 2 ? nbrPerCol + 1 : nbrPerCol,
for (let i = 0; i < this.nbrOfCol; i++) { ];
this.elements[i] = new Column(0, 0, []); for (let i = 0; i < this.nbrOfCol; i++) {
} this.elements[i] = new Column(0, 0, []);
for (let i = 0; i < labelledValues.length; i++) {
if (i < nbrPerCols[0]) {
currentIndex = 0;
} else if (i < nbrPerCols[0] + nbrPerCols[1]) {
currentIndex = 1;
} else {
currentIndex = 2;
} }
(<Column>this.elements[currentIndex]).elements.push( for (let i = 0; i < labelledValues.length; i++) {
new LabelledValue( if (i < nbrPerCols[0]) {
labelledValues[i].label, currentIndex = 0;
labelledValues[i].value, } else if (i < nbrPerCols[0] + nbrPerCols[1]) {
widthPercent, currentIndex = 1;
multiline } else {
currentIndex = 2;
}
(<Column>this.elements[currentIndex]).elements.push(
new LabelledValue(
labelledValues[i].label,
labelledValues[i].value,
widthPercent,
multiline
)
);
}
} else {
this.elements.push(
new Column(
0,
0,
labelledValues.map(
(libelledValue) =>
new LabelledValue(
libelledValue.label,
libelledValue.value,
widthPercent,
multiline
)
)
) )
); );
} }
} else {
this.elements.push(
new Column(
0,
0,
labelledValues.map(
(libelledValue) =>
new LabelledValue(
libelledValue.label,
libelledValue.value,
widthPercent,
multiline
)
)
)
);
} }
} }

View File

@@ -83,4 +83,8 @@ export class Row extends AbstractElement {
} }
return elements; return elements;
} }
public isEmpty(): boolean {
return this.elements.length === 0;
}
} }

View File

@@ -23,51 +23,53 @@ export class Texts extends Row {
this.nbrOfCol = 4; this.nbrOfCol = 4;
} }
let currentIndex = 0; let currentIndex = 0;
if (this.nbrOfCol > 1) { if (texts.length > 0) {
const nbrPerCol = Math.floor(texts.length / this.nbrOfCol); if (this.nbrOfCol > 1) {
const rest = texts.length - nbrPerCol * this.nbrOfCol; const nbrPerCol = Math.floor(texts.length / this.nbrOfCol);
const nbrPerCols = [ const rest = texts.length - nbrPerCol * this.nbrOfCol;
rest > 0 ? nbrPerCol + 1 : nbrPerCol, const nbrPerCols = [
rest > 1 ? nbrPerCol + 1 : nbrPerCol, rest > 0 ? nbrPerCol + 1 : nbrPerCol,
rest > 2 ? nbrPerCol + 1 : nbrPerCol, rest > 1 ? nbrPerCol + 1 : nbrPerCol,
rest > 3 ? nbrPerCol + 1 : nbrPerCol, rest > 2 ? nbrPerCol + 1 : nbrPerCol,
]; rest > 3 ? nbrPerCol + 1 : nbrPerCol,
for (let i = 0; i < this.nbrOfCol; i++) { ];
this.elements[i] = new Column(0, 0, []); for (let i = 0; i < this.nbrOfCol; i++) {
} this.elements[i] = new Column(0, 0, []);
for (let i = 0; i < texts.length; i++) {
if (i < nbrPerCols[0]) {
currentIndex = 0;
} else if (i < nbrPerCols[0] + nbrPerCols[1]) {
currentIndex = 1;
} else if (i < nbrPerCols[0] + nbrPerCols[1] + nbrPerCols[2]) {
currentIndex = 2;
} else {
currentIndex = 3;
} }
(<Column>this.elements[currentIndex]).elements.push( for (let i = 0; i < texts.length; i++) {
new Row(0, 0, [ if (i < nbrPerCols[0]) {
multiline currentIndex = 0;
? new MultilineText(0, 0, texts[i]) } else if (i < nbrPerCols[0] + nbrPerCols[1]) {
: new Text(0, 0, texts[i]), currentIndex = 1;
]) } else if (i < nbrPerCols[0] + nbrPerCols[1] + nbrPerCols[2]) {
currentIndex = 2;
} else {
currentIndex = 3;
}
(<Column>this.elements[currentIndex]).elements.push(
new Row(0, 0, [
multiline
? new MultilineText(0, 0, texts[i])
: new Text(0, 0, texts[i]),
])
);
}
} else {
this.elements.push(
new Column(
0,
0,
texts.map(
(text) =>
new Row(0, 0, [
multiline
? new MultilineText(0, 0, text)
: new Text(0, 0, text),
])
)
)
); );
} }
} else {
this.elements.push(
new Column(
0,
0,
texts.map(
(text) =>
new Row(0, 0, [
multiline
? new MultilineText(0, 0, text)
: new Text(0, 0, text),
])
)
)
);
} }
} }

View File

@@ -16,7 +16,6 @@ import { Blank } from './elements/blank';
Hooks.on( Hooks.on(
'renderActorSheetWfrp4eCharacter', 'renderActorSheetWfrp4eCharacter',
async (app: ActorSheet, html: JQuery) => { async (app: ActorSheet, html: JQuery) => {
console.dir(app);
const actor: Actor & any = app.actor; const actor: Actor & any = app.actor;
const actorData = actor.data; const actorData = actor.data;
// @ts-ignore // @ts-ignore
@@ -468,115 +467,175 @@ Hooks.on(
`${i18nLocalize('Talents')} : ${i18nLocalize('Tests')}` `${i18nLocalize('Talents')} : ${i18nLocalize('Tests')}`
), ),
talents, talents,
new Separator(0, 0), traits.elements.length > 0
new Text(0, 0, 'Traits'), ? new Separator(0, 0)
: Blank.heightBlank(0),
traits.elements.length > 0
? new Text(0, 0, 'Traits')
: Blank.heightBlank(0),
traits, traits,
new Separator(0, 0), weaponsMelee.elements.length > 0
new Text( ? new Separator(0, 0)
0, : Blank.heightBlank(0),
0, weaponsMelee.elements.length > 0
`${i18nLocalize('SHEET.MeleeWeaponHeader')} : ${i18nLocalize( ? new Text(
'Weapon Group' 0,
)}, ${i18nLocalize('Reach')}, ${i18nLocalize( 0,
'Damage' `${i18nLocalize('SHEET.MeleeWeaponHeader')} : ${i18nLocalize(
)}, ${i18nLocalize('Qualities')}, ${i18nLocalize('Flaws')}` 'Weapon Group'
), )}, ${i18nLocalize('Reach')}, ${i18nLocalize(
'Damage'
)}, ${i18nLocalize('Qualities')}, ${i18nLocalize('Flaws')}`
)
: Blank.heightBlank(0),
weaponsMelee, weaponsMelee,
new Separator(0, 0), weaponsRanged.elements.length > 0
new Text( ? new Separator(0, 0)
0, : Blank.heightBlank(0),
0, weaponsRanged.elements.length > 0
`${i18nLocalize('SHEET.RangedWeaponHeader')} : ${i18nLocalize( ? new Text(
'Weapon Group' 0,
)}, ${i18nLocalize('Range')}, ${i18nLocalize( 0,
'Damage' `${i18nLocalize('SHEET.RangedWeaponHeader')} : ${i18nLocalize(
)}, ${i18nLocalize('Qualities')}, ${i18nLocalize('Flaws')}` 'Weapon Group'
), )}, ${i18nLocalize('Range')}, ${i18nLocalize(
'Damage'
)}, ${i18nLocalize('Qualities')}, ${i18nLocalize('Flaws')}`
)
: Blank.heightBlank(0),
weaponsRanged, weaponsRanged,
new Separator(0, 0), ammunitions.elements.length > 0
new Text( ? new Separator(0, 0)
0, : Blank.heightBlank(0),
0, ammunitions.elements.length > 0
`${i18nLocalize('Ammunition')} : ${i18nLocalize( ? new Text(
'Range' 0,
)}, ${i18nLocalize('Damage')}, ${i18nLocalize( 0,
'Qualities' `${i18nLocalize('Ammunition')} : ${i18nLocalize(
)}, ${i18nLocalize('Flaws')}` 'Range'
), )}, ${i18nLocalize('Damage')}, ${i18nLocalize(
'Qualities'
)}, ${i18nLocalize('Flaws')}`
)
: Blank.heightBlank(0),
ammunitions, ammunitions,
new Separator(0, 0), armours.elements.length > 0
new Text(0, 0, 'Armour'), ? new Separator(0, 0)
: Blank.heightBlank(0),
armours.elements.length > 0
? new Text(0, 0, 'Armour')
: Blank.heightBlank(0),
armours, armours,
new Separator(0, 0), petty.elements.length > 0
new Text( ? new Separator(0, 0)
0, : Blank.heightBlank(0),
0, petty.elements.length > 0
`${i18nLocalize('SHEET.PettySpell')} : ${i18nLocalize( ? new Text(
'Casting Number' 0,
)}, ${i18nLocalize('Range')}, ${i18nLocalize( 0,
'Target' `${i18nLocalize('SHEET.PettySpell')} : ${i18nLocalize(
)}, ${i18nLocalize('Duration')}` 'Casting Number'
), )}, ${i18nLocalize('Range')}, ${i18nLocalize(
'Target'
)}, ${i18nLocalize('Duration')}`
)
: Blank.heightBlank(0),
petty, petty,
new Separator(0, 0), spell.elements.length > 0
new Text( ? new Separator(0, 0)
0, : Blank.heightBlank(0),
0, spell.elements.length > 0
`${i18nLocalize('SHEET.LoreSpell')} : ${i18nLocalize( ? new Text(
'Casting Number' 0,
)}, ${i18nLocalize('Range')}, ${i18nLocalize( 0,
'Target' `${i18nLocalize('SHEET.LoreSpell')} : ${i18nLocalize(
)}, ${i18nLocalize('Duration')}, ${i18nLocalize( 'Casting Number'
'WFRP4E.TrappingType.Ingredients' )}, ${i18nLocalize('Range')}, ${i18nLocalize(
)}` 'Target'
), )}, ${i18nLocalize('Duration')}, ${i18nLocalize(
'WFRP4E.TrappingType.Ingredients'
)}`
)
: Blank.heightBlank(0),
spell, spell,
new Separator(0, 0), blessing.elements.length > 0
new Text( ? new Separator(0, 0)
0, : Blank.heightBlank(0),
0, blessing.elements.length > 0
`${i18nLocalize('Blessing')} : ${i18nLocalize( ? new Text(
'Range' 0,
)}, ${i18nLocalize('Target')}, ${i18nLocalize('Duration')}` 0,
), `${i18nLocalize('Blessing')} : ${i18nLocalize(
'Range'
)}, ${i18nLocalize('Target')}, ${i18nLocalize('Duration')}`
)
: Blank.heightBlank(0),
blessing, blessing,
new Separator(0, 0), miracle.elements.length > 0
new Text( ? new Separator(0, 0)
0, : Blank.heightBlank(0),
0, miracle.elements.length > 0
`${i18nLocalize('Miracle')} : ${i18nLocalize( ? new Text(
'Range' 0,
)}, ${i18nLocalize('Target')}, ${i18nLocalize('Duration')}` 0,
), `${i18nLocalize('Miracle')} : ${i18nLocalize(
'Range'
)}, ${i18nLocalize('Target')}, ${i18nLocalize('Duration')}`
)
: Blank.heightBlank(0),
miracle, miracle,
new Separator(0, 0), new Separator(0, 0),
trappingsHeader, trappingsHeader,
trappings, trappings,
new Separator(0, 0), psychology.elements.length > 0
new Text(0, 0, 'Psychology'), ? new Separator(0, 0)
: Blank.heightBlank(0),
psychology.elements.length > 0
? new Text(0, 0, 'Psychology')
: Blank.heightBlank(0),
psychology, psychology,
new Separator(0, 0), critical.elements.length > 0
new Text(0, 0, 'Criticals'), ? new Separator(0, 0)
: Blank.heightBlank(0),
critical.elements.length > 0
? new Text(0, 0, 'Criticals')
: Blank.heightBlank(0),
critical, critical,
new Separator(0, 0), disease.elements.length > 0
new Text(0, 0, 'Diseases'), ? new Separator(0, 0)
: Blank.heightBlank(0),
disease.elements.length > 0
? new Text(0, 0, 'Diseases')
: Blank.heightBlank(0),
disease, disease,
new Separator(0, 0), injury.elements.length > 0
new Text(0, 0, 'Injuries'), ? new Separator(0, 0)
: Blank.heightBlank(0),
injury.elements.length > 0
? new Text(0, 0, 'Injuries')
: Blank.heightBlank(0),
injury, injury,
new Separator(0, 0), mutationP.elements.length > 0
new Text( ? new Separator(0, 0)
0, : Blank.heightBlank(0),
0, mutationP.elements.length > 0
`${i18nLocalize('Mutations')} (${i18nLocalize('Physical')})` ? new Text(
), 0,
0,
`${i18nLocalize('Mutations')} (${i18nLocalize('Physical')})`
)
: Blank.heightBlank(0),
mutationP, mutationP,
new Separator(0, 0), mutationM.elements.length > 0
new Text( ? new Separator(0, 0)
0, : Blank.heightBlank(0),
0, mutationM.elements.length > 0
`${i18nLocalize('Mutations')} (${i18nLocalize('Mental')})` ? new Text(
), 0,
0,
`${i18nLocalize('Mutations')} (${i18nLocalize('Mental')})`
)
: Blank.heightBlank(0),
mutationM, mutationM,
]), ]),
]); ]);

13
styles/main.css Normal file
View File

@@ -0,0 +1,13 @@
.app.window-app .window-header .print {
color: #e8d29c;
text-align: center;
height: 30px;
width: 30px;
margin: 0;
padding: 0;
background: url('/systems/wfrp4e/ui/buttons/button-blank.webp');
}
.app.window-app .window-header .print i {
font-size: 12px;
}