#!/opt/bin/perl use strict; no utf8; use bytes; use Storable; my %type = ( deep_sea => "#006", sea => "#008", shallow_sea => "#00a", beach => "#aa0", dunes => "#bb0", desert => "#cc0", steppe => "#880", steppelight => "#dd7", small_stones => "#eeb", marsh => "#0f8", grass => "#0f0", grassmedium => "#0e0", grassbrown => "#851", grassdark => "#274", desert => "#cc0", darkforest => "#040", evergreens => "#0a0", woods => "#080", swamp => "#660", deep_swamp => "#440", jungle_1 => "#084", flagstone => "#bbb", istone => "#bbc", hills_rocky => "#aa8", treed_hills => "#6a4", hills => "#aa4", mountain => "#ccc", mountain2 => "#cdd", # mountain3 => "#ddc", mountain4 => "#ddb", mountain5 => "#ddd", s_mountain => "#dff", wasteland => "#ddf", drifts => "#eef", snow => "#eff", cobblestones => "#ea2", ); my $world = { version => 1, minx => 100, miny => 100, maxx => 129, maxy => 129, tilew => 50, tileh => 50, arch => ["blocked"], }; open my $png, "convert world.png -depth 8 rgb:- |" or die "convert :$!"; 1500*1500*3 == read $png, my $data, 1500*1500*3 or die; my $type = "\x00" x (1500*1500); my %color; for my $k (keys %type) { my $v = join "", map chr, (map $_*255/15, map hex, split //, substr $type{$k}, 1); $color{$v} = @{$world->{arch}}; push @{$world->{arch}}, $k; } for my $Y (0 .. $world->{maxy} - $world->{miny}) { print "$Y "; $| = 1; for my $X (0 .. $world->{maxx} - $world->{minx}) { my $X = $X * $world->{tilew}; my $Y = $Y * $world->{tileh}; for my $y (0 .. $world->{tileh} - 1) { for my $x ( 0.. $world->{tilew} - 1) { my $ofs = (($Y + $y)* 1500 + $X + $x); my $pix = substr $data, $ofs * 3, 3; if (my $k = $color{$pix}) { substr $type, $ofs, 1, chr $k; } else { die sprintf "colour '%s' not defined at +%d+%d", (unpack "H*", $pix), $X + $x, $Y + $y; } } } } } print "\n"; $world->{data} = $type; Storable::nstore $world, "world.pst";