summaryrefslogtreecommitdiff
path: root/incantesimi/excel_to_incantesimi.pl
diff options
context:
space:
mode:
Diffstat (limited to 'incantesimi/excel_to_incantesimi.pl')
-rw-r--r--incantesimi/excel_to_incantesimi.pl85
1 files changed, 67 insertions, 18 deletions
diff --git a/incantesimi/excel_to_incantesimi.pl b/incantesimi/excel_to_incantesimi.pl
index e2d1899..d1c82cf 100644
--- a/incantesimi/excel_to_incantesimi.pl
+++ b/incantesimi/excel_to_incantesimi.pl
@@ -1,6 +1,7 @@
#!/usr/bin/perl
use strict;
use warnings;
+use utf8;
use Spreadsheet::ParseExcel;
use LaTeX::Encode;
use Template;
@@ -9,16 +10,23 @@ use Data::Printer;
# excel => latex
my %fieldmap = (
spellname => 'name',
+ name => 'name',
+ ability => 'name',
level => 'level',
+ equiv => 'level',
school => 'scuola',
+ source => 'source',
+ uses => 'uses',
+ type => 'type',
comp => 'components',
ct => 'tempo',
+ at => 'tempo',
range => 'range',
target => 'target',
duration => 'durata',
st => 'st',
sr => 'sr',
- spell => 'descrizione',
+ description => 'descrizione',
special => 'specialcomp',
page => 'ref',
notes => 'note',
@@ -33,25 +41,65 @@ my $parser = Spreadsheet::ParseExcel->new();
my $wb = $parser->parse($input_filename)
or die $parser->error;
-my $spells = parse_table($wb->worksheet('Incantesimi')
- // $wb->worksheet(0));
+sheet_2_latex(
+ sheet_name => 'Incantesimi',
+ output_filename => "${output_filename}.incantesimi.tex",
+);
+sheet_2_latex(
+ sheet_name => 'Domini',
+ sheet_idx => 1,
+ output_filename => "${output_filename}.domini.tex",
+ skip_col => 1,
+);
+sheet_2_latex(
+ sheet_name => 'Abilità speciali',
+ sheet_idx => 2,
+ output_filename => "${output_filename}.special.tex",
+ command => 'potere',
+ skip_col => 1,
+);
-munge($spells);
-p $spells;
-my $template = Template->new();
-$template->process(
- \*DATA,
- {
- spells => $spells,
+{
+my $template;
+sub template {
+ $template //= do {local $/;<DATA>};
+ return $template;
+}
+}
+
+sub sheet_2_latex {
+ my %opts = (
+ sheet_idx => 0,
fieldmap => \%fieldmap,
- lt => \&latexise,
- },
- $output_filename,
-)
+ command => 'incantesimo',
+ @_,
+ );
+
+ my $spells = parse_table(
+ $wb->worksheet($opts{sheet_name})
+ // $wb->worksheet($opts{sheet_idx}),
+ $opts{skip_col},
+ );
+
+ munge($spells);
+
+ my $template = Template->new();
+ $template->process(
+ \template(),
+ {
+ spells => $spells,
+ fieldmap => $opts{fieldmap},
+ command => $opts{command},
+ lt => \&latexise,
+ },
+ $opts{output_filename},
+ )
or die $template->error;
+}
sub parse_table {
- my ($ws) = @_;
+ my ($ws,$skip_col) = @_;
+ $skip_col //= 0;
my ($min_col,$max_col) = $ws->col_range();
my ($min_row,$max_row) = $ws->row_range();
@@ -59,6 +107,7 @@ sub parse_table {
$min_col .. $max_col;
for my $h (@headings) {
+ $h =~ s{^spell\W}{}i;
$h =~ s{\W.*$}{};
$h = lc($h);
}
@@ -67,7 +116,7 @@ sub parse_table {
for my $row ((1+$min_row) .. $max_row) {
# allow and skip empty rows
- next unless eval { $ws->get_cell($row,$min_col)->value };
+ next unless eval { $ws->get_cell($row,$min_col+$skip_col)->value };
my %record;
keys @headings;
@@ -112,8 +161,8 @@ __DATA__
\matrix {
[% FOREACH spell IN spells %]
-\incantesimo{type=spell,
-[%- FOREACH field IN fieldmap; IF spell.item(field.key) %]
+\[% command %]{
+[%- FOREACH field IN fieldmap; IF spell.item(field.key) != '' %]
[% field.value %]={[% lt(spell.item(field.key)) %]},
[%- END; END %]
} [% IF (loop.count() % 6) %]& [% ELSE %] \\ [% END -%]