From 6b3446cf86a1e2d99b1ce6808e2f9269f07cbe82 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Sun, 12 Jan 2020 09:57:55 +0800 Subject: [PATCH] display 3D avatar when applying texture to player --- app/Http/Controllers/TextureController.php | 25 ++++++++++++------ .../src/components/ApplyToPlayerDialog.vue | 2 +- resources/assets/src/components/Previewer.vue | 2 +- .../components/ApplyToPlayerDialog.test.ts | 2 +- .../assets/tests/views/user/Closet.test.ts | 2 +- resources/misc/changelogs/en/5.0.0.md | 2 ++ resources/misc/changelogs/zh_CN/5.0.0.md | 2 ++ .../misc/textures/avatar2d.png | Bin resources/misc/textures/avatar3d.png | Bin 0 -> 11612 bytes .../src/images => misc}/textures/steve.png | Bin storage/static_textures/broken.png | Bin 185 -> 0 bytes .../ControllersTest/TextureControllerTest.php | 9 +++++++ 12 files changed, 34 insertions(+), 12 deletions(-) rename storage/static_textures/avatar.png => resources/misc/textures/avatar2d.png (100%) create mode 100644 resources/misc/textures/avatar3d.png rename resources/{assets/src/images => misc}/textures/steve.png (100%) delete mode 100644 storage/static_textures/broken.png diff --git a/app/Http/Controllers/TextureController.php b/app/Http/Controllers/TextureController.php index c0074e52..4cfe0ed6 100644 --- a/app/Http/Controllers/TextureController.php +++ b/app/Http/Controllers/TextureController.php @@ -106,28 +106,31 @@ class TextureController extends Controller { $player = Player::where('name', $name)->firstOrFail(); - return $this->avatar($minecraft, $player->skin, (int) $request->query('size', 100)); + return $this->avatar($minecraft, $request, $player->skin); } public function avatarByUser(Minecraft $minecraft, Request $request, $uid) { $texture = Texture::find(optional(User::find($uid))->avatar); - return $this->avatar($minecraft, $texture, (int) $request->query('size', 100)); + return $this->avatar($minecraft, $request, $texture); } public function avatarByTexture(Minecraft $minecraft, Request $request, $tid) { $texture = Texture::find($tid); - return $this->avatar($minecraft, $texture, (int) $request->query('size', 100)); + return $this->avatar($minecraft, $request, $texture); } - protected function avatar(Minecraft $minecraft, Texture $texture = null, int $size = 100) + protected function avatar(Minecraft $minecraft, Request $request, Texture $texture = null) { + $size = (int) $request->query('size', 100); + $mode = $request->has('3d') ? '3d' : '2d'; + $disk = Storage::disk('textures'); if (is_null($texture) || $disk->missing($texture->hash)) { - return Image::make(storage_path('static_textures/avatar.png')) + return Image::make(resource_path("misc/textures/avatar$mode.png")) ->resize($size, $size) ->response('png', 100); } @@ -135,10 +138,16 @@ class TextureController extends Controller $hash = $texture->hash; $now = Carbon::now(); $response = Cache::remember( - 'avatar-2d-t'.$texture->tid.'-s'.$size, + 'avatar-'.$mode.'-t'.$texture->tid.'-s'.$size, option('enable_avatar_cache') ? $now->addYear() : $now->addMinute(), - function () use ($minecraft, $disk, $hash, $size) { - $image = $minecraft->render2dAvatar($disk->get($hash), 25); + function () use ($minecraft, $disk, $hash, $size, $mode) { + $file = $disk->get($hash); + if ($mode === '3d') { + $image = $minecraft->render3dAvatar($file, 25); + } else { + $image = $minecraft->render2dAvatar($file, 25); + } + $lastModified = Carbon::createFromTimestamp($disk->lastModified($hash)); return Image::make($image) diff --git a/resources/assets/src/components/ApplyToPlayerDialog.vue b/resources/assets/src/components/ApplyToPlayerDialog.vue index 7e926608..6d26b18a 100644 --- a/resources/assets/src/components/ApplyToPlayerDialog.vue +++ b/resources/assets/src/components/ApplyToPlayerDialog.vue @@ -92,7 +92,7 @@ export default { } }, avatarUrl(player) { - return `${blessing.base_url}/avatar/${player.tid_skin}?size=35` + return `${blessing.base_url}/avatar/${player.tid_skin}?3d&size=35` }, }, } diff --git a/resources/assets/src/components/Previewer.vue b/resources/assets/src/components/Previewer.vue index 4a33c1ce..7e30cfe4 100644 --- a/resources/assets/src/components/Previewer.vue +++ b/resources/assets/src/components/Previewer.vue @@ -53,7 +53,7 @@