From 2dd9265700fed514efeccfcab1badd11a10e2f4b Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Sun, 10 Aug 2025 21:43:32 +0200 Subject: [PATCH] Template/Update (Part 21) * convert dbtype 'emotes' * in setup use voicemacros as additional aliasses * also fix emote text descriptor --- {pages => endpoints/emote}/emote.php | 103 +++++++++++++++++---------- endpoints/emotes/emotes.php | 61 ++++++++++++++++ pages/emotes.php | 50 ------------- setup/tools/sqlgen/emotes.ss.php | 52 ++++++++------ 4 files changed, 156 insertions(+), 110 deletions(-) rename {pages => endpoints/emote}/emote.php (65%) create mode 100644 endpoints/emotes/emotes.php delete mode 100644 pages/emotes.php diff --git a/pages/emote.php b/endpoints/emote/emote.php similarity index 65% rename from pages/emote.php rename to endpoints/emote/emote.php index 79425311..d5e16070 100644 --- a/pages/emote.php +++ b/endpoints/emote/emote.php @@ -6,46 +6,57 @@ if (!defined('AOWOW_REVISION')) die('illegal access'); -// menuId 100: Emotes g_initPath() -// tabid 0: Database g_initHeader() -class EmotePage extends GenericPage +class EmoteBaseResponse extends TemplateResponse implements ICache { - use TrDetailPage; + use TrDetailPage, TrCache; - protected $type = Type::EMOTE; - protected $typeId = 0; - protected $tpl = 'detail-page-generic'; - protected $path = [0, 100]; - protected $tabId = 0; - protected $mode = CACHE_TYPE_PAGE; + protected int $cacheType = CACHE_TYPE_PAGE; - public function __construct($pageCall, $id) + protected string $template = 'detail-page-generic'; + protected string $pageName = 'emote'; + protected ?int $activeTab = parent::TAB_DATABASE; + protected array $breadcrumb = [0, 100]; + + public int $type = Type::EMOTE; + public int $typeId = 0; + + private EmoteList $subject; + + public function __construct(string $id) { + parent::__construct($id); + /* * id > 0: player text emote * id < 0: creature emote */ - parent::__construct($pageCall, $id); - - $this->typeId = intVal($id); + $this->typeId = intVal($id); + $this->contribute = Type::getClassAttrib($this->type, 'contribute') ?? CONTRIBUTE_NONE; + } + protected function generate() : void + { $this->subject = new EmoteList(array(['id', $this->typeId])); if ($this->subject->error) - $this->notFound(Lang::game('emote'), Lang::emote('notFound')); + $this->generateNotFound(Lang::game('emote'), Lang::emote('notFound')); - $this->name = Util::ucFirst($this->subject->getField('cmd')); - } + $this->h1 = Util::ucFirst($this->subject->getField('cmd')); - protected function generatePath() { } + $this->gPageInfo += array( + 'type' => $this->type, + 'typeId' => $this->typeId, + 'name' => $this->h1 + ); + + + /**************/ + /* Page Title */ + /**************/ + + array_unshift($this->title, $this->h1, Util::ucFirst(Lang::game('emote'))); - protected function generateTitle() - { - array_unshift($this->title, $this->name, Util::ucFirst(Lang::game('emote'))); - } - protected function generateContent() - { /***********/ /* Infobox */ /***********/ @@ -83,6 +94,10 @@ class EmotePage extends GenericPage } } + if ($infobox) + $this->infobox = new InfoboxMarkup($infobox, ['allow' => Markup::CLASS_STAFF, 'dbpage' => true], 'infobox-contents0'); + + /****************/ /* Main Content */ /****************/ @@ -110,7 +125,7 @@ class EmotePage extends GenericPage if ($_ = $this->subject->getField('extToNone', true)) $noTarget[] = $this->prepare($_); if ($_ = $this->subject->getField('meToNone', true)) - $noTarget[] =$this->prepare($_); + $noTarget[] = $this->prepare($_); if (!$target && !$noTarget) $text .= '[div][i class=q0]'.Lang::emote('noText').'[/i][/div]'; @@ -138,17 +153,21 @@ class EmotePage extends GenericPage $text .= '[h3]'.Lang::emote('eventSound').'[/h3][sound='.$_.']'; } - $this->extraText = $text; - $this->infobox = $infobox ? '[ul][li]'.implode('[/li][li]', $infobox).'[/li][/ul]' : null; + if ($text) + $this->extraText = new Markup($text, ['dbpage' => true, 'allow' => Markup::CLASS_ADMIN], 'text-generic'); + $this->redButtons = array( BUTTON_LINKS => ['type' => $this->type, 'typeId' => $this->typeId], BUTTON_WOWHEAD => false ); + /**************/ /* Extra Tabs */ /**************/ + $this->lvTabs = new Tabs(['parent' => "\$\$WH.ge('tabs-generic')"], 'tabsRelated', true); + // tab: achievement $condition = array( ['ac.type', ACHIEVEMENT_CRITERIA_TYPE_DO_EMOTE], @@ -157,32 +176,42 @@ class EmotePage extends GenericPage $acv = new AchievementList($condition); if (!$acv->error) { - $this->lvTabs[] = [AchievementList::$brickFile, ['data' => array_values($acv->getListviewData())]]; - $this->extendGlobalData($acv->getJsGlobals()); + $this->lvTabs->addListviewTab(new Listview(['data' => $acv->getListviewData()], AchievementList::$brickFile)); } // tab: sound - if ($em = DB::Aowow()->select('SELECT `soundId` AS ARRAY_KEY, BIT_OR(1 << (`raceId` - 1)) AS "raceMask", BIT_OR(1 << (`gender` - 1)) AS "gender" FROM ?_emotes_sounds WHERE -`emoteId` = ?d GROUP BY `soundId`', $this->typeId > 0 ? $this->subject->getField('parentEmote') : $this->typeId)) + $ems = DB::Aowow()->select( + 'SELECT `soundId` AS ARRAY_KEY, BIT_OR(1 << (`raceId` - 1)) AS "raceMask", BIT_OR(1 << (`gender` - 1)) AS "gender" + FROM ?_emotes_sounds + WHERE `emoteId` = ?d { OR -`emoteId` = ?d } + GROUP BY `soundId`', + $this->typeId, + $this->typeId < 0 ? $this->subject->getField('parentEmote') : DBSIMPLE_SKIP + ); + + if ($ems) { - $sounds = new SoundList(array(['id', array_keys($em)])); + $sounds = new SoundList(array(['id', array_keys($ems)])); if (!$sounds->error) { $this->extendGlobalData($sounds->getJSGlobals(GLOBALINFO_SELF)); $data = $sounds->getListviewData(); - foreach($data as $id => &$d) + foreach ($data as $id => &$d) { - $d['races'] = $em[$id]['raceMask']; - $d['gender'] = $em[$id]['gender']; + $d['races'] = $ems[$id]['raceMask']; + $d['gender'] = $ems[$id]['gender']; } - $this->lvTabs[] = [SoundList::$brickFile, array( - 'data' => array_values($data), + $this->lvTabs->addListviewTab(new Listview(array( + 'data' => $data, // gender races 'extraCols' => ['$Listview.templates.title.columns[1]', '$Listview.templates.classs.columns[1]'] - )]; + ), SoundList::$brickFile)); } } + + parent::generate(); } private function prepare(string $emote) : string diff --git a/endpoints/emotes/emotes.php b/endpoints/emotes/emotes.php new file mode 100644 index 00000000..f3103995 --- /dev/null +++ b/endpoints/emotes/emotes.php @@ -0,0 +1,61 @@ +getCategoryFromUrl($pageParam); + + parent::__construct($pageParam); + } + + protected function generate() : void + { + $this->h1 = Util::ucFirst(Lang::game('emotes')); + + + /**************/ + /* Page Title */ + /**************/ + + array_unshift($this->title, $this->h1); + + + /****************/ + /* Main Content */ + /****************/ + + $cnd = [Cfg::get('SQL_LIMIT_NONE')]; + if (!User::isInGroup(U_GROUP_STAFF)) + $cnd[] = [['cuFlags', CUSTOM_EXCLUDE_FOR_LISTVIEW, '&'], 0]; + + $this->lvTabs = new Tabs(['parent' => "\$\$WH.ge('tabs-generic')"]); + + $tabData = array( + 'data' => (new EmoteList($cnd))->getListviewData(), + 'name' => Util::ucFirst(Lang::game('emotes')) + ); + + $this->lvTabs->addListviewTab(new Listview($tabData, EmoteList::$brickFile, 'emote')); + + parent::generate(); + } +} + +?> diff --git a/pages/emotes.php b/pages/emotes.php deleted file mode 100644 index df0a3692..00000000 --- a/pages/emotes.php +++ /dev/null @@ -1,50 +0,0 @@ -name = Util::ucFirst(Lang::game('emotes')); - } - - protected function generateContent() - { - $cnd = [Cfg::get('SQL_LIMIT_NONE')]; - if (!User::isInGroup(U_GROUP_STAFF)) - $cnd[] = [['cuFlags', CUSTOM_EXCLUDE_FOR_LISTVIEW, '&'], 0]; - - $tabData = array( - 'data' => array_values((new EmoteList($cnd))->getListviewData()), - 'name' => Util::ucFirst(Lang::game('emotes')) - ); - - $this->lvTabs[] = [EmoteList::$brickFile, $tabData, 'emote']; - } - - protected function generateTitle() - { - array_unshift($this->title, $this->name); - } - - protected function generatePath() { } -} - -?> diff --git a/setup/tools/sqlgen/emotes.ss.php b/setup/tools/sqlgen/emotes.ss.php index cae6b4a9..6a3258ca 100644 --- a/setup/tools/sqlgen/emotes.ss.php +++ b/setup/tools/sqlgen/emotes.ss.php @@ -42,15 +42,15 @@ CLISetup::registerSetup("sql", new class extends SetupScript /*********************/ /* EmotesText Data offsets - gender seenBy hasTarget mergedWith example - 0 male others yes 8 %s raises fist in anger at %s. - 1 male self yes 9 %s raises fist in anger at you. - 2 self self yes You raise your fist in anger at %s. - 4 male others no 12 %s raises fist in anger. - 6 self self no You raise your fist in anger. - 8 female others yes 0 - - 9 female self yes 1 - - 12 female others no 4 - + gender seenBy hasTarget effective mergedWith example + 0 male others yes ext -> ext 8 %s raises fist in anger at %s. + 1 male self yes ext -> me 9 %s raises fist in anger at you. + 2 self self yes me -> ext You raise your fist in anger at %s. + 4 male others no ext -> none 12 %s raises fist in anger. + 6 self self no me -> none You raise your fist in anger. + 8 female others yes ext -> ext 0 - + 9 female self yes ext -> me 1 - + 12 female others no ext -> none 4 - */ $this->textData = DB::Aowow()->select('SELECT `id` AS ARRAY_KEY, `text_loc0` AS "0", `text_loc2` AS "2", `text_loc3` AS "3", `text_loc4` AS "4", `text_loc6` AS "6", `text_loc8` AS "8" FROM dbc_emotestextdata'); @@ -70,39 +70,45 @@ CLISetup::registerSetup("sql", new class extends SetupScript VALUES (?d, ?, ?d, ?d, ?d, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $id, $t['cmd'], $t['anim'], $t['parent'], $t['soundId'], - $this->mergeGenderedStrings($t['etd0'], $t['etd8'], Locale::EN), $this->mergeGenderedStrings($t['etd1'], $t['etd9'], Locale::EN), $this->mergeGenderedStrings($t['etd4'], $t['etd12'], Locale::EN), $this->textData[$t['etd2']][Locale::EN->value] ?? '', $this->textData[$t['etd6']][Locale::EN->value] ?? '', - $this->mergeGenderedStrings($t['etd0'], $t['etd8'], Locale::FR), $this->mergeGenderedStrings($t['etd1'], $t['etd9'], Locale::FR), $this->mergeGenderedStrings($t['etd4'], $t['etd12'], Locale::FR), $this->textData[$t['etd2']][Locale::FR->value] ?? '', $this->textData[$t['etd6']][Locale::FR->value] ?? '', - $this->mergeGenderedStrings($t['etd0'], $t['etd8'], Locale::DE), $this->mergeGenderedStrings($t['etd1'], $t['etd9'], Locale::DE), $this->mergeGenderedStrings($t['etd4'], $t['etd12'], Locale::DE), $this->textData[$t['etd2']][Locale::DE->value] ?? '', $this->textData[$t['etd6']][Locale::DE->value] ?? '', - $this->mergeGenderedStrings($t['etd0'], $t['etd8'], Locale::CN), $this->mergeGenderedStrings($t['etd1'], $t['etd9'], Locale::CN), $this->mergeGenderedStrings($t['etd4'], $t['etd12'], Locale::CN), $this->textData[$t['etd2']][Locale::CN->value] ?? '', $this->textData[$t['etd6']][Locale::CN->value] ?? '', - $this->mergeGenderedStrings($t['etd0'], $t['etd8'], Locale::ES), $this->mergeGenderedStrings($t['etd1'], $t['etd9'], Locale::ES), $this->mergeGenderedStrings($t['etd4'], $t['etd12'], Locale::ES), $this->textData[$t['etd2']][Locale::ES->value] ?? '', $this->textData[$t['etd6']][Locale::ES->value] ?? '', - $this->mergeGenderedStrings($t['etd0'], $t['etd8'], Locale::RU), $this->mergeGenderedStrings($t['etd1'], $t['etd9'], Locale::RU), $this->mergeGenderedStrings($t['etd4'], $t['etd12'], Locale::RU), $this->textData[$t['etd2']][Locale::RU->value] ?? '', $this->textData[$t['etd6']][Locale::RU->value] ?? '' + $this->mergeGenderedStrings($t['etd0'], $t['etd8'], Locale::EN), $this->mergeGenderedStrings($t['etd1'], $t['etd9'], Locale::EN), $this->textData[$t['etd2']][Locale::EN->value] ?? '', $this->mergeGenderedStrings($t['etd4'], $t['etd12'], Locale::EN), $this->textData[$t['etd6']][Locale::EN->value] ?? '', + $this->mergeGenderedStrings($t['etd0'], $t['etd8'], Locale::FR), $this->mergeGenderedStrings($t['etd1'], $t['etd9'], Locale::FR), $this->textData[$t['etd2']][Locale::FR->value] ?? '', $this->mergeGenderedStrings($t['etd4'], $t['etd12'], Locale::FR), $this->textData[$t['etd6']][Locale::FR->value] ?? '', + $this->mergeGenderedStrings($t['etd0'], $t['etd8'], Locale::DE), $this->mergeGenderedStrings($t['etd1'], $t['etd9'], Locale::DE), $this->textData[$t['etd2']][Locale::DE->value] ?? '', $this->mergeGenderedStrings($t['etd4'], $t['etd12'], Locale::DE), $this->textData[$t['etd6']][Locale::DE->value] ?? '', + $this->mergeGenderedStrings($t['etd0'], $t['etd8'], Locale::CN), $this->mergeGenderedStrings($t['etd1'], $t['etd9'], Locale::CN), $this->textData[$t['etd2']][Locale::CN->value] ?? '', $this->mergeGenderedStrings($t['etd4'], $t['etd12'], Locale::CN), $this->textData[$t['etd6']][Locale::CN->value] ?? '', + $this->mergeGenderedStrings($t['etd0'], $t['etd8'], Locale::ES), $this->mergeGenderedStrings($t['etd1'], $t['etd9'], Locale::ES), $this->textData[$t['etd2']][Locale::ES->value] ?? '', $this->mergeGenderedStrings($t['etd4'], $t['etd12'], Locale::ES), $this->textData[$t['etd6']][Locale::ES->value] ?? '', + $this->mergeGenderedStrings($t['etd0'], $t['etd8'], Locale::RU), $this->mergeGenderedStrings($t['etd1'], $t['etd9'], Locale::RU), $this->textData[$t['etd2']][Locale::RU->value] ?? '', $this->mergeGenderedStrings($t['etd4'], $t['etd12'], Locale::RU), $this->textData[$t['etd6']][Locale::RU->value] ?? '' ); } // i have no idea, how the indexing in this file works. // sometimes the \d+ after EMOTE is the emoteTextId, but not nearly often enough - $aliasses = []; - foreach (CLISetup::searchGlobalStrings('/^EMOTE(\d+)_CMD\d+\s=\s\"\/([^"]+)\";$/') as $lId => $match) - $aliasses[$match[1]][] = [$lId, $match[2]]; + $aliasses = $voiceAliases = []; + foreach (CLISetup::searchGlobalStrings('/^EMOTE(\d+)_CMD\d+ = \"\/([^"]+)\";$/') as $locId => [, $etID, $cmd]) + $aliasses[$etID][] = [$locId, $cmd]; + + foreach (CLISetup::searchGlobalStrings('/^VOICEMACRO_LABEL_([A-Z]+)\d+ = \"([^"]+)\";$/') as $locId => [, $cmd, $alias]) + $voiceAliases[$cmd][] = [$locId, $alias]; $emotes = DB::Aowow()->selectCol('SELECT id AS ARRAY_KEY, cmd FROM ?_emotes'); foreach($emotes as $eId => $cmd) { + foreach ($voiceAliases[strtoupper($cmd)] ?? [] as [$locId, $alias]) + DB::Aowow()->query('INSERT IGNORE INTO ?_emotes_aliasses VALUES (?d, ?d, ?) ON DUPLICATE KEY UPDATE `locales` = `locales` | ?d', $eId, (1 << $locId), mb_strtolower($alias), (1 << $locId)); + foreach ($aliasses as $data) { if (!in_array($cmd, array_column($data, 1))) continue; - foreach ($data as $d) - DB::Aowow()->query('INSERT IGNORE INTO ?_emotes_aliasses VALUES (?d, ?d, ?) ON DUPLICATE KEY UPDATE locales = locales | ?d', $eId, (1 << $d[0]), strtolower($d[1]), (1 << $d[0])); + foreach ($data as [$locId, $alias]) + DB::Aowow()->query('INSERT IGNORE INTO ?_emotes_aliasses VALUES (?d, ?d, ?) ON DUPLICATE KEY UPDATE `locales` = `locales` | ?d', $eId, (1 << $locId), mb_strtolower($alias), (1 << $locId)); - continue 2; + break; } - - DB::Aowow()->query('UPDATE ?_emotes SET `cuFlags` = `cuFlags` | ?d WHERE `id` = ?d', CUSTOM_EXCLUDE_FOR_LISTVIEW | EMOTE_CU_MISSING_CMD, $eId); } + DB::Aowow()->query('UPDATE ?_emotes e LEFT JOIN ?_emotes_aliasses ea ON ea.`id` = e.`id` SET e.`cuFlags` = e.`cuFlags` | ?d WHERE ea.`id` IS NULL', CUSTOM_EXCLUDE_FOR_LISTVIEW | EMOTE_CU_MISSING_CMD); + /*********************/ /* Server controlled */