From 979a21afae6e10ea8e3686a90fd4b542219fcd1e Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Wed, 31 Jan 2024 22:00:17 +0100 Subject: [PATCH] Localization/Caching * store source lists as object so different locales can be fetched * store parsed spell texts locale dependent so the locale isn't fixed --- includes/basetype.class.php | 8 ++++---- includes/types/achievement.class.php | 5 ++++- includes/types/creature.class.php | 5 ++++- includes/types/gameobject.class.php | 5 ++++- includes/types/item.class.php | 5 ++++- includes/types/quest.class.php | 5 ++++- includes/types/spell.class.php | 11 +++++++---- 7 files changed, 31 insertions(+), 13 deletions(-) diff --git a/includes/basetype.class.php b/includes/basetype.class.php index 3f6f454b..11e60343 100644 --- a/includes/basetype.class.php +++ b/includes/basetype.class.php @@ -445,7 +445,7 @@ abstract class BaseType 'c2': subCat [Quests] 'icon': iconString */ - public function getSourceData() {} + public function getSourceData(int $id = 0) : array { return []; } // should return data required to display a listview of any kind // this is a rudimentary example, that will not suffice for most Types @@ -863,12 +863,12 @@ trait sourceHelper $buff[$_curTpl['moreType']][] = $_curTpl['moreTypeId']; foreach ($buff as $type => $ids) - $this->sourceMore[$type] = (Type::newList($type, [CFG_SQL_LIMIT_NONE, ['id', $ids]]))->getSourceData(); + $this->sourceMore[$type] = Type::newList($type, [CFG_SQL_LIMIT_NONE, ['id', $ids]]); } $s = array_keys($this->sources[$this->id]); - if ($this->curTpl['moreType'] && $this->curTpl['moreTypeId'] && !empty($this->sourceMore[$this->curTpl['moreType']][$this->curTpl['moreTypeId']])) - $sm = $this->sourceMore[$this->curTpl['moreType']][$this->curTpl['moreTypeId']]; + if ($this->curTpl['moreType'] && $this->curTpl['moreTypeId'] && ($srcData = $this->sourceMore[$this->curTpl['moreType']]->getSourceData($this->curTpl['moreTypeId']))) + $sm = $srcData; else if (!empty($this->sources[$this->id][SRC_PVP])) $sm['p'] = $this->sources[$this->id][SRC_PVP][0]; diff --git a/includes/types/achievement.class.php b/includes/types/achievement.class.php index bc2eb62b..b9559d78 100644 --- a/includes/types/achievement.class.php +++ b/includes/types/achievement.class.php @@ -257,12 +257,15 @@ class AchievementList extends BaseType return $x; } - public function getSourceData() + public function getSourceData(int $id = 0) : array { $data = []; foreach ($this->iterate() as $__) { + if ($id && $id != $this->id) + continue; + $data[$this->id] = array( "n" => $this->getField('name', true), "s" => $this->curTpl['faction'], diff --git a/includes/types/creature.class.php b/includes/types/creature.class.php index e2f7d662..68b092a2 100644 --- a/includes/types/creature.class.php +++ b/includes/types/creature.class.php @@ -257,12 +257,15 @@ class CreatureList extends BaseType return $data; } - public function getSourceData() + public function getSourceData(int $id = 0) : array { $data = []; foreach ($this->iterate() as $__) { + if ($id && $id != $this->id) + continue; + $data[$this->id] = array( 'n' => $this->getField('parentId') ? $this->getField('parent', true) : $this->getField('name', true), 't' => Type::NPC, diff --git a/includes/types/gameobject.class.php b/includes/types/gameobject.class.php index e0351b7e..03137964 100644 --- a/includes/types/gameobject.class.php +++ b/includes/types/gameobject.class.php @@ -120,12 +120,15 @@ class GameObjectList extends BaseType return $data; } - public function getSourceData() + public function getSourceData(int $id = 0) : array { $data = []; foreach ($this->iterate() as $__) { + if ($id && $id != $this->id) + continue; + $data[$this->id] = array( 'n' => $this->getField('name', true), 't' => Type::OBJECT, diff --git a/includes/types/item.class.php b/includes/types/item.class.php index 177b0728..ab263bcf 100644 --- a/includes/types/item.class.php +++ b/includes/types/item.class.php @@ -1363,12 +1363,15 @@ class ItemList extends BaseType return $onUseStats; } - public function getSourceData() + public function getSourceData(int $id = 0) : array { $data = []; foreach ($this->iterate() as $__) { + if ($id && $id != $this->id) + continue; + $data[$this->id] = array( 'n' => $this->getField('name', true), 't' => Type::ITEM, diff --git a/includes/types/quest.class.php b/includes/types/quest.class.php index 4927c8b6..7560f35b 100644 --- a/includes/types/quest.class.php +++ b/includes/types/quest.class.php @@ -148,12 +148,15 @@ class QuestList extends BaseType return in_array($this->getField('zoneOrSortBak'), [-22, -284, -366, -369, -370, -376, -374]) && !$this->isRepeatable(); } - public function getSourceData() + public function getSourceData(int $id = 0) : array { $data = []; foreach ($this->iterate() as $__) { + if ($id && $id != $this->id) + continue; + $data[$this->id] = array( "n" => $this->getField('name', true), "t" => Type::QUEST, diff --git a/includes/types/spell.class.php b/includes/types/spell.class.php index 05c65297..022d8e36 100644 --- a/includes/types/spell.class.php +++ b/includes/types/spell.class.php @@ -1586,8 +1586,8 @@ class SpellList extends BaseType $this->charLevel = $level; // step -1: already handled? - if (isset($this->parsedText[$this->id][$type][$this->charLevel][(int)$this->interactive])) - return $this->parsedText[$this->id][$type][$this->charLevel][(int)$this->interactive]; + if (isset($this->parsedText[$this->id][$type][User::$localeId][$this->charLevel][(int)$this->interactive])) + return $this->parsedText[$this->id][$type][User::$localeId][$this->charLevel][(int)$this->interactive]; // step 0: get text $data = $this->getField($type, true); @@ -1693,7 +1693,7 @@ class SpellList extends BaseType $data = strtr($data, ["\r" => '', "\n" => '
']); // cache result - $this->parsedText[$this->id][$type][$this->charLevel][(int)$this->interactive] = [$data, $relSpells]; + $this->parsedText[$this->id][$type][User::$localeId][$this->charLevel][(int)$this->interactive] = [$data, $relSpells]; return [$data, $relSpells]; } @@ -2397,12 +2397,15 @@ class SpellList extends BaseType return $castingTime; } - public function getSourceData() + public function getSourceData(int $id = 0) : array { $data = []; foreach ($this->iterate() as $__) { + if ($id && $id != $this->id) + continue; + $data[$this->id] = array( 'n' => $this->getField('name', true), 't' => Type::SPELL,