annotate index.pl @ 3:2e849c856026 boosterpack

[svn r5] it works!
author robert
date Tue, 08 Sep 2009 05:55:51 -0400
parents d7dd496a4fa6
children e91d6f908222
rev   line source
robert@0 1 #!C:/strawberry/perl/bin/perl.exe
robert@0 2
robert@2 3 use List::Util qw(first max maxstr min minstr reduce shuffle sum);
robert@2 4 use Storable;
robert@0 5 use CGI::Ajax;
robert@0 6 use CGI;
robert@2 7 use Rule;
robert@2 8 use Filter;
robert@2 9 use Card;
robert@0 10 my $q = new CGI;
robert@0 11
robert@0 12
robert@2 13
robert@2 14 my $refstruct = retrieve 'CARD.perl';
robert@2 15 my @pokes = @$refstruct;
robert@2 16
robert@2 17
robert@2 18
robert@2 19
robert@2 20
robert@2 21 my %hash = ( 'gen_pack' => \&gen_pack, 'change_rules' => \&change_rules);
robert@0 22
robert@0 23
robert@0 24
robert@0 25
robert@0 26
robert@0 27
robert@0 28 my $pjx = CGI::Ajax->new(%hash);
robert@2 29 #$pjx->JSDEBUG(1);
robert@2 30 #$pjx->DEBUG(1);
robert@2 31
robert@0 32 print $pjx->build_html($q,\&gen); # this outputs the html for the page
robert@0 33
robert@0 34
robert@0 35
robert@0 36
robert@0 37
robert@2 38 sub change_rules
robert@2 39 {
robert@2 40 my $currentRuleref = retrieve 'rlm/booster.prefs';
robert@2 41 $currentRule = $$currentRuleref;
robert@2 42 $a = shift;
robert@2 43 $currentRule -> setSets(($a));
robert@2 44 store \$currentRule, 'rlm/booster.prefs';
robert@2 45 return $a;
robert@2 46
robert@2 47
robert@2 48 }
robert@0 49
robert@2 50
robert@2 51
robert@2 52
robert@2 53
robert@2 54
robert@2 55
robert@2 56
robert@2 57
robert@2 58
robert@2 59 sub gen_pack
robert@0 60 {
robert@2 61 sub tag_analyze
robert@2 62 {
robert@2 63
robert@2 64
robert@2 65
robert@2 66 my @sets = $currentRule -> getSets();
robert@2 67 #print ERR @sets;
robert@2 68
robert@2 69 my $card = shift;
robert@2 70
robert@2 71 #print ERR $card->getPix();
robert@2 72 #print ERR "\n";
robert@2 73 return $card -> hasTags(@sets);
robert@2 74
robert@2 75
robert@2 76 }
robert@2 77
robert@2 78 my $currentRuleref = retrieve 'rlm/booster.prefs';
robert@2 79 $currentRule = $$currentRuleref;
robert@2 80
robert@3 81 my $mapRules = $currentRule -> getRarityMap();
robert@3 82 my %mapRules = %$mapRules;
robert@3 83
robert@3 84
robert@3 85
robert@3 86
robert@2 87 #print ERR "@pokes";
robert@2 88 @reduced = filter(\&tag_analyze, @pokes);
robert@3 89 @reduced = shuffle(@reduced);
robert@2 90
robert@3 91 my @final_list = ();
robert@3 92 my $rnum = $mapRules{"Rare"};
robert@3 93 my $unum = $mapRules{"Uncommon"};
robert@3 94 my $cnum = $mapRules{"Common"};
robert@2 95
robert@2 96 for $crd(@reduced)
robert@2 97 {
robert@3 98 if (($crd -> hasTags("Rare") or $crd -> hasTags("Rare Holo"))and ($rnum>0)){push @r_list, $crd; $rnum--;}
robert@3 99 if (($crd -> hasTags("Uncommon"))and ($unum>0)){push @u_list, $crd; $unum--;}
robert@3 100 if (($crd -> hasTags("Common"))and ($cnum>0)){push @c_list, $crd; $cnum--;}
robert@3 101 if ($rnum+$unum+$cnum == 0){last;}
robert@2 102 }
robert@3 103
robert@3 104 @final_list = (@r_list,@u_list,@c_list);
robert@3 105
robert@3 106
robert@3 107 for $crd(@final_list)
robert@3 108 {
robert@3 109 $rob = $rob."<img src = \"".$crd->getPix()."\"></img>";
robert@3 110 }
robert@3 111
robert@2 112 #print $rob;
robert@2 113
robert@2 114 #print ERR @reduced;
robert@2 115 #print ERR $rob;
robert@2 116 #print $rob;
robert@2 117 return $rob;
robert@2 118 #close ERR;
robert@2 119
robert@2 120
robert@0 121 };
robert@0 122
robert@0 123
robert@0 124
robert@0 125
robert@0 126
robert@0 127 sub gen
robert@0 128 {
robert@0 129 open FILE, "<index.html";
robert@0 130 return do { local $/; <FILE> };
robert@2 131 };
robert@2 132
robert@2 133 #print "done";
robert@2 134
robert@2 135 #print &change_rules("Fossil");
robert@2 136 #print &gen_pack;