Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.73 KB | None | 0 0
  1. <?php
  2. declare(strict_types=1);
  3.  
  4. $debug = true;
  5.  
  6. $save_columns = [
  7. 'Adventurers' => [
  8. 'Id',
  9. 'Name',
  10. 'NameJP',
  11. 'WeaponTypeId',
  12. 'Rarity',
  13. 'ElementalType',
  14. 'ElementalTypeId',
  15. 'CharaType',
  16. 'VariationId',
  17. 'MinHp3',
  18. 'MinHp4',
  19. 'MinHp5',
  20. 'MaxHp',
  21. 'MinAtk3',
  22. 'MinAtk4',
  23. 'MinAtk5',
  24. 'MaxAtk',
  25. 'PlusHp0', // マナサークル1段目
  26. 'PlusHp1',
  27. 'PlusHp2',
  28. 'PlusHp3',
  29. 'PlusHp4',
  30. 'McFullBonusHp5', // ManaCircleFullBonusHp
  31. 'PlusAtk0',
  32. 'PlusAtk1',
  33. 'PlusAtk2',
  34. 'PlusAtk3',
  35. 'PlusAtk4',
  36. 'McFullBonusAtk5',
  37. 'MinDef',
  38. 'DefCoef', // MinDefと同じ値、敵の場合のOD時?
  39. 'Abilities11',
  40. 'Abilities12',
  41. 'Abilities13',
  42. 'Abilities14',
  43. 'Abilities21',
  44. 'Abilities22',
  45. 'Abilities23',
  46. 'Abilities24',
  47. 'Abilities31',
  48. 'Abilities32',
  49. 'Abilities33',
  50. 'Abilities34',
  51. 'ExAbilityData1',
  52. 'ExAbilityData2',
  53. 'ExAbilityData3',
  54. 'ExAbilityData4',
  55. 'ExAbilityData5',
  56. 'ManaCircleName',
  57. ],
  58. 'Dragons' => [
  59. 'BaseId',
  60. 'Id',
  61. 'Name',
  62. 'NameJP',
  63. 'Rarity',
  64. 'ElementalType',
  65. 'ElementalTypeId',
  66. 'MinHp',
  67. 'MaxHp',
  68. 'MinAtk',
  69. 'MaxAtk',
  70. 'Skill1',
  71. 'Abilities11',
  72. 'Abilities12',
  73. 'Abilities21',
  74. 'Abilities22',
  75. 'FavoriteType',
  76. 'ReleaseDate',
  77. ],
  78. 'Skills' => [
  79. 'SkillId',
  80. 'SkillLv1IconName',
  81. 'SkillLv2IconName',
  82. 'SkillLv3IconName',
  83. 'HideLevel3',
  84. 'Sp',
  85. 'SPLv2',
  86. ],
  87. 'CoAbilities' => [
  88. 'Id',
  89. 'AbilityIconName',
  90. 'Category',
  91. 'PartyPowerWeight',
  92. ],
  93. 'Weapons' => [
  94. 'Id',
  95. 'BaseId',
  96. 'FormId',
  97. 'WeaponName',
  98. 'WeaponNameJP',
  99. 'Type',
  100. 'TypeId',
  101. 'Rarity',
  102. 'ElementalType',
  103. 'ElementalTypeId',
  104. 'MinHp',
  105. 'MaxHp',
  106. 'MinAtk',
  107. 'MaxAtk',
  108. 'VariationId',
  109. 'Skill',
  110. 'Abilities11',
  111. 'Abilities21',
  112. 'CraftNodeId',
  113. 'ParentCraftNodeId',
  114. 'CraftGroupId',
  115. 'AssembleCoin', // 制作費用
  116. 'DisassembleCoin', // 分解費用
  117. 'MainWeaponId',
  118. 'CraftMaterialType1',
  119. 'CraftMaterial1',
  120. 'CraftMaterialQuantity1',
  121. 'CraftMaterialType2',
  122. 'CraftMaterial2',
  123. 'CraftMaterialQuantity2',
  124. 'CraftMaterialType3',
  125. 'CraftMaterial3',
  126. 'CraftMaterialQuantity3',
  127. 'CraftMaterialType4',
  128. 'CraftMaterial4',
  129. 'CraftMaterialQuantity4',
  130. 'CraftMaterialType5',
  131. 'CraftMaterial5',
  132. 'CraftMaterialQuantity5',
  133. ],
  134. 'Wyrmprints' => [
  135. 'BaseId',
  136. 'Name',
  137. 'NameJP',
  138. 'Rarity',
  139. 'MinHp',
  140. 'MaxHp',
  141. 'MinAtk',
  142. 'MaxAtk',
  143. 'VariationId',
  144. 'Abilities11',
  145. 'Abilities12',
  146. 'Abilities13',
  147. 'Abilities21',
  148. 'Abilities22',
  149. 'Abilities23',
  150. 'Abilities31',
  151. 'Abilities32',
  152. 'Abilities33',
  153. ],
  154. 'Abilities' => [
  155. 'Id',
  156. 'GenericName',
  157. 'Name',
  158. 'Details',
  159. 'AbilityIconName',
  160. 'AbilityGroup',
  161. 'PartyPowerWeight',
  162. 'AbilityLimitedGroupId1',
  163. 'AbilityLimitedGroupId2',
  164. 'AbilityLimitedGroupId3',
  165. ],
  166. 'AbilityLimitedGroup' => [
  167. 'Id',
  168. 'IsEffectMix',
  169. 'MaxLimitedValue',
  170. ],
  171. 'Gifts' => ['Id', 'Name', 'FavoriteType',],
  172. ];
  173.  
  174. function combine_header(array $jsonObject): array {
  175. $header = array_shift($jsonObject);
  176. foreach ($jsonObject as &$row) {
  177. $row = array_combine($header, $row);
  178. }
  179. return $jsonObject;
  180. }
  181.  
  182. function filter_columns(array &$row, string $key, array $save_columns): void {
  183. foreach ($row as $column => &$value) {
  184. if ( ! in_array($column, $save_columns)) {
  185. unset($row[$column]);
  186. }
  187.  
  188. if (strpos($value, ',') !== false && preg_match('/^[0-9,]+$/', $value)) {
  189. $value = str_replace(',', '', $value);
  190. }
  191.  
  192. if (is_numeric($value)) {
  193. $value = (int)$value;
  194. }
  195. }
  196. }
  197.  
  198. function master_Adventurers(array &$jsonObject): void {
  199. foreach ($jsonObject as $i => &$row) {
  200. $row['Name'] = $row['NameJP'];
  201. unset($row['NameJP']);
  202.  
  203. if ( ! is_numeric($row['Id'])) {
  204. log_debug("deleted: {$row['Id']} in " . __METHOD__);
  205. unset($jsonObject[$i]);
  206. }
  207. }
  208. $jsonObject = array_values($jsonObject);
  209. }
  210.  
  211. function master_Weapons(array &$jsonObject): void {
  212. foreach ($jsonObject as $i => &$row) {
  213. $row['Name'] = empty($row['WeaponNameJP']) ? $row['WeaponName'] : $row['WeaponNameJP'];
  214. unset($row['WeaponNameJP']);
  215.  
  216. if ( ! is_numeric($row['Id'])) {
  217. log_debug("deleted: {$row['Id']} in " . __METHOD__);
  218. unset($jsonObject[$i]);
  219. }
  220.  
  221. if ($row['Id'] == 39900001) {
  222. log_debug("deleted: {$row['Id']} in " . __METHOD__);
  223. unset($jsonObject[$i]);
  224. }
  225. }
  226. $jsonObject = array_values($jsonObject);
  227. }
  228.  
  229. function master_Dragons(array &$jsonObject): void {
  230. foreach ($jsonObject as $i => &$row) {
  231. $row['Name'] = $row['NameJP'];
  232. unset($row['NameJP']);
  233.  
  234. if ( ! is_numeric($row['Id'])) {
  235. log_debug("deleted: {$row['Id']} in " . __METHOD__);
  236. unset($jsonObject[$i]);
  237. }
  238.  
  239. if (empty($row['Name'])) {
  240. log_debug("deleted: {$row['Id']} in " . __METHOD__);
  241. unset($jsonObject[$i]);
  242. }
  243.  
  244. if (strtotime($row['ReleaseDate']) > strtotime('+1 year')) {
  245. log_debug("deleted: {$row['Id']} in " . __METHOD__);
  246. unset($jsonObject[$i]);
  247. }
  248.  
  249. unset($row['ReleaseDate']);
  250. }
  251. $jsonObject = array_values($jsonObject);
  252. }
  253.  
  254. function log_debug(string $message): void {
  255. global $debug;
  256. if ($debug) {
  257. echo $message . PHP_EOL;
  258. }
  259. }
  260.  
  261. $assetsPath = __DIR__;
  262.  
  263. // CSV
  264. foreach (glob($assetsPath . '/*.csv') as $path) {
  265. log_debug("opened: {$path}");
  266. $name = basename($path, '.csv');
  267.  
  268. $csv = array_map('str_getcsv', file($path));
  269. $header = array_shift($csv);
  270. $data = array_map(function ($row) use ($header) {
  271. return array_combine($header, array_map(function ($value) {
  272. if ($value === 'TRUE') { return true; }
  273. if ($value === 'FALSE') { return false; }
  274. return $value;
  275. }, $row));
  276. }, $csv);
  277.  
  278. $outputPath = "{$assetsPath}/json/{$name}.json";
  279. file_put_contents($outputPath, json_encode($data, JSON_PRETTY_PRINT));
  280. file_put_contents("{$assetsPath}/json/{$name}.min.json", json_encode($data));
  281. log_debug("saved: {$outputPath}");
  282. }
  283.  
  284. // JSON
  285. foreach (glob($assetsPath . '/*.json') as $path) {
  286. $inputJson = file_get_contents($path);
  287. if ($inputJson === false) {
  288. echo "failed to open {$path}";
  289. continue;
  290. }
  291. log_debug("opend: {$path}");
  292. $name = basename($path, '.json');
  293.  
  294. $jsonObject = combine_header(json_decode($inputJson));
  295. if (array_key_exists($name, $save_columns)) {
  296. array_walk($jsonObject, 'filter_columns', $save_columns[$name]);
  297. }
  298. $method = "master_{$name}";
  299. if (function_exists($method)) {
  300. $method($jsonObject);
  301. }
  302.  
  303. $outputPath = "{$assetsPath}/json/{$name}.json";
  304. file_put_contents($outputPath, json_encode($jsonObject, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
  305. file_put_contents("{$assetsPath}/json/{$name}.min.json", json_encode($jsonObject));
  306. log_debug("saved: {$outputPath}");
  307. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement