리셋 시 시나리오 정보를 간단히 보여주는 기능 추가

This commit is contained in:
2018-03-27 02:44:28 +09:00
parent 492a7676c6
commit 0ad8db5a63
6 changed files with 191 additions and 18 deletions
+3 -9
View File
@@ -94,13 +94,7 @@ if(Session::getUserGrade(true) < 5){
<div class="form-group row">
<label for="confirm_password" class="col-sm-3 col-form-label">시나리오 선택</label>
<div class="col-sm-9">
<select class="form-control" size="1">
<optgroup label="공백지">
<option value="0">공백지</option>
</optgroup>
<optgroup label="역사모드">
<option value="1">황건적의 난</option>
</optgroup>
<select class="form-control" size="1" id="scenario_sel">
</select>
</div>
@@ -183,9 +177,9 @@ if(Session::getUserGrade(true) < 5){
<tr><th>설정</th><th>값</th>
</thead>
<tbody>
<tr><th>일자</th><td ><span id="scenario_begin">180년 1월</span><small id="scenario_begin_with_sync"></small></td></tr>
<tr><th>시작 연도</th><td ><span id="scenario_begin">180년</span><small id="scenario_begin_with_sync"></small></td></tr>
<tr><th>NPC 수</th><td><span id="scenario_npc"></span><span id="scenario_npc_extend"></span></td></tr>
<tr><th>국가</th><td><span id="scenario_nation"></span></td></tr>
<tr><th>국가</th><td><span id="scenario_nation"></span></td></tr>
</tbody>
<tfoot>
<tr><td colspan="2">
+10 -4
View File
@@ -2,8 +2,8 @@
namespace sammo;
require "lib.php";
if(Session::getUserGrade() < 5){
$session = Session::Instance()->setReadOnly();
if($session->userGrade < 5){
Json::die([
'result'=>false,
'reason'=>'관리자가 아닙니다.'
@@ -21,7 +21,13 @@ if ($scenarioIdx !== null) {
]);
}
$scenarios = [];
foreach(Scenario::getAllScenarios() as $scenario){
$scenarios[$scenario->getScenarioIdx()] = $scenario->getScenarioBrief();
}
Json::die([
'result'=>false,
'reason'=>'NYI'
'result'=>true,
'scenario'=>$scenarios
]);
+76 -1
View File
@@ -19,16 +19,91 @@ function loadScenarioPreview(scenarioIdx){
}
*/
function loadScenarios(){
$.ajax({
method:'post',
url:'j_load_scenarios.php',
dataType:'json'
}).then(function(result){
if(!result.result){
var deferred = $.Deferred();
deferred.reject('fail');
return deferred.promise();
}
var list = {};
$.each(result.scenario, function(idx, value){
var title = value.title || "-";
var titles = title.split(/【|[0-9]*】/);
var category = titles.length>2?titles[1]:'-';
value.title = title;
value.category = category;
value.idx = idx;
value.year = value.year || 180;
if(!(category in list)){
list[category] = {};
}
list[category][idx] = value;
});
var $select = $('#scenario_sel');
$.each(list, function(category, items){
var $optgroup = $('<optgroup>').attr('label', category);
$.each(items, function(idx, scenario){
var $option = $('<option>')
.data('scenario',scenario)
.val(idx)
.html(scenario.title);
$optgroup.append($option);
});
$select.append($optgroup);
});
$select.val(0);
$select.change();
});
}
function scenarioPreview(){
var $select = $(this);
var $option = $select.find('option:selected');
var $year = $('#scenario_begin');
var $npc = $('#scenario_npc');
var $npcEx = $('#scenario_npc_extend');
var $nation = $('#scenario_nation');
var scenario = $option.data('scenario');
console.log(scenario.idx, scenario.title);
$year.html('{0}년'.format(scenario.year));
$npc.html('{0}명'.format(scenario.npc_cnt));
if(scenario.npcEx_cnt == 0){
$npcEx.html('');
}
else{
$npcEx.html('+{0}명'.format(scenario.npcEx_cnt));
}
$nation.html('');
$.each(scenario.nation, function(idx, nation){
$nation.append('<span style="color:{0}">{1}</span> {2}명. {3}<br>'.format(
nation.color, nation.name, nation.generals, nation.cities.join(', ')
));
});
}
$(function(){
loadScenarios();
$('#scenario_sel').change(scenarioPreview);
//loadScenarioPreview(8);
})
})
+96 -3
View File
@@ -10,7 +10,7 @@ class Scenario{
private $data;
public function __construct(int $scenarioIdx){
$scenarioPath = SCENARIO_PATH."/scenario_{$scenarioIdx}.json";
$scenarioPath = self::SCENARIO_PATH."/scenario_{$scenarioIdx}.json";
$this->scenarioIdx = $scenarioIdx;
$this->scenarioPath = $scenarioPath;
@@ -22,15 +22,108 @@ class Scenario{
return $this->scenarioIdx;
}
public function getYear(){
return Util::array_get($this->data['startYear']);
}
public function getTitle(){
return Util::array_get($this->data['title']);
}
public function getNPC(){
return Util::array_get($this->data['general']);
}
public function getNPCex(){
return Util::array_get($this->data['general_ex']);
}
public function getNation(){
$nationsRaw = Util::array_get($this->data['nation']);
if(!$nationsRaw){
return [];
}
$nations = [];
foreach($nationsRaw as $idx=>$nation){
list($name, $color, $gold, $rice, $infoText, $tech, $genCount, $type, $nationLevel, $cities) = $nation;
$nationID = $idx+1;
$nation['id'] = $nationID;
$nations[$nationID] = [
'id'=>$nationID,
'name'=>$name,
'color'=>$color,
'gold'=>$gold,
'rice'=>$rice,
'infoText'=>$infoText,
'tech'=>$tech,
'type'=>$type,
'nationLevel'=>$nationLevel,
'cities'=>$cities,
'generals'=>0
];
}
$nations[0] = [
'id'=>0,
'name'=>'재야',
'color'=>'#ffffff',
'gold'=>0,
'rice'=>0,
'infoText'=>'재야',
'tech'=>0,
'type'=>'재야',
'nationLevel'=>0,
'cities'=>[],
'generals'=>0
];
foreach(Util::array_get($this->data['general'], []) as $idx=>$general){
while(count($general) < 14){
$general[] = null;
}
list(
$a, $name, $npcname, $nationID, $specifiedCity,
$leadership, $power, $intel, $birth, $death,
$charDom, $charWar, $text
) = $general;
if(array_key_exists($nationID, $nations)){
$nations[$nationID]['generals']++;
};
}
return $nations;
}
public function getScenarioBrief(){
$nations = [];
return [
'year'=>$this->getYear(),
'title'=>$this->getTitle(),
'npc_cnt'=>count($this->getNPC()),
'npcEx_cnt'=>count($this->getNPCex()),
'nation'=>$this->getNation()
];
}
/**
* @return \sammo\Scenario[]
*/
public static function getAllScenarios(){
$result = [];
foreach(glob(SCENARIO_PATH.'/scenario_*.json') as $scenarioPath){
$scenarioName = pathinfo(basename($scenarioName), PATHINFO_FILENAME);
foreach(glob(self::SCENARIO_PATH.'/scenario_*.json') as $scenarioPath){
$scenarioName = pathinfo(basename($scenarioPath), PATHINFO_FILENAME);
$scenarioIdx = Util::array_last(explode('_', $scenarioName));
if(!is_numeric($scenarioIdx)){
continue;
}
$scenarioIdx = Util::toInt($scenarioIdx);
if($scenarioIdx === null){
+5
View File
@@ -0,0 +1,5 @@
{
"title":"【공백지】 공백지",
"history":[
]
}
+1 -1
View File
@@ -1,5 +1,5 @@
{
"title":"",
"title":"【가상모드4】 결사항전",
"life":1,
"fiction":1,
"nation":[