Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- declare(strict_types=1);
- $debug = true;
- $save_columns = [
- 'Adventurers' => [
- 'Id',
- 'Name',
- 'NameJP',
- 'WeaponTypeId',
- 'Rarity',
- 'ElementalType',
- 'ElementalTypeId',
- 'CharaType',
- 'VariationId',
- 'MinHp3',
- 'MinHp4',
- 'MinHp5',
- 'MaxHp',
- 'MinAtk3',
- 'MinAtk4',
- 'MinAtk5',
- 'MaxAtk',
- 'PlusHp0', // マナサークル1段目
- 'PlusHp1',
- 'PlusHp2',
- 'PlusHp3',
- 'PlusHp4',
- 'McFullBonusHp5', // ManaCircleFullBonusHp
- 'PlusAtk0',
- 'PlusAtk1',
- 'PlusAtk2',
- 'PlusAtk3',
- 'PlusAtk4',
- 'McFullBonusAtk5',
- 'MinDef',
- 'DefCoef', // MinDefと同じ値、敵の場合のOD時?
- 'Abilities11',
- 'Abilities12',
- 'Abilities13',
- 'Abilities14',
- 'Abilities21',
- 'Abilities22',
- 'Abilities23',
- 'Abilities24',
- 'Abilities31',
- 'Abilities32',
- 'Abilities33',
- 'Abilities34',
- 'ExAbilityData1',
- 'ExAbilityData2',
- 'ExAbilityData3',
- 'ExAbilityData4',
- 'ExAbilityData5',
- 'ManaCircleName',
- ],
- 'Dragons' => [
- 'BaseId',
- 'Id',
- 'Name',
- 'NameJP',
- 'Rarity',
- 'ElementalType',
- 'ElementalTypeId',
- 'MinHp',
- 'MaxHp',
- 'MinAtk',
- 'MaxAtk',
- 'Skill1',
- 'Abilities11',
- 'Abilities12',
- 'Abilities21',
- 'Abilities22',
- 'FavoriteType',
- 'ReleaseDate',
- ],
- 'Skills' => [
- 'SkillId',
- 'SkillLv1IconName',
- 'SkillLv2IconName',
- 'SkillLv3IconName',
- 'HideLevel3',
- 'Sp',
- 'SPLv2',
- ],
- 'CoAbilities' => [
- 'Id',
- 'AbilityIconName',
- 'Category',
- 'PartyPowerWeight',
- ],
- 'Weapons' => [
- 'Id',
- 'BaseId',
- 'FormId',
- 'WeaponName',
- 'WeaponNameJP',
- 'Type',
- 'TypeId',
- 'Rarity',
- 'ElementalType',
- 'ElementalTypeId',
- 'MinHp',
- 'MaxHp',
- 'MinAtk',
- 'MaxAtk',
- 'VariationId',
- 'Skill',
- 'Abilities11',
- 'Abilities21',
- 'CraftNodeId',
- 'ParentCraftNodeId',
- 'CraftGroupId',
- 'AssembleCoin', // 制作費用
- 'DisassembleCoin', // 分解費用
- 'MainWeaponId',
- 'CraftMaterialType1',
- 'CraftMaterial1',
- 'CraftMaterialQuantity1',
- 'CraftMaterialType2',
- 'CraftMaterial2',
- 'CraftMaterialQuantity2',
- 'CraftMaterialType3',
- 'CraftMaterial3',
- 'CraftMaterialQuantity3',
- 'CraftMaterialType4',
- 'CraftMaterial4',
- 'CraftMaterialQuantity4',
- 'CraftMaterialType5',
- 'CraftMaterial5',
- 'CraftMaterialQuantity5',
- ],
- 'Wyrmprints' => [
- 'BaseId',
- 'Name',
- 'NameJP',
- 'Rarity',
- 'MinHp',
- 'MaxHp',
- 'MinAtk',
- 'MaxAtk',
- 'VariationId',
- 'Abilities11',
- 'Abilities12',
- 'Abilities13',
- 'Abilities21',
- 'Abilities22',
- 'Abilities23',
- 'Abilities31',
- 'Abilities32',
- 'Abilities33',
- ],
- 'Abilities' => [
- 'Id',
- 'GenericName',
- 'Name',
- 'Details',
- 'AbilityIconName',
- 'AbilityGroup',
- 'PartyPowerWeight',
- 'AbilityLimitedGroupId1',
- 'AbilityLimitedGroupId2',
- 'AbilityLimitedGroupId3',
- ],
- 'AbilityLimitedGroup' => [
- 'Id',
- 'IsEffectMix',
- 'MaxLimitedValue',
- ],
- 'Gifts' => ['Id', 'Name', 'FavoriteType',],
- ];
- function combine_header(array $jsonObject): array {
- $header = array_shift($jsonObject);
- foreach ($jsonObject as &$row) {
- $row = array_combine($header, $row);
- }
- return $jsonObject;
- }
- function filter_columns(array &$row, string $key, array $save_columns): void {
- foreach ($row as $column => &$value) {
- if ( ! in_array($column, $save_columns)) {
- unset($row[$column]);
- }
- if (strpos($value, ',') !== false && preg_match('/^[0-9,]+$/', $value)) {
- $value = str_replace(',', '', $value);
- }
- if (is_numeric($value)) {
- $value = (int)$value;
- }
- }
- }
- function master_Adventurers(array &$jsonObject): void {
- foreach ($jsonObject as $i => &$row) {
- $row['Name'] = $row['NameJP'];
- unset($row['NameJP']);
- if ( ! is_numeric($row['Id'])) {
- log_debug("deleted: {$row['Id']} in " . __METHOD__);
- unset($jsonObject[$i]);
- }
- }
- $jsonObject = array_values($jsonObject);
- }
- function master_Weapons(array &$jsonObject): void {
- foreach ($jsonObject as $i => &$row) {
- $row['Name'] = empty($row['WeaponNameJP']) ? $row['WeaponName'] : $row['WeaponNameJP'];
- unset($row['WeaponNameJP']);
- if ( ! is_numeric($row['Id'])) {
- log_debug("deleted: {$row['Id']} in " . __METHOD__);
- unset($jsonObject[$i]);
- }
- if ($row['Id'] == 39900001) {
- log_debug("deleted: {$row['Id']} in " . __METHOD__);
- unset($jsonObject[$i]);
- }
- }
- $jsonObject = array_values($jsonObject);
- }
- function master_Dragons(array &$jsonObject): void {
- foreach ($jsonObject as $i => &$row) {
- $row['Name'] = $row['NameJP'];
- unset($row['NameJP']);
- if ( ! is_numeric($row['Id'])) {
- log_debug("deleted: {$row['Id']} in " . __METHOD__);
- unset($jsonObject[$i]);
- }
- if (empty($row['Name'])) {
- log_debug("deleted: {$row['Id']} in " . __METHOD__);
- unset($jsonObject[$i]);
- }
- if (strtotime($row['ReleaseDate']) > strtotime('+1 year')) {
- log_debug("deleted: {$row['Id']} in " . __METHOD__);
- unset($jsonObject[$i]);
- }
- unset($row['ReleaseDate']);
- }
- $jsonObject = array_values($jsonObject);
- }
- function log_debug(string $message): void {
- global $debug;
- if ($debug) {
- echo $message . PHP_EOL;
- }
- }
- $assetsPath = __DIR__;
- // CSV
- foreach (glob($assetsPath . '/*.csv') as $path) {
- log_debug("opened: {$path}");
- $name = basename($path, '.csv');
- $csv = array_map('str_getcsv', file($path));
- $header = array_shift($csv);
- $data = array_map(function ($row) use ($header) {
- return array_combine($header, array_map(function ($value) {
- if ($value === 'TRUE') { return true; }
- if ($value === 'FALSE') { return false; }
- return $value;
- }, $row));
- }, $csv);
- $outputPath = "{$assetsPath}/json/{$name}.json";
- file_put_contents($outputPath, json_encode($data, JSON_PRETTY_PRINT));
- file_put_contents("{$assetsPath}/json/{$name}.min.json", json_encode($data));
- log_debug("saved: {$outputPath}");
- }
- // JSON
- foreach (glob($assetsPath . '/*.json') as $path) {
- $inputJson = file_get_contents($path);
- if ($inputJson === false) {
- echo "failed to open {$path}";
- continue;
- }
- log_debug("opend: {$path}");
- $name = basename($path, '.json');
- $jsonObject = combine_header(json_decode($inputJson));
- if (array_key_exists($name, $save_columns)) {
- array_walk($jsonObject, 'filter_columns', $save_columns[$name]);
- }
- $method = "master_{$name}";
- if (function_exists($method)) {
- $method($jsonObject);
- }
- $outputPath = "{$assetsPath}/json/{$name}.json";
- file_put_contents($outputPath, json_encode($jsonObject, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
- file_put_contents("{$assetsPath}/json/{$name}.min.json", json_encode($jsonObject));
- log_debug("saved: {$outputPath}");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement