From a47669ff754ccd7f670b906e9594e36d92ea2809 Mon Sep 17 00:00:00 2001 From: hide_d Date: Wed, 23 Feb 2022 23:46:40 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=97=B0=EA=B0=90=EC=97=90=20=EA=B8=B0?= =?UTF-8?q?=EC=A1=B4=20=EC=84=B8=EB=A0=A5=EB=8F=84=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=ED=86=B5=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/a_history.php | 72 ++++++++++++++++++++++++++------------------ hwe/func_history.php | 48 ++++++++++++++++------------- hwe/ts/history.ts | 21 ++++++------- 3 files changed, 80 insertions(+), 61 deletions(-) diff --git a/hwe/a_history.php b/hwe/a_history.php index cffb467f..26a19358 100644 --- a/hwe/a_history.php +++ b/hwe/a_history.php @@ -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']; ?> @@ -129,7 +134,7 @@ $nations = Json::decode($history['nations']); @@ -177,7 +182,7 @@ $nations = Json::decode($history['nations']); - + @@ -185,7 +190,7 @@ $nations = Json::decode($history['nations']); - + @@ -201,6 +206,13 @@ $nations = Json::decode($history['nations']); diff --git a/hwe/func_history.php b/hwe/func_history.php index 66e2b0da..fd5241e4 100644 --- a/hwe/func_history.php +++ b/hwe/func_history.php @@ -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; } diff --git a/hwe/ts/history.ts b/hwe/ts/history.ts index d5f0a513..5ec050dd 100644 --- a/hwe/ts/history.ts +++ b/hwe/ts/history.ts @@ -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 = $(``); + + const more = currDate == endDate? ' (현재)':''; + const 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);