-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #234 from P3D-Legacy/develop
- Loading branch information
Showing
49 changed files
with
2,131 additions
and
203 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,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
86
app/Console/Commands/SyncGameSaveGamejoltAccountTrophies.php
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,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; | ||
} | ||
} |
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
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,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) | ||
{ | ||
// | ||
} | ||
} |
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 | ||
|
||
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'); | ||
} | ||
} |
Oops, something went wrong.