User:Stabbot/skill rewrite.pl


 * 1) !/usr/bin/perl


 * 1) stdin: old style skill page
 * 2) stdout: new style skill page
 * 3) stderr: debug

$catre = qr/\[\cC]ategory:\s*([^\+)\]\]/; $attre = qr/Axe Mastery|Hammer Mastery|Strength|Swordsmanship|Tactics|Beast Mastery|Expertise|Marksmanship|Wilderness Survival|Divine Favor|Healing Prayers|Protection Prayers|Smiting Prayers|Blood Magic|Curses|Death Magic|Soul Reaping|Domination Magic|Fast Casting|Illusion Magic|Inspiration Magic|Air Magic|Earth Magic|Energy Storage|Fire Magic|Water Magic|Critical Strikes|Dagger Mastery|Deadly Arts|Shadow Arts|Channeling Magic|Communing|Restoration Magic|Spawning Power/; $profre = qr/Warrior|Ranger|Monk|Necromancer|Mesmer|Elementalist|Assassin|Ritualist/; $campre = qr/Core|Prophecies|Factions/; $typere = qr/Attack|Bow Attack|Melee Attack|Lead Attack|Off-Hand Attack|Dual Attack|Hammer Attack|Sword Attack|Pet Attack|Binding Ritual|Glyph|Nature Ritual|Preparation|Shout|Signet|Spell|Enchantment Spell|Item Spell|Hex Spell|Well Spell|Ward Spell|Stance|Trap|Skill/;

@cats = ;

$text = join ("", );

$text =~ s# .*? ##sg;
 * 1) remove any includeonly sections

$text =~ s###g;
 * 1) remove noinclude tags

while ($text =~ $catre) { push @cats, $1; $text =~ s/$catre//; }
 * 1) grab cats

@sections = split (/^==(?=[^=])/m, $text);

print STDERR "there are ". ($#sections + 1). " section(s)\n";

$header = shift @sections;

for $cat (@cats) { # print STDERR "washing cat: $cat\n"; if ($cat =~ /Elite skills/) { $elite = "yes"; # print STDERR "elite = $elite\n"; } elsif ($cat =~ /($attre) skills/) { $attribute = $1; # print STDERR "attribute = $attribute\n"; } elsif ($cat =~ /($typere)s/) { $type = $1; # print STDERR "type = $type\n"; } elsif ($cat =~ /($profre) skills \(($campre)\)/) { $profession = $1; $campaign = $2; # print STDERR "profession = $profession\n"; # print STDERR "campaign = $campaign\n"; } }
 * 1) wash the cats

$ch2 = 1 if ($header =~ //);
 * 1) glean whether it needs

$stub = 1 if ($header =~ //);
 * 1) glean whether it needs


 * 1) glean the name
 * 2) $name = "Undefined Name";
 * 3) if ($header =~ /^/m) { $name = $1; }

if (not defined $profession) { if ($header =~ /^{{[Ss]kill[ _]profession[ _]entry\s*\|.*value\s*=\s*\[\[(.*?)\]\]/m) { $profession = $1; } }
 * 1) get the profession from the skillbox if undefined

if (not defined $attribute) { if ($header =~ /^\s*{{[Ss]kill[ _]attribute[ _]entry\s*?\|.*?value\s*=\s*\[\[(.*?)\]\]/m) { $attribute = $1; } else { $attribute = "No Attribute"; } }
 * 1) get the attribute from the skillbox if undefined

if (not defined $type) { if ($header =~ /^\s*{{[Ss]kill[ _]type[ _]entry\s*?\|.*?value\s*?=[^}]*?\[\[($typere)\]\]/m){ $type = $1; } }
 * 1) get the type from the skillbox if undefined

if (not defined $elite) { if ($header =~ /^\s*{{[Ss]kill[ _]type[ _]entry.*?\[\[Elite\]\]/m){ $elite = "yes"; } }
 * 1) get the eliteness from the skillbox if undefined

if ($header =~ /^\s*{{[Ss]kill[ _]adrenaline[ _]entry\s*\|.*value\s*=\s*(\d+)/m){ $stat1 = "Adrenaline"; $val1 = $1; }
 * 1) glean the adrenaline cost

if ($header =~ /^\s*{{[Ss]kill[ _]energy[ _]entry\s*\|.*value\s*=\s*(\d+)/m){ $stat1 = "Energy"; $val1 = $1; }
 * 1) glean the energy cost

if ($header =~ /^\s*{{[Ss]kill[ _]activation[ _]entry\s*\|.*value\s*=\s*(.*?)\s*}}/m){ $stat2 = "Activation"; $val2 = $1 }
 * 1) glean the activation

if ($header =~ /^\s*{{[Ss]kill[ _]recharge[ _]entry\s*\|.*value\s*=\s*(\d+)/m){ $stat3 = "Recharge"; $val3 = $1 }
 * 1) glean the recharge

if ($header =~ /^\s*{{[Ss]kill[ _]upkeep[ _]entry\s*/m){ $stat0 = "Upkeep"; $val0 = "-1"; }
 * 1) glean the upkeep

$desc = shift @sections;       # FIX: assumes desc is first section after skillbox $desc =~ s/^\s*Description\s*==//s; $desc =~ s/^\s*//s; $desc =~ s/\s*$//s;
 * 1) glean the skilldesc

print " \n" if ($ch2); print " \n" if ($stub);
 * 1) metadata

print "{{skill box qr   | name = {{subst:PAGENAME}}   | campaign = $campaign   | profession = $profession   | attribute = $attribute   | type = $type";
 * 1) box

if ($elite eq "yes") { print "  | elite = yes"; }
 * 1) elite

print "  | description = $desc";
 * 1) desc

if (defined $stat0) { print "  | stat0 = $stat0 | val0 = $val0"; } if (defined $stat1) { print "  | stat1 = $stat1 | val1 = $val1"; } if (defined $stat2) { print "  | stat2 = $stat2 | val2 = $val2"; } if (defined $stat3) { print "  | stat3 = $stat3 | val3 = $val3"; }
 * 1) stats

print "  }} ";

for $section (@sections){ ($secname, $secbody) = $section =~ /\s*(.*?)\s*==(.*)/s; print "== $secname ==$secbody"; }
 * 1) other sections

print "\n\n";

foreach $cat (@cats) { print "\n"; }
 * 1) cats

print "
 * 1) footer

\n";