This is really good research!
I worked on it a bit and have a basic system in place to generate the book content. Since the items/text do not already exist, they all need to be created.
The way this works in our environment is that a book (item) references a sql table (books) in the db, and reads from a field to populate content. This is not a fun process, because lines are separated with backticks `, one for single line spacing, two for 2 lines, and so on with no strict guidelines for line or page length. There is also an issue with proportional font, e.g. iiiii consumes less space than LLLLL.
Since this will need to be done roughly 80 times, here is my first pass at a book content generator (Perl):
Code:
use strict;
use warnings;
my $max_line_length = 28; # characters per line (hack guess)
my $lines_per_column = 12; # lines per column
sub format_text {
my ($text) = @_;
my @words = split(/\s+/, $text);
my @lines;
my $line = '';
#wrap
foreach my $word (@words) {
if (length($line) + length($word) + 1 <= $max_line_length) {
$line .= ($line ? " " : "") . $word;
} else {
push @lines, $line;
$line = $word;
}
}
push @lines, $line if $line;
# basic handling
foreach my $i (reverse 0 .. $#lines) {
if ($lines[$i] =~ /----+/) {
splice(@lines, $i + 1, 0, ''); #blank line insert
}
}
# more formatting
foreach my $i (reverse 0 .. $#lines) {
if ($lines[$i] =~ /^Ingredients:/) {
splice(@lines, $i, 0, ''); #blank line before "Ingredients:"
splice(@lines, $i + 2, 0, ''); #blank line after "Ingredients:"
}
}
#grouping
my @columns;
my @current_column;
foreach my $line (@lines) {
if (scalar(@current_column) < $lines_per_column) {
push @current_column, $line;
} else {
push @columns, [@current_column];
@current_column = ($line);
}
}
push @columns, [@current_column] if @current_column;
#padding
foreach my $col_num (0 .. $#columns) {
while (scalar(@{$columns[$col_num]}) < $lines_per_column) {
push @{$columns[$col_num]}, '';
}
scalar(@{$columns[$col_num]}) . " lines\n";
}
#sql output
my $formatted_text = join("``", map { join("`", @$_) } @columns);
#escape
$formatted_text =~ s/'/''/g;
return $formatted_text;
}
#file I/O
my $input_file = 'raw_text.txt'; #input
my $output_file = 'formatted_output.sql'; #output
my $book_name = 'NewBookName'; #variable
#read raw_text
open my $in_fh, '<', $input_file or die "Could not open '$input_file': $!";
my $raw_text = do { local $/; <$in_fh> };
close $in_fh;
#format
my $formatted_text = format_text($raw_text);
#write to output
open my $out_fh, '>', $output_file or die "Could not open '$output_file': $!";
print $out_fh "INSERT INTO `books` (`name`, `txtfile`) VALUES ('$book_name', '$formatted_text');\n";
close $out_fh;
While this works "ok", there are cases where it could be a lot better. The following is an example of output from ingested Volume 7 (1st edition) text:
[You must be logged in to view images. Log in or Register.]
I'm not aware of a publicly available book content generator for eqemu, so I'm opening this up for anyone who is interested in either helping to fine-tune this, or use it for your own purposes.
---------------------------------------------------------------------------
-Rivervale Voice (all 8 copies) implemented with vendor working on ruled system per months. Please note, some text may appear poorly structured due to above.
Adding drops to npcs: Could use opinions of what all should be encompassed. From Passenger's research, it seems any type of race that could be a bandit? What about ogres, erudites, orcs, etc.