#!/opt/bin/perl
# cfmap2html - convert crossfire maps to html
# Copyright (C) 2005,2007 Marc Lehmann
#
# CFMAP2HTML is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cfmaps; if not, write to the Free Software
# Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
our $VERSION = '2.1';
use strict;
use List::Util qw(min max);
use Crossfire 1.0;
my $T = 32;
sub escape_html($) {
local $_ = shift;
s/([<>&])/sprintf "%d;", ord $1/ge;
$_
}
my @cfmap2png;
for my $path (@ARGV) {
(my $base = $path) =~ s/\.map//;
# print STDERR "$path\n";
if (!-e "$base.png"
|| -M "$base.png" > -M "$base.map") {
# regenerate png and metainfo
push @cfmap2png, $path;
}
}
system "cfmap2png", @cfmap2png
if @cfmap2png;
for my $path (@ARGV) {
(my $base = $path) =~ s/\.map//;
if (!-e "$base.xhtml"
|| -M "$base.xhtml" > -M "$base.map") {
Crossfire::load_archetypes
unless %ARCH;
my $meta = read_arch "$base.map";
my $arch = $meta->{arch};
open my $fh, ">:utf8", "$base.xhtml"
or die "$base.xhtml: $!";
select $fh;
my $W = (1 + max map $_->{x}, @$arch);
my $H = (1 + max map $_->{y}, @$arch);
my $info = shift @$arch;
my @map;
push @{ $map[$_->{x}][$_->{y}] }, $_
for @$arch;
my $W2 = $W * $T + 600;
my (@path) = split /\//, $base;
print "",
'',
"",
"",
"Deliantra Map \"$path\"",
"\n",
"\n",
"\n",
"",
"",
"";
print "
",
"
",
"Deliantra Map ",
"";
print "/ ";
for (0 .. $#path - 1) {
print "$path[$_] / ";
}
my @dir = qw(none up right down left);
my @tile = map {
my $path = delete $info->{"tile_path_$_"};
$path
? ""
: ""
} 1..4;
print "$path[-1]",
"",
"
";
for my $a (@{$_[0]}) {
my $o = $ARCH{$a->{_name}};
my $type = $a->{type} || $o->{type};
my $aname = escape_html $a->{_name};
my $name = escape_html $a->{name} || $o->{name};
print "