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
|
<?php
$npcs = [];
// modules/tuxemon
$basePath = dirname(__DIR__) . '/modules/tuxemon/mods/tuxemon/db/npc';
foreach (scandir($basePath) as $fileName) {
if (in_array($fileName, ['.', '..'])) continue;
$filePath = "$basePath/$fileName";
$json = json_decode(file_get_contents($filePath), true);
if (isset($json['slug']) && isset($json['template'])) {
$npcs[$json['slug']] = $json;
} else {
foreach ($json as $npc) {
$npcs[$npc['slug']] = $npc;
}
}
}
// tuxemon clicker
$basePath = __DIR__ . '/npc';
foreach (scandir($basePath) as $fileName) {
if (in_array($fileName, ['.', '..'])) continue;
$filePath = "$basePath/$fileName";
$npcData = json_decode(file_get_contents($filePath), true);
$slug = $npcData['modules/tuxemon.slug'] ?? pathinfo($fileName, PATHINFO_FILENAME);
$npc = [
'slug' => $slug,
'template' => [
[
'sprite_name' => $npcData['sprite'],
'combat_front' => $npcData['sprite'],
],
],
];
if (isset($npcs[$slug])) {
$npcs[$slug] = array_replace_recursive($npcs[$slug], $npc);
} else {
$npcs[$slug] = $npc;
}
}
foreach ($npcs as $slug => $npc) {
file_put_contents(__DIR__ . "/_generated/npc/$slug.json", json_encode($npc));
}
|