From 0c82cd395028d103fe277ddaad8e379f5259d9d7 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Tue, 21 Aug 2018 14:47:37 +0800 Subject: [PATCH] Set model preference to slim when applying slim skin to new players --- app/Http/Controllers/PlayerController.php | 7 +++++++ tests/PlayerControllerTest.php | 24 ++++++++++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/PlayerController.php b/app/Http/Controllers/PlayerController.php index 16da793a..bd4d38a9 100644 --- a/app/Http/Controllers/PlayerController.php +++ b/app/Http/Controllers/PlayerController.php @@ -158,6 +158,13 @@ class PlayerController extends Controller $this->player->setTexture([$fieldName => $value]); } + // When user applies an alex skin to a newly added player, + // which textures and model preference are all default value, + // we will automatically set the player's model preference to "slim". + if ($this->player->preference == 'default' && $this->player->tid_steve == 0 && $this->player->tid_alex != 0) { + $this->player->setPreference('slim'); + } + return json(trans('user.player.set.success', ['name' => $this->player->player_name]), 0); } diff --git a/tests/PlayerControllerTest.php b/tests/PlayerControllerTest.php index f15f2c59..3d36b696 100644 --- a/tests/PlayerControllerTest.php +++ b/tests/PlayerControllerTest.php @@ -247,6 +247,19 @@ class PlayerControllerTest extends TestCase 'msg' => trans('skinlib.un-existent') ]); + // Set for "alex" type + // Model preference should be automatically set to "slim" + $this->postJson('/user/player/set', [ + 'pid' => $player->pid, + 'tid' => ['alex' => $alex->tid] + ])->assertJson([ + 'errno' => 0, + 'msg' => trans('user.player.set.success', ['name' => $player->player_name]) + ]); + $this->expectsEvents(Events\PlayerProfileUpdated::class); + $this->assertEquals(Player::find($player->pid)->preference, 'slim'); + $this->assertEquals($alex->tid, Player::find($player->pid)->tid_alex); + // Set for "steve" type $this->postJson('/user/player/set', [ 'pid' => $player->pid, @@ -255,19 +268,8 @@ class PlayerControllerTest extends TestCase 'errno' => 0, 'msg' => trans('user.player.set.success', ['name' => $player->player_name]) ]); - $this->expectsEvents(Events\PlayerProfileUpdated::class); $this->assertEquals($steve->tid, Player::find($player->pid)->tid_steve); - // Set for "alex" type - $this->postJson('/user/player/set', [ - 'pid' => $player->pid, - 'tid' => ['alex' => $alex->tid] - ])->assertJson([ - 'errno' => 0, - 'msg' => trans('user.player.set.success', ['name' => $player->player_name]) - ]); - $this->assertEquals($alex->tid, Player::find($player->pid)->tid_alex); - // Set for "cape" type $this->postJson('/user/player/set', [ 'pid' => $player->pid,