Set model preference to slim when applying slim skin to new players

This commit is contained in:
Pig Fang 2018-08-21 14:47:37 +08:00
parent 7ec7eb2467
commit 0c82cd3950
2 changed files with 20 additions and 11 deletions

View File

@ -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);
}

View File

@ -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,