-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrename.php
146 lines (139 loc) · 6.85 KB
/
rename.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
include('config.php');
/* Current mega icons */
$megaPokemon = [3, 6, 9, 15, 18, 65, 94, 115, 127, 130, 142, 150, 181, 229, 302, 303, 310, 334, 354, 384, 428, 460];
/* Start processing pokemon icons */
$iconsInFolder = dirtree($oldIconPath);
foreach ($iconsInFolder as $k => $icon) {
if (!is_array($icon)) {
$oldIcon = $oldIconPath . $icon;
if (str_starts_with($icon, 'pokemon_icon_')) {
$iconInfo = explode('_', (basename(str_replace('pokemon_icon_', '', $icon), '.png')));
$pokemonId = ($iconInfo[0] === '000') ? '0' : ltrim($iconInfo[0], '0');
$formId = ($iconInfo[1] === '00') ? '' : '_f' . ltrim($iconInfo[1], '0');
$evolutionId = '';
$costumeId = '';
$genderId = '';
$shiny = '';
if (in_array($pokemonId, $megaPokemon)) {
$evolutionId = array_key_exists(2, $iconInfo) ? '_e' . ltrim($iconInfo[2], '0') : '';
if (array_key_exists(3, $iconInfo)) {
$costumeId = ($iconInfo[3] === 'shiny' && $iconInfo[2] > 0) ? '' : '_c' . ltrim($iconInfo[3], '0');
$shiny = $iconInfo[3] === 'shiny' ? '_s' : '';
}
} else {
if (array_key_exists(2, $iconInfo)) {
$costumeId = ($iconInfo[2] === 'shiny' && $iconInfo[2] > 0) ? '' : '_c' . ltrim($iconInfo[2], '0');
$shiny = $iconInfo[2] === 'shiny' ? '_s' : '';
}
}
if (!is_dir($newIconPath . 'pokemon')) {
mkdir($newIconPath . 'pokemon', 0755);
echo 'New pokemon folder created.' . PHP_EOL;
}
$newIcon = $newIconPath . 'pokemon/' . $pokemonId . $evolutionId . $formId . $costumeId . $genderId . $shiny . '.png';
print_r('Old icon name: ' . $icon . " \t New icon name: " . $newIcon . PHP_EOL);
copy($oldIcon, $newIcon);
}
/* Start processing reward icons*/
} else if ($k == 'rewards') {
$rewardsInFolder = dirtree($oldIconPath . 'rewards');
foreach ($rewardsInFolder as $k => $reward) {
$oldRewardIcon = $oldIconPath . 'rewards/' . $reward;
if (str_starts_with($reward, 'reward_') && ! str_starts_with($reward, 'reward_mega') && ! str_starts_with($reward, 'reward_stardust')) {
$rewardInfo = explode('_', (basename(str_replace('reward_', '', $reward), '.png')));
$itemId = $rewardInfo[0];
$itemAmount = array_key_exists(1, $rewardInfo) ? (($rewardInfo[1] > 0) ? '_a' . $rewardInfo[1] : '') : '';
if (!is_dir($newIconPath . 'reward')) {
mkdir($newIconPath . 'reward', 0755);
echo 'New reward folder created.' . PHP_EOL;
}
if (!is_dir($newIconPath . 'reward/item')) {
mkdir($newIconPath . 'reward/item', 0755);
echo 'New item folder created.' . PHP_EOL;
}
$newRewardIcon = $newIconPath . 'reward/item/' . $itemId . $itemAmount . '.png';
print_r('Old icon name: ' . $reward . " \t New icon name: " . $newRewardIcon . PHP_EOL);
copy($oldRewardIcon, $newRewardIcon);
}
if (str_starts_with($reward, 'reward_mega_energy')) {
$megaInfo = explode('_', (basename(str_replace('reward_mega_energy_', '', $reward), '.png')));
$megaId = is_array($megaInfo) ? $megaInfo[0] : '0';
if (!is_dir($newIconPath . 'reward')) {
mkdir($newIconPath . 'reward', 0755);
echo 'New reward folder created.' . PHP_EOL;
}
if (!is_dir($newIconPath . 'reward/mega_resource')) {
mkdir($newIconPath . 'reward/mega_resource', 0755);
echo 'New mega_resource folder created.' . PHP_EOL;
}
if ($reward === 'reward_mega_energy.png') {
$megaId = '0';
}
$newMegaIcon = $newIconPath . 'reward/mega_resource/' . $megaId . '.png';
print_r('Old icon name: ' . $reward . " \t New icon name: " . $newMegaIcon . PHP_EOL);
copy($oldRewardIcon, $newMegaIcon);
}
if (str_starts_with($reward, 'reward_stardust')) {
$dustInfo = explode('_', (basename(str_replace('reward_stardust_', '', $reward), '.png')));
$dustAmount = is_array($dustInfo) ? $dustInfo[0] : '0';
if (!is_dir($newIconPath . 'reward')) {
mkdir($newIconPath . 'reward', 0755);
echo 'New reward folder created.' . PHP_EOL;
}
if (!is_dir($newIconPath . 'reward/stardust')) {
mkdir($newIconPath . 'reward/stardust', 0755);
echo 'New stardust folder created.' . PHP_EOL;
}
if ($reward === 'reward_stardust.png') {
$dustAmount = '0';
}
$newDustIcon = $newIconPath . 'reward/stardust/' . $dustAmount . '.png';
print_r('Old icon name: ' . $reward . " \t New icon name: " . $newDustIcon . PHP_EOL);
copy($oldRewardIcon, $newDustIcon);
}
}
}
}
/* Create master json file */
file_put_contents($newIconPath . 'index.json', json_encode(dirtree($newIconPath)));
/* Create subfolder json files */
foreach (dirtree($newIconPath) as $k => $dir) {
if (is_dir($newIconPath . $k)) {
$jsonFile = $newIconPath . $k . DIRECTORY_SEPARATOR . 'index.json';
$directory = dirtree($newIconPath . $k);
file_put_contents($jsonFile, json_encode($directory));
}
if ($k === 'reward') {
foreach ($dir as $ks => $subdir) {
if (is_dir($newIconPath . $k . DIRECTORY_SEPARATOR . $ks)) {
$jsonFile = $newIconPath . $k . DIRECTORY_SEPARATOR . $ks . DIRECTORY_SEPARATOR . 'index.json';
$directory = dirtree($newIconPath . $k . DIRECTORY_SEPARATOR . $ks);
file_put_contents($jsonFile, json_encode($directory));
}
}
}
}
function dirtree($dir, $ignoreEmpty=false) {
if (!$dir instanceof DirectoryIterator) {
$dir = new DirectoryIterator((string)$dir);
}
$dirs = array();
$files = array();
foreach ($dir as $node) {
if ($node->isDir() && !$node->isDot()) {
$tree = dirtree($node->getPathname(), $ignoreEmpty);
if (!$ignoreEmpty || count($tree)) {
$dirs[$node->getFilename()] = $tree;
}
} elseif ($node->isFile()) {
$name = $node->getFilename();
if (!str_ends_with($name, '.json')) {
$files[] = $name;
}
}
}
asort($dirs);
sort($files);
return array_merge($dirs, $files);
}