2024-07-27 15:40:35 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\Models\GameSession;
|
2024-07-28 18:06:05 -04:00
|
|
|
use App\Models\Palette;
|
|
|
|
use App\Models\WinningState;
|
2024-07-27 15:40:35 -04:00
|
|
|
|
|
|
|
class GameSessionController extends Controller
|
|
|
|
{
|
|
|
|
public function start(Request $request)
|
|
|
|
{
|
2024-07-28 18:06:05 -04:00
|
|
|
$request->validate([
|
|
|
|
'session_name' => 'required|string|max:255',
|
|
|
|
'palette_id' => 'required|exists:palettes,id',
|
|
|
|
'image_path' => 'required|string'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$gameSession = GameSession::create([
|
|
|
|
'session_name' => $request->session_name,
|
|
|
|
'palette_id' => $request->palette_id,
|
|
|
|
'image_path' => $request->image_path,
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Logic to initialize the winning state based on the provided image
|
|
|
|
// ...
|
|
|
|
|
|
|
|
return response()->json($gameSession);
|
2024-07-27 15:40:35 -04:00
|
|
|
}
|
|
|
|
|
2024-07-28 18:06:05 -04:00
|
|
|
public function end(Request $request, $id)
|
2024-07-27 15:40:35 -04:00
|
|
|
{
|
2024-07-28 18:06:05 -04:00
|
|
|
$gameSession = GameSession::findOrFail($id);
|
|
|
|
$gameSession->update(['ended_at' => now()]);
|
2024-07-27 15:40:35 -04:00
|
|
|
|
2024-07-28 18:06:05 -04:00
|
|
|
return response()->json($gameSession);
|
2024-07-27 15:40:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function current()
|
|
|
|
{
|
2024-07-28 18:06:05 -04:00
|
|
|
$currentGame = GameSession::whereNull('ended_at')->latest()->first();
|
|
|
|
return response()->json($currentGame);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCurrentGameSession()
|
|
|
|
{
|
|
|
|
$gameSession = GameSession::whereNull('ended_at')->latest()->first();
|
|
|
|
|
|
|
|
if (!$gameSession) {
|
|
|
|
$gameSession = GameSession::create(['session_name' => 'Session ' . now(), 'palette_id' => 1, 'image_path' => '']);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $gameSession;
|
2024-07-27 15:40:35 -04:00
|
|
|
}
|
|
|
|
}
|