리셋 시 시나리오 정보를 간단히 보여주는 기능 추가
This commit is contained in:
+3
-9
@@ -94,13 +94,7 @@ if(Session::getUserGrade(true) < 5){
|
|||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label for="confirm_password" class="col-sm-3 col-form-label">시나리오 선택</label>
|
<label for="confirm_password" class="col-sm-3 col-form-label">시나리오 선택</label>
|
||||||
<div class="col-sm-9">
|
<div class="col-sm-9">
|
||||||
<select class="form-control" size="1">
|
<select class="form-control" size="1" id="scenario_sel">
|
||||||
<optgroup label="공백지">
|
|
||||||
<option value="0">공백지</option>
|
|
||||||
</optgroup>
|
|
||||||
<optgroup label="역사모드">
|
|
||||||
<option value="1">황건적의 난</option>
|
|
||||||
</optgroup>
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -183,9 +177,9 @@ if(Session::getUserGrade(true) < 5){
|
|||||||
<tr><th>설정</th><th>값</th>
|
<tr><th>설정</th><th>값</th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<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>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>
|
</tbody>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr><td colspan="2">
|
<tr><td colspan="2">
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
namespace sammo;
|
namespace sammo;
|
||||||
|
|
||||||
require "lib.php";
|
require "lib.php";
|
||||||
|
$session = Session::Instance()->setReadOnly();
|
||||||
if(Session::getUserGrade() < 5){
|
if($session->userGrade < 5){
|
||||||
Json::die([
|
Json::die([
|
||||||
'result'=>false,
|
'result'=>false,
|
||||||
'reason'=>'관리자가 아닙니다.'
|
'reason'=>'관리자가 아닙니다.'
|
||||||
@@ -21,7 +21,13 @@ if ($scenarioIdx !== null) {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$scenarios = [];
|
||||||
|
foreach(Scenario::getAllScenarios() as $scenario){
|
||||||
|
$scenarios[$scenario->getScenarioIdx()] = $scenario->getScenarioBrief();
|
||||||
|
}
|
||||||
|
|
||||||
Json::die([
|
Json::die([
|
||||||
'result'=>false,
|
'result'=>true,
|
||||||
'reason'=>'NYI'
|
'scenario'=>$scenarios
|
||||||
]);
|
]);
|
||||||
+76
-1
@@ -19,16 +19,91 @@ function loadScenarioPreview(scenarioIdx){
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function loadScenarios(){
|
function loadScenarios(){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
method:'post',
|
method:'post',
|
||||||
url:'j_load_scenarios.php',
|
url:'j_load_scenarios.php',
|
||||||
dataType:'json'
|
dataType:'json'
|
||||||
}).then(function(result){
|
}).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(){
|
$(function(){
|
||||||
loadScenarios();
|
loadScenarios();
|
||||||
|
$('#scenario_sel').change(scenarioPreview);
|
||||||
//loadScenarioPreview(8);
|
//loadScenarioPreview(8);
|
||||||
})
|
})
|
||||||
|
|||||||
+96
-3
@@ -10,7 +10,7 @@ class Scenario{
|
|||||||
private $data;
|
private $data;
|
||||||
|
|
||||||
public function __construct(int $scenarioIdx){
|
public function __construct(int $scenarioIdx){
|
||||||
$scenarioPath = SCENARIO_PATH."/scenario_{$scenarioIdx}.json";
|
$scenarioPath = self::SCENARIO_PATH."/scenario_{$scenarioIdx}.json";
|
||||||
|
|
||||||
$this->scenarioIdx = $scenarioIdx;
|
$this->scenarioIdx = $scenarioIdx;
|
||||||
$this->scenarioPath = $scenarioPath;
|
$this->scenarioPath = $scenarioPath;
|
||||||
@@ -22,15 +22,108 @@ class Scenario{
|
|||||||
return $this->scenarioIdx;
|
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[]
|
* @return \sammo\Scenario[]
|
||||||
*/
|
*/
|
||||||
public static function getAllScenarios(){
|
public static function getAllScenarios(){
|
||||||
$result = [];
|
$result = [];
|
||||||
|
|
||||||
foreach(glob(SCENARIO_PATH.'/scenario_*.json') as $scenarioPath){
|
foreach(glob(self::SCENARIO_PATH.'/scenario_*.json') as $scenarioPath){
|
||||||
$scenarioName = pathinfo(basename($scenarioName), PATHINFO_FILENAME);
|
$scenarioName = pathinfo(basename($scenarioPath), PATHINFO_FILENAME);
|
||||||
$scenarioIdx = Util::array_last(explode('_', $scenarioName));
|
$scenarioIdx = Util::array_last(explode('_', $scenarioName));
|
||||||
|
|
||||||
|
if(!is_numeric($scenarioIdx)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$scenarioIdx = Util::toInt($scenarioIdx);
|
$scenarioIdx = Util::toInt($scenarioIdx);
|
||||||
|
|
||||||
if($scenarioIdx === null){
|
if($scenarioIdx === null){
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"title":"【공백지】 공백지",
|
||||||
|
"history":[
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"title":"",
|
"title":"【가상모드4】 결사항전",
|
||||||
"life":1,
|
"life":1,
|
||||||
"fiction":1,
|
"fiction":1,
|
||||||
"nation":[
|
"nation":[
|
||||||
|
|||||||
Reference in New Issue
Block a user