-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into conditional-aotw-gold-border
- Loading branch information
Showing
7 changed files
with
333 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Connect\Actions; | ||
|
||
use App\Models\GameAchievementSet; | ||
use App\Platform\Enums\AchievementSetType; | ||
|
||
/** | ||
* Note that this action is somewhat naive and does not take into | ||
* account any hash loaded by a user or any user settings. It simply | ||
* attempts to find what the ultimate "parent" game is. | ||
*/ | ||
class ResolveRootGameIdFromGameIdAction | ||
{ | ||
public function execute(int $gameId): int | ||
{ | ||
// Get the game's achievement sets. | ||
$sets = GameAchievementSet::whereGameId($gameId)->get(); | ||
if ($sets->isEmpty()) { | ||
return $gameId; | ||
} | ||
|
||
// For each achievement set, look for other games that reference this set. | ||
foreach ($sets as $set) { | ||
// Find all games that reference this achievement set. | ||
$linkedSets = GameAchievementSet::whereAchievementSetId($set->achievement_set_id) | ||
->where('game_id', '!=', $gameId) | ||
->get(); | ||
|
||
// Look for a game that uses this set as a non-core type. | ||
$parentSet = $linkedSets->first(function ($linkedSet) { | ||
return $linkedSet->type !== AchievementSetType::Core; | ||
}); | ||
|
||
if ($parentSet) { | ||
// We found a parent - return its game_id value. | ||
return $parentSet->game_id; | ||
} | ||
} | ||
|
||
// No parent found, this must be the root game. | ||
return $gameId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.