Skip to content

Commit

Permalink
Merge branch 'feature'
Browse files Browse the repository at this point in the history
  • Loading branch information
Zlimon committed Apr 19, 2021
2 parents cf2690e + 009e286 commit 2b58ca6
Show file tree
Hide file tree
Showing 109 changed files with 1,851 additions and 220 deletions.
113 changes: 113 additions & 0 deletions app/Console/Commands/ResourcePackFetch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

namespace App\Console\Commands;

use App\ResourcePack;
use Artisan;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;

class ResourcePackFetch extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'resourcepack:fetch
{name : Filename of resource pack located on GitHub}
{--use= : Whether the resource pack should be used}
{--update= : Whether the resource pack should be updated}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Fetch resource pack, and optionally apply it as currently used textures';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
if (File::exists(public_path('storage/resource-packs-downloaded/' . $this->argument('name') . '.zip'))) {
if ($this->option('update') !== "yes") {
$this->info(
sprintf("Resource pack '%s' already exists! Use --update=yes to update it", $this->argument('name'))
);

return 1;
}
}

$this->info(sprintf("Downloading '%s'", $this->argument('name')));

// Download resource pack
$resourcePack = @file_get_contents(
'https://github.com/melkypie/resource-packs/archive/' . $this->argument('name') . '.zip'
);

if ($resourcePack === false) {
$this->info(sprintf("Could not fetch '%s' from '%s'", $this->argument('name'), 'https://github.com/melkypie/resource-packs/archive/' . $this->argument('name') . '.zip'));

return 1;
}

// Put resource pack file to download directory
Storage::disk('public')->put(
'resource-packs-downloaded/' . $this->argument('name') . '.zip',
$resourcePack
);

// Verify resource pack is correctly downloaded, and insert to database
if (File::exists(public_path('storage/resource-packs-downloaded/'.$this->argument('name').'.zip'))) {
$resourcePack = ResourcePack::firstWhere('name', $this->argument('name'));

if (!$resourcePack) {
$this->info(sprintf("Inserting '%s' to database", $this->argument('name')));

$resourcePack = new ResourcePack();

$resourcePack->name = $this->argument('name');
$resourcePack->alias = ucfirst(str_replace("pack-", "", $this->argument('name')));
$resourcePack->url = 'https://github.com/melkypie/resource-packs/archive/' . $this->argument(
'name'
) . '.zip';

$resourcePack->save();
} else {
$this->info(sprintf("Updating '%s' in database", $this->argument('name')));

$resourcePack->touch();
}
} else {
$this->info(sprintf("Something went wrong"));

return 1;
}

if ($this->option('use') == "yes") {
$this->info(sprintf("Applying new textures"));

Artisan::call("resourcepack:switch " . $this->argument('name'));
}

$this->info(sprintf("Finished!"));

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

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use VIPSoft\Unzip\Unzip;

class ResourcePackSwitch extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'resourcepack:switch
{name : Filename of resource pack located on GitHub}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Switch and apply resource pack to current textures';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
if (!File::exists(public_path('storage/resource-packs-downloaded/'.$this->argument('name').'.zip'))) {
$this->info(sprintf("Resource pack '%s' does not exist!", $this->argument('name')));

return 1;
}

$extractFrom = public_path('storage/resource-packs-downloaded/'.$this->argument('name').'.zip');
$extractTo = public_path('storage/resource-pack-tmp');

// Clean tmp dir
File::cleanDirectory(public_path('storage/resource-pack-tmp'));

$unzipper = new Unzip();
$filenames = $unzipper->extract($extractFrom, $extractTo);

$this->info(sprintf("Applying new textures"));

// Copy resource pack from parent dir in tmp dir, and extract files one level up
File::copyDirectory(public_path('storage/resource-pack-tmp/'.$filenames[0]), public_path('storage/resource-pack'));

// Clean tmp dir
File::cleanDirectory(public_path('storage/resource-pack-tmp'));

$this->info(sprintf("Finished!"));

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

namespace App\Console\Commands;

use App\Helpers\Helper;
use Artisan;
use Illuminate\Console\Command;

class SkillCreate extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'skill:create';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create skill migration and model files';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$skills = Helper::listSkills();
$skillCount = sizeof($skills);

// This method create a skill migration and model file for each skill
foreach (Helper::listSkills() as $key => $skill) {
$count = ($key+1)."/".$skillCount;

$this->info(sprintf("[%s] Making '%s' migration", $count, $skill));

$makeMigration = "make:migration create_".$skill."_table";
Artisan::call($makeMigration);

$this->info(sprintf("[%s] Making '%s' model", $count, $skill));

$makeModel = "make:model Skill/".ucfirst($skill);
Artisan::call($makeModel);
}

return 0;
}
}
39 changes: 39 additions & 0 deletions app/Events/AccountQuest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Events;

use App\Quest;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class AccountQuest implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $quest;

/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Quest $quest)
{
$this->quest = $quest;
}

/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new Channel('account-quest');
}
}
2 changes: 1 addition & 1 deletion app/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public static function listSkills()
"thieving",
"slayer",
"farming",
"runecrafting",
"runecraft",
"hunter",
"construction"
];
Expand Down
29 changes: 27 additions & 2 deletions app/Http/Controllers/Api/AccountBankController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ public function show($accountUsername)
$account = Account::where('username', $accountUsername)->pluck('id')->first();

if ($account) {
$bank = Bank::where('account_id', $account)->first();
$bank = Bank::where([
['account_id', '=', $account],
['display', '=', 1]
])->first();

if ($bank) {
return response()->json($bank, 200);
} else {
return response()->json("No bank for " . $accountUsername . " were found!", 404);
return response("No bank for " . $accountUsername . " were found!", 404);
}
}
}
Expand Down Expand Up @@ -74,4 +77,26 @@ public function update($accountUsername, Request $request)

return response("Updated bank for " . $accountUsername, 200);
}

public function updateDisplay($accountUsername)
{
$account = Account::where('user_id', auth()->user()->id)->where('username', $accountUsername)->first();
if (!$account) {
return response($accountUsername . " is not authenticated with " . auth()->user()->name, 401);
}

$bank = Bank::where('account_id', $account->id)->first();

if (!$bank) {
return response("No bank for " . $accountUsername . " were found!", 404);
}

$bank->display ^= 1;

$bank->save();

AccountBank::dispatch($account);

return response(($bank->display === 1 ? "Displaying" : "No longer displaying") . " bank for " . $accountUsername, 200);
}
}
29 changes: 27 additions & 2 deletions app/Http/Controllers/Api/AccountEquipmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ public function show($accountUsername)
$account = Account::where('username', $accountUsername)->pluck('id')->first();

if ($account) {
$equipment = Equipment::where('account_id', $account)->first();
$equipment = Equipment::where([
['account_id', '=', $account],
['display', '=', 1]
])->first();

if ($equipment) {
return response()->json($equipment, 200);
} else {
return response()->json("No equipment for " . $accountUsername . " were found!", 404);
return response("No equipment for " . $accountUsername . " were found!", 404);
}
}
}
Expand Down Expand Up @@ -59,4 +62,26 @@ public function update($accountUsername, Request $request)

return response("Updated equipment for " . $accountUsername, 200);
}

public function updateDisplay($accountUsername)
{
$account = Account::where('user_id', auth()->user()->id)->where('username', $accountUsername)->first();
if (!$account) {
return response($accountUsername . " is not authenticated with " . auth()->user()->name, 401);
}

$equipment = Equipment::where('account_id', $account->id)->first();

if (!$equipment) {
return response("No equipment for " . $accountUsername . " were found!", 404);
}

$equipment->display ^= 1;

$equipment->save();

AccountEquipment::dispatch($equipment);

return response(($equipment->display === 1 ? "Displaying" : "No longer displaying") . " equipment for " . $accountUsername, 200);
}
}
Loading

0 comments on commit 2b58ca6

Please sign in to comment.