diff --git a/hwe/d_setting/GameConst.orig.php b/hwe/d_setting/GameConst.orig.php new file mode 100644 index 00000000..f3640da0 --- /dev/null +++ b/hwe/d_setting/GameConst.orig.php @@ -0,0 +1,6 @@ +$this->data['stat']['total']??$default['stat']['total'], - 'statMin'=>$this->data['stat']['min']??$default['stat']['min'], - 'statMax'=>$this->data['stat']['max']??$default['stat']['max'], - 'statNPCMax'=>$this->data['stat']['npcMax']??$default['stat']['npcMax'], - 'statChiefMin'=>$this->data['stat']['chiefMin']??$default['stat']['chiefMin'], + 'defaultStatTotal'=>$this->data['stat']['total']??$default['stat']['total'], + 'defaultStatMin'=>$this->data['stat']['min']??$default['stat']['min'], + 'defaultStatMax'=>$this->data['stat']['max']??$default['stat']['max'], + 'defaultStatNPCMax'=>$this->data['stat']['npcMax']??$default['stat']['npcMax'], + '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']; return $this->gameConf; @@ -358,12 +358,7 @@ class Scenario{ public function buildConf(){ $path = __dir__.'/../d_setting'; - Util::generateFileUsingSimpleTemplate( - $path.'/GameCustomConst.orig.php', - $path.'/GameCustomConst.php', - $this->gameConf, - true - ); + Util::generatePHPClassFile($path.'/GameConst.php', $this->gameConf, 'GameConstBase', 'sammo'); $mapPath = __dir__.'/../scenario/map'; $unitPath = __dir__.'/../scenario/unit'; diff --git a/src/sammo/Util.php b/src/sammo/Util.php index 804106c0..ee8ea87b 100644 --- a/src/sammo/Util.php +++ b/src/sammo/Util.php @@ -128,6 +128,53 @@ class Util extends \utilphp\util 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[] = '$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 변환 * null -> null