Skip to content

Commit

Permalink
Merge pull request #234 from P3D-Legacy/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
dsbilling authored Jan 24, 2023
2 parents 9d4660d + 5c79b56 commit afe3eee
Show file tree
Hide file tree
Showing 49 changed files with 2,131 additions and 203 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ Mac (Requires Laravel Valet):
valet open
```

Run code styling checks:
``` bash
vendor/bin/pint
```

# Licence

This software is licensed under the GPL-3.0 License. Check out [LICENSE](LICENSE) for more info.
103 changes: 103 additions & 0 deletions app/Console/Commands/SyncGameSave.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

namespace App\Console\Commands;

use App\Models\GamejoltAccount;
use App\Models\GameSave;
use Harrk\GameJoltApi\Exceptions\TimeOutException;
use Harrk\GameJoltApi\GamejoltApi;
use Harrk\GameJoltApi\GamejoltConfig;
use Illuminate\Console\Command;
use Schema;

class SyncGameSave extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'sync:gamesave {gamejolt_user_id}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Sync a game save from the GameJolt API';

private function handleGameSave($gamejolt_user_id, $api)
{
$gja = GamejoltAccount::firstWhere('id', $gamejolt_user_id);
$new_game_save = new GameSave;
$columns = Schema::getColumnListing($new_game_save->getTable());
$result = [];
try {
foreach ($columns as $column) {
if ($column == 'uuid' or $column == 'created_at' or $column == 'updated_at' or $column == 'user_id') {
continue;
}
$key = 'saveStorageV1|'.$gamejolt_user_id.'|'.$column;
$this->info('Getting "'.$key.'" from datastore');
$ds_result = $api->dataStore()->fetch($key, $gja->username, $gja->token);
$success = $ds_result['response']['success'];
if (filter_var($success, FILTER_VALIDATE_BOOLEAN)) {
$result[$column] = $ds_result['response']['data'];
} else {
$message = $ds_result['response']['message'];
$this->error($message);
break;
}
}
} catch (TimeOutException $e) {
$this->error('Error: '.$e->getMessage());

return Command::FAILURE;
}
$game_save = GameSave::where(['user_id' => $gja->user_id])->first();
if ($game_save) {
$game_save->update($result);
} else {
$result['user_id'] = $gja->user_id;
GameSave::create($result);
}
}

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$game_id = config('services.gamejolt.game_id');
$private_key = config('services.gamejolt.private_key');
if (! $game_id || ! $private_key) {
$this->error('Game ID or private key not set.');

return Command::FAILURE;
}
$api = new GamejoltApi(new GamejoltConfig($game_id, $private_key));
$gamejolt_user_id = $this->argument('gamejolt_user_id');
if ($gamejolt_user_id != 'all') {
if (! is_numeric($gamejolt_user_id) || $gamejolt_user_id < 1) {
$this->error('GameJolt user ID must be numeric.');

return Command::FAILURE;
}
}

if ($gamejolt_user_id == 'all') {
$gamejolt_accounts = GamejoltAccount::all();
foreach ($gamejolt_accounts as $gamejolt_account) {
$this->handleGameSave($gamejolt_account->id, $api);
}
} else {
$this->handleGameSave($gamejolt_user_id, $api);
}

$this->info('Done.');

return Command::SUCCESS;
}
}
86 changes: 86 additions & 0 deletions app/Console/Commands/SyncGameSaveGamejoltAccountTrophies.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace App\Console\Commands;

use App\Models\GamejoltAccount;
use App\Models\GameSave;
use Illuminate\Console\Command;
use Illuminate\Support\Str;

class SyncGameSaveGamejoltAccountTrophies extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'sync:game-save-gamejolt-account-trophies {gamejolt_user_id}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Sync the game save achievements with gamejolt account trophies';

private function handleUser($gamejolt_user_id): void
{
$gja = GamejoltAccount::firstWhere('id', $gamejolt_user_id);
$trophies = $gja->trophies;

$gamesave = GameSave::firstWhere('user_id', $gja->user_id);
if (! $gamesave) {
$this->error('Game save not found for user ID '.$gja->user_id);

return;
}
$game_save_achievements = $gamesave->getAchievements();

foreach ($game_save_achievements as $game_save_achievement) {
if ($game_save_achievement == 'unodostres') {
$achievement_name = 'UnoDosTres';
} elseif ($game_save_achievement == 'pokedex') {
$achievement_name = 'Pokédex';
} else {
$achievement_name = Str::headline($game_save_achievement);
}
$trophy = $trophies->firstWhere('title', $achievement_name);
if ($trophy) {
// Set the trophy to achieved
$trophy->achieved = true;
$trophy->save();
$this->info('Trophy "'.$achievement_name.'" has been updated for user ID '.$gja->user_id);
} else {
$this->warn('Trophy "'.$achievement_name.'" not found for user ID '.$gja->user_id);
}
}
}

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$gamejolt_user_id = $this->argument('gamejolt_user_id');
if ($gamejolt_user_id != 'all') {
if (! is_numeric($gamejolt_user_id) || $gamejolt_user_id < 1) {
$this->error('GameJolt user ID must be numeric.');

return Command::FAILURE;
}
}

if ($gamejolt_user_id == 'all') {
$gamejolt_accounts = GamejoltAccount::all();
foreach ($gamejolt_accounts as $gamejolt_account) {
$this->handleUser($gamejolt_account->id);
}
} else {
$this->handleUser($gamejolt_user_id);
}

return Command::SUCCESS;
}
}
2 changes: 1 addition & 1 deletion app/Console/Commands/UpdateGamejoltAccountTrophies.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function handle(): int
if (filter_var($trophies['response']['success'], FILTER_VALIDATE_BOOLEAN) === false) {
$this->error("No success for {$account->username}");

return 0;
continue;
}
$trophies = $trophies['response']['trophies'];
$trophy_count = count($trophies);
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/UpdateLanguageFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct()
public function handle(): int
{
$this->info('Updating language files...');
$special_languages = ['cn', 'tw']; // these have a special long format
$special_languages = ['cn', 'tw', 'pt-BR']; // these have a special long format
$languages = Arr::flatten(config('language.allowed')); // get allowed languages
$all_lang_codes = Arr::pluck(config('language.all'), 'long', 'short'); // get all languages short and long codes from config
foreach ($languages as $lang) {
Expand Down
15 changes: 12 additions & 3 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use App\Console\Commands\NotifyGameUpdate;
use App\Console\Commands\PingAllServers;
use App\Console\Commands\SkinUserUpdate;
use App\Console\Commands\SyncGameSave;
use App\Console\Commands\SyncGameSaveGamejoltAccountTrophies;
use App\Console\Commands\SyncGameVersion;
use App\Console\Commands\UpdateGamejoltAccountTrophies;
use Illuminate\Console\Scheduling\Schedule;
Expand All @@ -23,14 +25,21 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
$schedule->command(SkinUserUpdate::class)->hourlyAt(10);
// Often commands
$schedule->command(PingAllServers::class)->hourly();
$schedule->command(UpdateGamejoltAccountTrophies::class)->hourly();
$schedule->command(SyncGameVersion::class)->dailyAt('00:00');
$schedule->command(SkinUserUpdate::class)->hourlyAt(10);
// Daily commands
$schedule->command(DiscordRoleSync::class)->dailyAt('12:00');
$schedule->command(DiscordUserRoleSync::class)->dailyAt('12:10');
$schedule->command(CleanActivitylogCommand::class)->dailyAt('01:00');
// Nightly commands
$schedule->command(SyncGameVersion::class)->dailyAt('00:00');
$schedule->command(NotifyGameUpdate::class)->dailyAt('00:30');
$schedule->command(CleanActivitylogCommand::class)->dailyAt('01:00');
// $schedule->command(SyncGameSave::class, ['gamejolt_user_id' => 'all'])->dailyAt('02:00');
// $schedule->command(SyncGameSaveGamejoltAccountTrophies::class, ['gamejolt_user_id' => 'all'])->dailyAt('02:15');
$schedule->command(SyncGameSave::class, ['gamejolt_user_id' => 'all'])->hourly();
$schedule->command(SyncGameSaveGamejoltAccountTrophies::class, ['gamejolt_user_id' => 'all'])->hourlyAt(5);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions app/Http/Controllers/MemberController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@

class MemberController extends Controller
{
/**
* Display a listing of the resource.
*
* @return View
*/
public function index(): View
{
$users = User::paginate(10);

return view('member.index', ['users' => $users]);
}

/**
* Display the specified resource.
*
Expand Down
85 changes: 85 additions & 0 deletions app/Http/Controllers/Save/MySaveController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace App\Http\Controllers\Save;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class MySaveController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('save.index');
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
23 changes: 23 additions & 0 deletions app/Http/Livewire/GameSave/Party.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Http\Livewire\GameSave;

use App\Helpers\GameSaveHelper;
use Livewire\Component;

class Party extends Component
{
protected $listeners = ['partyUpdated' => 'render'];

public $party;

public function mount()
{
$this->party = GameSaveHelper::getParty();
}

public function render()
{
return view('livewire.game-save.party');
}
}
Loading

0 comments on commit afe3eee

Please sign in to comment.