#!/usr/bin/env raku

use Draw2D::Furniture;

# this file is in the basic format to be used
# by this program:
my $ifil = '';

if !@*ARGS {
    say qq:to/HERE/;
    Usage: {$*PROGRAM.basename} <formatted input file> [scale=X][debug]

    The optional scale is a number representing page inches per
    real feet. The default is 0.25 (i.e., 1/4 inch per foot, a
    value commonly used in house blueprints).

    Produces:

      1. A pdf doc listing of rooms and furniture

      2. A pdf file with furniture numbers and other
         data (which may overflow) for cutting out. Items are
         scaled 1/4\" to the foot to match typical house blueprints.
         A different scale may be entered into the formatted
         input file (NYI).
    HERE

    exit;
}

my $debug = 0;

for @*ARGS {
    when /^ g/ { ;  }
    when /^ d/ { $debug = 1 }
    when /^ 'scale=' (\S+) / {
         $in-per-ft = +$0; # default is 0.25
    }
    default { $ifil = $_ }
}

if !$ifil.IO.f {
    die "FATAL: Input file '$ifil' cannot be opened.";
}

my @ofils; # list of output files generated
my @rooms; # list of room objects containing furniture objects
read-data-file $ifil, @rooms, :$debug;

write-list @rooms, @ofils, :$debug;

write-drawings @rooms, @ofils, :$debug;

say "Normal end.";
my $n = +@ofils;
if $n {
   my $s = $n > 1 ?? 's' !! '';
   say "See output file$s:";
   say "  $_" for @ofils;
}
else {
     say "No files generated.";
}
