#!/usr/bin/perl
use strict;
use warnings;
use lib "../adv";
use include;

my $AREA = "map";

use HexedUI;
my $ui = create HexedUI {
  Main => {
    Type   => "Map",
    At     => [0, 0],
    Size   => ["100%", "100%"],
    Border => 1,
    Render => sub {
      my $tile = shift;
      my ($char, $color);
      if (ref $tile->{_}) {
        ($char, $color) = $tile->{_}->symbol;
      } elsif ($tile->{color}) {
        $char = $tile->{_};
        $color = $tile->{color};
      } else {
        $char = $tile->{_};
        $color = {
          "#" => "orange",
          "." => "grey"
        }->{$char};
        $color ||= "yellow";
      }
      return ord($char) | HexedUI::paint($color);
    }
  },
};
GAME->{UI} = $ui;

use BDSM::Transform;
my $map;
if ($AREA) {
  $map = loadmap($AREA);
} else {
  $map = bdsm_map(26, 77, ".");
  border($map);
  fill($map, [11, 9], [11, 50], "#");
  fill($map, [17, 9], [17, 50], "#");
  fill($map, [11, 25], [17, 25], "#");
}

$ui->{Main}->setup($map);
$map->{OnChange} = sub {
  my ($map, $y, $x, $new) = @_;
  $ui->{Main}->_mod($y, $x, $map->{Map}[$y][$x]);
};

use Highway;
preprock($map);
GAME->{UI}->input;
