~extremepopcorn/dhlib/dhlib_ep

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use constant 
{
	INPUT_WATER => 0x00007f,
	INPUT_LAND => 0x007f00,
	INPUT_TOWER => 0x00ff00,

	OUTPUT_LAND => 2,
	OUTPUT_WATER => 1,
	OUTPUT_TOWER => 3
};

# Produces the standard HTML 0x form of an rgb value
sub rgbCombine
{
	my $c = shift(@_) * 0x10000;
	$c += shift(@_) * 0x100;
	$c += shift(@_);
	return $c;
}


# A version of split which takes a function to format the arguments
sub split_fmt
{
	my ( $fmtr, $sep, @arr ) = @_;
	my $out = '';
	
	for $i ( 0 .. $#arr )
	{
		$out = $out . ',' unless $i == 0;
		$out = $out . &$fmtr( $arr[$i] );	
	}
	return $out;
	
}

# formats a point item as a haxe array
sub point_fmtr
{
	my @pt = $_[0];
	return '[' . $pt[0][0] . ',' . $pt[0][1] . ']'; #WTF? triple indirection, where does this extra array come from!!?!
}

# prints a map in Haxe format
sub print_map
{
	my ( $name, @map ) = @_;
	$width = $#map + 1;
	$height = $#{$map[0]} + 1;
	
	print "\t$name: /*$width x $height*/ [\n";
	for $y ( 0 .. $height-1 )
	{
		print "\t\t[";
		
		for $x ( 0 .. $width-1 ) 
		{
			print $map[$x][$y];
			print "," unless $x == ($width-1);
		}
		
		print "]";
		print "," unless $y == ($height-1);
		print "\n";
	}
	print "\t],\n";
}

1;