initial commit
This commit is contained in:
commit
e8c3f9862a
193 files changed
+29795
No files matched your search
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
|
||||
final class GameInputController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request, string $room): JsonResponse
|
||||
{
|
||||
$playerId = (string) $request->input('id', '');
|
||||
if ($playerId === '') {
|
||||
return response()->json(['error' => 'missing id'], 422);
|
||||
}
|
||||
|
||||
$keys = $request->input('keys');
|
||||
$keys = is_array($keys)
|
||||
? array_values(array_filter($keys, 'is_string'))
|
||||
: [];
|
||||
|
||||
$aim = $request->input('aim');
|
||||
$aim = is_array($aim)
|
||||
? ['x' => (float) ($aim['x'] ?? 0.0), 'y' => (float) ($aim['y'] ?? 0.0)]
|
||||
: ['x' => 1.0, 'y' => 0.0];
|
||||
|
||||
$frame = [
|
||||
'id' => $playerId,
|
||||
'keys' => $keys,
|
||||
'aim' => $aim,
|
||||
'fire' => (bool) $request->input('fire', false),
|
||||
'autoAim' => (bool) $request->input('autoAim', false),
|
||||
];
|
||||
|
||||
Redis::rpush(sprintf('game:in:%s', $room), json_encode($frame, JSON_THROW_ON_ERROR));
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user