Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UHC Champions signature #62

Merged
merged 1 commit into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/Http/Controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public function signatureIndex() {
'name' => 'Bed Wars statistics',
'route' => 'bedwars'
],
[
'name' => 'UHC Champions statistics',
'route' => 'uhc_champions'
],
]
],
'skywars' => [
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/RedirectOldSignaturesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class RedirectOldSignaturesController extends Controller {
'bed-wars' => 'signatures.bedwars',
'skywars' => 'signatures.skywars',
'skywars-simple' => 'signatures.skywars_simple',
'skywars-gif' => 'signatures.skywars_gif'
'skywars-gif' => 'signatures.skywars_gif',
'uhc-champions' => 'signatures.uhc_champions'
];

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private function getKD(int $kills, int $deaths) {
* @return array
* @throws HypixelPHPException
*/
private function addBasicItems(Request $request, Player $player, &$image, string $title) {
private function addBasicItems(Request $request, Player $player, &$image, string $title): array {
if ($request->has('no_3d_avatar')) {
[, $textX, $textBeneathAvatarX] = $this->get2dAvatar($player, $image);
} else {
Expand All @@ -274,15 +274,7 @@ private function addBasicItems(Request $request, Player $player, &$image, string

imagettftext($image, 17, 0, $usernameBoundingBox[2] + 10, 30, $this->grey, $this->fontSourceSansProLight, $title);

$rank = $player->getRank(false);
$rankColour = $rank->getColor();
$rankName = $rank->getCleanName();

if ($rankName === 'DEFAULT') {
$rankName = 'Player';
}

$rankNameWithColour = $rankColour . $rankName;
$rankNameWithColour = $this->getColouredRankName($player);

ColourHelper::minecraftStringToTTFText($image, $this->fontSourceSansProLight, 20, $textX, 44, $rankNameWithColour); // Rank name (coloured)

Expand Down
19 changes: 18 additions & 1 deletion app/Http/Controllers/Signatures/BaseSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,23 @@ protected function get3dAvatar(Player $player, &$image): array {
return [$avatarWidth, $textX, $textBeneathAvatarX];
}

/**
* @param Player $player
*
* @return string
*/
protected function getColouredRankName(Player $player): string {
$rank = $player->getRank(false);
$rankColour = $rank->getColor();
$rankName = $rank->getCleanName();

if ($rankName === 'DEFAULT') {
$rankName = 'Player';
}

return $rankColour . $rankName;
}

/**
* @param string $uuid
*
Expand Down Expand Up @@ -196,7 +213,7 @@ public static function generateErrorImage($error, $statusCode = 500, $width = 74
*/
public static function getImage($width, $height) {
$image = imagecreatetruecolor($width, $height);
$transparent = imagecolorallocatealpha($image, 250, 100, 100, config('signatures.signature_debug_background') ? 0 : self::FULLY_TRANSPARENT);
$transparent = imagecolorallocatealpha($image, 230, 230, 255, config('signatures.signature_debug_background') ? 0 : self::FULLY_TRANSPARENT);
imagefill($image, 0, 0, $transparent);
imagesavealpha($image, true);
return $image;
Expand Down
11 changes: 2 additions & 9 deletions app/Http/Controllers/Signatures/BedWarsSignatureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,8 @@ protected function signature(Request $request, Player $player): Response {
$grey = imagecolorallocate($image, 203, 203, 203);
$fontSourceSansProLight = resource_path('fonts/SourceSansPro/SourceSansPro-Light.otf');

$username = $player->getName();

$rank = $player->getRank(false);
$rankColour = $rank->getColor();
$rankName = $rank->getCleanName();
if ($rankName === 'DEFAULT') {
$rankName = 'Player';
}
$rankNameWithColour = $rankColour . $rankName;
$username = $player->getName();
$rankNameWithColour = $this->getColouredRankName($player);

$mainStats = $player->getStats();
/** @var GameStats $stats */
Expand Down
19 changes: 6 additions & 13 deletions app/Http/Controllers/Signatures/GeneralSignatureController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/**
/*
* Copyright (c) 2020 Max Korlaar
* All rights reserved.
*
Expand Down Expand Up @@ -61,18 +61,11 @@ protected function signature(Request $request, Player $player): Response {
[$black, $purple, $yellow] = self::getColours($image);
$fontSourceSansProLight = resource_path('fonts/SourceSansPro/SourceSansPro-Light.otf');

$karma = $player->getInt('karma', 0);
$achievementPoints = Arr::get($player->getAchievementData(), 'standard.points.current', 0);
$mostRecentGame = $player->get('mostRecentGameType', 'None');
$username = $player->getName();

$rank = $player->getRank(false);
$rankColour = $rank->getColor();
$rankName = $rank->getCleanName();
if ($rankName === 'DEFAULT') {
$rankName = 'Player';
}
$rankNameWithColour = $rankColour . $rankName;
$karma = $player->getInt('karma', 0);
$achievementPoints = Arr::get($player->getAchievementData(), 'standard.points.current', 0);
$mostRecentGame = $player->get('mostRecentGameType', 'None');
$username = $player->getName();
$rankNameWithColour = $this->getColouredRankName($player);

$lastgameType = GameTypes::fromEnum($mostRecentGame);
if ($lastgameType !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,7 @@ protected function signature(Request $request, Player $player): Response {

$username = $player->getName();

$rank = $player->getRank(false);
$rankColour = $rank->getColor();
$rankName = $rank->getCleanName();
if ($rankName === 'DEFAULT') {
$rankName = 'Player';
}
$rankNameWithColour = $rankColour . $rankName;
$rankNameWithColour = $this->getColouredRankName($player);

$mainStats = $player->getStats();
/** @var GameStats $stats */
Expand Down
140 changes: 140 additions & 0 deletions app/Http/Controllers/Signatures/UHCChampionsSignatureController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?php
/*
* Copyright (c) 2020 Max Korlaar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions, a visible attribution to the original author(s)
* of the software available to the public, and the following disclaimer
* in the documentation and/or other materials provided with the distribution.
*
* Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

namespace App\Http\Controllers\Signatures;

use App\Utilities\ColourHelper;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Image;
use Plancke\HypixelPHP\classes\gameType\GameTypes;
use Plancke\HypixelPHP\exceptions\HypixelPHPException;
use Plancke\HypixelPHP\responses\player\GameStats;
use Plancke\HypixelPHP\responses\player\Player;

/**
* Class UHCChampionsSignatureController
*
* @package App\Http\Controllers\Signatures
*/
class UHCChampionsSignatureController extends BaseSignature {

/**
* @inheritDoc
* @throws HypixelPHPException
*/
protected function signature(Request $request, Player $player): Response {
$image = BaseSignature::getImage(460, 160);
$black = imagecolorallocate($image, 0, 0, 0);
$grey = imagecolorallocate($image, 203, 203, 203);
$fontSourceSansProLight = resource_path('fonts/SourceSansPro/SourceSansPro-Light.otf');

$username = $player->getName();
$rankNameWithColour = $this->getColouredRankName($player);

$mainStats = $player->getStats();
/** @var GameStats $stats */
$stats = $mainStats->getGameFromID(GameTypes::UHC);

$kills = $stats->getInt('kills') + $stats->getInt('kills_solo');
$deaths = $stats->getInt('deaths') + $stats->getInt('deaths_solo');
$wins = $stats->getInt('wins') + $stats->getInt('wins_solo');
$score = $stats->getInt('score');

if ($deaths !== 0) {
$kd = round($kills / $deaths, 2);
} else {
$kd = 'None';
}

if ($score >= 10210) {
$title = 'Champion';
} elseif ($score >= 5210) {
$title = 'Warlord';
} elseif ($score >= 2710) {
$title = 'Gladiator';
} elseif ($score >= 1710) {
$title = 'Centurion';
} elseif ($score >= 960) {
$title = 'Captain';
} elseif ($score >= 460) {
$title = 'Knight';
} elseif ($score >= 210) {
$title = 'Sergeant';
} elseif ($score >= 60) {
$title = 'Soldier';
} elseif ($score >= 10) {
$title = 'Initiate';
} else {
$title = 'Recruit';
}

if ($request->has('no_3d_avatar')) {
[, $textX, $textBeneathAvatarX] = $this->get2dAvatar($player, $image);
} else {
[, $textX, $textBeneathAvatarX] = $this->get3dAvatar($player, $image);
}

if ($request->has('guildTag')) {
$guildTag = '§7[' . $player->getGuildTag() . ']';
if ($guildTag === '§7[]') {
$guildTag = '§7[-]';
}
$usernameBoundingBox = ColourHelper::minecraftStringToTTFText($image, $fontSourceSansProLight, 25, $textX, 14, '§0' . $username . ' ' . $guildTag);
} else {
$usernameBoundingBox = imagettftext($image, 25, 0, $textX, 30, $black, $fontSourceSansProLight, $username);
}

imagettftext($image, 17, 0, $usernameBoundingBox[2] + 10, 30, $grey, $fontSourceSansProLight, 'UHC Champions statistics');

$linesY = [60, 95, 130]; // Y starting points of the various text lines

ColourHelper::minecraftStringToTTFText($image, $fontSourceSansProLight, 20, $textX, 44, $rankNameWithColour); // Rank name (coloured)

imagettftext($image, 20, 0, $textX, $linesY[1], $black, $fontSourceSansProLight, number_format($kills) . ' kills'); // Total kills

imagettftext($image, 20, 0, 275, $linesY[0], $black, $fontSourceSansProLight, $title);

imagettftext($image, 20, 0, 275, $linesY[1], $black, $fontSourceSansProLight, 'Score: ' . number_format($score)); // score

imagettftext($image, 20, 0, $textBeneathAvatarX, $linesY[2], $black, $fontSourceSansProLight, number_format($wins) . ' wins'); // Total wins

imagettftext($image, 20, 0, 275, $linesY[2], $black, $fontSourceSansProLight, 'KD: ' . $kd); // kill/death ratio

$this->addWatermark($image, $fontSourceSansProLight, 460, 160); // Watermark/advertisement

return Image::make($image)->response('png')->setCache([
'public' => true,
'max_age' => 600
]);
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"@primer/css": "^15.2.0",
"bourbon": "^7.0.0",
"moment": "^2.29.1",
"vue-lazyload": "^1.3.3"
"vue-google-adsense": "^1.9.0",
"vue-lazyload": "^1.3.3",
"vue-script2": "^2.1.0"
}
}
18 changes: 18 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions resources/js/signatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import Vue from 'vue';
import Ads from 'vue-google-adsense';
import vue_script2 from "vue-script2";

Vue.use(vue_script2);
Vue.use(Ads.InFeedAdsense);

const axios = require('axios').default;

Expand Down
20 changes: 6 additions & 14 deletions resources/views/signatures/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,12 @@
</label>
</div>
{% if config_get('signatures.google_ads_client_id') %}
<template v-if="index === current_signature_group.signatures.length - 2">
<ins class="adsbygoogle"
style="display:block"
data-ad-format="fluid"
data-ad-layout-key="-75+ev-15-20+86"
data-ad-client="{{ config_get('signatures.google_ads_client_id') }}"
data-ad-slot="2775738048"></ins>
</template>
<in-feed-adsense v-if="index === current_signature_group.signatures.length - 2"
data-ad-layout-key="-fg+5n+6t-e7+r"
data-ad-client="{{ config_get('signatures.google_ads_client_id') }}"
data-ad-layout-key="-75+ev-15-20+86"
data-ad-slot="2775738048">
</in-feed-adsense>
{% endif %}
</template>
</div>
Expand Down Expand Up @@ -125,10 +123,4 @@
window.Paniek.urls = {{ urls|json_encode|raw }};
</script>
<script src="{{ mix('js/signatures.js') }}"></script>
{% if config_get('signatures.google_ads_client_id') %}
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
{% endif %}
{% endblock %}
1 change: 1 addition & 0 deletions routes/web_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
Route::get('general-small', 'SmallGeneralSignatureController@render')->name('general_small');
Route::get('general-tooltip', 'TooltipSignatureController@render')->name('general_tooltip');

Route::get('uhc-champions', 'UHCChampionsSignatureController@render')->name('uhc_champions');
Route::get('bedwars', 'BedWarsSignatureController@render')->name('bedwars');

Route::get('skywars', 'SkyWarsSignatureController@render')->name('skywars');
Expand Down