blob: 4aabc8a30c587a428701fed31699d0bb7f43f51c (
plain)
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
|
<?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";
$npc = json_decode(file_get_contents($filePath), true);
$slug = $npc['modules/tuxemon.slug'] ?? pathinfo($fileName, PATHINFO_FILENAME);
$npcs[$slug] = [
'slug' => $slug,
'template' => [
[
'sprite_name' => $npc['sprite'],
],
],
];
}
foreach ($npcs as $slug => $npc) {
file_put_contents(__DIR__ . "/_generated/npc/$slug.json", json_encode($npc));
}
|