MediaWiki:TileSelectorUtils.js
Jump to navigation
Jump to search
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: "acronFeatureG_Label",
highwaymen: "acronFeatureH_Label",
farmhouse: "acronFeatureF_Label",
pigs: "acronFeatureP_Label",
cows: "acronFeatureC_Label",
donkeys: "acronFeatureD_Label",
water_tower: "acronFeatureW_Label",
}
var FeatureMap =
{
road: "showRoad",
city: "showCity",
monastery: "showMonastery",
field: "showField",
abbey: "showAbbey",
shrine: "showShrine",
cemetery: "showCemetery",
haunted_castle: "showHauntedCastle",
german_castle: "showGermanCastle",
german_cathedral: "showGermanCathedral",
german_monastery: "showGermanMonastery",
dutch_belgian_monastery: "showDutchAndBelgianMonastery",
japanese_building: "showJapaneseBuilding",
darmstadt_church: "showDarmstadtChurch",
baba_yagas_hut: "showBabaYagasHut",
tent: "showFortuneTellerTent",
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: "showTowerFoundation",
fair: "showFair",
bazaar: "showBazaar",
circus_area: "showCircusArea",
acrobat_area: "showAcrobatArea",
betting_office: "showBettingOffice",
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",
misty_field: "showMistyField",
haunted_castle_ruins: "showHauntedCastleRuins",
porxada: "showPorxada",
tunnel: "showTunnel",
darmstadtium: "showDarmstadtium",
labyrinth: "showLabyrinth",
ferry_lake: "showFerryLake",
siege: "showSiege",
festival: "showFestival",
watchtower: "showWatchtower",
bathhouse: "showBathhouse",
traveler_group: "showTravelerGroup",
pennant: "showCoatOfArms",
princess: "showPrincessSymbol",
barrel: "showBarrelSymbol",
cloth: "showClothSymbol",
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_gate: "showCityGate",
revolt: "showPeasantRevolt",
symbol_add_meeple: "showAddMeepleSymbol",
symbol_place_meeple: "showPlaceMeepleSymbol",
symbol_extra_turn: "showExtraTurnSymbol",
signposts: "showSignpostSymbol",
city_Carcassonne: "showCityOfCarcassonne",
wheel_of_Fortune: "showWheelOfFortune",
school: "showSchool",
city_of_Leipzig: "showCityOfLeipzig",
points_tile: "showPT50",
message: "showMMMM",
king_tile: "showKKRR",
robber_tile: "showKKRR",
goldmine_tile: "showPPPP",
rules_tile: "showRULE",
blank_tile: "showBLNK",
/*
// *** Not features anymore ***
points_tile: "showPointsTile",
goldmine_tile: "showGoldminesPointsTile",
king_tile: "showKingTile",
robber_tile: "showRobberBaronTile",
message: "showMessageTile",
*/
}
function getTileDescription( oPresentFeatures )
{
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++;
}
}
}
return strRes;
}
function getTileInfoOR( oTile )
{
var iTileCount = 0; // oTile.totalCount;
var oPresentFeatures = {};
var oRes = { tileCount: 0, tileDescription: "" };
var bFullyVisible = false;
var arrFeatures = oTile.features;
for ( var strFeature in arrFeatures )
{
var strFeatureClassId = FeatureMap[ strFeature ];
if ( !strFeatureClassId ) continue;
var bVisible = doEval( strFeatureClassId );
bFullyVisible = bFullyVisible || bVisible;
oPresentFeatures[ strFeature ] = arrFeatures[ strFeature ];
}
var arrOtherFeatures = {};
var bPartiallyVisible = false;
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 bCaseVisible = false;
for ( var strFeature in arrFeatures )
{
var strFeatureClassId = FeatureMap[ strFeature ];
if ( !strFeatureClassId ) continue;
var bVisible = doEval( strFeatureClassId );
bCaseVisible = bCaseVisible || bVisible;
if ( bVisible || bFullyVisible ){
arrOtherFeatures[ strFeature ] = iCount; // tweak to get right count // arrFeatures[ strFeature ];
}
}
bPartiallyVisible = bPartiallyVisible || bCaseVisible;
if ( bCaseVisible )
{
iTileCount += iCount;
}
}
if ( bPartiallyVisible || bFullyVisible )
{
// Accumulate full (possibly empty) + partial features (possible empty)
// Append special features
for ( var strFeature in arrOtherFeatures )
{
oPresentFeatures[ strFeature ] = arrOtherFeatures[ strFeature ];
}
}
if ( bFullyVisible )
{
// Total Count
iTileCount = oTile.totalCount;
}
if ( iTileCount > 0 )
{
var strRes = getTileDescription( oPresentFeatures );
if ( strRes.length > 0 )
{
oRes.tileDescription = "(" + strRes + ")";
}
}
oRes.tileCount = iTileCount;
return oRes;
}
function getTileInfoAND( 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 strRes = getTileDescription( oPresentFeatures );
if ( strRes.length > 0 )
{
oRes.tileDescription = "(" + strRes + ")";
}
}
oRes.tileCount = iTileCount;
return oRes;
}
function doUpdateTile( oTile, strParentRef )
{
// Switch between AND and OR filters for features
var FnGetFileInfo = ( PreferencesMap.requireAllFeatures ? getTileInfoAND : getTileInfoOR );
var bShowAllTiles = PreferencesMap.showAllTiles;
var oTileInfo = FnGetFileInfo( oTile );
var iTotalCount = oTileInfo.tileCount;
var iPreviousCount = oTile.currentCount;
// if ( iPreviousCount != iTotalCount )
{
oTile.currentCount = iTotalCount;
var strRef = strParentRef + " #" + oTile.id;
if ( bShowAllTiles )
{
$( strRef ).show();
if ( iTotalCount == 0 )
{
$( strRef ).css( "opacity", 0.2 );
}
else
{
$( strRef ).css( "opacity", 1.0 );
}
}
else
{
if ( iTotalCount == 0 )
{
$( strRef ).hide();
}
else
{
$( strRef ).show();
$( strRef ).css( "opacity", 1.0 );
}
}
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 iReferenceCount = 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 );
}
iReferenceCount = oExpansion.totalCount;
}
var iPreviousCount = oExpansion.currentCount;
// if ( iPreviousCount != iTotalCount )
{
oExpansion.currentCount = iTotalCount;
var strCounterText = iTotalCount + " / " + iReferenceCount; // oExpansion.totalCount;
var strCounterId = strRef + " " + EXPANSION_COUNTER;
$( strCounterId ).html( strCounterText );
}
var bShowAllTiles = PreferencesMap.showAllTiles;
if ( iReferenceCount == 0 || ( iTotalCount == 0 && !bShowAllTiles ) )
{
$( strRef ).hide();
}
else
{
$( strRef ).show();
}
var oCounterRes = { tileCount: iTotalCount, referenceCount: iReferenceCount };
return oCounterRes; // iTotalCount;
}
function doUpdateEdges( oEdges, strParentRef )
{
var iTotalCount = 0;
var iReferenceCount = 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 ];
var oCounterRes = doUpdateExpansion( oExpansion, strRef );
iTotalCount += oCounterRes.tileCount;
iReferenceCount += oCounterRes.referenceCount;
}
}
var iPreviousCount = oEdges.currentCount;
// if ( iPreviousCount != iTotalCount )
{
oEdges.currentCount = iTotalCount;
var strRawCounterText = iTotalCount + " / " + iReferenceCount; // 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 );
}
var bShowAllTiles = PreferencesMap.showAllTiles;
if ( iReferenceCount == 0 || ( iTotalCount == 0 && !bShowAllTiles ) )
{
$( strRef ).hide();
}
else
{
$( strRef ).show();
}
var oCounterRes = { tileCount: iTotalCount, referenceCount: iReferenceCount };
return oCounterRes; // iTotalCount;
}
function doUpdateSection( oSection, strParentRef )
{
var iTotalCount = 0;
var iReferenceCount = 0;
var strRef = strParentRef + " #" + oSection.id;
var arrEdges = oSection.edges;
for ( var i in arrEdges )
{
var oEdges = arrEdges[ i ];
var oResCount = doUpdateEdges( oEdges, strRef );
iTotalCount += oResCount.tileCount;
iReferenceCount += oResCount.referenceCount;
}
var iPreviousCount = oSection.currentCount;
// if ( iPreviousCount != iTotalCount )
{
oSection.currentCount = iTotalCount;
//var strCounterText = "(" + iTotalCount + "/" + oSection.totalCount + ")";
var strCounterText = iTotalCount + " / " + iReferenceCount; // oSection.totalCount;
var strCounterId = strRef + " " + SECTION_COUNTER;
$( strCounterId ).html( strCounterText );
}
/*
var bShowAllTiles = PreferencesMap.showAllTiles;
if ( iReferenceCount == 0 || ( iTotalCount == 0 && !bShowAllTiles ) )
{
$( strRef ).hide();
}
else
{
$( strRef ).show();
}
*/
var oCounterRes = { tileCount: iTotalCount, referenceCount: iReferenceCount };
return oCounterRes; // iTotalCount;
}
function doUpdateEdition( oEdition )
{
var iTotalCount = 0;
var iReferenceCount = 0;
var strRef = "#" + oEdition.id;
var arrSections = oEdition.sections;
for ( var i in arrSections )
{
var oSection = arrSections[ i ];
var oResCount = doUpdateSection( oSection, strRef );
iTotalCount += oResCount.tileCount;
iReferenceCount += oResCount.referenceCount;
}
var iPreviousCount = oEdition.currentCount;
// if ( iPreviousCount != iTotalCount )
{
oEdition.currentCount = iTotalCount;
// var strCounterText = "(" + iTotalCount + "/" + oEdition.totalCount + ")";
var strCounterText = iTotalCount + " / " + iReferenceCount; // 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();
}
var oCounterRes = { tileCount: iTotalCount, referenceCount: iReferenceCount };
return oCounterRes; // iTotalCount;
}
function doUpdateTileCounters()
{
var iTotalCount = 0;
var iReferenceCount = 0;
var arrEdition = PageInfoMap.editions;
for ( var strEditionKey in arrEdition )
{
var oEdition = arrEdition[ strEditionKey ];
var oResCount = doUpdateEdition( oEdition );
iTotalCount += oResCount.tileCount;
iReferenceCount += oResCount.referenceCount;
}
PageInfoMap.totalCount = iTotalCount;
PageInfoMap.referenceCount = iReferenceCount;
}