Skip to content

Commit

Permalink
Arena gametype overviews (#1582)
Browse files Browse the repository at this point in the history
* fix: support "Arena" gamevariant by reversing to category

* test: enhance suite for arena gametype test
  • Loading branch information
iBotPeaches authored Jan 28, 2025
1 parent be12ba1 commit 5dad4a5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/Jobs/ProcessOverviewAnalytic.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ private function parseOverviewGametypes(Overview $overview): void

$variantMapping = [];
Gamevariant::query()
->with('category')
->whereIn('id', $gametypeIds)
->each(function (Gamevariant $gamevariant) use ($overview, &$variantMapping) {
try {
$baseMode = GametypeHelper::findBaseGametype($gamevariant->name);
$baseMode = GametypeHelper::findBaseGametype($gamevariant);
$variantMapping[$baseMode->value][] = $gamevariant->id;
} catch (\InvalidArgumentException $e) {
if (! $overview->is_manual) {
Expand Down
10 changes: 9 additions & 1 deletion app/Support/Gametype/GametypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
namespace App\Support\Gametype;

use App\Enums\BaseGametype;
use App\Models\Gamevariant;
use Illuminate\Support\Str;

class GametypeHelper
{
public static function findBaseGametype(string $name): BaseGametype
public static function findBaseGametype(Gamevariant $gamevariant): BaseGametype
{
$name = $gamevariant->name;

// Some modes are just "Arena", but we can look back at the category to determine the base gametype
if ($name === 'Arena' && $gamevariant->category) {
$name = $gamevariant->category->name ?? $name;
}

foreach (BaseGametype::getKeys() as $baseGametype) {
if (Str::contains($name, Str::replace('_', ' ', $baseGametype), true)) {
return BaseGametype::fromKey($baseGametype);
Expand Down
12 changes: 11 additions & 1 deletion tests/Feature/Console/RefreshOverviewsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Tests\Feature\Console;

use App\Models\Category;
use App\Models\Game;
use App\Models\Gamevariant;
use App\Models\Level;
Expand Down Expand Up @@ -47,10 +48,14 @@ public function test_valid_generation_of_overviews(): void
$ninjaNaut = Gamevariant::factory()->createOne([
'name' => 'Ninjanaut',
]);

$alphaZombies = Gamevariant::factory()->createOne([
'name' => 'Alpha Zombies',
]);
$arena = Gamevariant::factory()
->for(Category::factory()->set('name', 'Slayer'))
->createOne([
'name' => 'Arena',
]);

$map1 = Map::factory()->createOne([
'name' => 'Absolute',
Expand Down Expand Up @@ -116,6 +121,11 @@ public function test_valid_generation_of_overviews(): void
'gamevariant_id' => $alphaZombies->id,
]);

Game::factory()->createOne([
'map_id' => $map1->id,
'gamevariant_id' => $arena->id,
]);

// Act
$this->artisan('analytics:overviews:refresh')
->expectsOutputToContain('Processed '.$game->map->name)
Expand Down

0 comments on commit 5dad4a5

Please sign in to comment.