Skip to content

Commit

Permalink
Merge branch 'master' into feature/discussion-post-markdown-preview
Browse files Browse the repository at this point in the history
  • Loading branch information
notbakaneko committed Apr 11, 2023
2 parents a3e5dc6 + 3946142 commit 5e5da6d
Show file tree
Hide file tree
Showing 21 changed files with 294 additions and 261 deletions.
8 changes: 4 additions & 4 deletions database/factories/LegacyMatch/EventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ public function definition(): array
{
return [
'match_id' => LegacyMatch::factory(),
'user_id' => User::factory(),
'timestamp' => fn() => Carbon::now(),
'user_id' => User::factory(),
];
}

public function stateCreate(): static
{
return $this->state([
'user_id' => null,
'text' => 'CREATE',
'user_id' => null,
]);
}

public function disband(): static
{
return $this->state([
'user_id' => null,
'text' => 'DISBAND',
'user_id' => null,
]);
}

Expand All @@ -56,9 +56,9 @@ public function part(): static
public function game(): static
{
return $this->state([
'game_id' => Game::factory()->inProgress(),
'text' => 'test game',
'user_id' => null,
'game_id' => Game::factory()->inProgress(),
]);
}
}
5 changes: 3 additions & 2 deletions database/factories/LegacyMatch/GameFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ public function definition(): array
{
return [
'beatmap_id' => Beatmap::factory(),
'start_time' => fn(array $attributes) => Carbon::now()->subSeconds(Beatmap::find($attributes['beatmap_id'])->total_length),
'play_mode' => fn(array $attributes) => Beatmap::find($attributes['beatmap_id'])->playmode,
'scoring_type' => fn() => $this->faker->numberBetween(0, 3),
'team_type' => fn() => $this->faker->numberBetween(0, 3),

'play_mode' => fn(array $attributes) => Beatmap::find($attributes['beatmap_id'])->playmode,
'start_time' => fn(array $attributes) => Carbon::now()->subSeconds(Beatmap::find($attributes['beatmap_id'])->total_length),
];
}

Expand Down
2 changes: 1 addition & 1 deletion database/factories/LegacyMatch/LegacyMatchFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public function definition(): array
{
return [
'name' => fn() => $this->faker->sentence(),
'start_time' => fn() => Carbon::now(),
'private' => 0,
'start_time' => fn() => Carbon::now(),
];
}

Expand Down
44 changes: 26 additions & 18 deletions database/factories/Multiplayer/PlaylistItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];
}
}
58 changes: 35 additions & 23 deletions database/factories/Multiplayer/RoomFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)]);
}
}
88 changes: 44 additions & 44 deletions database/factories/Multiplayer/ScoreFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
26 changes: 18 additions & 8 deletions database/factories/NotificationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
];
}
}
26 changes: 19 additions & 7 deletions database/factories/UserNotificationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];
}
}
9 changes: 5 additions & 4 deletions database/seeders/ModelSeeders/MultiplayerSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(),
Expand Down
Loading

0 comments on commit 5e5da6d

Please sign in to comment.