the browser-facing portion of osu!
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add support for disallowing usage of difficulty reduction mods to complete beatmap pack

nanaya 73efa232 34efbc03

+57 -2
+1
app/Libraries/ModsHelper.php
··· 35 35 36 36 [29, 'V2'], 37 37 ]; 38 + const DIFFICULTY_REDUCTION_MODS = ['NF', 'EZ', 'HT', 'SO']; 38 39 const PREFERENCE_MODS_BITSET = 0b01000000000000000100001000100000; // SD, NC, PF, MR 39 40 40 41 public static function toArray($bitset)
+13 -1
app/Models/BeatmapPack.php
··· 5 5 6 6 namespace App\Models; 7 7 8 + use App\Libraries\ModsHelper; 8 9 use Exception; 9 10 10 11 /** ··· 31 32 protected $table = 'osu_beatmappacks'; 32 33 protected $primaryKey = 'pack_id'; 33 34 34 - protected $casts = ['hidden' => 'boolean']; 35 + protected $casts = [ 36 + 'hidden' => 'boolean', 37 + 'no_diff_reduction' => 'boolean', 38 + ]; 35 39 36 40 protected $dates = ['date']; 37 41 public $timestamps = false; ··· 102 106 ->where('playmode', '=', $scoreRelation['playmode']) 103 107 ->whereHas($scoreRelation['relation'], function ($scoreQuery) use ($userId) { 104 108 $scoreQuery->where('user_id', '=', $userId); 109 + 110 + if ($this->no_diff_reduction) { 111 + $scoreQuery->withoutMods(ModsHelper::DIFFICULTY_REDUCTION_MODS); 112 + } 105 113 }); 106 114 }); 107 115 } ··· 117 125 118 126 $query->whereHas($scoreRelation, function ($query) use ($userId) { 119 127 $query->where('user_id', '=', $userId); 128 + 129 + if ($this->no_diff_reduction) { 130 + $query->withoutMods(ModsHelper::DIFFICULTY_REDUCTION_MODS); 131 + } 120 132 }); 121 133 } 122 134
+8 -1
app/Models/Score/Model.php
··· 6 6 namespace App\Models\Score; 7 7 8 8 use App\Exceptions\ClassNotFoundException; 9 + use App\Libraries\ModsHelper; 9 10 use App\Models\Beatmap; 10 11 use App\Models\Model as BaseModel; 11 12 use App\Models\User; 12 13 use App\Traits\Scoreable; 13 - use App\Libraries\ModsHelper; 14 14 15 15 /** 16 16 * @property Beatmap $beatmap ··· 118 118 $q->orWhereRaw('enabled_mods & ? = ?', [$preferenceMask | $bitset, $bitset]); 119 119 } 120 120 }); 121 + } 122 + 123 + public function scopeWithoutMods($query, $modsArray) 124 + { 125 + $bitset = ModsHelper::toBitset($modsArray); 126 + 127 + return $query->whereRaw('enabled_mods & ? = 0', $bitset); 121 128 } 122 129 123 130 public function beatmap()
+35
database/migrations/2020_11_13_025024_add_no_diff_reduction_to_beatmap_packs.php
··· 1 + <?php 2 + 3 + // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4 + // See the LICENCE file in the repository root for full licence text. 5 + 6 + use Illuminate\Database\Migrations\Migration; 7 + use Illuminate\Database\Schema\Blueprint; 8 + use Illuminate\Support\Facades\Schema; 9 + 10 + class AddNoDiffReductionToBeatmapPacks extends Migration 11 + { 12 + /** 13 + * Run the migrations. 14 + * 15 + * @return void 16 + */ 17 + public function up() 18 + { 19 + Schema::table('osu_beatmappacks', function (Blueprint $table) { 20 + $table->boolean('no_diff_reduction')->default(false); 21 + }); 22 + } 23 + 24 + /** 25 + * Reverse the migrations. 26 + * 27 + * @return void 28 + */ 29 + public function down() 30 + { 31 + Schema::table('osu_beatmappacks', function (Blueprint $table) { 32 + $table->dropColumn('no_diff_reduction'); 33 + }); 34 + } 35 + }