-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into track-theme-scheme
- Loading branch information
Showing
56 changed files
with
1,316 additions
and
400 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Data; | ||
|
||
use App\Models\User; | ||
use Spatie\LaravelData\Data; | ||
use Spatie\LaravelData\Lazy; | ||
use Spatie\TypeScriptTransformer\Attributes\TypeScript; | ||
|
||
#[TypeScript('UserPermissions')] | ||
class UserPermissionsData extends Data | ||
{ | ||
public function __construct( | ||
public Lazy|bool $manageGameHashes, | ||
) { | ||
} | ||
|
||
public static function fromUser(?User $user): self | ||
{ | ||
return new self( | ||
manageGameHashes: Lazy::create(fn () => $user ? $user->can('manage', \App\Models\GameHash::class) : false), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Platform\Data; | ||
|
||
use App\Models\Game; | ||
use Spatie\LaravelData\Data; | ||
use Spatie\LaravelData\Lazy; | ||
use Spatie\TypeScriptTransformer\Attributes\TypeScript; | ||
|
||
#[TypeScript('Game')] | ||
class GameData extends Data | ||
{ | ||
public function __construct( | ||
public int $id, | ||
public string $title, | ||
public Lazy|string $badgeUrl, | ||
public Lazy|int $forumTopicId, | ||
public Lazy|SystemData $system, | ||
) { | ||
} | ||
|
||
public static function fromGame(Game $game): self | ||
{ | ||
return new self( | ||
id: $game->id, | ||
title: $game->title, | ||
badgeUrl: Lazy::create(fn () => $game->badge_url), | ||
forumTopicId: Lazy::create(fn () => $game->ForumTopicID), | ||
system: Lazy::create(fn () => SystemData::fromSystem($game->system)) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Platform\Data; | ||
|
||
use App\Models\GameHash; | ||
use Illuminate\Database\Eloquent\Collection; | ||
use Spatie\LaravelData\Data; | ||
use Spatie\TypeScriptTransformer\Attributes\TypeScript; | ||
use Spatie\TypeScriptTransformer\Attributes\TypeScriptType; | ||
|
||
#[TypeScript('GameHash')] | ||
class GameHashData extends Data | ||
{ | ||
public function __construct( | ||
public int $id, | ||
public string $md5, | ||
public ?string $name, | ||
#[TypeScriptType('App\\Platform\\Data\\GameHashLabelData[]')] | ||
public array $labels, | ||
public ?string $patchUrl, | ||
) { | ||
} | ||
|
||
public static function fromGameHash(GameHash $gameHash): self | ||
{ | ||
return new self( | ||
id: $gameHash->id, | ||
md5: $gameHash->md5, | ||
name: $gameHash->name, | ||
labels: GameHashLabelData::fromLabelsString($gameHash->labels), | ||
patchUrl: $gameHash->patch_url, | ||
); | ||
} | ||
|
||
/** | ||
* @param Collection<int, GameHash> $gameHashes | ||
* @return GameHashData[] | ||
*/ | ||
public static function fromCollection(Collection $gameHashes): array | ||
{ | ||
return array_map( | ||
fn ($gameHash) => self::fromGameHash($gameHash), | ||
$gameHashes->all() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Platform\Data; | ||
|
||
use Illuminate\Support\Facades\File; | ||
use Spatie\LaravelData\Data; | ||
use Spatie\TypeScriptTransformer\Attributes\TypeScript; | ||
|
||
#[TypeScript('GameHashLabel')] | ||
class GameHashLabelData extends Data | ||
{ | ||
public function __construct( | ||
public string $label, | ||
public ?string $imgSrc | ||
) { | ||
} | ||
|
||
/** | ||
* @return GameHashLabelData[] | ||
*/ | ||
public static function fromLabelsString(string $labels): array | ||
{ | ||
$asArray = array_filter(explode(',', $labels)); | ||
|
||
return array_map(function (string $label) { | ||
$imagePath = "/assets/images/labels/" . $label . '.png'; | ||
$publicPath = public_path($imagePath); | ||
|
||
$imgSrc = File::exists($publicPath) ? asset($imagePath) : null; | ||
|
||
return new self( | ||
label: $label, | ||
imgSrc: $imgSrc | ||
); | ||
}, $asArray); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Platform\Data; | ||
|
||
use App\Data\UserPermissionsData; | ||
use Spatie\LaravelData\Data; | ||
use Spatie\TypeScriptTransformer\Attributes\TypeScript; | ||
|
||
#[TypeScript('GameHashesPageProps')] | ||
class GameHashesPagePropsData extends Data | ||
{ | ||
/** | ||
* @param GameHashData[] $hashes | ||
*/ | ||
public function __construct( | ||
public GameData $game, | ||
public array $hashes, | ||
public UserPermissionsData $can, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Platform\Data; | ||
|
||
use App\Models\System; | ||
use Spatie\LaravelData\Data; | ||
use Spatie\LaravelData\Lazy; | ||
use Spatie\TypeScriptTransformer\Attributes\TypeScript; | ||
|
||
#[TypeScript('System')] | ||
class SystemData extends Data | ||
{ | ||
public function __construct( | ||
public int $id, | ||
public string $name, | ||
public Lazy|string $nameFull, | ||
public Lazy|string $nameShort, | ||
) { | ||
} | ||
|
||
public static function fromSystem(System $system): self | ||
{ | ||
return new self( | ||
id: $system->id, | ||
name: $system->name, | ||
nameFull: Lazy::create(fn () => $system->name_full), | ||
nameShort: Lazy::create(fn () => $system->name_short), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.