initial commit
This commit is contained in:
commit
e8c3f9862a
193 files changed
+29795
No files matched your search
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Game\Room;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
final class GameSnapshot implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable;
|
||||
use InteractsWithSockets;
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $players
|
||||
* @param array<int, mixed> $entities
|
||||
* @param array<int, mixed> $events
|
||||
*/
|
||||
public function __construct(
|
||||
public Room $room,
|
||||
public array $players,
|
||||
public array $entities,
|
||||
public array $events,
|
||||
) {
|
||||
}
|
||||
|
||||
public function broadcastOn(): Channel
|
||||
{
|
||||
return new Channel('game.' . $this->room->id);
|
||||
}
|
||||
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'snapshot';
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'state' => $this->room->state,
|
||||
'elapsed' => round($this->room->elapsed, 2),
|
||||
'seq' => $this->room->seq,
|
||||
'players' => $this->players,
|
||||
'entities' => $this->entities,
|
||||
'events' => $this->events,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user