Luke Jones

intervle - commit 63a6cdc

feat: return different events based on difficulty63a6cdc36abb0eb12b9c519f22350a90364d20ebLukeJ<luke.jones.2567@gmail.com>2026-03-08T15:18:00Z
diff --git a/app/Http/Controllers/GameController.php b/app/Http/Controllers/GameController.php index 5c382f5..349277b 100644 --- a/app/Http/Controllers/GameController.php +++ b/app/Http/Controllers/GameController.php @@ -7,9 +7,13 @@ use Illuminate\Http\Request; class GameController extends Controller { - public function show(string $date) + public function show(string $difficulty, string $date) { - $seed = $this->getSeedFromDate($date); + if (!in_array($difficulty, ['easy', 'medium', 'hard'])) { + return response('', 400); + } + + $seed = $this->getSeedFromDateAndDifficulty($difficulty, $date); if ($seed == -1) { return response('', 400); @@ -20,25 +24,13 @@ class GameController extends Controller return view('game.show', compact('events')); } - private function getSeedFromDate(string $date) { - $today = intval(date('Ymd')); - - if ($date == 'today') { - $seed = $today; - } else { - if (intval($date) <= intval($today)) { - $seed = $date; - } else { - $seed = -1; - } + public function submit(Request $request, string $difficulty, string $date) + { + if (!in_array($difficulty, ['easy', 'medium', 'hard'])) { + return response('', 400); } - return $seed; - } - - public function submit(Request $request, string $date) - { - $seed = $this->getSeedFromDate($date); + $seed = $this->getSeedFromDateAndDifficulty($difficulty, $date); if ($seed == -1) { return response('', 400); @@ -64,4 +56,20 @@ class GameController extends Controller 'results' => $results ]); } + + private function getSeedFromDateAndDifficulty(string $difficulty, string $date) { + $today = intval(date('Ymd')); + + if ($date == 'today') { + $seed = $today; + } else { + if (intval($date) <= intval($today)) { + $seed = $date; + } else { + return -1; + } + } + + return $seed . $difficulty; + } } diff --git a/app/Models/Event.php b/app/Models/Event.php index f9151cd..d25ec72 100644 --- a/app/Models/Event.php +++ b/app/Models/Event.php @@ -18,19 +18,34 @@ class Event extends Model public function scopeDailyRandom($query, $seed) { + $count = $this->getCountFromSeed($seed); + return $query ->orderByRaw("md5(id::text || ?)", [$seed]) - ->limit(5); + ->limit($count); } public function scopeDailyRandomOrdered($query, $seed) { + $count = $this->getCountFromSeed($seed); + $sub = self::query() ->orderByRaw("md5(id::text || ?)", [$seed]) - ->limit(5); + ->limit($count); return $query ->fromSub($sub, 'daily_events') ->orderBy('date', 'asc'); } + + private function getCountFromSeed($seed) + { + $difficultyMapping = [ + 'easy' => 5, + 'medium' => 7, + 'hard' => 10, + ]; + + return $difficultyMapping[(preg_replace('/[0-9]+/', '', $seed))]; + } } diff --git a/resources/js/app.js b/resources/js/app.js index c07e274..8e72b1d 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -2,7 +2,7 @@ import './bootstrap'; document.addEventListener('DOMContentLoaded', () => { - if (/^\/(today|\d{8})\/?$/.test(window.location.pathname)) { + if (/^\/(easy|medium|hard)\/(today|\d{8})\/?$/.test(window.location.pathname)) { const currentDate = window.location.pathname; const eventsContainer = document.getElementById('events-container'); diff --git a/routes/web.php b/routes/web.php index 84cf5d6..2eab0d1 100644 --- a/routes/web.php +++ b/routes/web.php @@ -4,8 +4,9 @@ use App\Http\Controllers\GameController; use Illuminate\Support\Facades\Route; -Route::redirect('/', '/today'); +Route::redirect('/', '/easy/today'); +Route::redirect('/today', '/easy/today'); -Route::get('/{date}', [GameController::class, 'show']); +Route::get('/{difficulty}/{date}', [GameController::class, 'show']); -Route::post('/{date}/submit', [GameController::class, 'submit']); +Route::post('/{difficulty}/{date}/submit', [GameController::class, 'submit']);