misc/hats_js_anim.xhtml
changeset 15583 3c1c5ff824f7
parent 13513 7e188a28f078
child 15584 799fd0a6d3bf
equal deleted inserted replaced
15582:6d0682485ed5 15583:3c1c5ff824f7
     4 <!-- There is, at present, no official xsd for (X)HTML5. A pity. Usefulness would depend on the parser and extensions made by the site.  -->
     4 <!-- There is, at present, no official xsd for (X)HTML5. A pity. Usefulness would depend on the parser and extensions made by the site.  -->
     5     <title>Hedgewars Hats</title>
     5     <title>Hedgewars Hats</title>
     6 
     6 
     7     <style type="text/css">
     7     <style type="text/css">
     8 * {padding: 0; margin: 0; }
     8 * {padding: 0; margin: 0; }
     9 body 
     9 body
    10 {
    10 {
    11     background: url('//hg.hedgewars.org/hedgewars/raw-file/tip/share/hedgewars/Data/Themes/Nature/Sky.png') fixed no-repeat bottom left;
    11     background: url('https://hg.hedgewars.org/hedgewars/raw-file/tip/share/hedgewars/Data/Themes/Nature/Sky.png') fixed no-repeat bottom left;
    12     background-color: #0B203D;
    12     background-color: #0B203D;
    13     color: #FFD902;
    13     color: #FFD902;
    14     -moz-background-size: 200%;
    14     -moz-background-size: 200%;
    15     background-size: 100% 100%;
    15     background-size: 100% 100%;
    16     font-family: sans-serif;
    16     font-family: sans-serif;
    17 }
    17 }
    18 h1 { text-shadow: 0 0 2px white; color: black;}
    18 form, p
    19 a 
    19 {
       
    20     background-color: #0B203D;
       
    21     padding: 1em;
       
    22     margin: 1em;
       
    23     border-style: solid;
       
    24     border-radius: 5px;
       
    25     border-width: 2px;
       
    26     border-color: #FFD902;
       
    27 }
       
    28 h1 {
       
    29     text-shadow: 0 0 2px white;
       
    30     color: black;
       
    31     margin:10px;
       
    32 }
       
    33 a
    20 {
    34 {
    21     margin-top: 12px;
    35     margin-top: 12px;
    22     margin-left: 20px;
    36     margin-left: 20px;
    23     float: left;
    37     float: left;
    24     height: 32px;
    38     height: 32px;
    25     width: 32px;
    39     width: 32px;
    26     color: transparent;
    40     color: transparent;
    27     background-image: url("//hg.hedgewars.org/hedgewars/raw-file/tip/share/hedgewars/Data/Graphics/Hedgehog/Idle.png");
    41     background-image: url("https://hg.hedgewars.org/hedgewars/raw-file/tip/share/hedgewars/Data/Graphics/Hedgehog/Idle.png");
    28 }
    42 }
    29 .girder
    43 .girder
    30 {
    44 {
    31     width: 100%;
    45     width: 100%;
    32     height: 30px;
    46     height: 30px;
    33     clear: left;
    47     clear: left;
    34     background-image: url('//hg.hedgewars.org/hedgewars/raw-file/tip/share/hedgewars/Data/Themes/Nature/Girder.png');
    48     background-image: url('https://hg.hedgewars.org/hedgewars/raw-file/tip/share/hedgewars/Data/Themes/Nature/Girder.png');
    35     background-repeat: repeat-x;
    49     background-repeat: repeat-x;
    36 }
    50 }
    37 .hide { visibility: hidden; }
    51 .hide { visibility: hidden; }
    38 a div
    52 a div
    39 {
    53 {
    42     width: 32px;
    56     width: 32px;
    43 }
    57 }
    44     </style>
    58     </style>
    45     <script type="application/ecmascript">
    59     <script type="application/ecmascript">
    46 //<![CDATA[
    60 //<![CDATA[
    47 /* javascript version of a sprite sheet - this could be pretty trivially done in pure HTML, but maintenance
    61 var IS_LOCAL=false; // set to true to fetch hats locally. Useful for testing.
       
    62 var masks;
       
    63 if (IS_LOCAL) {
       
    64 /* JavaScript version of a sprite sheet - this could be pretty trivially done in pure HTML, but maintenance
    48 would be easier with a server-side portion. list of sprites could be gotten from server, but would require XSS whitelisting */
    65 would be easier with a server-side portion. list of sprites could be gotten from server, but would require XSS whitelisting */
    49 /*var masks = ['2001suit2', '2001suit', '4gsuif', 'AkuAku', 'android', 'angel', 'anzac', 'apple', 'ash', 'Balrog', 'banana', 'Bandit', 'bat', 'beaver', 'beefeater', 'Blanka', 'BlankaToothless', 'BlueCap', 'BlueHair', 'bobby2v', 'bobby', 'Bob', 'BrainSlugMouth', 'BrainSlug', 'britishpithhelmet', 'britmedic', 'britsapper', 'Bub', 'Bunny', 'bushhider', 'charlesdegaulle', 'charmander', 'chef', 'chikorita', 'Chunli', 'clown-copper', 'clown-crossed', 'clown', 'Coonskin3', 'Cororon', 'Cowboy', 'crown', 'cyborg', 'darthvader', 'Deer', 'desertgrenadier01', 'desertgrenadier02', 'desertgrenadier04', 'desertgrenadier05', 'desertgrenadierofficer', 'desertmedic', 'desertsapper1', 'desertsapper2', 'diglett', 'Disguise', 'Dragon', 'dwarf', 'eastertop', 'Elvis', 'Eva_00b', 'Eva_00y', 'Falcon', 'frenchwwigasmask', 'frenchwwihelmet', 'Gasmask', 'Geordi', 'germanwiimedichelmet', 'germanwwihelmetmustache', 'germanwwiipithhelmetdes', 'germanwwitankhelmet', 'Glasses', 'GreenCap', 'GreenHair', 'grenadier1', 'GreyHair', 'Guile', 'hedgehogk', 'HogInTheHat', 'hogpharoah', 'Honda', 'IndianChief', 'infernalhorns', 'InfernalHorns', 'Jason', 'jigglypuff', 'judo', 'junior', 'Ken', 'KirbyMask', 'kiss_criss', 'kiss_frehley', 'kiss_simmons', 'kiss_stanley', 'knight', 'Kululun', 'Ladle', 'lambda', 'Laminaria', 'laurel', 'lemon', 'link', 'lugia', 'Luigi', 'Mario', 'MegaHogX', 'metalband', 'mexicansunbrero', 'mickey_ears', 'Moose', 'mp3', 'mudkip', 'Mummy', 'naruto', 'NinjaFull', 'NinjaStraight', 'NinjaTriangle', 'OldMan', 'OrangeHair', 'orange', 'Pantsu', 'Pig', 'pikachu', 'PinkHair', 'pinksunhat', 'pirate_jack_bandana', 'pirate_jack', 'plainpith', 'Plunger', 'policecap', 'porkey', 'PrincessDaisy', 'PrincessPeach', 'Pumpkin_Hat', 'PurpleHair', 'quotecap', 'Rain', 'Rambo', 'rasta', 'RedCap', 'RedHair', 'RobinHood', 'royalguard', 'RSR', 'Ryu', 'Samurai', 'Samus', 'Santa', 'SauceBoatSilver', 'ShaggyYeti', 'sheep', 'ShortHair_Black', 'ShortHair_Brown', 'ShortHair_Grey', 'ShortHair_Red', 'ShortHair_Yellow', 'Skull', 'Sleepwalker', 'slowpoke', 'Sniper', 'Sonic', 'sovietcomrade2', 'sovietcomrade', 'SparkleSuperFun', 'SparkssHelmet', 'spartan', 'spcartman', 'spidey', 'spkenny', 'spkyle', 'spstan', 'squirtle', 'sth_AmyClassic', 'sth_Amy', 'sth_Eggman', 'sth_Knux', 'sth_Metal', 'sth_Shadow', 'sth_Sonic', 'sth_Super', 'sth_Tails', 'stormcloud', 'stormtrooper', 'StrawHatEyes', 'StrawHatFacial', 'StrawHat', 'Sunglasses', 'SunWukong', 'Teacup', 'Teapot', 'terminatorc', 'Terminator_Glasses', 'thug', 'Toad', 'tophats', 'touhou_chen', 'touhou_marisa', 'touhou_patchouli', 'touhou_remelia', 'touhou_suwako', 'touhou_yukari', 'trenchgrenadier1', 'trenchgrenadier2', 'trenchgrenadier3', 'ushanka', 'vampirichog', 'Vega', 'venom', 'Viking', 'voltorb', 'Wario', 'WhySoSerious', 'WizardHat', 'YellowCap', 'YellowHair', 'Zombi'];*/
    66 // Last updated: 1.0.0
    50 var masks = [];
    67 masks = ['4gsuif','AkuAku','android','angel','anzac','Bandit','barrelhider','bb_bob','bb_bub','bb_cororon','bb_kululun','beefeater','beefeaterhat','bishop','bobby','bobby2v','bubble','bushhider','cap_blue','cap_green','cap_junior','cap_red','cap_thinking','cap_yellow','car','chef','chuckl','clown','clown-copper','clown-crossed','constructor','Coonskin3','Cowboy','cratehider','crown','cyborg1','cyborg2','cyclops','Dan','Dauber','DayAndNight','Disguise','dish_Ladle','dish_SauceBoatSilver','dish_Teacup','dish_Teapot','doctor','Dragon','dwarf','eastertop','Einstein','Elvis','Eva_00b','Eva_00y','Evil','flag_french','flag_germany','flag_italy','flag_usa','footballhelmet','fr_apple','fr_banana','fr_lemon','fr_orange','fr_pumpkin','fr_tomato','Gasmask','Glasses','hair_blue','hair_green','hair_grey','hair_orange','hair_pink','hair_purple','hair_red','hair_yellow','HogInTheHat','hogpharoah','IndianChief','InfernalHorns','Jason','jester','Joker','judo','kiss_criss','kiss_frehley','kiss_simmons','kiss_stanley','knight','lambda','lambdahat','Laminaria','lamp','laurel','leprechaun','mechanicaltoy','MegaHogX','metalband','Meteorhelmet','mexicansunbrero','mickey_ears','Moustache','Moustache_glasses','mp3','Mummy','mv_Spidey','mv_Venom','naruto','NinjaFull','NinjaStraight','NinjaTriangle','noface','ntd_Falcon','ntd_Kirby','ntd_Link','ntd_Samus','nurse','nursehat','OldMan','Pantsu','pinksunhat','pirate_bandana','pirate_eyepatch','pirate_hat','pirate_jack','pirate_jack_bandana','Plunger',
       
    68 'poke_ash','poke_ash_hat','poke_charmander','poke_chikorita','poke_diglett','poke_jigglypuff','poke_lugia','poke_mudkip','poke_pikachu','poke_slowpoke','poke_squirtle','poke_voltorb','policecap','policegirl','punkman','quotecap','Rain','Rambo','RamboClean','rasta','RobinHood','royalguard','RSR','Samurai','Santa','scif_2001O','scif_2001Y','scif_BrainSlug','scif_BrainSlug2','scif_cosmonaut','scif_cyberpunk','scif_Geordi','scif_SparkssHelmet','scif_swDarthvader','scif_swStormtrooper','sf_balrog','sf_blanka','sf_blankatoothless','sf_chunli','sf_guile','sf_guile_hat','sf_honda','sf_ken','sf_ryu','sf_vega','sf_vega_hat','ShaggyYeti','ShortHair_Black','ShortHair_Brown','ShortHair_Grey','ShortHair_Red','ShortHair_Yellow','simple_green','simple_red','simple_yellow','Skull','Sleepwalker','sm_daisy','sm_luigi','sm_mario','sm_peach','sm_toad','sm_wario','Sniper','snorkel','snowhog','SparkleSuperFun','spartan','spcartman','spkenny','spkyle','spstan','sth_Amy','sth_AmyClassic','sth_Eggman','sth_Knux','sth_Metal','sth_Shadow','sth_Sonic','sth_SonicClassic','sth_Super','sth_Tails','stormcloud',
       
    69 'StrawHat','StrawHatEyes','StrawHatFacial','Sunglasses','SunWukong','swordsmensquire','TeamHeadband','TeamSoldier','TeamWheatley','Terminator_Glasses','tf_demoman','tf_scout','thug','thugclean','tiara','tophats','touhou_chen','touhou_marisa','touhou_patchouli','touhou_remelia','touhou_suwako','touhou_yukari','ushanka','vampirichog','vc_gakupo','vc_gumi','vc_kaito','vc_len','vc_luka','vc_meiko','vc_miku','vc_rin','Viking','war_airwarden02','war_airwarden03','war_americanww2helmet','war_britmedic','war_britpthhelmet','war_britsapper','war_desertgrenadier1','war_desertgrenadier2','war_desertgrenadier4','war_desertgrenadier5','war_desertmedic','war_desertofficer','war_desertsapper1','war_desertsapper2','war_frenchww1gasmask','war_frenchww1helmet','war_germanww1helmet2','war_germanww1tankhelm','war_germanww2medic','war_germanww2pith','war_grenadier1','war_plainpith','war_sovietcomrade1','war_sovietcomrade2','war_trenchfrench01','war_trenchfrench02','war_trenchgrenadier1','war_trenchgrenadier2','war_trenchgrenadier3','war_UNPeacekeeper01','war_UNPeacekeeper02','WhySoSerious','WizardHat','Zombi','zoo_Bat','zoo_Beaver','zoo_Bunny','zoo_chicken','zoo_crocodile','zoo_Deer','zoo_elephant','zoo_fish','zoo_frog','zoo_Hedgehog','zoo_Moose','zoo_octopus','zoo_Pig','zoo_Porkey','zoo_Sheep','zoo_snail','zoo_turtle'
       
    70 ,'NoHat','cap_team','hair_team','TeamTophat'
       
    71 ];
       
    72 }
       
    73 else
       
    74 {
       
    75 masks = [];
       
    76 }
       
    77 
    51 var themes = {
    78 var themes = {
       
    79 // Last updated: 1.0.0
       
    80 "Art":1,
       
    81 "Beach":1,
       
    82 "Bamboo":1,
       
    83 "Bath":1,
       
    84 "Blox":0,
       
    85 "Brick":0,
       
    86 "Cake":0,
       
    87 "Castle":1,
    52 "Cave":1,
    88 "Cave":1,
       
    89 "City":1,
       
    90 "Cheese":0,
       
    91 "Christmas":1,
       
    92 "Compost":1,
       
    93 "CrazyMission":0,
       
    94 "Deepspace":0,
       
    95 "Desert":1,
       
    96 "EarthRise":0,
       
    97 "Eyes":0,
       
    98 "Freeway":0,
       
    99 "Fruit":1,
       
   100 "Halloween":1,
       
   101 "Hell":0,
       
   102 "Hoggywood":1,
       
   103 "Island":0,
       
   104 "Jungle":1,
    53 "Golf":1,
   105 "Golf":1,
       
   106 "Nature":1,
       
   107 "Olympics":1,
       
   108 "Planes":0,
       
   109 "Sheep":1,
       
   110 "Snow":1,
    54 "Stage":1,
   111 "Stage":1,
    55 "Island":0,
   112 "Underwater":1};
    56 "Eyes":0,
       
    57 "Deepspace":0,
       
    58 "Jungle":1,
       
    59 "Cake":0,
       
    60 "Compost":1,
       
    61 "Planes":0,
       
    62 "Olympics":1,
       
    63 "Bath":1,
       
    64 "Cheese":0,
       
    65 "Desert":1,
       
    66 "Christmas":1,
       
    67 "CrazyMission":0,
       
    68 "Sheep":1,
       
    69 "Brick":0,
       
    70 "Underwater":1,
       
    71 "City":1,
       
    72 "EarthRise":0,
       
    73 "Blox":0,
       
    74 "Hell":0,
       
    75 "Bamboo":1,
       
    76 "Freeway":0,
       
    77 "Nature":1,
       
    78 "Art":1,
       
    79 "Halloween":1,
       
    80 "Snow":1,
       
    81 "Castle":1};
       
    82 var girder;
   113 var girder;
    83 var animationInterval;
   114 var animationInterval;
       
   115 
       
   116 var staticMasks = [];
       
   117 
    84 window.onload = function()
   118 window.onload = function()
    85 {
   119 {
    86     var xml=new XMLHttpRequest();
   120     // Load list of hats
    87     xml.open("GET", "/hedgewars/file/tip/share/hedgewars/Data/Graphics/Hats/", false);
   121     if (!IS_LOCAL) {
    88     xml.send(null);
   122         // Request list of hats from repository URL
    89     /*var resp = xml.responseXML; unfortunately not served as XHTML
   123         var xml=new XMLHttpRequest();
    90     var a = resp.getElementsByTagName("a");
   124         xml.open("GET", "/hedgewars/file/tip/share/hedgewars/Data/Graphics/Hats/", false);
    91     for(var i=0;i<a.length;i++);
   125         try {
    92         if (/\.png/.test(a[0].href)) m.push(a[0].replace(/.png/,''));*/
   126            xml.send(null);
    93 
   127         } catch (NetworkError) {
    94     var resp = xml.responseText;
   128            var p = document.createElement("p");
    95     var r = />([^<]*).png</g;
   129            p.appendChild(document.createTextNode("ERROR: List of hats could not be fetched from the server!"));
    96     var x;
   130            document.body.appendChild(p);
    97     while(x = r.exec(resp)) 
   131            return;
    98         if (!/NoHat|hair_team|cap_team|TeamTophat/.test(x[1])) // Exclude NoHat as uninteresting. hair_team, cap_team and TeamTophat as repetitive team hats
   132         }
    99             masks.push(x[1]);
   133     }
   100 
   134 
   101     var opt = document.createElement("option");
   135     // Exclude NoHat as uninteresting. Exclude team hats as we can't properly display them yet
   102     opt.appendChild(document.createTextNode(""));
   136     // TODO: Add support for team hats
   103     var sel = document.body.appendChild(document.createElement("select"));
   137     var disallowedMasks = {
   104     sel.onchange = switchTheme;
   138         "NoHat":true,
   105     for(var theme in themes)
   139         "hair_team":true,
   106     {
   140         "cap_team":true,
   107         sel.appendChild(opt.cloneNode(true));
   141         "TeamTophat":true,
   108         sel.lastChild.value = theme;
   142     };
   109         sel.lastChild.lastChild.data = theme;
   143 
   110         if(theme === "Nature") sel.lastChild.selected = true;
   144     // Render girders
   111     }
       
   112     var chk = document.createElement("input");
       
   113     chk.type = "checkbox";
       
   114     chk.onclick = switchAnim;
       
   115     document.body.appendChild(chk);
       
   116     chk = chk.cloneNode(false);
       
   117     chk.onclick = hideGirders;
       
   118     document.body.appendChild(chk);
       
   119     var s = document.styleSheets[0].cssRules;
   145     var s = document.styleSheets[0].cssRules;
   120     for(var i=0;i<s.length;i++)
   146     for(var i=0;i<s.length;i++)
   121         if (s[i].selectorText.toLowerCase() === ".girder") girder = s[i];
   147     {
   122         
   148         if (s[i].selectorText.toLowerCase() === ".girder")
       
   149             girder = s[i];
       
   150     }
       
   151 
   123     var a = document.createElement("a");
   152     var a = document.createElement("a");
   124     var g = document.createElement("div");
   153     var g = document.createElement("div");
   125     g.className="girder";
   154     g.className="girder";
   126     a.appendChild(document.createElement("div"));
   155     a.appendChild(document.createElement("div"));
   127     a.lastChild.appendChild(document.createTextNode(""));
   156     a.lastChild.appendChild(document.createTextNode(""));
       
   157 
       
   158     // Render hats
       
   159     var missingMasks = [];
       
   160     var img;
   128     for (var i=0;i<masks.length;i++)
   161     for (var i=0;i<masks.length;i++)
   129     {
   162     {
       
   163         if (disallowedMasks[masks[i]] === true) {
       
   164             missingMasks.push(masks[i]);
       
   165             continue;
       
   166         }
   130         var h = document.body.appendChild(a.cloneNode(true));
   167         var h = document.body.appendChild(a.cloneNode(true));
   131         h.href = "//hg.hedgewars.org/hedgewars/raw-file/tip/share/hedgewars/Data/Graphics/Hats/"+masks[i]+".png";
   168         if (IS_LOCAL)
       
   169             h.href = "../share/hedgewars/Data/Graphics/Hats/"+masks[i]+".png";
       
   170         else
       
   171             h.href = "https://hg.hedgewars.org/hedgewars/raw-file/tip/share/hedgewars/Data/Graphics/Hats/"+masks[i]+".png";
       
   172 
       
   173         img = new Image();
       
   174         img.onload = function() {
       
   175             var name = this.id.substr(7);
       
   176             if (this.height === 32) {
       
   177                 staticMasks[name] = true;
       
   178             }
       
   179             this.remove();
       
   180         }
       
   181         img.src = h.href;
       
   182         img.id = "__mask_"+masks[i];
       
   183 
   132         h.lastChild.style.backgroundImage = 'url("'+h.href+'")';
   184         h.lastChild.style.backgroundImage = 'url("'+h.href+'")';
   133         h.lastChild.lastChild.data = masks[i];
   185         h.lastChild.lastChild.data = masks[i];
   134         h.title = masks[i];
   186         h.title = masks[i];
   135         h.idle = Math.floor(Math.random()*19);
   187         h.idle = Math.floor(Math.random()*19);
   136         if (i%17 === 16 || i === masks.length-1) document.body.appendChild(g.cloneNode(false));
   188         if (i%17 === 16 || i === masks.length-1)
   137     }
   189             document.body.appendChild(g.cloneNode(false));
   138     
   190     }
   139 /* quick and dirty animation */
   191     document.body.appendChild(g.cloneNode(false));
   140 animationInterval = setInterval(animateHogs, 128);
   192 
       
   193     // List missing hats
       
   194     var missingMasksStr = "";
       
   195     for (var i=0; i<missingMasks.length; i++)
       
   196     {
       
   197         if (missingMasks[i] === "NoHat")
       
   198             continue;
       
   199         missingMasksStr = missingMasksStr + missingMasks[i];
       
   200         if (i<missingMasks.length-1)
       
   201             missingMasksStr = missingMasksStr + ", ";
       
   202     }
       
   203     var pm = document.createElement("p");
       
   204     pm.appendChild(document.createTextNode("Other hats: " + missingMasksStr));
       
   205     document.body.appendChild(pm);
       
   206 
       
   207     // Quick and dirty animation
       
   208     animationInterval = setInterval(animateHogs, 128);
       
   209 
       
   210     // Theme selection drop-down list
       
   211     var form = document.body.appendChild(document.createElement("form"));
       
   212 
       
   213     var opt = document.createElement("option");
       
   214     opt.appendChild(document.createTextNode(""));
       
   215 
       
   216     var label = document.createElement("label");
       
   217     label.htmlFor = "theme_select";
       
   218     label.appendChild(document.createTextNode("Theme: "));
       
   219     form.appendChild(label);
       
   220 
       
   221     var sel = form.appendChild(document.createElement("select"));
       
   222     sel.id = "theme_select";
       
   223     sel.onchange = switchTheme;
       
   224     for(var theme in themes)
       
   225     {
       
   226         sel.appendChild(opt.cloneNode(true));
       
   227         sel.lastChild.value = theme;
       
   228         sel.lastChild.lastChild.data = theme;
       
   229         if(theme === "Nature")
       
   230             sel.lastChild.selected = true;
       
   231     }
       
   232     form.appendChild(document.createElement("br"));
       
   233 
       
   234     // Checkbox: Switch animation
       
   235     var chk = document.createElement("input");
       
   236     chk.id = "anim";
       
   237     chk.type = "checkbox";
       
   238     chk.onclick = switchAnim;
       
   239     chk.checked = true;
       
   240     form.appendChild(chk);
       
   241     label = document.createElement("label");
       
   242     label.htmlFor = "anim";
       
   243     label.appendChild(document.createTextNode("Animate hats"));
       
   244     form.appendChild(label);
       
   245 
       
   246     form.appendChild(document.createElement("br"));
       
   247 
       
   248     // Checkbox: Hide girders
       
   249     chk = document.createElement("input");
       
   250     chk.id = "hide_girders";
       
   251     chk.type = "checkbox";
       
   252     chk.onclick = hideGirders;
       
   253     chk.checked = true;
       
   254     form.appendChild(chk);
       
   255     label = document.createElement("label");
       
   256     label.htmlFor = "hide_girders";
       
   257     label.appendChild(document.createTextNode("Show girders"));
       
   258     form.appendChild(label);
       
   259 
       
   260     document.body.appendChild(form);
       
   261 
       
   262 
   141 }
   263 }
   142 
   264 
   143 function animateHogs()
   265 function animateHogs()
   144 {
   266 {
   145     var a = document.getElementsByTagName("a");
   267     var a = document.getElementsByTagName("a");
   146     for (var i=0;i<a.length;i++)
   268     for (var i=0;i<a.length;i++)
   147     {
   269     {
       
   270         // Cycle through hedgehog and hat animation frames
       
   271 
       
   272         // Hedgehog
   148         a[i].style.backgroundPosition=Math.floor(a[i].idle/16)*-32+"px "+(a[i].idle%16)*-32+"px";
   273         a[i].style.backgroundPosition=Math.floor(a[i].idle/16)*-32+"px "+(a[i].idle%16)*-32+"px";
   149         a[i].firstChild.style.backgroundPosition=Math.floor(a[i].idle/16)*-32+"px "+(a[i].idle%16)*-32+"px";
   274 
       
   275         // Hat
       
   276         if (staticMasks[masks[i]]) {
       
   277             // Hat offset for static hats
       
   278             if (a[i].idle === 2 || a[i].idle === 7 || a[i].idle === 12)
       
   279                 a[i].firstChild.style.marginTop="-4px";
       
   280             else if (a[i].idle === 16)
       
   281                 a[i].firstChild.style.marginTop="-6px";
       
   282             else
       
   283                 a[i].firstChild.style.marginTop="-5px";
       
   284 
       
   285             a[i].firstChild.style.backgroundPosition="0px 0px";
       
   286         }
       
   287         else
       
   288         {
       
   289             // Animated hat frames
       
   290             a[i].firstChild.style.backgroundPosition=Math.floor(a[i].idle/16)*-32+"px "+(a[i].idle%16)*-32+"px";
       
   291         }
       
   292 
       
   293         // Next frame
   150         a[i].idle++;
   294         a[i].idle++;
   151         if (a[i].idle > 18) a[i].idle = 0;
   295         if (a[i].idle > 18)
   152     }
   296             a[i].idle = 0;
   153 }
   297     }
   154 
   298 }
       
   299 
       
   300 // Turn on or off hog+hat animation
   155 function switchAnim()
   301 function switchAnim()
   156 {
   302 {
   157     if (animationInterval) 
   303     if (animationInterval)
   158     {
   304     {
   159         clearInterval(animationInterval);
   305         clearInterval(animationInterval);
   160         animationInterval = null;
   306         animationInterval = null;
   161     }
   307     }
   162     else animationInterval = setInterval(animateHogs, 128);
   308     else animationInterval = setInterval(animateHogs, 128);
   163 }
   309 }
   164 
   310 
       
   311 // Turn on or off girders
   165 function hideGirders()
   312 function hideGirders()
   166 {
   313 {
   167     var g = document.getElementsByClassName("girder");
   314     var g = document.getElementsByClassName("girder");
   168     for(var i=0;i<g.length;i++) 
   315     for(var i=0;i<g.length;i++)
   169         if (this.checked)
   316         if (this.checked)
       
   317             g[i].className = "girder";
       
   318         else
   170             g[i].className = "girder hide";
   319             g[i].className = "girder hide";
   171         else
   320 
   172             g[i].className = "girder";
   321 }
   173     
   322 
   174 }
   323 // Select theme according to drop-down list value
   175 
       
   176 function switchTheme()
   324 function switchTheme()
   177 {
   325 {
   178     document.body.style.backgroundImage='url("//hg.hedgewars.org/hedgewars/raw-file/tip/share/hedgewars/Data/Themes/'+this.value+'/Sky.png")';
   326     var prefix;
       
   327     if (IS_LOCAL)
       
   328         prefix = "https://hg.hedgewars.org/hedgewars/raw-file/tip";
       
   329     else
       
   330         prefix = "..";
       
   331     document.body.style.backgroundImage='url("'+prefix+'/share/hedgewars/Data/Themes/'+this.value+'/Sky.png")';
   179     if (themes[this.value])
   332     if (themes[this.value])
   180         girder.style.backgroundImage='url("//hg.hedgewars.org/hedgewars/raw-file/tip/share/hedgewars/Data/Themes/'+this.value+'/Girder.png")';
   333         girder.style.backgroundImage='url("'+prefix+'/share/hedgewars/Data/Themes/'+this.value+'/Girder.png")';
   181     else
   334     else
   182         girder.style.backgroundImage='url("//hg.hedgewars.org/hedgewars/raw-file/tip/share/hedgewars/Data/Graphics/Girder.png")';
   335         girder.style.backgroundImage='url("'+prefix+'/share/hedgewars/Data/Graphics/Girder.png")';
   183 }
   336 }
   184 //]]>
   337 //]]>
   185     </script>
   338     </script>
   186 </head>
   339 </head>
   187 <body>
   340 <body>
   188 <h1>List of Hedgewars hats</h1>
   341 <h1>List of Hedgewars hats</h1>
   189 <noscript>
   342 <noscript>
   190 <p><strong>ERROR</strong>: We're so sorry, but this webpage only works with JavaScript enabled. It seems JavaScript is disabled or not supported in your browser.</p>
   343 <p><strong>ERROR</strong>: We're so sorry, but this webpage only works with JavaScript enabled. It seems JavaScript is disabled or not supported in your browser.<br/>
   191 <p>Normally, this webpage would display an animated preview of the hats in Hedgewars.</p>
   344 Normally, this webpage would display an animated preview of the hats in Hedgewars.</p>
   192 </noscript>
   345 </noscript>
   193 </body>
   346 </body>
   194 </html>
   347 </html>