diff --git a/system/libs/DataLoader.php b/system/libs/DataLoader.php index 12511e4d..4ca934e4 100644 --- a/system/libs/DataLoader.php +++ b/system/libs/DataLoader.php @@ -63,6 +63,16 @@ class DataLoader self::$startTime = microtime(true); + require LIBS . 'npc.php'; + if(NPCs::loadFromXML()) { + success(self::$locale['step_database_loaded_npcs'] . self::getLoadedTime()); + } + else { + error(self::$locale['step_database_error_npcs']); + } + + self::$startTime = microtime(true); + require LIBS . 'spells.php'; if(Spells::loadFromXML()) { success(self::$locale['step_database_loaded_spells'] . self::getLoadedTime()); @@ -100,4 +110,4 @@ class DataLoader $endTime = round(microtime(true) - self::$startTime, 3); return ' (' . str_replace('$TIME$', $endTime, self::$locale['loaded_in_ms']) . ')'; } -} \ No newline at end of file +} diff --git a/system/libs/npc.php b/system/libs/npc.php new file mode 100644 index 00000000..3229830e --- /dev/null +++ b/system/libs/npc.php @@ -0,0 +1,59 @@ + + * @author Slawkens + * @author Lee + * @copyright 2021 MyAAC + * @link https://my-aac.org + */ +defined('MYAAC') or die('Direct access not allowed!'); + +class NPCs +{ + public static $npcs; + + public static function loadFromXML($show = false) + { + $npc_path = config('data_path') . 'npc/'; + if (!file_exists($npc_path)) + return false; + + $npcs = []; + $xml = new DOMDocument(); + foreach (preg_grep('~\.(xml)$~i', scandir($npc_path)) as $npc) { + $xml->load($npc_path . $npc); + if ($xml) { + $element = $xml->getElementsByTagName('npc')->item(0); + if (isset($element)) { + $name = $element->getAttribute('name'); + if (!empty($name) && !in_array($name, $npcs)) { + $npcs[] = strtolower($name); + } + } + } + } + + if (count($npcs) == 0) { + return false; + } + + require_once LIBS . 'cache_php.php'; + $cache_php = new Cache_PHP(config('cache_prefix'), CACHE); + $cache_php->set('npcs', $npcs, 5 * 365 * 24 * 60 * 60); + return true; + } + + public static function load() + { + if (self::$npcs) { + return; + } + + require_once LIBS . 'cache_php.php'; + $cache_php = new Cache_PHP(config('cache_prefix'), CACHE); + self::$npcs = $cache_php->get('npcs'); + } +} diff --git a/system/locale/en/install.php b/system/locale/en/install.php index 36500d1c..f9e75756 100644 --- a/system/locale/en/install.php +++ b/system/locale/en/install.php @@ -85,6 +85,8 @@ $locale['step_database_loaded_items'] = 'Items has been loaded...'; $locale['step_database_loaded_weapons'] = 'Weapons has been loaded...'; $locale['step_database_loaded_monsters'] = 'Monsters has been loaded...'; $locale['step_database_error_monsters'] = 'There were some problems loading your monsters.xml file. Please check $LOG$ for more info.'; +$locale['step_database_loaded_npcs'] = 'NPCs has been loaded...'; +$locale['step_database_error_npcs'] = 'There were some problems loading your NPCs'; $locale['step_database_loaded_spells'] = 'Spells has been loaded...'; $locale['step_database_loaded_towns'] = 'Towns has been loaded...'; $locale['step_database_error_towns'] = 'There were some problems loading your towns. You will need to configure them manually in config.'; diff --git a/system/locale/pl/install.php b/system/locale/pl/install.php index c54bb30b..c26a5fc9 100644 --- a/system/locale/pl/install.php +++ b/system/locale/pl/install.php @@ -84,6 +84,8 @@ $locale['step_database_loaded_items'] = 'Załadowano przedmioty (items)...'; $locale['step_database_loaded_weapons'] = 'Załadowano bronie (weapons)...'; $locale['step_database_loaded_monsters'] = 'Załadowano potworki (monsters)...'; $locale['step_database_error_monsters'] = 'Wystąpiły problemy podczas ładowania pliku monsters.xml. Zobacz $LOG$ po więcej informacji.'; +$locale['step_database_loaded_npcs'] = 'Załadowano NPCs...'; +$locale['step_database_error_npcs'] = 'Wystąpił problem podczas ładowania NPCs'; $locale['step_database_loaded_spells'] = 'Załadowano czary (spells)...'; $locale['step_database_loaded_towns'] = 'Załadowano miasta (towns)...'; $locale['step_database_error_towns'] = 'Wystąpił problem podczas ładowania miast. Trzeba będzie je skonfigurować manualnie.'; diff --git a/system/templates/admin.data.html.twig b/system/templates/admin.data.html.twig index 9ff8c1bc..17fcbc76 100644 --- a/system/templates/admin.data.html.twig +++ b/system/templates/admin.data.html.twig @@ -1,11 +1,11 @@ -

Clicking the button will reload server data (items, monsters, spells, towns, weapons).

+

Clicking the button will reload server data (items, monsters, npcs, spells, towns, weapons).

It may take up to few minutes.

-
- Loading... -
- +
@@ -19,6 +19,7 @@ $(function () { $('#reload_button').on('click', function (e) { $('#spinner').show(); + $('#reload_button').hide(); $('[id^=success]').remove(); $('#messages').append('
'); diff --git a/tools/installer.js b/tools/installer.js index 9f7492ba..a17b970a 100644 --- a/tools/installer.js +++ b/tools/installer.js @@ -31,6 +31,7 @@ function performInstall(url) { // On completed ajaxRequest.done(function(data) { $('#spinner').hide(); + $('#reload_button').show(); }); // On failed ajaxRequest.fail(function(error){