CLISetup/locales

* removed redundant declaration of locales to process
This commit is contained in:
Sarjuuk
2024-06-29 13:03:18 +02:00
parent 5d4051928a
commit 2386e35207
13 changed files with 56 additions and 58 deletions

View File

@@ -10,7 +10,6 @@ if (!CLI)
class CLISetup
{
public static $locales = [];
public static $localeIds = [];
public static $srcDir = 'setup/mpqdata/';
@@ -199,14 +198,10 @@ class CLISetup
// restrict actual locales
foreach (self::$locales as $idx => $_)
{
if (!($l = Cfg::get('LOCALES')) || ($l & (1 << $idx)))
self::$localeIds[] = $idx;
else
if (($l = Cfg::get('LOCALES')) && !($l & (1 << $idx)))
unset(self::$locales[$idx]);
}
if (!self::$localeIds)
if (!self::$locales)
CLI::write('No valid locale specified. Check your config or --locales parameter, if used', CLI::LOG_ERROR);
// get site status
@@ -562,7 +557,7 @@ class CLISetup
foreach (self::$expectedPaths as $xp => $locId)
{
if (!in_array($locId, self::$localeIds))
if (!in_array($locId, array_keys(self::$locales)))
continue;
if (isset($result[$locId]))
@@ -582,7 +577,7 @@ class CLISetup
if (!$matchAll && !$result)
$status = false;
if ($matchAll && array_diff(self::$localeIds, array_keys($result)))
if ($matchAll && array_diff_key(self::$locales, $result))
$status = false;
return $result;
@@ -606,7 +601,7 @@ class CLISetup
self::$gsFiles[$lId] = file($gsFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
}
if ($missing = array_diff(self::$localeIds, array_keys(self::$gsFiles)))
if ($missing = array_diff_key(self::$locales, self::$gsFiles))
{
ClI::write('GlobalStrings.lua not found for locale '. Lang::concat($missing), CLI::LOG_WARN);
return false;

View File

@@ -112,7 +112,7 @@ class DBC
$foundMask = 0x0;
foreach (CLISetup::$expectedPaths as $locStr => $locId)
{
if (!in_array($locId, CLISetup::$localeIds))
if (!in_array($locId, array_keys(CLISetup::$locales)))
continue;
if ($foundMask & (1 << $locId))

View File

@@ -97,7 +97,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
return false;
}
foreach (CLISetup::$localeIds as $lId)
foreach (CLISetup::$locales as $lId => $jsonStr)
{
User::useLocale($lId);
Lang::load($lId);
@@ -254,7 +254,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
$ench[$k] = $v[0];
$toFile = "var g_enchants = ".Util::toJSON($enchantsOut).";";
$file = 'datasets/'.User::$localeString.'/enchants';
$file = 'datasets/'.$jsonStr.'/enchants';
if (!CLISetup::writeFile($file, $toFile))
$this->success = false;

View File

@@ -59,7 +59,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
return false;
}
foreach (CLISetup::$localeIds as $lId)
foreach (CLISetup::$locales as $lId => $jsonStr)
{
set_time_limit(5);
@@ -88,7 +88,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
}
$toFile = "var g_gems = ".Util::toJSON($gemsOut).";";
$file = 'datasets/'.User::$localeString.'/gems';
$file = 'datasets/'.$jsonStr.'/gems';
if (!CLISetup::writeFile($file, $toFile))
$this->success = false;

View File

@@ -52,7 +52,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
$glyphSpells = new SpellList(array(['s.id', array_keys($glyphList)], Cfg::get('SQL_LIMIT_NONE')));
foreach (CLISetup::$localeIds as $lId)
foreach (CLISetup::$locales as $lId => $jsonStr)
{
set_time_limit(30);
@@ -82,7 +82,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
}
$toFile = "var g_glyphs = ".Util::toJSON($glyphsOut).";";
$file = 'datasets/'.User::$localeString.'/glyphs';
$file = 'datasets/'.$jsonStr.'/glyphs';
if (!CLISetup::writeFile($file, $toFile))
$this->success = false;

View File

@@ -84,8 +84,8 @@ CLISetup::registerSetup("build", new class extends SetupScript
if (strpos($dir[0], '%s') === false)
$this->requiredDirs[] = $dir[0];
else
foreach (CLISetup::$localeIds as $l)
$this->requiredDirs[] = sprintf($dir[0], strtolower(Util::$localeStrings[$l]).'/');
foreach (CLISetup::$locales as $l => $locJsonStr)
$this->requiredDirs[] = sprintf($dir[0], $locJsonStr.'/');
}
}
}
@@ -143,9 +143,9 @@ CLISetup::registerSetup("build", new class extends SetupScript
{
$sumFloors = array_sum(array_column($this->dmFloorData, 1));
$sumAreas = count($this->wmAreas);
$sumMaps = count(CLISetup::$localeIds) * ($sumAreas + $sumFloors);
$sumMaps = count(CLISetup::$locales) * ($sumAreas + $sumFloors);
CLI::write('Processing '.$sumAreas.' zone maps and '.$sumFloors.' dungeon maps from Interface/WorldMap/ for locale: '.Lang::concat(array_intersect_key(Util::$localeStrings, array_flip(CLISetup::$localeIds))));
CLI::write('Processing '.$sumAreas.' zone maps and '.$sumFloors.' dungeon maps from Interface/WorldMap/ for locale: '.Lang::concat(array_intersect_key(Util::$localeStrings, CLISetup::$locales)));
/* todo: retrain brain and generate maps by given files and GlobalStrings. Then assign dbc data to them not the other way round like it is now.
foreach ($this->mapFiles as $name => [$floors, $isMultilevel])
@@ -236,8 +236,11 @@ CLISetup::registerSetup("build", new class extends SetupScript
}
*/
foreach (CLISetup::$localeIds as $progressLoc => $l)
$progressLoc = -1;
foreach (CLISetup::$locales as $l => $locJsonStr)
{
$progressLoc++;
// source for mapFiles
$mapSrcDir = '';
if ($this->modeMask & self::M_SPAWNS)
@@ -280,7 +283,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
if (!CLISetup::fileExists($srcPath))
{
$this->success = false;
CLI::write('worldmap file '.$srcPath.' missing for selected locale '.Util::$localeStrings[$l], CLI::LOG_ERROR);
CLI::write('worldmap file '.$srcPath.' missing for selected locale '.$locJsonStr, CLI::LOG_ERROR);
continue;
}
@@ -330,7 +333,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
foreach (self::DEST_DIRS as $sizeIdx => [$path, $width, $height])
{
$outFile[$sizeIdx] = sprintf($path, strtolower(Util::$localeStrings[$l]).'/') . $zoneId;
$outFile[$sizeIdx] = sprintf($path, $locJsonStr.'/') . $zoneId;
/* dataset 'zones' requires that ...
* 3959 - Black Temple: starts with empty floor suffix
@@ -503,11 +506,11 @@ CLISetup::registerSetup("build", new class extends SetupScript
{
$sumFloors = array_sum(array_column($this->dmFloorData, 1));
$sumAreas = count($this->wmAreas);
$sumMaps = count(CLISetup::$localeIds) * ($sumAreas + $sumFloors);
$sumMaps = count(CLISetup::$locales) * ($sumAreas + $sumFloors);
CLI::write('[img-maps] Processing '.$sumAreas.' zone maps and '.$sumFloors.' dungeon maps from Interface/WorldMap/ for locale: '.Lang::concat(array_intersect_key(Util::$localeStrings, array_flip(CLISetup::$localeIds))));
CLI::write('[img-maps] Processing '.$sumAreas.' zone maps and '.$sumFloors.' dungeon maps from Interface/WorldMap/ for locale: '.Lang::concat(array_intersect_key(Util::$localeStrings, CLISetup::$locales)));
foreach (CLISetup::$localeIds as $l)
foreach (CLISetup::$locales as $l => $locJsonStr)
{
// source for mapFiles
$mapSrcDir = '';
@@ -519,7 +522,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
$mapSrcDir = $this->genSteps[self::M_MAPS][1][$l] ?? '';
if (!$mapSrcDir)
{
CLI::write('[img-maps] - No suitable localized map files found for locale ['.$l.': '.Util::$localeStrings[$l].'].', CLI::LOG_ERROR);
CLI::write('[img-maps] - No suitable localized map files found for locale ['.$l.': '.$locJsonStr.'].', CLI::LOG_ERROR);
$this->success = false;
continue;
}
@@ -554,7 +557,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
$dmFloors = array_combine($dmFloors, $dmFloors);
CLI::write(
'['.Util::$localeStrings[$l].'] ' .
'['.$locJsonStr.'] ' .
str_pad('['.$areaEntry['areaId'].']', 7) .
str_pad($areaEntry['nameINT'], 22) .
str_pad('Overlays: '.count($this->wmOverlays[$areaEntry['id']] ?? []), 14) .
@@ -564,7 +567,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
$srcPath = $mapSrcDir.'/'.$textureStr;
if (!CLISetup::fileExists($srcPath))
{
CLI::write('[img-maps] - WorldMap file path '.$srcPath.' missing for selected locale '.Util::$localeStrings[$l], CLI::LOG_ERROR);
CLI::write('[img-maps] - WorldMap file path '.$srcPath.' missing for selected locale '.$locJsonStr, CLI::LOG_ERROR);
$this->success = false;
continue;
}
@@ -616,7 +619,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
foreach (self::DEST_DIRS as $sizeIdx => [$path, $width, $height])
{
$outPaths[$sizeIdx] = sprintf($path, strtolower(Util::$localeStrings[$l]).'/') . $outFile . '.jpg';
$outPaths[$sizeIdx] = sprintf($path, strtolower($locJsonStr).'/') . $outFile . '.jpg';
if (!CLISetup::getOpt('force') && file_exists($outPaths[$sizeIdx]))
{

View File

@@ -44,7 +44,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
$setList = DB::Aowow()->Select('SELECT * FROM ?_itemset ORDER BY refSetId DESC');
$jsonBonus = [];
foreach (CLISetup::$localeIds as $lId)
foreach (CLISetup::$locales as $lId => $jsonStr)
{
User::useLocale($lId);
Lang::load($lId);
@@ -120,7 +120,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
}
$toFile = "var g_itemsets = ".Util::toJSON($itemsetOut).";";
$file = 'datasets/'.User::$localeString.'/itemsets';
$file = 'datasets/'.$jsonStr.'/itemsets';
if (!CLISetup::writeFile($file, $toFile))
$this->success = false;

View File

@@ -63,7 +63,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
);
$result = [];
foreach (CLISetup::$localeIds as $l)
foreach (CLISetup::$locales as $l => $_)
if (isset($available[$l]))
$result[] = $available[$l];

View File

@@ -57,7 +57,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
$locations = DB::Aowow()->selectCol('SELECT `typeId` AS ARRAY_KEY, `areaId` AS ARRAY_KEY2, `areaId` FROM ?_spawns WHERE `type` = ?d AND `typeId` IN (?a) GROUP BY `typeId`, `areaId`', Type::NPC, array_column($petList, 'id'));
foreach (CLISetup::$localeIds as $lId)
foreach (CLISetup::$locales as $lId => $jsonStr)
{
User::useLocale($lId);
Lang::load($lId);
@@ -82,7 +82,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
}
$toFile = "var g_pets = ".Util::toJSON($petsOut).";";
$file = 'datasets/'.User::$localeString.'/pets';
$file = 'datasets/'.$jsonStr.'/pets';
if (!CLISetup::writeFile($file, $toFile))
$this->success = false;

View File

@@ -90,7 +90,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
$relCurr = new CurrencyList(array(['id', $_]));
foreach (CLISetup::$localeIds as $l)
foreach (CLISetup::$locales as $l => $jsonStr)
{
set_time_limit(20);
@@ -108,7 +108,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
foreach ($questz->getListviewData() as $id => $data)
$buff .= '_['.$id.'] = '.Util::toJSON($data).";\n";
if (!CLISetup::writeFile('datasets/'.User::$localeString.'/p-quests-'.$cat2, $buff))
if (!CLISetup::writeFile('datasets/'.$jsonStr.'/p-quests-'.$cat2, $buff))
$this->success = false;
}
}
@@ -135,7 +135,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
if (empty($titlez->sources[$id][4]) && empty($titlez->sources[$id][12]))
$this->addExclusion(Type::TITLE, $id, PR_EXCLUDE_GROUP_UNAVAILABLE);
foreach (CLISetup::$localeIds as $l)
foreach (CLISetup::$locales as $l => $jsonStr)
{
set_time_limit(5);
@@ -152,7 +152,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
$buff .= '_['.$id.'] = '.Util::toJSON($data).";\n";
}
if (!CLISetup::writeFile('datasets/'.User::$localeString.'/p-titles-'.$g, $buff))
if (!CLISetup::writeFile('datasets/'.$jsonStr.'/p-titles-'.$g, $buff))
$this->success = false;
}
}
@@ -179,7 +179,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
if (!$mountz->getSources())
$this->addExclusion(Type::SPELL, $id, PR_EXCLUDE_GROUP_UNAVAILABLE);
foreach (CLISetup::$localeIds as $l)
foreach (CLISetup::$locales as $l => $jsonStr)
{
set_time_limit(5);
@@ -203,7 +203,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
$buff .= '_['.$id.'] = '.Util::toJSON($data).";\n";
}
if (!CLISetup::writeFile('datasets/'.User::$localeString.'/p-mounts', $buff))
if (!CLISetup::writeFile('datasets/'.$jsonStr.'/p-mounts', $buff))
$this->success = false;
}
}
@@ -222,7 +222,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
if (!$companionz->getSources())
$this->addExclusion(Type::SPELL, $id, PR_EXCLUDE_GROUP_UNAVAILABLE);
foreach (CLISetup::$localeIds as $l)
foreach (CLISetup::$locales as $l => $jsonStr)
{
set_time_limit(5);
@@ -241,7 +241,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
$buff .= '_['.$id.'] = '.Util::toJSON($data).";\n";
}
if (!CLISetup::writeFile('datasets/'.User::$localeString.'/p-companions', $buff))
if (!CLISetup::writeFile('datasets/'.$jsonStr.'/p-companions', $buff))
$this->success = false;
}
}
@@ -254,7 +254,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
);
$factionz = new FactionList($condition);
foreach (CLISetup::$localeIds as $l)
foreach (CLISetup::$locales as $l => $jsonStr)
{
set_time_limit(5);
@@ -267,7 +267,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
$buff .= "\ng_faction_order = [0, 469, 891, 1037, 1118, 67, 1052, 892, 936, 1117, 169, 980, 1097];\n";
if (!CLISetup::writeFile('datasets/'.User::$localeString.'/p-factions', $buff))
if (!CLISetup::writeFile('datasets/'.$jsonStr.'/p-factions', $buff))
$this->success = false;
}
}
@@ -307,7 +307,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
}
}
foreach (CLISetup::$localeIds as $l)
foreach (CLISetup::$locales as $l => $jsonStr)
{
set_time_limit(10);
@@ -324,7 +324,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
if (!$buff)
{
// this behaviour is intended, do not create an error
CLI::write('[profiler] - file datasets/'.User::$localeString.'/p-recipes-'.$file.' has no content => skipping', CLI::LOG_INFO);
CLI::write('[profiler] - file datasets/'.$jsonStr.'/p-recipes-'.$file.' has no content => skipping', CLI::LOG_INFO);
continue;
}
@@ -333,7 +333,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
if (is_array($s))
$buff .= "\ng_skill_order = [171, 164, 333, 202, 182, 773, 755, 165, 186, 393, 197, 185, 129, 356];\n";
if (!CLISetup::writeFile('datasets/'.User::$localeString.'/p-recipes-'.$file, $buff))
if (!CLISetup::writeFile('datasets/'.$jsonStr.'/p-recipes-'.$file, $buff))
$this->success = false;
}
}
@@ -348,7 +348,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
);
$achievez = new AchievementList($condition);
foreach (CLISetup::$localeIds as $l)
foreach (CLISetup::$locales as $l => $jsonStr)
{
set_time_limit(5);
@@ -368,7 +368,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
// sum points
$buff .= "\ng_achievement_points = [".$sumPoints."];\n";
if (!CLISetup::writeFile('datasets/'.User::$localeString.'/achievements', $buff))
if (!CLISetup::writeFile('datasets/'.$jsonStr.'/achievements', $buff))
$this->success = false;
}
}

View File

@@ -54,7 +54,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
$tSpellIds = DB::Aowow()->selectCol('SELECT rank1 FROM dbc_talent UNION SELECT rank2 FROM dbc_talent UNION SELECT rank3 FROM dbc_talent UNION SELECT rank4 FROM dbc_talent UNION SELECT rank5 FROM dbc_talent');
$this->tSpells = new SpellList(array(['s.id', $tSpellIds], Cfg::get('SQL_LIMIT_NONE')));
foreach (CLISetup::$localeIds as $lId)
foreach (CLISetup::$locales as $lId => $jsonStr)
{
User::useLocale($lId);
Lang::load($lId);
@@ -67,7 +67,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
set_time_limit(20);
$file = 'datasets/'.User::$localeString.'/talents-'.$i;
$file = 'datasets/'.$jsonStr.'/talents-'.$i;
$toFile = '$WowheadTalentCalculator.registerClass('.$i.', '.Util::toJSON($this->buildTree(1 << ($i - 1))).')';
if (!CLISetup::writeFile($file, $toFile))
@@ -77,7 +77,7 @@ CLISetup::registerSetup("build", new class extends SetupScript
// PetCalc
$toFile = "var g_pet_icons = ".$petIcons.";\n\n";
$toFile .= 'var g_pet_talents = '.Util::toJSON($this->buildTree(0)).';';
$file = 'datasets/'.User::$localeString.'/pet-talents';
$file = 'datasets/'.$jsonStr.'/pet-talents';
if (!CLISetup::writeFile($file, $toFile))
$this->success = false;

View File

@@ -179,7 +179,7 @@ trait TrImageProcessor
$locList = [];
foreach (CLISetup::$expectedPaths as $xp => $locId)
if (in_array($locId, CLISetup::$localeIds))
if (in_array($locId, array_keys(CLISetup::$locales)))
$locList[] = $xp;
CLI::write('[img-proc] required resources overview:', CLI::LOG_INFO);
@@ -202,11 +202,11 @@ trait TrImageProcessor
{
$foundLoc = [];
foreach (CLISetup::$expectedPaths as $xp => $lId)
if (in_array($lId, CLISetup::$localeIds))
if (in_array($lId, array_keys(CLISetup::$locales)))
if (isset($realPaths[$lId]) && ($n = stripos($realPaths[$lId], '/'.$xp.'/')))
$foundLoc[$lId] = substr($realPaths[$lId], $n + 1, 4);
if ($diff = array_diff(CLISetup::$localeIds, array_keys($foundLoc)))
if ($diff = array_diff_key(CLISetup::$locales, $foundLoc))
{
$buff = [];
foreach ($diff as $d)

View File

@@ -24,7 +24,7 @@ CLISetup::registerSetup("sql", new class extends SetupScript
$allOK = true;
$locPath = CLISetup::filesInPathLocalized($globStrPath, $allOK);
if ($x = array_diff(CLISetup::$localeIds, array_keys($locPath)))
if ($x = array_diff_key(CLISetup::$locales, $locPath))
{
$locs = array_intersect_key(CLISetup::$locales, array_flip($x));
CLI::write('[emotes] '.sprintf($globStrPath, CLI::bold('['.implode('/,', $locs).'/]')) . ' not found!', CLI::LOG_WARN);