#!/usr/bin/perl -w
# Books of Pumpkins, etc.  Extensions to Quacks of Quedlinburg
#  SPDX-License-Identifier: GPL-3.0-or-later OR CC-BY-SA-4.0
# Copyright 2020-2022 Ian Jackson

use strict;

BEGIN { unshift @INC, '.'; }
use Quacks;

sub o {
  local $_;
  for (@_) { $ps_framing .= $_ }
}

ps_start(<<END);
90 rotate
0 -210 translate
END

my $x_cut = 27;
my $y_cut = 120; # XX
my $y_top = 160; # XX
my $y_cutd = 20;

my $spacing = 23;
my $colspacing = 24;
my $vhalf = sqrt( $spacing ** 2 - ($colspacing*0.5) ** 2 );

o <<END;
gsave
0.5 setgray

/cut_line {
                              newpath
  $x_cut 0                    moveto
  $x_cut $y_cut               lineto
  0      $y_cut $y_cutd add   lineto
  0      $y_top               lineto
                              stroke
} def

cut_line
END

sub places ($) {
  my ($repi) = @_;
  my $data = <<END;
	-1 -1
	-1  0	34 14
	-H  V	34 14 *
	 0  0	34 15
	 0 -1	35 15
	 0 -2	35 16
	 H -2-V	35 16 *
	 1 -2	36 16
	 1 -1	37 16
	 1  0
END
  my @line_poses;
  foreach (split /\n/, $data) {
    s{\#.*}{};
    next unless m/\S/;
    s{^\s*}{};
    s{H}{ -0.5 }g;
    s{V}{ $vhalf / $spacing }ge;
    s{\*}{1}eg;
    my ($x,$y,$money,$veeps,$ruby) = map { eval $_ } split /\s+/;
    $ruby ||= 0;
    $x *= $colspacing;
    $y *= $spacing;

    push @line_poses, "$x $y";
    next unless defined $money;

    $money += 4 * $repi;
    $veeps += 2 * $repi;

    o <<END;
% place $x $y $money $veeps $ruby
gsave
  $x $y translate
  
grestore
END
  }
}

places(0);

print $ps_framing or die $!;
