-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-230 Move Planet name change screen's code completely to its submodule
- Loading branch information
Showing
5 changed files
with
147 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
modules/overview/screens/PlanetNameChange/PlanetNameChange.screen.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace UniEngine\Engine\Modules\Overview\Screens\PlanetNameChange; | ||
|
||
use UniEngine\Engine\Common; | ||
use UniEngine\Engine\Modules\Overview\Screens\PlanetNameChange; | ||
|
||
/** | ||
* @param array $params | ||
* @param arrayRef $params['input'] | ||
* @param arrayRef $params['user'] | ||
* @param arrayRef $params['planet'] | ||
*/ | ||
function render($props) { | ||
global $_Lang; | ||
|
||
$input = &$props['input']; | ||
$user = &$props['user']; | ||
$planet = &$props['planet']; | ||
|
||
$effectsResult = PlanetNameChange\runEffects([ | ||
'input' => &$input, | ||
'user' => &$user, | ||
'planet' => &$planet, | ||
]); | ||
|
||
$screenTitle = $_Lang['Rename_TitleMain']; | ||
$localTemplateLoader = createLocalTemplateLoader(__DIR__); | ||
|
||
$isOnPlanet = $planet['planet_type'] == 1; | ||
$galaxyPlanetLink = Common\Components\GalaxyPlanetLink\render([ | ||
'coords' => $planet, | ||
]); | ||
|
||
$tplBodyParams = [ | ||
'Rename_CurrentName' => sprintf( | ||
$_Lang['Rename_CurrentName'], | ||
( | ||
$isOnPlanet ? | ||
$_Lang['Rename_Planet'] : | ||
$_Lang['Rename_Moon'] | ||
) | ||
), | ||
'Rename_Ins_CurrentName' => "{$planet['name']} {$galaxyPlanetLink}", | ||
|
||
'Rename_Ins_MsgHide' => ( | ||
$effectsResult['isSuccess'] === null ? | ||
'style="display: none;"' : | ||
'' | ||
), | ||
'Rename_Ins_MsgColor' => ( | ||
$effectsResult['isSuccess'] !== null ? | ||
$effectsResult['payload']['color'] : | ||
'' | ||
), | ||
'Rename_Ins_MsgTxt' => ( | ||
$effectsResult['isSuccess'] !== null ? | ||
$effectsResult['payload']['message'] : | ||
'' | ||
), | ||
]; | ||
$tplBodyParams = array_merge($_Lang, $tplBodyParams); | ||
|
||
$componentHTML = parsetemplate( | ||
$localTemplateLoader('body'), | ||
$tplBodyParams | ||
); | ||
|
||
display($componentHTML, $screenTitle); | ||
} | ||
|
||
?> |
69 changes: 69 additions & 0 deletions
69
modules/overview/screens/PlanetNameChange/PlanetNameChange.utils.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace UniEngine\Engine\Modules\Overview\Screens\PlanetNameChange; | ||
|
||
use UniEngine\Engine\Modules\Overview\Screens\PlanetNameChange; | ||
|
||
/** | ||
* @param array $params | ||
* @param arrayRef $params['input'] | ||
* @param arrayRef $params['user'] | ||
* @param arrayRef $params['planet'] | ||
*/ | ||
function runEffects($props) { | ||
global $_Lang; | ||
|
||
$input = &$props['input']; | ||
$user = &$props['user']; | ||
$planet = &$props['planet']; | ||
|
||
if ( | ||
!isset($input['action']) || | ||
$input['action'] != 'do' | ||
) { | ||
return [ | ||
'isSuccess' => null, | ||
]; | ||
} | ||
|
||
$newName = ( | ||
isset($input['set_newname']) ? | ||
trim($input['set_newname']) : | ||
'' | ||
); | ||
|
||
$nameChangeValidationResult = PlanetNameChange\Utils\Validators\validateNewName([ | ||
'input' => [ | ||
'newName' => $newName, | ||
], | ||
'planet' => &$planet, | ||
]); | ||
|
||
if (!$nameChangeValidationResult['isSuccess']) { | ||
$errorMessage = PlanetNameChange\Utils\ErrorMappers\mapValidateNewNameErrorToReadableMessage( | ||
$nameChangeValidationResult['error'] | ||
); | ||
|
||
return [ | ||
'isSuccess' => false, | ||
'payload' => [ | ||
'message' => $errorMessage, | ||
'color' => 'red', | ||
], | ||
]; | ||
} | ||
|
||
$planet['name'] = $newName; | ||
|
||
doquery("UPDATE {{table}} SET `name` = '{$newName}' WHERE `id` = {$user['current_planet']} LIMIT 1;", 'planets'); | ||
|
||
return [ | ||
'isSuccess' => true, | ||
'payload' => [ | ||
'message' => $_Lang['RenamePlanet_NameSaved'], | ||
'color' => 'lime', | ||
], | ||
]; | ||
} | ||
|
||
?> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters