feat: 연감에 기존 세력도 기능 통합

This commit is contained in:
2022-02-23 23:46:40 +09:00
parent 9f84eb8d4d
commit a47669ff75
3 changed files with 80 additions and 61 deletions
+43 -29
View File
@@ -5,7 +5,7 @@ namespace sammo;
include "lib.php"; include "lib.php";
include "func.php"; include "func.php";
$btn = Util::getReq('btn'); $btn = Util::getReq('btn');
$yearmonth = Util::getReq('yearmonth', 'int'); $yearMonth = Util::getReq('yearmonth', 'int');
$serverID = Util::getReq('serverID', 'string', null); $serverID = Util::getReq('serverID', 'string', null);
//로그인 검사 //로그인 검사
@@ -36,7 +36,7 @@ if ($con >= 2) {
[$s_year, $s_month] = $db->queryFirstList('SELECT year, month FROM ng_history WHERE server_id = %s ORDER BY year ASC, month ASC LIMIT 1', $serverID); [$s_year, $s_month] = $db->queryFirstList('SELECT year, month FROM ng_history WHERE server_id = %s ORDER BY year ASC, month ASC LIMIT 1', $serverID);
$s = $s_year * 12 + $s_month; $s = Util::joinYearMonth($s_year, $s_month);
if ($s_year === null) { if ($s_year === null) {
echo '인자 에러'; echo '인자 에러';
@@ -44,7 +44,7 @@ if ($s_year === null) {
} }
[$e_year, $e_month] = $db->queryFirstList('SELECT year, month FROM ng_history WHERE server_id = %s ORDER BY year DESC, month DESC LIMIT 1', $serverID); [$e_year, $e_month] = $db->queryFirstList('SELECT year, month FROM ng_history WHERE server_id = %s ORDER BY year DESC, month DESC LIMIT 1', $serverID);
$e = $e_year * 12 + $e_month; $e = Util::joinYearMonth($e_year, $e_month);
if ($serverID !== UniqueConst::$serverID) { if ($serverID !== UniqueConst::$serverID) {
$mapTheme = $db->queryFirstField('SELECT map FROM ng_games WHERE server_id=%s', $serverID) ?: 'che'; $mapTheme = $db->queryFirstField('SELECT map FROM ng_games WHERE server_id=%s', $serverID) ?: 'che';
@@ -53,42 +53,47 @@ if ($serverID !== UniqueConst::$serverID) {
} }
//FIXME: $yearmonth가 올바르지 않을 경우에 처리가 필요. //FIXME: $yearmonth가 올바르지 않을 경우에 처리가 필요.
if ($serverID !== UniqueConst::$serverID && !$yearmonth) { if ($serverID !== UniqueConst::$serverID && !$yearMonth) {
$year = $s_year; $yearMonth = $s;
$month = $s_month; } else if (!$yearMonth) {
} else if (!$yearmonth) { $yearMonth = Util::joinYearMonth($admin['year'], $admin['month']);
$year = $admin['year'];
$month = $admin['month'] - 1;
} else { } else {
$year = intdiv($yearmonth, 100);
$month = $yearmonth % 100;
if ($btn == "◀◀ 이전달") { if ($btn == "◀◀ 이전달") {
$month -= 1; $yearMonth -= 1;
} elseif ($btn == "다음달 ▶▶") { } elseif ($btn == "다음달 ▶▶") {
$month += 1; $yearMonth += 1;
} }
} }
$now = ($year * 12) + $month;
if ($now < $s) { $isCurrent = false;
$now = $s; if ($yearMonth < $s) {
$yearMonth = $s;
} }
if ($now > $e) { if ($yearMonth > $e) {
$now = $e; $isCurrent = true;
$yearMonth = $e + 1;
} }
$year = intdiv($now, 12); [$year, $month] = Util::parseYearMonth($yearMonth);
$month = $now % 12;
if ($month <= 0) { function getHistory($serverID, $year, $month):array{
$year -= 1; $db = DB::db();
$month += 12; $history = $db->queryFirstRow('SELECT * FROM ng_history WHERE server_id = %s AND year = %i AND month = %i', $serverID, $year, $month);
$history['global_history'] = Json::decode($history['global_history']);
$history['global_action'] = Json::decode($history['global_action']);
$history['nations'] = Json::decode($history['nations']);
return $history;
} }
$history = $db->queryFirstRow('SELECT * FROM ng_history WHERE server_id = %s AND year = %i AND month = %i', $serverID, $year, $month);
if($isCurrent){
$history = getCurrentHistory();
}
else{
$history = getHistory($serverID, $year, $month);
}
$nations = Json::decode($history['nations']); $nations = $history['nations'];
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@@ -129,7 +134,7 @@ $nations = Json::decode($history['nations']);
<input type=submit name=btn value="◀◀ 이전달"> <input type=submit name=btn value="◀◀ 이전달">
<select id='yearmonth' name=yearmonth size=1> <select id='yearmonth' name=yearmonth size=1>
<option selected='selected'><?= $year ?>년 <?= $month ?>월</option> <option selected='selected'><?= $year ?>년 <?= $month ?>월</option>
<option><?= $e_year ?>년 12월</option> <option><?= $e_year ?>년 12월 (현재)</option>
</select> </select>
<input type=submit name=btn value='조회하기'> <input type=submit name=btn value='조회하기'>
<input type=submit name=btn value="다음달 ▶▶"> <input type=submit name=btn value="다음달 ▶▶">
@@ -177,7 +182,7 @@ $nations = Json::decode($history['nations']);
</tr> </tr>
<tr> <tr>
<td colspan=5 valign=top> <td colspan=5 valign=top>
<?= formatHistoryToHTML(Json::decode($history['global_history'])) ?> <?= formatHistoryToHTML($history['global_history']) ?>
</td> </td>
</tr> </tr>
<tr> <tr>
@@ -185,7 +190,7 @@ $nations = Json::decode($history['nations']);
</tr> </tr>
<tr> <tr>
<td colspan=5 valign=top> <td colspan=5 valign=top>
<?= formatHistoryToHTML(Json::decode($history['global_action'])) ?> <?= formatHistoryToHTML($history['global_action']) ?>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@@ -201,6 +206,13 @@ $nations = Json::decode($history['nations']);
<script> <script>
window.serverNick = '<?= DB::prefix() ?>'; window.serverNick = '<?= DB::prefix() ?>';
window.serverID = '<?= UniqueConst::$serverID ?>'; window.serverID = '<?= UniqueConst::$serverID ?>';
<?php if($isCurrent): ?>
reloadWorldMap({
showMe: false,
neutralView: true,
useCachedMap: true,
});
<?php else: ?>
reloadWorldMap({ reloadWorldMap({
targetJson: 'j_map_history.php?year=<?= $year ?>&month=<?= $month ?>&serverID=<?= $serverID ?>', targetJson: 'j_map_history.php?year=<?= $year ?>&month=<?= $month ?>&serverID=<?= $serverID ?>',
showMe: false, showMe: false,
@@ -209,6 +221,8 @@ $nations = Json::decode($history['nations']);
year: <?= $year ?>, year: <?= $year ?>,
month: <?= $month ?>, month: <?= $month ?>,
}); });
<?php endif; ?>
</script> </script>
</body> </body>
+27 -21
View File
@@ -371,10 +371,11 @@ function getGlobalActionLogWithDate(int $year, int $month):array {
return $texts; return $texts;
} }
function LogHistory($isFirst=0) { function getCurrentHistory($isFirst=false) {
$db = DB::db(); $db = DB::db();
$gameStor = KVStorage::getStorage($db, 'game_env'); $gameStor = KVStorage::getStorage($db, 'game_env');
$obj = $gameStor->getValues(['startyear', 'year', 'month']); [$startYear, $year, $month]= $gameStor->getValuesAsArray(['startyear', 'year', 'month']);
$yearMonth = Util::joinYearMonth($year, $month);
$map = getWorldMap([ $map = getWorldMap([
'year'=>null, 'year'=>null,
@@ -384,21 +385,14 @@ function LogHistory($isFirst=0) {
'aux'=>[] 'aux'=>[]
]); ]);
if($isFirst){
$map['month'] = $obj['month']; $yearMonth -= 1;
$map['year'] = $obj['year'];
$map['startYear'] = $obj['startyear'];
if($isFirst == 1){
$map['month'] -= 1;
if($map['month'] == 0){
$map['month'] = 12;
$map['year'] -= 1;
}
} }
$year = $map['year']; [$year, $month] = Util::parseYearMonth($yearMonth);
$month = $map['month']; $map['startYear'] = $startYear;
$map['year'] = $year;
$map['month'] = $month;
$globalHistory = getGlobalHistoryLogWithDate($year, $month); $globalHistory = getGlobalHistoryLogWithDate($year, $month);
$globalAction = getGlobalActionLogWithDate($year, $month); $globalAction = getGlobalActionLogWithDate($year, $month);
@@ -418,15 +412,27 @@ function LogHistory($isFirst=0) {
return -($lhs['power']<=>$rhs['power']); return -($lhs['power']<=>$rhs['power']);
}); });
$db->insert('ng_history', [ return [
'server_id' => UniqueConst::$serverID, 'server_id' => UniqueConst::$serverID,
'year' => $year, 'year' => $year,
'month' => $month, 'month' => $month,
'map' => Json::encode($map), 'map' => $map,
'global_history' => Json::encode($globalHistory), 'global_history' => $globalHistory,
'global_action' => Json::encode($globalAction), 'global_action' => $globalAction,
'nations' => Json::encode($nations), 'nations' => $nations,
]); ];
}
function LogHistory($isFirst=false) {
$history = getCurrentHistory($isFirst);
$db = DB::db();
$history['map'] = Json::encode($history['map']);
$history['global_history'] = Json::encode($history['global_history']);
$history['global_action'] = Json::encode($history['global_action']);
$history['nations'] = Json::encode($history['nations']);
$db->insert('ng_history', $history);
return true; return true;
} }
+10 -11
View File
@@ -1,5 +1,7 @@
import $ from 'jquery'; import $ from 'jquery';
import '@/map'; import '@/map';
import { joinYearMonth } from './util/joinYearMonth';
import { parseYearMonth } from './util/parseYearMonth';
declare const startYear:number; declare const startYear:number;
declare const startMonth:number; declare const startMonth:number;
@@ -13,28 +15,25 @@ declare const selectMonth: number;
$(function ($) { $(function ($) {
let currYear = startYear; let currYear = startYear;
let currMonth = startMonth; let currMonth = startMonth;
const selectDate = joinYearMonth(selectYear, selectMonth);
const $yearMonth = $('#yearmonth'); const $yearMonth = $('#yearmonth');
let $elements = $(); let $elements = $();
const endDate = lastYear * 12 + lastMonth - 1; const endDate = joinYearMonth(lastYear, lastMonth) + 1;//연감 마지막 + 1(현재)
let currDate = startYear * 12 + startMonth - 1; let currDate = joinYearMonth(startYear, startMonth);
while (currDate <= endDate) { while (currDate <= endDate) {
const target = currYear * 100 + currMonth;
let sel = ''; let sel = '';
if (currYear == selectYear && currMonth == selectMonth) { if (currDate == selectDate) {
sel = 'selected="selected"'; sel = 'selected="selected"';
} }
const option = $(`<option value="${target}" ${sel} >${currYear}${currMonth}월</option>`);
const more = currDate == endDate? ' (현재)':'';
const option = $(`<option value="${currDate}" ${sel} >${currYear}${currMonth}${more}</option>`);
$elements = $elements.add(option); $elements = $elements.add(option);
currMonth += 1;
if (currMonth > 12) {
currYear += 1;
currMonth -= 12;
}
currDate += 1; currDate += 1;
[currYear, currMonth] = parseYearMonth(currDate);
} }
$yearMonth.empty(); $yearMonth.empty();
$yearMonth.append($elements); $yearMonth.append($elements);