MediaWiki:TileSelectorUtils.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
// ***** Updating tile counter *****
var EDITION_COUNTER = "#_Edition_Tile_Counter_";
var EDITION_SEPARATOR = "#_Tile_Separator_";
var SECTION_COUNTER = "#_Section_Tile_Counter_";
var EDGES_HEADER_COUNTER = "#_Edges_Header_Tile_Counter_";
var EDGES_TABLE_COUNTER = "#_Edges_Table_Tile_Counter_";
var EXPANSION_COUNTER = "#_Expansion_Tile_Counter_";
var TILE_COUNTER = "#_Tile_Counter_";
var TILE_DESCRIPTION = "#_Tile_Description_";
var TILE_DESCRIPTION_VISIBILITY = "#_Tile_Desc_Visible_";
var BaseGameFeaturesMap =
{
garden: "acronG_Label",
highwaymen: "acronH_Label",
farmhouse: "acronF_Label",
pigs: "acronP_Label",
cows: "acronC_Label",
donkeys: "acronD_Label",
water_tower: "acronW_Label",
}
var FeatureMap =
{
road: "showRoad",
city: "showCity",
monastery: "showMonastery",
field: "showField",
abbey: "showAbbey",
shrine: "showShrine",
german_castle: "showGermanCastle",
german_cathedral: "showGermanCathedral",
german_monastery: "showGermanMonastery",
dutch_belgian_monastery: "showDutchAndBelgianMonastery",
japanese_building: "showJapaneseBuilding",
darmstadt_church: "showDarmstadtChurch",
baba_yagas_Hut: "showBabaYagasHut",
garden: "showGarden",
highwaymen: "showHighwaymen",
farmhouse: "showFarmhouse",
pigs: "showPigsty",
cows: "showCowShed",
donkeys: "showDonkeyStable",
water_tower: "showWaterTower",
river_source: "showRiverSource",
river_lake: "showRiverLake",
river_fork: "showRiverFork",
river_segment: "showRiverSegment",
magic_portal: "showMagicPortal",
volcano: "showVolcano",
tower_foundation: "showTowerFoundation",
fair: "showFair",
bazaar: "showBazaar",
circus_area: "showCircusArea",
acrobat_area: "showAcrobatArea",
flying_machine: "showFlyingMachine",
crop_circle: "showCropCicle",
fruit_tree: "showFruitBearingTree",
solovei: "showSoloveiRazboyniksTree",
vodyanoy: "showVodyanoysLake",
farm_cottage: "showFieldCottage",
farm_cattle: "showFieldCattle",
small_bridge: "showSmallBridge",
large_bridge: "showLargeBridge",
city_overpass: "showCityOverpass",
road_village : "showCrossroadWithVillage",
road_trees: "showCrossroadsWithTrees",
road_cottage: "showRoadCottage",
bogatyr: "showBogatyrsStone",
roundabout: "showRoundabout",
inn: "showInn",
cathedral: "showCathedral",
pig_herd: "showPigHerd",
vineyard: "showVineyard",
printed_sheep: "showPrintedSheep",
porxada: "showPorxada",
tunnel: "showTunnel",
darmstadtium: "showDarmstadtium",
labyrinth: "showLabyrinth",
ferryLake: "showFerryLake",
siege: "showSiege",
festival: "showFestival",
watchtower: "showWatchtower",
bathhouse: "showBathhouse",
traveler_group: "showTravelerGroup",
pennant: "showCoatOfArms",
princess: "showPrincessSymbol",
barrel: "showBarrelSymbol",
cloth: "shoeClothSymbol",
wheat: "showWheatSymbol",
dragon: "showDragonSymbol",
wheel_number: "showWheelWithNumber",
gold: "showGoldSymbol",
magic_symbol: "showMagicSymbol",
robber_symbol: "showRobberSymbol",
cathar: "showCatharSymbol",
festival_symbol: "showFestivalSymbol",
gingerbread_man: "showGingerbreadManSymbol",
outbreak: "showOutbreakSymbol",
wind_rose: "showWindRose",
city_Carcassonne: "showCityOfCarcassonne",
wheel_of_Fortune: "showWheelOfFortune",
school: "showSchool",
city_of_Leipzig: "showCityOfLeipzig",
/*
// *** Not features anymore ***
points_tile: "showPointsTile",
goldmine_tile: "showGoldminesPointsTile",
king_tile: "showKingTile",
robber_tile: "showRobberBaronTile",
message: "showMessageTile",
*/
}
function getTileInfo( oTile )
{
var iTileCount = oTile.totalCount;
var oPresentFeatures = {};
var oRes = { tileCount: 0, tileDescription: "" };
var arrFeatures = oTile.features;
for ( var strFeature in arrFeatures )
{
var strFeatureClassId = FeatureMap[ strFeature ];
if ( !strFeatureClassId ) continue;
var bVisible = doEval( strFeatureClassId );
// As soon as one feature in the tile is not active, returns notifying no tile is visible
if( !bVisible ) return oRes;
oPresentFeatures[ strFeature ] = arrFeatures[ strFeature ];
}
var arrSpecialCases = oTile.specialCases;
for ( var i in arrSpecialCases )
{
var oSpecialCase = arrSpecialCases[ i ];
var bRes = true;
var iCount = oSpecialCase.totalCount;
var arrFeatures = oSpecialCase.features;
var arrOtherFeatures = {};
for ( var strFeature in arrFeatures )
{
var strFeatureClassId = FeatureMap[ strFeature ];
if ( !strFeatureClassId ) continue;
var bVisible = doEval( strFeatureClassId );
bRes = bRes && bVisible;
if ( !bRes ) break;
arrOtherFeatures[ strFeature ] = iCount; // tweak to get right count // arrFeatures[ strFeature ];
}
if ( !bRes )
{
iTileCount -= iCount;
}
else
{
// Append special features
for ( var strFeature in arrOtherFeatures )
{
oPresentFeatures[ strFeature ] = arrOtherFeatures[ strFeature ];
}
}
}
if ( iTileCount > 0 )
{
var nCount = Object.keys( oPresentFeatures ).length;
var bShortFormat = ( nCount > 3 );
var iItems = 0;
var strRes = "";
for ( var strFeature in BaseGameFeaturesMap )
{
var iFeatureCount = oPresentFeatures[ strFeature ];
// If no entry exits, skip feature
if ( !iFeatureCount ) continue;
var strLabelId = BaseGameFeaturesMap[ strFeature ];
var strLabel = getLabel( strLabelId );
if ( bShortFormat )
{
strRes += ( iItems > 0 ? ";" : "" ) + ( iFeatureCount > 1 ? iFeatureCount + "x" : "" ) + strLabel;
iItems++;
}
else
{
for ( var i = 0; i < iFeatureCount; i++ )
{
strRes += ( iItems > 0 ? ";" : "" ) + strLabel;
iItems++;
}
}
}
if ( strRes.length > 0 )
{
oRes.tileDescription = "(" + strRes + ")";
}
}
oRes.tileCount = iTileCount;
return oRes;
}
function doUpdateTile( oTile, strParentRef )
{
var oTileInfo = getTileInfo( oTile );
var iTotalCount = oTileInfo.tileCount;
var iPreviousCount = oTile.currentCount;
if ( iPreviousCount != iTotalCount )
{
oTile.currentCount = iTotalCount;
var strRef = strParentRef + " #" + oTile.id;
if ( iTotalCount == 0 )
{
$( strRef ).hide();
}
else
{
$( strRef ).show();
}
var strTileCountId = strRef + " " + TILE_COUNTER;
var strTileCount = "" + ( oTile.displayedCount || iTotalCount );
$( strTileCountId ).html( strTileCount );
var strTileDescriptionId = strRef + " " + TILE_DESCRIPTION;
var strDescription = oTileInfo.tileDescription;
$( strTileDescriptionId ).html( strDescription );
var strTileDescriptionVisibilityId = strRef + " " + TILE_DESCRIPTION_VISIBILITY;
var bDescriptionVisible = (strDescription.length > 0 );
if ( bDescriptionVisible )
{
$( strTileDescriptionVisibilityId ).show();
}
else
{
$( strTileDescriptionVisibilityId ).hide();
}
}
return iTotalCount;
}
function doUpdateExpansion( oExpansion, strParentRef )
{
var iTotalCount = 0;
var strRef = strParentRef + " #" + oExpansion.id;
var strClassId = "show" + oExpansion.id;
var bVisible = doEval( strClassId );
if ( bVisible )
{
var arrTiles = oExpansion.tiles;
for ( var i in arrTiles )
{
var oTile = arrTiles[ i ];
iTotalCount += doUpdateTile( oTile, strRef );
}
}
var iPreviousCount = oExpansion.currentCount;
if ( iPreviousCount != iTotalCount )
{
oExpansion.currentCount = iTotalCount;
var strCounterText = iTotalCount + " / " + oExpansion.totalCount;
var strCounterId = strRef + " " + EXPANSION_COUNTER;
$( strCounterId ).html( strCounterText );
}
if ( iTotalCount == 0 )
{
$( strRef ).hide();
}
else
{
$( strRef ).show();
}
return iTotalCount;
}
function doUpdateEdges( oEdges, strParentRef )
{
var iTotalCount = 0;
var strRef = strParentRef + " #" + oEdges.id;
var strClassId = "show" + oEdges.id;
var bVisible = doEval( strClassId );
if ( bVisible )
{
var arrExpansions = oEdges.expansions;
for ( var i in arrExpansions )
{
var oExpansion = arrExpansions[ i ];
iTotalCount += doUpdateExpansion( oExpansion, strRef );
}
}
var iPreviousCount = oEdges.currentCount;
if ( iPreviousCount != iTotalCount )
{
oEdges.currentCount = iTotalCount;
var strRawCounterText = iTotalCount + " / " + oEdges.totalCount;
//var strHeaderCounterText = "(" + strRawCounterText + ")";
var strHeaderCounterText = strRawCounterText;
var strTableCounterText = strRawCounterText;
var strHeaderCounterId = strRef + " " + EDGES_HEADER_COUNTER;
$( strHeaderCounterId ).html( strHeaderCounterText );
var strTableCounterId = strRef + " " + EDGES_TABLE_COUNTER;
$( strTableCounterId ).html( strTableCounterText );
}
if ( iTotalCount == 0 )
{
$( strRef ).hide();
}
else
{
$( strRef ).show();
}
return iTotalCount;
}
function doUpdateSection( oSection, strParentRef )
{
var iTotalCount = 0;
var strRef = strParentRef + " #" + oSection.id;
var arrEdges = oSection.edges;
for ( var i in arrEdges )
{
var oEdges = arrEdges[ i ];
iTotalCount += doUpdateEdges( oEdges, strRef );
}
var iPreviousCount = oSection.currentCount;
if ( iPreviousCount != iTotalCount )
{
oSection.currentCount = iTotalCount;
//var strCounterText = "(" + iTotalCount + "/" + oSection.totalCount + ")";
var strCounterText = iTotalCount + " / " + oSection.totalCount;
var strCounterId = strRef + " " + SECTION_COUNTER;
$( strCounterId ).html( strCounterText );
}
if ( iTotalCount == 0 )
{
$( strRef ).hide();
}
else
{
$( strRef ).show();
}
return iTotalCount;
}
function doUpdateEdition( oEdition )
{
var iTotalCount = 0;
var strRef = "#" + oEdition.id;
var arrSections = oEdition.sections;
for ( var i in arrSections )
{
var oSection = arrSections[ i ];
iTotalCount += doUpdateSection( oSection, strRef );
}
var iPreviousCount = oEdition.currentCount;
if ( iPreviousCount != iTotalCount )
{
oEdition.currentCount = iTotalCount;
// var strCounterText = "(" + iTotalCount + "/" + oEdition.totalCount + ")";
var strCounterText = iTotalCount + " / " + oEdition.totalCount;
var strCounterId = strRef + " " + EDITION_COUNTER;
$( strCounterId ).html( strCounterText );
}
var strSeparator = strRef + " " + EDITION_SEPARATOR;
if ( iTotalCount == 0 )
{
$( strSeparator ).hide();
//$( strRef ).hide();
}
else
{
$( strSeparator ).show();
//$( strRef ).show();
}
return iTotalCount;
}
function doUpdateTileCounters()
{
var iTotalCount = 0;
var arrEdition = PageInfoMap.editions;
for ( var strEditionKey in arrEdition )
{
var oEdition = arrEdition[ strEditionKey ];
iTotalCount += doUpdateEdition( oEdition );
}
PageInfoMap.totalCount = iTotalCount;
}