Archived
1
0
Fork 0

Initial Commit

This commit is contained in:
Henrik Hautakoski 2021-10-18 11:53:33 +02:00
commit ddf09fe00c
113 changed files with 187148 additions and 0 deletions

View file

@ -0,0 +1,13 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}

View file

@ -0,0 +1,17 @@
<?php
namespace App\Http\Controllers;
use App\Game\GameService;
use App\Models\Setting;
class SettingController extends Controller
{
public function hash(GameService $service, Setting $setting)
{
// Generate a new game with these settings.
$service->newSession($setting->value);
return redirect()->route('game');
}
}

36
app/Http/Kernel.php Normal file
View file

@ -0,0 +1,36 @@
<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
\Illuminate\Session\Middleware\StartSession::class,
\App\Http\Middleware\TrustProxies::class,
\Fruitcake\Cors\HandleCors::class,
\Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\Illuminate\Routing\Middleware\SubstituteBindings::class,
]
];
}

View file

@ -0,0 +1,62 @@
<?php
namespace App\Http\Livewire;
class Game extends GameComponent
{
/**
* Get the game session
*/
public function getSessionProperty()
{
return $this->service->session();
}
/**
* Get the game board.
*/
public function getBoardProperty()
{
return $this->session->getBoard();
}
/**
* Get the game state.
*/
public function getStateProperty()
{
return $this->session->getBoardState();
}
/**
* Clear everything.
*/
public function clear()
{
$this->board->clear();
}
/**
* Triggered wen a card is pressed.
*/
public function toggle($pos)
{
$this->state->toggle($pos);
}
/**
* Reset game session.
*/
public function restart()
{
$this->service->newSession();
}
/**
* Render the game board.
*/
public function render()
{
return view('game');
}
}

View file

@ -0,0 +1,18 @@
<?php
namespace App\Http\Livewire;
use App\Game\GameService;
use Livewire\Component;
abstract class GameComponent extends Component
{
/**
* Get the game service object
*/
public function getServiceProperty() : GameService
{
return app()->make(GameService::class);
}
}

View file

@ -0,0 +1,78 @@
<?php
namespace App\Http\Livewire;
use App\Models\Setting;
use App\Models\Raid;
use App\Models\Character;
use App\Models\Card;
class Setup extends GameComponent
{
public $all_raids;
public $all_characters;
public $all_classes;
public $shared_settings;
public $values = [
'classes' => [],
'raids' => [],
'characters' => []
];
function mount()
{
$this->all_classes = Card::select('class')
->whereNotNull('class')
->groupBy('class')->orderBy('class')->get()->pluck('class');
$this->all_raids = Raid::select('id', 'name')->orderBy('name')->get();
$this->all_characters = Character::select('id', 'name')
->orderBy('name')->get();
// Load values from settings
$this->values['classes'] = $this->settings->classes->toArray();
$this->values['raids'] = $this->settings->raids->toArray();
$this->values['characters'] = $this->settings->characters->toArray();
}
public function getSettingsProperty()
{
return $this->service->session()->getSettings();
}
public function resetSettings()
{
$this->reset('values');
}
public function share()
{
$setting = Setting::create(['value' => $this->values]);
$this->shared_settings = $setting->hash;
}
public function save()
{
// Store values
$this->settings->classes->fill($this->values['classes']);
$this->settings->raids->fill($this->values['raids']);
$this->settings->characters->fill($this->values['characters']);
$this->service->newSession($this->settings);
$this->redirectRoute('game');
}
/**
* Render the setup page
*/
public function render()
{
return view('setup');
}
}

View file

@ -0,0 +1,19 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
class TrimStrings extends Middleware
{
/**
* The names of the attributes that should not be trimmed.
*
* @var array
*/
protected $except = [
'current_password',
'password',
'password_confirmation',
];
}

View file

@ -0,0 +1,28 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Middleware\TrustProxies as Middleware;
use Illuminate\Http\Request;
class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application.
*
* @var array|string|null
*/
protected $proxies;
/**
* The headers that should be used to detect proxies.
*
* @var int
*/
protected $headers =
Request::HEADER_X_FORWARDED_FOR |
Request::HEADER_X_FORWARDED_HOST |
Request::HEADER_X_FORWARDED_PORT |
Request::HEADER_X_FORWARDED_PROTO |
Request::HEADER_X_FORWARDED_AWS_ELB;
}