-
Notifications
You must be signed in to change notification settings - Fork 384
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 feature/discussion-post-markdown-preview
- Loading branch information
Showing
21 changed files
with
294 additions
and
261 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
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 |
---|---|---|
|
@@ -3,21 +3,29 @@ | |
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
$factory->define(App\Models\Multiplayer\PlaylistItem::class, function (Faker\Generator $faker) { | ||
return [ | ||
'beatmap_id' => function () { | ||
return App\Models\Beatmap::factory()->create()->getKey(); | ||
}, | ||
'room_id' => function () { | ||
return factory(App\Models\Multiplayer\Room::class)->create()->getKey(); | ||
}, | ||
'ruleset_id' => function (array $self) { | ||
return App\Models\Beatmap::find($self['beatmap_id'])->playmode; | ||
}, | ||
'allowed_mods' => [], | ||
'required_mods' => [], | ||
'owner_id' => function () { | ||
return App\Models\User::factory()->create()->getKey(); | ||
}, | ||
]; | ||
}); | ||
declare(strict_types=1); | ||
|
||
namespace Database\Factories\Multiplayer; | ||
|
||
use App\Models\Beatmap; | ||
use App\Models\Multiplayer\PlaylistItem; | ||
use App\Models\Multiplayer\Room; | ||
use App\Models\User; | ||
use Database\Factories\Factory; | ||
|
||
class PlaylistItemFactory extends Factory | ||
{ | ||
protected $model = PlaylistItem::class; | ||
|
||
public function definition(): array | ||
{ | ||
return [ | ||
'beatmap_id' => Beatmap::factory(), | ||
'room_id' => Room::factory(), | ||
'ruleset_id' => fn(array $attributes) => Beatmap::find($attributes['beatmap_id'])->playmode, | ||
'allowed_mods' => [], | ||
'required_mods' => [], | ||
'owner_id' => User::factory(), | ||
]; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,29 +3,41 @@ | |
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Database\Factories\Multiplayer; | ||
|
||
use App\Models\Chat\Channel; | ||
use App\Models\Multiplayer\Room; | ||
use App\Models\User; | ||
use Carbon\Carbon; | ||
use Database\Factories\Factory; | ||
|
||
class RoomFactory extends Factory | ||
{ | ||
protected $model = Room::class; | ||
|
||
public function configure(): static | ||
{ | ||
return $this->afterCreating(function (Room $room) { | ||
$channel = Channel::createMultiplayer($room); | ||
|
||
$room->update(['channel_id' => $channel->getKey()]); | ||
}); | ||
} | ||
|
||
public function definition(): array | ||
{ | ||
return [ | ||
'user_id' => User::factory(), | ||
'name' => fn() => $this->faker->realText(20), | ||
'starts_at' => fn() => Carbon::now()->subHours(1), | ||
'ends_at' => fn() => Carbon::now()->addHours(1), | ||
]; | ||
} | ||
|
||
$factory->define(Room::class, function (Faker\Generator $faker) { | ||
return [ | ||
'user_id' => function (array $self) { | ||
return App\Models\User::factory()->create()->getKey(); | ||
}, | ||
'name' => function () use ($faker) { | ||
return $faker->realText(20); | ||
}, | ||
'starts_at' => Carbon\Carbon::now()->subHours(1), | ||
'ends_at' => Carbon\Carbon::now()->addHours(1), | ||
]; | ||
}); | ||
|
||
$factory->state(Room::class, 'ended', function (Faker\Generator $faker) { | ||
return [ | ||
'ends_at' => Carbon\Carbon::now()->subMinutes(1), | ||
]; | ||
}); | ||
|
||
$factory->afterCreating(Room::class, function (Room $room, $faker) { | ||
$channel = Channel::createMultiplayer($room); | ||
$room->update(['channel_id' => $channel->getKey()]); | ||
}); | ||
public function ended(): static | ||
{ | ||
return $this->state(['ends_at' => Carbon::now()->subMinutes(1)]); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,51 +3,51 @@ | |
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Database\Factories\Multiplayer; | ||
|
||
use App\Models\Multiplayer\PlaylistItem; | ||
use App\Models\Multiplayer\Score; | ||
use App\Models\User; | ||
use Carbon\Carbon; | ||
use Database\Factories\Factory; | ||
|
||
class ScoreFactory extends Factory | ||
{ | ||
protected $model = Score::class; | ||
|
||
public function completed(): static | ||
{ | ||
return $this->state(['ended_at' => Carbon::now()->subMinutes(1)]); | ||
} | ||
|
||
public function definition(): array | ||
{ | ||
return [ | ||
'playlist_item_id' => PlaylistItem::factory(), | ||
'beatmap_id' => fn(array $attributes) => PlaylistItem::find($attributes['playlist_item_id'])->beatmap_id, | ||
'room_id' => fn(array $attributes) => PlaylistItem::find($attributes['playlist_item_id'])->room_id, | ||
'user_id' => User::factory(), | ||
'total_score' => 1, | ||
'started_at' => fn() => Carbon::now()->subMinutes(5), | ||
'accuracy' => 0.5, | ||
'pp' => 1, | ||
]; | ||
} | ||
|
||
public function failed(): static | ||
{ | ||
return $this->completed()->state(['passed' => false]); | ||
} | ||
|
||
public function passed(): static | ||
{ | ||
return $this->completed()->state(['passed' => true]); | ||
} | ||
|
||
$factory->define(Score::class, function (Faker\Generator $faker) { | ||
return [ | ||
'playlist_item_id' => function () { | ||
return factory(PlaylistItem::class)->create()->getKey(); | ||
}, | ||
'beatmap_id' => function (array $self) { | ||
return PlaylistItem::find($self['playlist_item_id'])->beatmap_id; | ||
}, | ||
'room_id' => function (array $self) { | ||
return PlaylistItem::find($self['playlist_item_id'])->room_id; | ||
}, | ||
'user_id' => function () { | ||
return User::factory()->create()->getKey(); | ||
}, | ||
'total_score' => 1, | ||
'started_at' => now()->subMinutes(5), | ||
'accuracy' => 0.5, | ||
'pp' => 1, | ||
]; | ||
}); | ||
|
||
$factory->state(Score::class, 'completed', function (Faker\Generator $faker) { | ||
return [ | ||
'ended_at' => now(), | ||
]; | ||
}); | ||
|
||
$factory->state(Score::class, 'passed', function (Faker\Generator $faker) { | ||
return [ | ||
'passed' => true, | ||
]; | ||
}); | ||
|
||
$factory->state(Score::class, 'failed', function (Faker\Generator $faker) { | ||
return [ | ||
'passed' => false, | ||
]; | ||
}); | ||
|
||
$factory->state(Score::class, 'scoreless', function (Faker\Generator $faker) { | ||
return [ | ||
'total_score' => 0, | ||
]; | ||
}); | ||
public function scoreless(): static | ||
{ | ||
return $this->state(['total_score' => 0]); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,14 +3,24 @@ | |
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Libraries\MorphMap; | ||
use App\Models\Notification; | ||
|
||
$factory->define(Notification::class, function (Faker\Generator $faker) { | ||
return [ | ||
'notifiable_type' => array_rand_val(MorphMap::MAP), | ||
'notifiable_id' => rand(), | ||
'name' => array_rand(Notification::NAME_TO_CATEGORY), | ||
'details' => [], | ||
]; | ||
}); | ||
class NotificationFactory extends Factory | ||
{ | ||
protected $model = Notification::class; | ||
|
||
public function definition(): array | ||
{ | ||
return [ | ||
'details' => [], | ||
'name' => array_rand(Notification::NAME_TO_CATEGORY), | ||
'notifiable_id' => rand(), | ||
'notifiable_type' => array_rand_val(MorphMap::MAP), | ||
]; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,12 +3,24 @@ | |
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Models\Notification; | ||
use App\Models\User; | ||
use App\Models\UserNotification; | ||
|
||
$factory->define(UserNotification::class, function (Faker\Generator $faker) { | ||
return [ | ||
'delivery' => UserNotification::deliveryMask(array_rand(UserNotification::DELIVERY_OFFSETS)), | ||
'notification_id' => rand(), | ||
'user_id' => rand(), | ||
]; | ||
}); | ||
class UserNotificationFactory extends Factory | ||
{ | ||
protected $model = UserNotification::class; | ||
|
||
public function definition(): array | ||
{ | ||
return [ | ||
'delivery' => UserNotification::deliveryMask(array_rand(UserNotification::DELIVERY_OFFSETS)), | ||
'notification_id' => Notification::factory(), | ||
'user_id' => User::factory(), | ||
]; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Database\Seeders\ModelSeeders; | ||
|
||
use App\Models\Beatmap; | ||
|
@@ -22,23 +24,22 @@ class MultiplayerSeeder extends Seeder | |
*/ | ||
public function run() | ||
{ | ||
$rooms = factory(Room::class, 10)->create(); | ||
$rooms = Room::factory()->count(10)->create(); | ||
|
||
foreach ($rooms as $room) { | ||
$beatmaps = Beatmap::orderByRaw('RAND()')->limit(rand(4, 10))->get(); | ||
foreach ($beatmaps as $beatmap) { | ||
$playlistItem = factory(PlaylistItem::class)->create([ | ||
$playlistItem = PlaylistItem::factory()->create([ | ||
'room_id' => $room->getKey(), | ||
'beatmap_id' => $beatmap->getKey(), | ||
'ruleset_id' => $beatmap->playmode, | ||
]); | ||
|
||
$users = User::orderByRaw('RAND()')->limit(rand(4, 10))->get(); | ||
foreach ($users as $user) { | ||
$attempts = rand(1, 10); | ||
for ($i = 0; $i < $attempts; $i++) { | ||
$completed = rand(0, 100) > 20; | ||
factory(Score::class)->create([ | ||
Score::factory()->create([ | ||
'playlist_item_id' => $playlistItem->getKey(), | ||
'user_id' => $user->getKey(), | ||
'beatmap_id' => $beatmap->getKey(), | ||
|
Oops, something went wrong.