mirror of
https://github.com/slawkens/myaac.git
synced 2025-05-06 14:19:21 +02:00
Better monster images (no image not found anymore) + use cache
This commit is contained in:
parent
497338c2d6
commit
73a5829974
@ -74,7 +74,3 @@ function fieldExist($field, $table)
|
||||
global $db;
|
||||
return $db->hasColumn($table, $field);
|
||||
}
|
||||
|
||||
function getCreatureImgPath($creature): string {
|
||||
return getMonsterImgPath($creature);
|
||||
}
|
||||
|
@ -1572,22 +1572,6 @@ function right($str, $length) {
|
||||
return substr($str, -$length);
|
||||
}
|
||||
|
||||
function getMonsterImgPath($monster): string
|
||||
{
|
||||
$monster_path = setting('core.monsters_images_url');
|
||||
$monster_gfx_name = trim(strtolower($monster)) . setting('core.monsters_images_extension');
|
||||
if (!file_exists($monster_path . $monster_gfx_name)) {
|
||||
$monster_gfx_name = str_replace(" ", "", $monster_gfx_name);
|
||||
if (file_exists($monster_path . $monster_gfx_name)) {
|
||||
return $monster_path . $monster_gfx_name;
|
||||
} else {
|
||||
return $monster_path . 'nophoto.png';
|
||||
}
|
||||
} else {
|
||||
return $monster_path . $monster_gfx_name;
|
||||
}
|
||||
}
|
||||
|
||||
function between($x, $lim1, $lim2) {
|
||||
if ($lim1 < $lim2) {
|
||||
$lower = $lim1; $upper = $lim2;
|
||||
|
@ -284,7 +284,7 @@ class OTS_Monster extends DOMDocument
|
||||
*/
|
||||
public function getLook()
|
||||
{
|
||||
$look = array();
|
||||
$look = [];
|
||||
|
||||
$element = $this->documentElement->getElementsByTagName('look')->item(0);
|
||||
|
||||
@ -292,14 +292,30 @@ class OTS_Monster extends DOMDocument
|
||||
return $look;
|
||||
}
|
||||
|
||||
$look['type'] = $element->getAttribute('type');
|
||||
$look['typeex'] = $element->getAttribute('typeex');
|
||||
$look['head'] = $element->getAttribute('head');
|
||||
$look['body'] = $element->getAttribute('body');
|
||||
$look['legs'] = $element->getAttribute('legs');
|
||||
$look['feet'] = $element->getAttribute('feet');
|
||||
$look['addons'] = $element->getAttribute('addons');
|
||||
$look['corpse'] = $element->getAttribute('corpse');
|
||||
if ($element->hasAttribute('typeex')) {
|
||||
$look['typeEx'] = (int) $element->getAttribute('typeex');
|
||||
}
|
||||
if ($element->hasAttribute('type')) {
|
||||
$look['type'] = (int) $element->getAttribute('type');
|
||||
}
|
||||
if ($element->hasAttribute('head')) {
|
||||
$look['head'] = (int) $element->getAttribute('head');
|
||||
}
|
||||
if ($element->hasAttribute('body')) {
|
||||
$look['body'] = (int) $element->getAttribute('body');
|
||||
}
|
||||
if ($element->hasAttribute('legs')) {
|
||||
$look['legs'] = (int) $element->getAttribute('legs');
|
||||
}
|
||||
if ($element->hasAttribute('feet')) {
|
||||
$look['feet'] = (int) $element->getAttribute('feet');
|
||||
}
|
||||
if ($element->hasAttribute('addons')) {
|
||||
$look['addons'] = (int) $element->getAttribute('addons');
|
||||
}
|
||||
if ($element->hasAttribute('corpse')) {
|
||||
$look['corpse'] = (int) $element->getAttribute('corpse');
|
||||
}
|
||||
|
||||
return $look;
|
||||
}
|
||||
|
@ -16,19 +16,23 @@ defined('MYAAC') or die('Direct access not allowed!');
|
||||
$title = 'Monsters';
|
||||
|
||||
if (empty($_REQUEST['name'])) {
|
||||
// display list of monsters
|
||||
$preview = setting('core.monsters_images_preview');
|
||||
|
||||
// display list of monsters
|
||||
$monsters = MyAAC\Cache::remember('monsters', 30 * 60, function () use ($preview) {
|
||||
$monsters = Monster::where('hide', '!=', 1)->when(!empty($_REQUEST['boss']), function ($query) {
|
||||
$query->where('rewardboss', 1);
|
||||
})->get()->toArray();
|
||||
|
||||
if ($preview) {
|
||||
foreach($monsters as $key => &$monster)
|
||||
{
|
||||
$monster['img_link'] = getMonsterImgPath($monster['name']);
|
||||
foreach($monsters as &$monster) {
|
||||
$monster['img_link'] = getMonsterImage($monster);
|
||||
}
|
||||
}
|
||||
|
||||
return $monsters;
|
||||
});
|
||||
|
||||
$twig->display('monsters.html.twig', array(
|
||||
'monsters' => $monsters,
|
||||
'preview' => $preview
|
||||
@ -45,7 +49,7 @@ if ($monsterModel && isset($monsterModel->name)) {
|
||||
/** @var array $monster */
|
||||
$monster = $monsterModel->toArray();
|
||||
|
||||
function sort_by_chance($a, $b)
|
||||
function sort_by_chance($a, $b): int
|
||||
{
|
||||
if ($a['chance'] == $b['chance']) {
|
||||
return 0;
|
||||
@ -55,7 +59,7 @@ if ($monsterModel && isset($monsterModel->name)) {
|
||||
|
||||
$title = $monster['name'] . " - Monsters";
|
||||
|
||||
$monster['img_link']= getMonsterImgPath($monster_name);
|
||||
$monster['img_link']= getMonsterImage($monster);
|
||||
|
||||
$voices = json_decode($monster['voices'], true);
|
||||
$summons = json_decode($monster['summons'], true);
|
||||
@ -89,3 +93,39 @@ if ($monsterModel && isset($monsterModel->name)) {
|
||||
|
||||
// back button
|
||||
$twig->display('monsters.back_button.html.twig');
|
||||
|
||||
function getMonsterImage($monster): string
|
||||
{
|
||||
$outfit = json_decode($monster['look'], true);
|
||||
|
||||
if (!empty($outfit['typeEx'])) {
|
||||
return setting('core.item_images_url') . $outfit['typeEx'] . setting('core.item_images_extension');
|
||||
}
|
||||
|
||||
if (isset($outfit['type'])) {
|
||||
$getValue = function ($val) use ($outfit) {
|
||||
return (!empty($outfit[$val])
|
||||
? '&' . $val . '=' . $outfit[$val] : '');
|
||||
};
|
||||
|
||||
return setting('core.outfit_images_url') . '?id=' . $outfit['type'] . $getValue('addons') . $getValue('head') . $getValue('body') . $getValue('legs') . $getValue('feet');
|
||||
}
|
||||
|
||||
return getMonsterImgPath($monster['name']);
|
||||
}
|
||||
|
||||
function getMonsterImgPath($name): string
|
||||
{
|
||||
$monster_path = setting('core.monsters_images_url');
|
||||
$monster_gfx_name = trim(strtolower($name)) . setting('core.monsters_images_extension');
|
||||
if (!file_exists($monster_path . $monster_gfx_name)) {
|
||||
$monster_gfx_name = str_replace(" ", "", $monster_gfx_name);
|
||||
if (file_exists($monster_path . $monster_gfx_name)) {
|
||||
return $monster_path . $monster_gfx_name;
|
||||
} else {
|
||||
return $monster_path . 'nophoto.png';
|
||||
}
|
||||
} else {
|
||||
return $monster_path . $monster_gfx_name;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user