-
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.
Browse files
Browse the repository at this point in the history
GH-230 | Overview - Planet name change screen refactor
- Loading branch information
Showing
19 changed files
with
336 additions
and
97 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
26 changes: 26 additions & 0 deletions
26
common/components/GalaxyPlanetLink/GalaxyPlanetLink.component.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,26 @@ | ||
<?php | ||
|
||
namespace UniEngine\Engine\Common\Components\GalaxyPlanetLink; | ||
|
||
use UniEngine\Engine\Common\Utils\Routing; | ||
|
||
/** | ||
* @param array $props | ||
* @param array $props['coords'] | ||
* @param number $props['coords']['galaxy'] | ||
* @param number $props['coords']['system'] | ||
* @param number $props['coords']['planet'] | ||
*/ | ||
function render($props) { | ||
$linkText = "[{$props['coords']['galaxy']}:{$props['coords']['system']}:{$props['coords']['planet']}]"; | ||
|
||
return buildDOMElementHTML([ | ||
'tagName' => 'a', | ||
'contentHTML' => $linkText, | ||
'attrs' => [ | ||
'href' => Routing\getGalaxyTargetUrl($props['coords']), | ||
], | ||
]); | ||
} | ||
|
||
?> |
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,5 @@ | ||
<?php | ||
|
||
header("Location: ../index.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,5 @@ | ||
<?php | ||
|
||
header("Location: ../index.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,5 @@ | ||
<?php | ||
|
||
header("Location: ../index.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,23 @@ | ||
<?php | ||
|
||
namespace UniEngine\Engine\Common\Utils\Routing; | ||
|
||
/** | ||
* @param array $params | ||
* @param number $params['galaxy'] | ||
* @param number $params['system'] | ||
* @param number $params['planet'] | ||
*/ | ||
function getGalaxyTargetUrl($params) { | ||
return buildHref([ | ||
'path' => 'galaxy.php', | ||
'query' => [ | ||
'mode' => '3', | ||
'galaxy' => $params['galaxy'], | ||
'system' => $params['system'], | ||
'planet' => $params['planet'], | ||
], | ||
]); | ||
} | ||
|
||
?> |
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,5 @@ | ||
<?php | ||
|
||
header("Location: ../index.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
header("Location: ../index.php"); | ||
|
||
?> |
5 changes: 5 additions & 0 deletions
5
modules/overview/screens/PlanetNameChange/utils/errorMappers/index.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,5 @@ | ||
<?php | ||
|
||
header("Location: ../index.php"); | ||
|
||
?> |
28 changes: 28 additions & 0 deletions
28
modules/overview/screens/PlanetNameChange/utils/errorMappers/validateNewName.errorMapper.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,28 @@ | ||
<?php | ||
|
||
namespace UniEngine\Engine\Modules\Overview\Screens\PlanetNameChange\Utils\ErrorMappers; | ||
|
||
/** | ||
* @param object $error As returned by Overview\Screens\PlanetNameChange\Utils\Validators\validateNewName | ||
*/ | ||
function mapValidateNewNameErrorToReadableMessage($error) { | ||
global $_Lang; | ||
|
||
$errorCode = $error['code']; | ||
|
||
$knownErrorsByCode = [ | ||
'NEW_NAME_EMPTY' => $_Lang['RenamePlanet_0Lenght'], | ||
'NEW_NAME_SAME_AS_OLD' => $_Lang['RenamePlanet_SameName'], | ||
'NEW_NAME_TOO_SHORT' => $_Lang['RenamePlanet_TooShort'], | ||
'NEW_NAME_TOO_LONG' => $_Lang['RenamePlanet_TooLong'], | ||
'NEW_NAME_INVALID' => $_Lang['RenamePlanet_BadSigns'], | ||
]; | ||
|
||
if (!isset($knownErrorsByCode[$errorCode])) { | ||
return $_Lang['sys_unknownError']; | ||
} | ||
|
||
return $knownErrorsByCode[$errorCode]; | ||
} | ||
|
||
?> |
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,5 @@ | ||
<?php | ||
|
||
header("Location: ../index.php"); | ||
|
||
?> |
5 changes: 5 additions & 0 deletions
5
modules/overview/screens/PlanetNameChange/utils/validators/index.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,5 @@ | ||
<?php | ||
|
||
header("Location: ../index.php"); | ||
|
||
?> |
63 changes: 63 additions & 0 deletions
63
modules/overview/screens/PlanetNameChange/utils/validators/validateNewName.validator.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,63 @@ | ||
<?php | ||
|
||
namespace UniEngine\Engine\Modules\Overview\Screens\PlanetNameChange\Utils\Validators; | ||
|
||
/** | ||
* @param array $params | ||
* @param array $params['input'] | ||
* @param string $params['input']['newName'] | ||
* @param arrayRef $params['planet'] | ||
*/ | ||
function validateNewName($params) { | ||
$planet = &$params['planet']; | ||
|
||
$executor = function ($input, $resultHelpers) use (&$planet) { | ||
$newName = $input['newName']; | ||
|
||
$currentName = $planet['name']; | ||
|
||
$MIN_LENGTH = 3; | ||
$MAX_LENGTH = 20; | ||
|
||
if (empty($newName)) { | ||
return $resultHelpers['createFailure']([ | ||
'code' => 'NEW_NAME_EMPTY', | ||
]); | ||
} | ||
if ($newName == $currentName) { | ||
return $resultHelpers['createFailure']([ | ||
'code' => 'NEW_NAME_SAME_AS_OLD', | ||
]); | ||
} | ||
|
||
$newNameLength = strlen($newName); | ||
|
||
if ($newNameLength < $MIN_LENGTH) { | ||
return $resultHelpers['createFailure']([ | ||
'code' => 'NEW_NAME_TOO_SHORT', | ||
'params' => [ | ||
'minLength' => $MIN_LENGTH | ||
], | ||
]); | ||
} | ||
if ($newNameLength > $MAX_LENGTH) { | ||
return $resultHelpers['createFailure']([ | ||
'code' => 'NEW_NAME_TOO_LONG', | ||
'params' => [ | ||
'maxLength' => $MAX_LENGTH | ||
], | ||
]); | ||
} | ||
if (!preg_match(REGEXP_PLANETNAME_ABSOLUTE, $newName)) { | ||
return $resultHelpers['createFailure']([ | ||
'code' => 'NEW_NAME_INVALID', | ||
]); | ||
} | ||
|
||
return $resultHelpers['createSuccess']([]); | ||
}; | ||
|
||
return createFuncWithResultHelpers($executor)($params['input']); | ||
} | ||
|
||
?> |
Oops, something went wrong.