From c657c77d0cf49afba627b93848e1915e2ce7d3ff Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Thu, 31 Aug 2023 20:23:06 +0200 Subject: story and npcs --- db/areas.php | 49 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) (limited to 'db/areas.php') diff --git a/db/areas.php b/db/areas.php index d2c9af9..fd0943a 100644 --- a/db/areas.php +++ b/db/areas.php @@ -8,16 +8,15 @@ foreach (scandir(__DIR__ . '/areas') as $file) { $area = json_decode(file_get_contents($filePath), true); - $encounterSlug = $area['modules/tuxemon.encounter'] ?? ''; - $encounters = json_decode(@file_get_contents(dirname(__DIR__) . "/modules/tuxemon/mods/tuxemon/db/encounter/$encounterSlug.json") ?? '', true); - - $environmentSlug = $area['modules/tuxemon.environment'] ?? ''; - $environment = json_decode(@file_get_contents(dirname(__DIR__) . "/modules/tuxemon/mods/tuxemon/db/environment/$environmentSlug.json") ?? '', true); - $map = @file_get_contents(__DIR__ . "/maps/$fileName.svg"); + // encounters $area['encounters'] ??= []; + + $encounterSlug = $area['modules/tuxemon.encounter'] ?? ''; + $encounters = json_decode(@file_get_contents(dirname(__DIR__) . "/modules/tuxemon/mods/tuxemon/db/encounter/$encounterSlug.json") ?? '', true); array_push($area['encounters'], ...$encounters['monsters'] ?? []); + if (! empty($area['encounters'])) { // filter out duplicates, because day/night is ignored for now $duplicates = []; @@ -34,16 +33,38 @@ foreach (scandir(__DIR__ . '/areas') as $file) { } $area['encounter_percent_total'] = array_sum(array_column($area['encounters'], 'encounter_percent')); } + $area['requiredEncounters'] ??= 0; + + // trainers + $area['trainers'] ??= []; + + // environment + + $environmentSlug = $area['modules/tuxemon.environment'] ?? ''; + $environment = json_decode(@file_get_contents(dirname(__DIR__) . "/modules/tuxemon/mods/tuxemon/db/environment/$environmentSlug.json") ?? '', true); + + if (isset($area['environment'])) { + $environment = json_decode(file_get_contents(__DIR__ . "/environment/$area[environment].json"), true); + $environment['battle_graphics']['background'] = '/db/environment/' . $environment['battle_graphics']['background']; + } else if (! empty($environment)) { + $environment['battle_graphics']['background'] = '/modules/tuxemon/mods/tuxemon/gfx/ui/combat/' . $environment['battle_graphics']['background']; + } + $area['environment'] = $environment; + + + // map + + $map = @file_get_contents(__DIR__ . "/maps/$fileName.svg"); + $area['map'] = $map; - foreach ($area['connections'] as $areaSlug => $connection) { - $area['connections'][$areaSlug]['modules/tuxemon.slug'] = json_decode(@file_get_contents(__DIR__ . "/areas/$areaSlug.json") ?? '', true)['modules/tuxemon.slug'] ?? ''; - } + + // locations $area['locations'] ??= []; foreach ($area['locations'] as $locationId => $location) { @@ -54,5 +75,15 @@ foreach (scandir(__DIR__ . '/areas') as $file) { } } + + // connections + + foreach ($area['connections'] as $areaSlug => $connection) { + $area['connections'][$areaSlug]['modules/tuxemon.slug'] = json_decode(@file_get_contents(__DIR__ . "/areas/$areaSlug.json") ?? '', true)['modules/tuxemon.slug'] ?? ''; + } + + + // build + file_put_contents(__DIR__ . "/_generated/areas/$fileName.json", json_encode($area)); } -- cgit v1.2.3