From 24d683332d3f15883f5edbfd3b23047017bbc4b7 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Thu, 8 Jun 2023 13:29:45 +0200 Subject: [PATCH] Profiler/Completion * fix partial loading of quests in profiler * provide inital category totals on a per class & race basis --- includes/ajaxHandler/data.class.php | 11 +- includes/ajaxHandler/profile.class.php | 31 ++++-- includes/profiler.class.php | 2 + includes/user.class.php | 18 ++++ setup/tools/filegen/profiler.func.php | 135 +++++++++++++++++-------- setup/updates/1683672833_01.sql | 1 + static/js/Profiler.js | 12 +++ 7 files changed, 151 insertions(+), 59 deletions(-) create mode 100644 setup/updates/1683672833_01.sql diff --git a/includes/ajaxHandler/data.class.php b/includes/ajaxHandler/data.class.php index 6b6c7b10..5b10fcba 100644 --- a/includes/ajaxHandler/data.class.php +++ b/includes/ajaxHandler/data.class.php @@ -59,14 +59,13 @@ class AjaxData extends AjaxHandler $result .= $this->loadProfilerData($set, '777'); break; case 'quests': - // &partial: im not doing this right - // it expects a full quest dump on first lookup but will query subCats again if clicked..? - // for now omiting the detail clicks with empty results and just set catg update $catg = isset($this->_get['catg']) ? $this->_get['catg'] : 'null'; if ($catg == 'null') - $result .= $this->loadProfilerData($set); - else if ($this->_get['callback']) - $result .= "\n\$WowheadProfiler.loadOnDemand('quests', ".$catg.");\n"; + Util::loadStaticFile('p-'.$set, $result, false); + else + Util::loadStaticFile('p-'.$set.'-'.$catg, $result, true); + + $result .= "\n\$WowheadProfiler.loadOnDemand('".$set."', ".$catg.");\n"; break; case 'recipes': diff --git a/includes/ajaxHandler/profile.class.php b/includes/ajaxHandler/profile.class.php index 94a4d63a..3e664c26 100644 --- a/includes/ajaxHandler/profile.class.php +++ b/includes/ajaxHandler/profile.class.php @@ -613,10 +613,12 @@ class AjaxProfile extends AjaxHandler $profile['titles'] = $data; break; case Type::QUEST: - foreach ($data as &$d) - $d = 1; + $qList = new QuestList(array(['id', array_keys($data)], CFG_SQL_LIMIT_NONE)); + $qResult = []; + foreach ($qList->iterate() as $id => $__) + $qResult[$id] = [$qList->getField('cat1'), $qList->getField('cat2')]; - $profile['quests'] = $data; + $profile['quests'] = $qResult; break; case Type::SPELL: foreach ($data as &$d) @@ -651,7 +653,7 @@ class AjaxProfile extends AjaxHandler } } - $buff = ''; + $gItems = []; $usedSlots = []; if ($this->_get['items']) @@ -668,7 +670,12 @@ class AjaxProfile extends AjaxHandler if (in_array($sl, $invTypes) && !in_array($slot, $usedSlots)) { // get and apply inventory - $buff .= 'g_items.add('.$iId.', {name_'.User::$localeString.":'".Util::jsEscape($phItems->getField('name', true))."', quality:".$phItems->getField('quality').", icon:'".$phItems->getField('iconString')."', jsonequip:".Util::toJSON($data[$iId])."});\n"; + $gItems[$iId] = array( + 'name_'.User::$localeString => $phItems->getField('name', true), + 'quality' => $phItems->getField('quality'), + 'icon' => $phItems->getField('iconString'), + 'jsonequip' => $data[$iId] + ); $profile['inventory'][$slot] = [$iId, 0, 0, 0, 0, 0, 0, 0]; $usedSlots[] = $slot; @@ -684,22 +691,28 @@ class AjaxProfile extends AjaxHandler $itemz = new ItemList(array(['id', array_column($items, 'item')], CFG_SQL_LIMIT_NONE)); if (!$itemz->error) { - $data = $itemz->getListviewData(ITEMINFO_JSON | ITEMINFO_SUBITEMS); + $data = $itemz->getListviewData(ITEMINFO_JSON | ITEMINFO_SUBITEMS); foreach ($items as $i) { if ($itemz->getEntry($i['item']) && !in_array($i['slot'], $usedSlots)) { // get and apply inventory - $buff .= 'g_items.add('.$i['item'].', {name_'.User::$localeString.":'".Util::jsEscape($itemz->getField('name', true))."', quality:".$itemz->getField('quality').", icon:'".$itemz->getField('iconString')."', jsonequip:".Util::toJSON($data[$i['item']])."});\n"; + $gItems[$i['item']] = array( + 'name_'.User::$localeString => $itemz->getField('name', true), + 'quality' => $itemz->getField('quality'), + 'icon' => $itemz->getField('iconString'), + 'jsonequip' => $data[$i['item']] + ); $profile['inventory'][$i['slot']] = [$i['item'], $i['subItem'], $i['permEnchant'], $i['tempEnchant'], $i['gem1'], $i['gem2'], $i['gem3'], $i['gem4']]; } } } } - if ($buff) - $buff .= "\n"; + $buff = ''; + foreach ($gItems as $id => $item) + $buff .= 'g_items.add('.$id.', '.Util::toJSON($item, JSON_NUMERIC_CHECK | JSON_UNESCAPED_UNICODE).");\n"; // if ($au = $char->getField('auras')) diff --git a/includes/profiler.class.php b/includes/profiler.class.php index b18535d9..a2bb9c92 100644 --- a/includes/profiler.class.php +++ b/includes/profiler.class.php @@ -727,6 +727,8 @@ class Profiler $data['guildRank'] = $guild['rank']; } + CLI::write(' ..basic guild data'); + // arena teams $teams = DB::Characters($realmId)->select('SELECT at.arenaTeamId AS ARRAY_KEY, at.name, at.type, IF(at.captainGuid = atm.guid, 1, 0) AS captain, atm.* FROM arena_team at JOIN arena_team_member atm ON atm.arenaTeamId = at.arenaTeamId WHERE atm.guid = ?d', $char['guid']); diff --git a/includes/user.class.php b/includes/user.class.php index da0847d9..185f5853 100644 --- a/includes/user.class.php +++ b/includes/user.class.php @@ -652,6 +652,24 @@ class User return self::$profiles->getJSGlobals(PROFILEINFO_PROFILE); } + public static function getPinnedCharacter() : array + { + if (!self::$profiles) + return []; + + $realms = Profiler::getRealms(); + + foreach (self::$profiles->iterate() as $id => $_) + if (self::$profiles->getField('cuFlags') & PROFILER_CU_PINNED) + return [ + $id, + self::$profiles->getField('name'), + self::$profiles->getField('region') . '.' . Profiler::urlize($realms[self::$profiles->getField('realm')]['name'], true) . '.' . Profiler::urlize(self::$profiles->getField('name'), true, true) + ]; + + return []; + } + public static function getGuides() { $result = []; diff --git a/setup/tools/filegen/profiler.func.php b/setup/tools/filegen/profiler.func.php index 5ca1d526..1f877226 100644 --- a/setup/tools/filegen/profiler.func.php +++ b/setup/tools/filegen/profiler.func.php @@ -31,66 +31,113 @@ if (!CLI) }; + $sumTotal = function(array &$sumArr, int $raceMask = -1, int $classMask= -1) + { + for ($i = 0; $i < RACE_MASK_ALL; $i++) + { + if (!((1 << $i) & $raceMask) || !((1 << $i) & RACE_MASK_ALL)) + continue; + + for ($j = 0; $j < CLASS_MASK_ALL; $j++) + { + if (!((1 << $j) & $classMask) || !((1 << $j) & CLASS_MASK_ALL)) + continue; + + if (!isset($sumArr[$i+1][$j+1])) + $sumArr[$i+1][$j+1] = 1; + else + $sumArr[$i+1][$j+1]++; + } + } + }; + + /**********/ /* Quests */ /**********/ - $scripts[] = function() use ($exAdd) + $scripts[] = function() use ($exAdd, $sumTotal) { - $success = true; - $condition = [ + $success = true; + $questorder = []; + $questtotal = []; + $condition = [ CFG_SQL_LIMIT_NONE, 'AND', - [['cuFlags', CUSTOM_EXCLUDE_FOR_LISTVIEW], 0], + [['cuFlags', CUSTOM_EXCLUDE_FOR_LISTVIEW | CUSTOM_UNAVAILABLE | CUSTOM_DISABLED, '&'], 0], [['flags', QUEST_FLAG_DAILY | QUEST_FLAG_WEEKLY | QUEST_FLAG_REPEATABLE | QUEST_FLAG_AUTO_REWARDED, '&'], 0], [['specialFlags', QUEST_FLAG_SPECIAL_REPEATABLE | QUEST_FLAG_SPECIAL_DUNGEON_FINDER | QUEST_FLAG_SPECIAL_MONTHLY, '&'], 0] ]; - $questz = new QuestList($condition); - // get quests for exclusion - foreach ($questz->iterate() as $id => $__) + foreach (Game::$questClasses as $cat2 => $cat) { - switch ($questz->getField('reqSkillId')) + if ($cat2 < 0) + continue; + + $cond = array_merge($condition, [['zoneOrSort', $cat]]); + $questz = new QuestList($cond); + if ($questz->error) + continue; + + $questorder[] = $cat2; + $questtotal[$cat2] = []; + + // get quests for exclusion + foreach ($questz->iterate() as $id => $__) { - case 356: - $exAdd(Type::QUEST, $id, PR_EXCLUDE_GROUP_REQ_FISHING); - break; - case 202: - $exAdd(Type::QUEST, $id, PR_EXCLUDE_GROUP_REQ_ENGINEERING); - break; - case 197: - $exAdd(Type::QUEST, $id, PR_EXCLUDE_GROUP_REQ_TAILORING); - break; + $sumTotal($questtotal[$cat2], $questz->getField('reqRaceMask') ?: -1, $questz->getField('reqClassMask') ?: -1); + + switch ($questz->getField('reqSkillId')) + { + case 356: + $exAdd(Type::QUEST, $id, PR_EXCLUDE_GROUP_REQ_FISHING); + break; + case 202: + $exAdd(Type::QUEST, $id, PR_EXCLUDE_GROUP_REQ_ENGINEERING); + break; + case 197: + $exAdd(Type::QUEST, $id, PR_EXCLUDE_GROUP_REQ_TAILORING); + break; + } + } + + $_ = []; + $currencies = array_column($questz->rewards, Type::CURRENCY); + foreach ($currencies as $curr) + foreach ($curr as $cId => $qty) + $_[] = $cId; + + $relCurr = new CurrencyList(array(['id', $_])); + + foreach (CLISetup::$localeIds as $l) + { + set_time_limit(20); + + User::useLocale($l); + Lang::load(Util::$localeStrings[$l]); + + if (!$relCurr->error) + { + $buff = "var _ = g_gatheredcurrencies;\n"; + foreach ($relCurr->getListviewData() as $id => $data) + $buff .= '_['.$id.'] = '.Util::toJSON($data).";\n"; + } + + $buff .= "var _ = g_quests;\n"; + foreach ($questz->getListviewData() as $id => $data) + $buff .= '_['.$id.'] = '.Util::toJSON($data).";\n"; + + if (!CLISetup::writeFile('datasets/'.User::$localeString.'/p-quests-'.$cat2, $buff)) + $success = false; } } - $_ = []; - $currencies = array_column($questz->rewards, Type::CURRENCY); - foreach ($currencies as $curr) - foreach ($curr as $cId => $qty) - $_[] = $cId; + $buff = "g_quest_catorder = ".Util::toJSON($questorder).";\n"; + $buff .= "g_quest_catorder_total = {};\n"; + foreach ($questtotal as $cat => $totals) + $buff .= "g_quest_catorder_total[".$cat."] = ".Util::toJSON($totals).";\n"; - $relCurr = new CurrencyList(array(['id', $_])); - - foreach (CLISetup::$localeIds as $l) - { - set_time_limit(20); - - User::useLocale($l); - Lang::load(Util::$localeStrings[$l]); - - $buff = "var _ = g_gatheredcurrencies;\n"; - foreach ($relCurr->getListviewData() as $id => $data) - $buff .= '_['.$id.'] = '.Util::toJSON($data).";\n"; - - $buff .= "\n\nvar _ = g_quests;\n"; - foreach ($questz->getListviewData() as $id => $data) - $buff .= '_['.$id.'] = '.Util::toJSON($data).";\n"; - - $buff .= "\ng_quest_catorder = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n"; - - if (!CLISetup::writeFile('datasets/'.User::$localeString.'/p-quests', $buff)) - $success = false; - } + if (!CLISetup::writeFile('datasets/p-quests', $buff)) + $success = false; return $success; }; diff --git a/setup/updates/1683672833_01.sql b/setup/updates/1683672833_01.sql new file mode 100644 index 00000000..6d163b57 --- /dev/null +++ b/setup/updates/1683672833_01.sql @@ -0,0 +1 @@ +UPDATE `aowow_dbversion` SET `build` = CONCAT(IFNULL(`build`, ''), ' profiler'); diff --git a/static/js/Profiler.js b/static/js/Profiler.js index 4f21c3ea..ade3a3e9 100644 --- a/static/js/Profiler.js +++ b/static/js/Profiler.js @@ -7728,6 +7728,18 @@ function ProfilerCompletion(_parent) { } } + // aowow: added for &partial init + if (subtotal == null && window[_opt.order] && window[_opt.cattotal]) { + let sumtotal = 0; + + for (var i = 0, len = window[_opt.order].length; i < len; ++i) { + let cat = window[_opt.order][i]; + result.all[cat] = window[_opt.cattotal][cat][_profile.race][_profile.classs]; + sumtotal += window[_opt.cattotal][cat][_profile.race][_profile.classs]; + } + result.all[overall] = sumtotal; + } + if (_opt.noempty) { for (var catg in result.complete) { if (catg == overall) {