Skip to content

Commit

Permalink
bugfix autoRename & chrome unitsown table display
Browse files Browse the repository at this point in the history
  • Loading branch information
Laoujin committed Apr 3, 2013
1 parent c737dd0 commit e16ff9c
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 70 deletions.
22 changes: 11 additions & 11 deletions sangupackage_todo.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/* Troepenlijst type=own_home */
tekst filter, continent

/*troepenlijst:
per dag kunnen dichtklappen! -> per dag sowieso een lijn toevoeegn (met + icon om te openen)
en hoeveel per dag X / Y (Z): x = aantal vegen, y is vegen in de nachtbonus, z totaal aantal dorpen
dag = met nachtbonus!
+ de filters op tekst, continent, min/max afstand/tijdsduur... ik kan het gebruiken :)*/




search: \$\(("|')[^#]
and replace with content_value at least

INCOMINGS
-> onthouden wanneer laatste keer aanvallen bekeken: icon naast aantal incomings?
Expand All @@ -11,15 +20,6 @@ and replace with content_value at least
- extra zoekmogelijkheden (op tekst, zonder tekst, ...)
- overzichten: aanvallen per speler, aanvallen per dag, aanvallen gegroepeerd per tag (check dat je geen 100 verschillende namen hebt)
-> sorteren moet beter!!! eerstaankomende bovenaan!

/* Troepenlijst type=own_home */
tekst filter, continent

/*troepenlijst:
per dag kunnen dichtklappen! -> per dag sowieso een lijn toevoeegn (met + icon om te openen)
en hoeveel per dag X / Y (Z): x = aantal vegen, y is vegen in de nachtbonus, z totaal aantal dorpen
dag = met nachtbonus!
+ de filters op tekst, continent, min/max afstand/tijdsduur... ik kan het gebruiken :)*/

SMEDERIJ:
- zelf kunnen instellen welke groep bij welke levels hoort
Expand Down
2 changes: 1 addition & 1 deletion source/config/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ $.extend(user_data, {
attackAutoRename: true,

confirm: {
addExtraOkButton: true,
addExtraOkButton: false,
autoAttackFocus: true,
replaceNightBonus: true,
replaceTribeClaim: true,
Expand Down
1 change: 1 addition & 0 deletions source/func/persistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ var pers;
setGlobal(getWorldKey(key), value);
}

pers.getWorldKey = getWorldKey;
pers.set = set;
pers.setCookie = setCookie;
pers.setGlobal = setGlobal;
Expand Down
16 changes: 8 additions & 8 deletions source/page/overview_villages/units_there_ownhome.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
overviewTable = $("#units_table");

var villageCounter = 0;
var rowSize = world_data.units.length + 1;
if (world_config.hasMilitia) {
Expand Down Expand Up @@ -58,12 +56,12 @@ function ReplaceUnitRow(row) {
mod = !villageType.isDef ? "row_a" : "row_b";
}

finalRow += "<tbody>";
//finalRow += "<tbody>";
finalRow += "<tr arrival='0' class='row_marker " + mod + (game_data.village.id == villageId ? " selected" : "") + "'>";
finalRow += "<td>" + $("td:first", row).html() + "</td>";
finalRow += newRow;
finalRow += "<td></td></tr>";
finalRow += "</tbody>";
//finalRow += "</tbody>";

villageCounter++;

Expand Down Expand Up @@ -275,7 +273,7 @@ $("#filterAxe").click(function () {
else
villageCounter++;
});
goners.parent().hide();
goners.hide();
pageSize.val(villageCounter);
});

Expand Down Expand Up @@ -339,7 +337,7 @@ $("#filterPop").click(function () {
else villageCounter++;
});
});
goners.parent().hide();
goners.hide();
pageSize.val(villageCounter);
});

Expand All @@ -355,7 +353,7 @@ $("#snobFilter").click(function () {
} else
villageCounter++;
});
goners.parent().hide();
goners.hide();
pageSize.val(villageCounter);
});

Expand All @@ -365,13 +363,15 @@ $("#attackFilter").click(function () {
var villageCounter = 0;
var goners = $();
$("#units_table").find("tr:visible:gt(1)").each(function () {
q("'" + $(this).html() + "'");
q("---------------------------------------------------");
if ($('td:first:not(:has(img[title=\'' + trans.tw.command.attack + '\']))', this).size() != 0) {
goners = goners.add($(this));
$("input:first", $(this)).val("");
} else {
villageCounter++;
}
});
goners.parent().hide();
goners.hide();
pageSize.val(villageCounter);
});
89 changes: 44 additions & 45 deletions source/page/place/confirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,57 +57,56 @@ if (village.isValid) {
pers.set("lastVil", village.coord);
}

if (user_data.attackAutoRename) {
var isAttack = $("input[name='attack']").val() == "true";
var isAttack = $("input[name='attack']").val() == "true";
var isBarbarian = infoTable.size() == (isAttack ? 4 : 3);
var player = (isBarbarian ? '' : infoTable.eq(1).text());

var isBarbarian = infoTable.size() == (isAttack ? 4 : 3);
var player = (isBarbarian ? '' : infoTable.eq(1).text());
var unitsSent = {};
$.each(world_data.units, function (i, val) {
unitsSent[val] = parseInt($("input[name='" + val + "']", attackFrame).val(), 10);
});

var unitsSent = {};
$.each(world_data.units, function (i, val) {
unitsSent[val] = parseInt($("input[name='" + val + "']", attackFrame).val(), 10);
});
var unitsCalc = calcTroops(unitsSent);

// compare runtime with dodgetime
var dodgeCookie = pers.getCookie("sanguDodge" + getQueryStringParam("village"));
if (dodgeCookie) {
dodgeCookie = dodgeCookie.split("~");
var durationCell = $("#content_value table.vis:first td:contains('" + trans.tw.command.walkingTimeTitle + "')").next();
var attackRunTime = getTimeFromTW(durationCell.text());
var dodgeTime = getTimeFromTW(dodgeCookie[1]);

var runtimeIsOk = attackRunTime.totalSecs >= dodgeTime.totalSecs;
var diffSecs = (attackRunTime.totalSecs - dodgeTime.totalSecs);

var dodgeCellText = "<table border=0 cellpadding=0 cellspacing=0 width='1%'><tr>";
dodgeCellText += "<td width='25%' align=center>" + durationCell.text() + "</td>";
dodgeCellText += "<td width='50%' align=center><b>" + (runtimeIsOk ? "&gt;&gt;&gt;" : "&lt;&lt;&lt;") + "</b></td>";
dodgeCellText += "<td width='25%' align=center nowrap>" + dodgeCookie[1] + "&nbsp;";
if (diffSecs > 0) {
dodgeCellText += trans.sp.command.dodgeMinuteReturn.replace("{minutes}", prettyDate(diffSecs * 2000, true)); // 2000 = Method expects milliseconds and distance is walked 2 times!
}
dodgeCellText += "</td>";
// compare runtime with dodgetime
var unitsCalc = calcTroops(unitsSent);
var dodgeCookie = pers.getCookie("sanguDodge" + getQueryStringParam("village"));
if (dodgeCookie) {
dodgeCookie = dodgeCookie.split("~");
var durationCell = $("#content_value table.vis:first td:contains('" + trans.tw.command.walkingTimeTitle + "')").next();
var attackRunTime = getTimeFromTW(durationCell.text());
var dodgeTime = getTimeFromTW(dodgeCookie[1]);

dodgeCellText += "</tr></table>";
durationCell.html(dodgeCellText);
var runtimeIsOk = attackRunTime.totalSecs >= dodgeTime.totalSecs;
var diffSecs = (attackRunTime.totalSecs - dodgeTime.totalSecs);

if (!runtimeIsOk) {
durationCell.find("table").attr("title", trans.sp.command.dodgeNotFarEnough).css("background-color", user_data.colors.error).find("td").css("background-color", user_data.colors.error);
}
var dodgeCellText = "<table border=0 cellpadding=0 cellspacing=0 width='1%'><tr>";
dodgeCellText += "<td width='25%' align=center>" + durationCell.text() + "</td>";
dodgeCellText += "<td width='50%' align=center><b>" + (runtimeIsOk ? "&gt;&gt;&gt;" : "&lt;&lt;&lt;") + "</b></td>";
dodgeCellText += "<td width='25%' align=center nowrap>" + dodgeCookie[1] + "&nbsp;";
if (diffSecs > 0) {
dodgeCellText += trans.sp.command.dodgeMinuteReturn.replace("{minutes}", prettyDate(diffSecs * 2000, true)); // 2000 = Method expects milliseconds and distance is walked 2 times!
}
dodgeCellText += "</td>";

if (dodgeCookie[0] != "unit_" + unitsCalc.getSlowest()) {
$("h2:first", attackFrame).css("background-color", user_data.colors.error);
}
} else {
// If a dodgecookie is in use, nightbonus etc isn't relevant
unitsCalc.colorIfNotRightAttackType($("h2:first", attackFrame), isAttack);
var arrivalTime = getDateFromTodayTomorrowTW($.trim($("#date_arrival").text()));
if (user_data.proStyle && user_data.confirm.replaceNightBonus && isDateInNightBonus(arrivalTime)) {
$("#date_arrival").css("background-color", user_data.colors.error).css("font-weight", "bold");
}
dodgeCellText += "</tr></table>";
durationCell.html(dodgeCellText);

if (!runtimeIsOk) {
durationCell.find("table").attr("title", trans.sp.command.dodgeNotFarEnough).css("background-color", user_data.colors.error).find("td").css("background-color", user_data.colors.error);
}

if (dodgeCookie[0] != "unit_" + unitsCalc.getSlowest()) {
$("h2:first", attackFrame).css("background-color", user_data.colors.error);
}
} else {
// If a dodgecookie is in use, nightbonus etc isn't relevant
unitsCalc.colorIfNotRightAttackType($("h2:first", attackFrame), isAttack);
var arrivalTime = getDateFromTodayTomorrowTW($.trim($("#date_arrival").text()));
if (user_data.proStyle && user_data.confirm.replaceNightBonus && isDateInNightBonus(arrivalTime)) {
$("#date_arrival").css("background-color", user_data.colors.error).css("font-weight", "bold");
}

}

if (user_data.attackAutoRename) {
// rename attack command
var villageCoord = $("input[name='x']", attackFrame).val() + '|' + $("input[name='y']", attackFrame).val();
var sent = buildAttackString(villageCoord, unitsSent, player, !isAttack);
Expand Down
11 changes: 7 additions & 4 deletions source/page/place/place.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// Auto rename attacks
if (user_data.attackAutoRename) {
// Less then ideal solution:
// Does work properly when sending many attacks (ie snobtrain)
// Does not work properly when sending many attacks (ie snobtrain)
// In confirm.js they are saved as a cookie (with expiration)
var cooks = document.cookie.split("; ");
var x;
for (x = 0; x < cooks.length; x++) {
var cookie = cooks[x];
if (cookie.indexOf("attRen") == 0) {
//q(x + " -> " + cookie);
if (cookie.indexOf(pers.getWorldKey("attRen")) == 0) {
var val = cookie.substr(cookie.indexOf("=") + 1);
var thisVil = val.substr(0, val.indexOf('_'));
val = val.substr(val.indexOf('_') + 1);
Expand Down Expand Up @@ -51,8 +52,10 @@ $("#inputx,#inputy").focus(function() {

if (server_settings.autoFillCoordinatesAllowed && window.location.search.indexOf("&sanguX=") != -1) {
var match = window.location.search.match(/sanguX=(\d+)&sanguY=(\d+)/);
$("#inputx").val(match[1]);
$("#inputy").val(match[2]);
if (match[1] != 0) {
$("#inputx").val(match[1]);
$("#inputy").val(match[2]);
}
}

// Show current selected speed + ability to change active speed
Expand Down
2 changes: 1 addition & 1 deletion source/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.5.4
3.5.8

0 comments on commit e16ff9c

Please sign in to comment.