빙의 코드 개선

- 유효 기간 관련 늘림.
- 유효 기간 가까워지면 색으로 표시. 만료 표기도 추가
- 다른 장수 보기를 남은 초 기준으로 수정
This commit is contained in:
2018-05-05 22:39:21 +09:00
parent a75eb5b74e
commit 683a844a08
4 changed files with 49 additions and 14 deletions
+7 -2
View File
@@ -39,5 +39,10 @@
position: relative;
top: -1px;
*overflow: hidden;
}
}
#outdate_token{
color:red;
display:none;
}
+7 -2
View File
@@ -4,7 +4,7 @@ namespace sammo;
include "lib.php";
include "func.php";
const VALID_SECOND = 25;
const VALID_SECOND = 90;
const PICK_MORE_SECOND = 10;
const KEEP_CNT = 3;
@@ -74,10 +74,14 @@ if($token && $refresh){
}
if($token && !$refresh){
$pickMoreFrom = (new \DateTime($token['pick_more_from']))->getTimestamp();
$nowT = $oNow->getTimestamp();
Json::die([
'result'=>true,
'pick'=>Json::decode($token['pick_result']),
'pickMoreFrom'=>$token['pick_more_from'],
'pickMoreSeconds'=>$pickMoreFrom-$nowT,
'validUntil'=>$token['valid_until']
]);
}
@@ -114,7 +118,7 @@ while(count($pickResult) < $pickLimit){
$newNonce = mt_rand(0, 0xfffffff);
$validSecond = max(VALID_SECOND, $turnterm*25);
$validSecond = max(VALID_SECOND, $turnterm*40);
$pickMoreSecond = max(PICK_MORE_SECOND, $turnterm*10);
$validUntil = $oNow->add(new \DateInterval(sprintf('PT%dS', $validSecond)));
@@ -160,5 +164,6 @@ Json::die([
'result'=>true,
'pick'=>$pickResult,
'pickMoreFrom'=>($inserted===-1)?$pickMoreFrom->format('Y-m-d H:i:s'):'2000-01-01 01:00:00',
'pickMoreSeconds'=>($inserted===-1)?$pickMoreSecond:0,
'validUntil'=>$validUntil->format('Y-m-d H:i:s')
]);
+27 -2
View File
@@ -29,8 +29,29 @@ function pickGeneral(){
return false;
}
function updateOutdateTimer(){
var $validUntilText = $('#valid_until_text');
var now = Date.now();
var validUntil = $validUntilText.data('until');
if(validUntil <= 0){
return;
}
else if(validUntil < now){
$validUntilText.data('until',0);
$('#valid_until').hide();
$('#outdate_token').show();
return;
}
else if(validUntil - now <= 30000){
$validUntilText.css('color', "rgb(255, {0}, {0})".format(255*(validUntil - now)/30000));
}
setTimeout(updateOutdateTimer, 1000);
}
function updatePickMoreTimer(){
var $btn = $('#btn_pick_more');
var now = Date.now();
var remain = ($btn.data('available') - now) / 1000;
if(remain <= 0){
@@ -46,8 +67,10 @@ function updatePickMoreTimer(){
function printGenerals(value){
$('.card_holder').empty();
$('#valid_until_text').html(value.validUntil);
$('#btn_pick_more').data('available', new Date(value.pickMoreFrom).getTime()).prop('disabled',true);
$('#valid_until_text').html(value.validUntil).data('until', (new Date(value.validUntil)).getTime()).show().css('color','white');
$('#outdate_token').hide();
var time = Date.now() + value.pickMoreSeconds*1000;
$('#btn_pick_more').data('available', time).prop('disabled',true);
$.each(value.pick, function(idx, cardData){
cardData.iconPath = getIconPath(cardData.imgsvr, cardData.picture);
@@ -59,6 +82,7 @@ function printGenerals(value){
});
updatePickMoreTimer();
updateOutdateTimer();
}
$(function($){
@@ -90,6 +114,7 @@ $('#btn_pick_more').click(function(){
alert(result.reason);
location.refresh();
}
console.log(result);
printGenerals(result);
});
});
+8 -8
View File
@@ -24,15 +24,15 @@ $nations = $db->queryAllLists('SELECT `name`, scoutmsg, color FROM nation');
<head>
<title><?=UniqueConst::$serverName?>: NPC빙의</title>
<meta HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=utf-8'>
<link rel='stylesheet' href='css/normalize.css' type='text/css'>
<link rel='stylesheet' href='../d_shared/common.css' type='text/css'>
<link rel='stylesheet' href='../css/config.css' type='text/css'>
<link rel='stylesheet' href='css/common.css' type='text/css'>
<link rel='stylesheet' href='css/select_npc.css' type='text/css'>
<link rel='stylesheet' href='css/normalize.css?180505_2' type='text/css'>
<link rel='stylesheet' href='../d_shared/common.css?180505_2' type='text/css'>
<link rel='stylesheet' href='../css/config.css?180505_2' type='text/css'>
<link rel='stylesheet' href='css/common.css?180505_2' type='text/css'>
<link rel='stylesheet' href='css/select_npc.css?180505_2' type='text/css'>
<script type="text/javascript" src="../d_shared/common_path.js"></script>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../e_lib/jquery-3.2.1.min.js"></script>
<script src="js/select_npc.js"></script>
<script type="text/javascript" src="../js/common.js?180505_2"></script>
<script src="js/select_npc.js?180505_2"></script>
</head>
@@ -78,7 +78,7 @@ history.go(-1);
<div class="bg0">
<div class="bg1 with_border legacy_layout font1" style="text-align:center;font-weight:bold;">장수 빙의</div>
<div class="with_border legacy_layout" style="text-align:center;">
<small id="valid_until">(<span id="valid_until_text"></span> 까지 유효)</small><br>
<small id="valid_until">(<span id="valid_until_text"></span> 까지 유효)</small><small id="outdate_token">- 만료 -</small><br>
<form class="card_holder">
</form>
</div>