![]() ![]() |
weathermap |
Subversion Repositories: |
| Line No. | Rev | Author | Line |
|---|---|---|---|
| 1 | 1 | simandl | <?php |
| 2 | require_once 'Weathermap.class.php'; |
||
| 3 | |
||
| 4 | // EDIT THESE! |
||
| 5 | // Which file to read in (the big map) |
||
| 6 | $input_mapfile = "configs/09-test.conf"; |
||
| 7 | // how big do you want your new maps to be? |
||
| 8 | $desired_width = 640; |
||
| 9 | $desired_height = 480; |
||
| 10 | |
||
| 11 | $map = new WeatherMap; |
||
| 12 | $map->ReadConfig($input_mapfile); |
||
| 13 | |
||
| 14 | print "Size of source is ".$map->width."x".$map->height."\n"; |
||
| 15 | |
||
| 16 | $rows = intval($map->height/$desired_height)+1; |
||
| 17 | $cols = intval($map->width/$desired_width)+1; |
||
| 18 | $num = $rows * $cols; |
||
| 19 | |
||
| 20 | |
||
| 21 | if($num == 1) |
||
| 22 | { |
||
| 23 | print "This map is already within your constraints.\n"; |
||
| 24 | } |
||
| 25 | else |
||
| 26 | { |
||
| 27 | print "We'll need to make $num ($cols x $rows) smaller maps\n"; |
||
| 28 | for($row=0;$row < $rows; $row++) |
||
| 29 | { |
||
| 30 | for($col=0;$col<$cols; $col++) |
||
| 31 | { |
||
| 32 | print "=====================================\nMaking the submap $col,$row\n"; |
||
| 33 | $min_x = $col*$desired_width; |
||
| 34 | $min_y = $row*$desired_height; |
||
| 35 | $max_x = ($col+1)*$desired_width; |
||
| 36 | $max_y = ($row+1)*$desired_height; |
||
| 37 | print "We'll read the map, and throw out everything not inside ($min_x,$min_y)->($max_x,$max_y)\n"; |
||
| 38 | |
||
| 39 | $map = new WeatherMap; |
||
| 40 | $map->ReadConfig($input_mapfile); |
||
| 41 | |
||
| 42 | foreach ($map->nodes as $node) |
||
| 43 | { |
||
| 44 | $target = $node->name; |
||
| 45 | if( ($node->x < $min_x) || ($node->x >= $max_x) || |
||
| 46 | ($node->y < $min_y) || ($node->y >= $max_y) ) |
||
| 47 | { |
||
| 48 | |
||
| 49 | print "$target falls outside of this map. Deleting it and links that use it.\n"; |
||
| 50 | |
||
| 51 | foreach ($map->links as $link) |
||
| 52 | { |
||
| 53 | if( ($target == $link->a->name) || ($target == $link->b->name) ) |
||
| 54 | { |
||
| 55 | print "link $link->name uses it. Deleted.\n"; |
||
| 56 | unset($map->links[$link->name]); |
||
| 57 | } |
||
| 58 | } |
||
| 59 | unset($map->nodes[$target]); |
||
| 60 | } |
||
| 61 | else |
||
| 62 | { |
||
| 63 | print "$target is OK, but will be moved for the new map from ".$node->x.",".$node->y." to "; |
||
| 64 | $x = $node->x; |
||
| 65 | $y = $node->y; |
||
| 66 | |
||
| 67 | $x = $node->x - $min_x; |
||
| 68 | $y = $node->y - $min_y; |
||
| 69 | $map->nodes[$target]->x = $x; |
||
| 70 | $map->nodes[$target]->y = $y; |
||
| 71 | print "$x,$y\n"; |
||
| 72 | } |
||
| 73 | } |
||
| 74 | $output_mapfile = $input_mapfile."-".$row."-".$col.".conf"; |
||
| 75 | $map->width = $desired_width; |
||
| 76 | $map->height = $desired_height; |
||
| 77 | $map->background=""; |
||
| 78 | $map->WriteConfig($output_mapfile); |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |
||
| 82 | } |
||
| 83 | |
||
| 84 | ?> |