Skip to content

Commit

Permalink
better looter timers
Browse files Browse the repository at this point in the history
  • Loading branch information
Kivou-2000607 committed Jun 23, 2020
1 parent 819948d commit 610ecd7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 44 deletions.
11 changes: 4 additions & 7 deletions templates/loot/loot.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,10 @@ <h2 class="title">List of NPC</h2>
<div class="loot-npc-content">
{% for k, v in npc.lootTimings.items %}
{% if forloop.counter0 %}
{% if v.due < 0 %}
<p class="loot-level overdue"><b>Loot level {{v.lvl|lootLevel}}</b><br>
Since {{v.due|mul:-1|ts2ago}} at {{v.ts|ts2date:"%H:%M:%S"}} TCT</p>
{% else %}
<p class="loot-level"><b>Loot level {{v.lvl|lootLevel}} {% if v.pro > 0 %}<span class="flush-right">{{v.pro}}%{% endif %}</b><br>
In <span class="update-timer{% if npc.nextLevel.lvl == forloop.counter0 %} valid{% endif %}">{{v.due|ts2time}}</span> at <span {% if npc.nextLevel.lvl == forloop.counter0 %}class="valid"{% endif %}>{{v.ts|ts2date:"%H:%M:%S"}}</span> TCT</p>
{% endif %}
<p class="loot-level{% if v.due < 0 %} overdue{% endif %}">
<b>Loot level {{v.lvl|lootLevel}}</b><br>
At {{v.ts|ts2date:"%H:%M:%S"}} TCT <span class="update-timer" data-lts="{{v.ts}}" data-lvl="{{v.lvl}}"><i class="fas fa-spinner fa-pulse"></i></span>
</p>
{% endif %}
{% endfor %}
<p class='loot-level-update'>Last update: {{npc.updateTS|ts2date}} TCT</p>
Expand Down
1 change: 1 addition & 0 deletions yata/static/perso/css/loot.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ div.miniloot > img {

p.loot-level {
margin-bottom: 0.4em;
width: 220px;
}

p.loot-level-update {
Expand Down
46 changes: 14 additions & 32 deletions yata/static/perso/js/loot/loot.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,20 @@
// refresh timer target update
window.setInterval(function(){
$(".update-timer").each(function() {
var timeRefresh = $.trim($(this).text());
if ( timeRefresh.search(" s")!=-1 ) {
var splitRefresh = timeRefresh.split(" ");
var sRefresh = 0;
if (splitRefresh.length == 2) {
sRefresh = parseInt(splitRefresh[0]);
} else if (splitRefresh.length == 4) {
sRefresh = parseInt(splitRefresh[2]) + 60 * parseInt(splitRefresh[0]);
} else if (splitRefresh.length == 6) {
sRefresh = parseInt(splitRefresh[4]) + 60 * parseInt(splitRefresh[2]) + 3600 * parseInt(splitRefresh[0]);
}
const lvl = parseInt($.trim($(this).attr("data-lvl")));
const loot = parseInt($.trim($(this).attr("data-lts")));
const now = parseInt(Date.now() / 1000);
const diff = Math.max(loot-now, 0);
const lvlt = lvl > 1 ? 30 * (Math.pow(2, lvl - 2)) * 60 : 0;
let cd = fancyTimeFormat(diff);
let cl = "";

sRefresh --;
sRefresh = Math.max(sRefresh, 0)
hRefresh = Math.floor(sRefresh / 3600);
sRefresh = sRefresh % 3600;
mRefresh = Math.floor(sRefresh / 60);
sRefresh = sRefresh % 60;
if (hRefresh) {
spad = ("0"+sRefresh.toString()).slice(-2);
$(this).html(hRefresh.toString()+" hrs "+mRefresh.toString()+" mins "+spad+" s");
}
else if (mRefresh) {
spad = ("0"+sRefresh.toString()).slice(-2);
$(this).html(mRefresh.toString()+" mins "+spad+" s");
} else {
$(this).html(sRefresh.toString()+" s");
}
} else {
if (!tr.hasClass('old-refresh')) {
tr.addClass('old-refresh');
}
}
// cl = diff < 60*30 ? "valid" : cl;
cl = diff < 60*15 ? "warning" : cl;
cl = diff < 15 ? "error" : cl;
const prog = diff < lvlt ? ' <span class="flush-right">'+parseInt(100 * (lvlt - diff) / lvlt)+'%</span>' : ''
const html = diff > 0 ? 'in <span class="'+cl+'">' +cd+'</span>'+prog : ''

$(this).html(html);
});
}, 1000);
7 changes: 2 additions & 5 deletions yata/static/perso/js/yata.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
function fancyCountdown(time)
{ // From https://stackoverflow.com/a/11486026
// days, hours, minutes and seconds
// days:hours:minutes:seconds
var days = ~~(time / 86400);
var hrs = ~~((time % 86400) / 3600);
var mins = ~~((time % 3600) / 60);
var secs = ~~time % 60;
console.log(days, hrs, mins, secs);

// Output like "1:01" or "4:03:59" or "123:03:59"
var ret = "";

if (days > 0) {
Expand All @@ -23,12 +21,11 @@ function fancyCountdown(time)

function fancyTimeFormat(time)
{ // From https://stackoverflow.com/a/11486026
// Hours, minutes and seconds
// Hours:minutes:seconds
var hrs = ~~(time / 3600);
var mins = ~~((time % 3600) / 60);
var secs = ~~time % 60;

// Output like "1:01" or "4:03:59" or "123:03:59"
var ret = "";

if (hrs > 0) {
Expand Down

0 comments on commit 610ecd7

Please sign in to comment.