d_setting 디렉도리 보관 방식 변경
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
namespace sammo;
|
||||||
|
|
||||||
|
class GameConst extends GameConstBase
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace sammo;
|
|
||||||
|
|
||||||
class GameCustomConst
|
|
||||||
{
|
|
||||||
/** @var int 유저 스탯 총합 */
|
|
||||||
public static $defaultStatTotal = _tK_statTotal_;
|
|
||||||
public static $defaultStatMin = _tK_statMin_;
|
|
||||||
public static $defaultStatMax = _tK_statMax_;
|
|
||||||
public static $defaultStatNPCMax = _tK_statNPCMax_;
|
|
||||||
public static $chiefStatMin = _tK_statChiefMin_;
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace sammo;
|
namespace sammo;
|
||||||
|
|
||||||
class GameConst extends GameCustomConst
|
class GameConstBase
|
||||||
{
|
{
|
||||||
/** @var string 버전 */
|
/** @var string 버전 */
|
||||||
public static $title = "삼국지 모의전투 PHP HiDCHe";
|
public static $title = "삼국지 모의전투 PHP HiDCHe";
|
||||||
+7
-12
@@ -182,14 +182,14 @@ class Scenario{
|
|||||||
$default = Json::decode(file_get_contents($defaultPath));
|
$default = Json::decode(file_get_contents($defaultPath));
|
||||||
|
|
||||||
$stat = [
|
$stat = [
|
||||||
'statTotal'=>$this->data['stat']['total']??$default['stat']['total'],
|
'defaultStatTotal'=>$this->data['stat']['total']??$default['stat']['total'],
|
||||||
'statMin'=>$this->data['stat']['min']??$default['stat']['min'],
|
'defaultStatMin'=>$this->data['stat']['min']??$default['stat']['min'],
|
||||||
'statMax'=>$this->data['stat']['max']??$default['stat']['max'],
|
'defaultStatMax'=>$this->data['stat']['max']??$default['stat']['max'],
|
||||||
'statNPCMax'=>$this->data['stat']['npcMax']??$default['stat']['npcMax'],
|
'defaultStatNPCMax'=>$this->data['stat']['npcMax']??$default['stat']['npcMax'],
|
||||||
'statChiefMin'=>$this->data['stat']['chiefMin']??$default['stat']['chiefMin'],
|
'chiefStatMin'=>$this->data['stat']['chiefMin']??$default['stat']['chiefMin'],
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->gameConf = array_merge($stat, $this->data['map']??[]);
|
$this->gameConf = array_merge($stat, $this->data['map']??[], $this->data['const']??[]);
|
||||||
|
|
||||||
$this->iconPath = $this->data['iconPath']??$default['iconPath'];
|
$this->iconPath = $this->data['iconPath']??$default['iconPath'];
|
||||||
return $this->gameConf;
|
return $this->gameConf;
|
||||||
@@ -358,12 +358,7 @@ class Scenario{
|
|||||||
|
|
||||||
public function buildConf(){
|
public function buildConf(){
|
||||||
$path = __dir__.'/../d_setting';
|
$path = __dir__.'/../d_setting';
|
||||||
Util::generateFileUsingSimpleTemplate(
|
Util::generatePHPClassFile($path.'/GameConst.php', $this->gameConf, 'GameConstBase', 'sammo');
|
||||||
$path.'/GameCustomConst.orig.php',
|
|
||||||
$path.'/GameCustomConst.php',
|
|
||||||
$this->gameConf,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
$mapPath = __dir__.'/../scenario/map';
|
$mapPath = __dir__.'/../scenario/map';
|
||||||
$unitPath = __dir__.'/../scenario/unit';
|
$unitPath = __dir__.'/../scenario/unit';
|
||||||
|
|||||||
@@ -128,6 +128,53 @@ class Util extends \utilphp\util
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* params에 맞도록 class를 생성해주는 함수
|
||||||
|
*/
|
||||||
|
public static function generatePHPClassFile(string $destFilePath, array $params, ?string $srcClassName=null, string $namespace='sammo'){
|
||||||
|
if ($destFilePath === $srcFilePath) {
|
||||||
|
return 'invalid destFilePath';
|
||||||
|
}
|
||||||
|
if (!is_writable(dirname($destFilePath))) {
|
||||||
|
return 'destFilePath is not writable';
|
||||||
|
}
|
||||||
|
|
||||||
|
$newClassName = basename($destFilePath, '.php');
|
||||||
|
$newClassName = basename($newClassName, '.orig');
|
||||||
|
$head = [];
|
||||||
|
$head[] = '<?php';
|
||||||
|
$head[] = "namespace $namespace;";
|
||||||
|
if($srcClassName === null){
|
||||||
|
$head[] = "class $newClassName";
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$head[] = "class $newClassName extends $srcClassName";
|
||||||
|
}
|
||||||
|
|
||||||
|
$head[] = '{';
|
||||||
|
$head[] = '';
|
||||||
|
$head = join("\n", $head);
|
||||||
|
|
||||||
|
$body = [];
|
||||||
|
foreach($params as $key=>$value){
|
||||||
|
|
||||||
|
if(!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/',$key)){
|
||||||
|
return "$key is not valid variable name";
|
||||||
|
}
|
||||||
|
|
||||||
|
$body[] = ' public static $'.$key.' = '.var_export($value, true).';';
|
||||||
|
}
|
||||||
|
$tail = "\n}";
|
||||||
|
|
||||||
|
if(file_exists($destFilePath)){
|
||||||
|
unlink($destFilePath);
|
||||||
|
}
|
||||||
|
$result = file_put_contents($destFilePath, $head.join("\n", $body).$tail, LOCK_EX);
|
||||||
|
assert($result);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* '비교적' 안전한 int 변환
|
* '비교적' 안전한 int 변환
|
||||||
* null -> null
|
* null -> null
|
||||||
|
|||||||
Reference in New Issue
Block a user