feat: 연감에 기존 세력도 기능 통합
This commit is contained in:
+43
-29
@@ -5,7 +5,7 @@ namespace sammo;
|
||||
include "lib.php";
|
||||
include "func.php";
|
||||
$btn = Util::getReq('btn');
|
||||
$yearmonth = Util::getReq('yearmonth', 'int');
|
||||
$yearMonth = Util::getReq('yearmonth', 'int');
|
||||
$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 = $s_year * 12 + $s_month;
|
||||
$s = Util::joinYearMonth($s_year, $s_month);
|
||||
|
||||
if ($s_year === null) {
|
||||
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 = $e_year * 12 + $e_month;
|
||||
$e = Util::joinYearMonth($e_year, $e_month);
|
||||
|
||||
if ($serverID !== UniqueConst::$serverID) {
|
||||
$mapTheme = $db->queryFirstField('SELECT map FROM ng_games WHERE server_id=%s', $serverID) ?: 'che';
|
||||
@@ -53,42 +53,47 @@ if ($serverID !== UniqueConst::$serverID) {
|
||||
}
|
||||
|
||||
//FIXME: $yearmonth가 올바르지 않을 경우에 처리가 필요.
|
||||
if ($serverID !== UniqueConst::$serverID && !$yearmonth) {
|
||||
$year = $s_year;
|
||||
$month = $s_month;
|
||||
} else if (!$yearmonth) {
|
||||
$year = $admin['year'];
|
||||
$month = $admin['month'] - 1;
|
||||
if ($serverID !== UniqueConst::$serverID && !$yearMonth) {
|
||||
$yearMonth = $s;
|
||||
} else if (!$yearMonth) {
|
||||
$yearMonth = Util::joinYearMonth($admin['year'], $admin['month']);
|
||||
} else {
|
||||
$year = intdiv($yearmonth, 100);
|
||||
$month = $yearmonth % 100;
|
||||
|
||||
if ($btn == "◀◀ 이전달") {
|
||||
$month -= 1;
|
||||
$yearMonth -= 1;
|
||||
} elseif ($btn == "다음달 ▶▶") {
|
||||
$month += 1;
|
||||
$yearMonth += 1;
|
||||
}
|
||||
}
|
||||
$now = ($year * 12) + $month;
|
||||
|
||||
if ($now < $s) {
|
||||
$now = $s;
|
||||
$isCurrent = false;
|
||||
if ($yearMonth < $s) {
|
||||
$yearMonth = $s;
|
||||
}
|
||||
if ($now > $e) {
|
||||
$now = $e;
|
||||
if ($yearMonth > $e) {
|
||||
$isCurrent = true;
|
||||
$yearMonth = $e + 1;
|
||||
}
|
||||
|
||||
$year = intdiv($now, 12);
|
||||
$month = $now % 12;
|
||||
if ($month <= 0) {
|
||||
$year -= 1;
|
||||
$month += 12;
|
||||
[$year, $month] = Util::parseYearMonth($yearMonth);
|
||||
|
||||
function getHistory($serverID, $year, $month):array{
|
||||
$db = DB::db();
|
||||
$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>
|
||||
<html>
|
||||
@@ -129,7 +134,7 @@ $nations = Json::decode($history['nations']);
|
||||
<input type=submit name=btn value="◀◀ 이전달">
|
||||
<select id='yearmonth' name=yearmonth size=1>
|
||||
<option selected='selected'><?= $year ?>년 <?= $month ?>월</option>
|
||||
<option><?= $e_year ?>년 12월</option>
|
||||
<option><?= $e_year ?>년 12월 (현재)</option>
|
||||
</select>
|
||||
<input type=submit name=btn value='조회하기'>
|
||||
<input type=submit name=btn value="다음달 ▶▶">
|
||||
@@ -177,7 +182,7 @@ $nations = Json::decode($history['nations']);
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan=5 valign=top>
|
||||
<?= formatHistoryToHTML(Json::decode($history['global_history'])) ?>
|
||||
<?= formatHistoryToHTML($history['global_history']) ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -185,7 +190,7 @@ $nations = Json::decode($history['nations']);
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan=5 valign=top>
|
||||
<?= formatHistoryToHTML(Json::decode($history['global_action'])) ?>
|
||||
<?= formatHistoryToHTML($history['global_action']) ?>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@@ -201,6 +206,13 @@ $nations = Json::decode($history['nations']);
|
||||
<script>
|
||||
window.serverNick = '<?= DB::prefix() ?>';
|
||||
window.serverID = '<?= UniqueConst::$serverID ?>';
|
||||
<?php if($isCurrent): ?>
|
||||
reloadWorldMap({
|
||||
showMe: false,
|
||||
neutralView: true,
|
||||
useCachedMap: true,
|
||||
});
|
||||
<?php else: ?>
|
||||
reloadWorldMap({
|
||||
targetJson: 'j_map_history.php?year=<?= $year ?>&month=<?= $month ?>&serverID=<?= $serverID ?>',
|
||||
showMe: false,
|
||||
@@ -209,6 +221,8 @@ $nations = Json::decode($history['nations']);
|
||||
year: <?= $year ?>,
|
||||
month: <?= $month ?>,
|
||||
});
|
||||
<?php endif; ?>
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
||||
+27
-21
@@ -371,10 +371,11 @@ function getGlobalActionLogWithDate(int $year, int $month):array {
|
||||
return $texts;
|
||||
}
|
||||
|
||||
function LogHistory($isFirst=0) {
|
||||
function getCurrentHistory($isFirst=false) {
|
||||
$db = DB::db();
|
||||
$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([
|
||||
'year'=>null,
|
||||
@@ -384,21 +385,14 @@ function LogHistory($isFirst=0) {
|
||||
'aux'=>[]
|
||||
]);
|
||||
|
||||
|
||||
$map['month'] = $obj['month'];
|
||||
$map['year'] = $obj['year'];
|
||||
$map['startYear'] = $obj['startyear'];
|
||||
if($isFirst == 1){
|
||||
$map['month'] -= 1;
|
||||
if($map['month'] == 0){
|
||||
$map['month'] = 12;
|
||||
$map['year'] -= 1;
|
||||
}
|
||||
if($isFirst){
|
||||
$yearMonth -= 1;
|
||||
}
|
||||
|
||||
$year = $map['year'];
|
||||
$month = $map['month'];
|
||||
|
||||
[$year, $month] = Util::parseYearMonth($yearMonth);
|
||||
$map['startYear'] = $startYear;
|
||||
$map['year'] = $year;
|
||||
$map['month'] = $month;
|
||||
|
||||
$globalHistory = getGlobalHistoryLogWithDate($year, $month);
|
||||
$globalAction = getGlobalActionLogWithDate($year, $month);
|
||||
@@ -418,15 +412,27 @@ function LogHistory($isFirst=0) {
|
||||
return -($lhs['power']<=>$rhs['power']);
|
||||
});
|
||||
|
||||
$db->insert('ng_history', [
|
||||
return [
|
||||
'server_id' => UniqueConst::$serverID,
|
||||
'year' => $year,
|
||||
'month' => $month,
|
||||
'map' => Json::encode($map),
|
||||
'global_history' => Json::encode($globalHistory),
|
||||
'global_action' => Json::encode($globalAction),
|
||||
'nations' => Json::encode($nations),
|
||||
]);
|
||||
'map' => $map,
|
||||
'global_history' => $globalHistory,
|
||||
'global_action' => $globalAction,
|
||||
'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;
|
||||
}
|
||||
|
||||
+10
-11
@@ -1,5 +1,7 @@
|
||||
import $ from 'jquery';
|
||||
import '@/map';
|
||||
import { joinYearMonth } from './util/joinYearMonth';
|
||||
import { parseYearMonth } from './util/parseYearMonth';
|
||||
|
||||
declare const startYear:number;
|
||||
declare const startMonth:number;
|
||||
@@ -13,28 +15,25 @@ declare const selectMonth: number;
|
||||
$(function ($) {
|
||||
let currYear = startYear;
|
||||
let currMonth = startMonth;
|
||||
const selectDate = joinYearMonth(selectYear, selectMonth);
|
||||
|
||||
const $yearMonth = $('#yearmonth');
|
||||
let $elements = $();
|
||||
|
||||
const endDate = lastYear * 12 + lastMonth - 1;
|
||||
let currDate = startYear * 12 + startMonth - 1;
|
||||
const endDate = joinYearMonth(lastYear, lastMonth) + 1;//연감 마지막 + 1(현재)
|
||||
let currDate = joinYearMonth(startYear, startMonth);
|
||||
while (currDate <= endDate) {
|
||||
|
||||
const target = currYear * 100 + currMonth;
|
||||
let sel = '';
|
||||
if (currYear == selectYear && currMonth == selectMonth) {
|
||||
if (currDate == selectDate) {
|
||||
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);
|
||||
|
||||
currMonth += 1;
|
||||
if (currMonth > 12) {
|
||||
currYear += 1;
|
||||
currMonth -= 12;
|
||||
}
|
||||
currDate += 1;
|
||||
[currYear, currMonth] = parseYearMonth(currDate);
|
||||
}
|
||||
$yearMonth.empty();
|
||||
$yearMonth.append($elements);
|
||||
|
||||
Reference in New Issue
Block a user