1 # This is part of ypp-sc-tools, a set of third-party tools for assisting
2 # players of Yohoho Puzzle Pirates.
4 # Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
20 # are used without permission. This program is not endorsed or
21 # sponsored by Three Rings.
23 package CommodsScrape;
35 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
38 @EXPORT = qw(yppedia_chart_parse);
44 sub yppedia_chart_parse ($$ $$$$ $) {
46 $conv_nxy, $on_archlabel, $on_island, $on_league,
47 $on_incomprehensible) = @_;
49 my ($x,$y, $arch,$island,$solid,$dirn);
50 my $nn= sub { return $conv_nxy->($x,$y) };
52 # We don't even bother with tag soup; instead we do line-oriented parsing.
55 s/^\s*//; chomp; s/\s+$//; s/\s+/ /g;
57 s/\{\{chart\ style\|[^{}]*\}\}//gi;
58 next unless m/\{\{/; # only interested in chart template stuff
61 m/^\{\{ chart\ label \|(\d+)\|(\d+)\| .*
62 (?: \<(?: big|center )\>)* \'+
64 [^][\']* \| ([^][\'|]+)\ archipelago
66 \'+ (?: \<\/(?: big|center )\>)* \}\}$/xi) {
67 printf $debugfh "%2d,%-2d arch %s\n", $x,$y,$arch;
68 $on_archlabel->($x,$y,$arch);
69 } elsif (m/^\{\{ chart\ label \|\d+\|\d+\|
70 \<big\> \'+ \[\[ .* \b ocean \]\]/xi) {
71 } elsif (($x,$y,$island) =
72 m/^\{\{ chart\ island\ icon \|(\d+)\|(\d+)\|
73 ([^| ][^|]*[^| ]) \| .*\}\}$/xi) {
75 printf $debugfh "%2d,%-2d island %s\n", $x,$y,$island;
76 $on_island->($n, $island);
77 } elsif (($solid,$x,$y,$dirn) =
78 m/^\{\{ chart\ league((?:\ solid)?) \|(\d+)\|(\d+)\|
79 ([-\/\\o]) \| .*\}\}$/xi) {
82 printf $debugfh "%2d,%-2d league %-6s %s\n", $x,$y,
83 $solid?'solid':'dotted', $dirn;
85 my ($bx,$by) = ($x,$y);
86 if ($dirn eq '-') { $bx+=2; }
87 elsif ($dirn eq '\\') { $bx++; $by++; }
88 elsif ($dirn eq '/') { $x++; $by++; }
92 my $nb= $conv_nxy->($bx,$by);
93 $on_league->($na,$nb,$solid);
95 m/^\{\{ chart\ head \}\}$/xi
99 $on_incomprehensible->($.,$_);