Admin - Dataloader updates

-Npc Lib added
-Admin Dataloader updated to load NPC names into a cached array.
-Spinner Updated to a loading button.
This commit is contained in:
Lee 2021-03-09 23:38:23 +00:00
parent 7ce005341e
commit 31f0050f4e
6 changed files with 81 additions and 6 deletions

View File

@ -63,6 +63,16 @@ class DataLoader
self::$startTime = microtime(true); 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'; require LIBS . 'spells.php';
if(Spells::loadFromXML()) { if(Spells::loadFromXML()) {
success(self::$locale['step_database_loaded_spells'] . self::getLoadedTime()); success(self::$locale['step_database_loaded_spells'] . self::getLoadedTime());
@ -100,4 +110,4 @@ class DataLoader
$endTime = round(microtime(true) - self::$startTime, 3); $endTime = round(microtime(true) - self::$startTime, 3);
return ' (' . str_replace('$TIME$', $endTime, self::$locale['loaded_in_ms']) . ')'; return ' (' . str_replace('$TIME$', $endTime, self::$locale['loaded_in_ms']) . ')';
} }
} }

59
system/libs/npc.php Normal file
View File

@ -0,0 +1,59 @@
<?php
/**
* NPC class
*
* @package MyAAC
* @author Gesior <jerzyskalski@wp.pl>
* @author Slawkens <slawkens@gmail.com>
* @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');
}
}

View File

@ -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_weapons'] = 'Weapons has been loaded...';
$locale['step_database_loaded_monsters'] = 'Monsters 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_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_spells'] = 'Spells has been loaded...';
$locale['step_database_loaded_towns'] = 'Towns 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.'; $locale['step_database_error_towns'] = 'There were some problems loading your towns. You will need to configure them manually in config.';

View File

@ -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_weapons'] = 'Załadowano bronie (weapons)...';
$locale['step_database_loaded_monsters'] = 'Załadowano potworki (monsters)...'; $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_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_spells'] = 'Załadowano czary (spells)...';
$locale['step_database_loaded_towns'] = 'Załadowano miasta (towns)...'; $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.'; $locale['step_database_error_towns'] = 'Wystąpił problem podczas ładowania miast. Trzeba będzie je skonfigurować manualnie.';

View File

@ -1,11 +1,11 @@
<p>Clicking the button will reload server data (items, monsters, spells, towns, weapons).</p> <p>Clicking the button will reload server data (items, monsters, npcs, spells, towns, weapons).</p>
<p>It may take up to few minutes.</p> <p>It may take up to few minutes.</p>
<button id="reload_button" class="btn btn-info"><i class="fas fa-update"></i>Reload</button> <button id="reload_button" class="btn btn-info"><i class="fas fa-update"></i>Reload</button>
<div id="spinner" class="spinner-border" role="status"> <button id="spinner" class="btn btn-info" type="button" disabled>
<span class="sr-only">Loading...</span> <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
</div> Loading...
</button>
<div style="height: 20px"></div> <div style="height: 20px"></div>
<div id="messages"></div> <div id="messages"></div>
@ -19,6 +19,7 @@
$(function () { $(function () {
$('#reload_button').on('click', function (e) { $('#reload_button').on('click', function (e) {
$('#spinner').show(); $('#spinner').show();
$('#reload_button').hide();
$('[id^=success]').remove(); $('[id^=success]').remove();
$('#messages').append('<div id="success-1"></div>'); $('#messages').append('<div id="success-1"></div>');

View File

@ -31,6 +31,7 @@ function performInstall(url) {
// On completed // On completed
ajaxRequest.done(function(data) { ajaxRequest.done(function(data) {
$('#spinner').hide(); $('#spinner').hide();
$('#reload_button').show();
}); });
// On failed // On failed
ajaxRequest.fail(function(error){ ajaxRequest.fail(function(error){