src/GameOfLife/Inputs/TemplateInput.php
/**
     * Places the template on the board.
     *
     * @param Board $_board The board on which the template will be placed
     * @param Getopt $_options The option list
     * @param String $_templateName The name of the template
     * @param Bool $_isTemplateOption Indicates whether this function was called because the option "template" was set
     *
     * @throws \Exception The exception when the template could not be loaded or exceeds one of the board borders
     */
Places the template on the board.
@param Board $_board The board on which the template will be placed
@param Getopt $_options The option list
@param String $_templateName The name of the template
@param Bool $_isTemplateOption Indicates whether this function was called because the option "template" was set

@throws \Exception The exception when the template could not be loaded or exceeds one of the board borders
Places the template on the board . @param Board $_board The board on which the template will be placed @param Getopt $_options The option list @param String $_templateName The name of the template @param Bool $_isTemplateOption Indicates whether this function was called because the option " template " was set @throws \ Exception The exception when the template could not be loaded or exceeds one of the board borders
private function placeTemplate(Board $_board, Getopt $_options, String $_templateName, Bool $_isTemplateOption)
    {
        $templateFields = $this->templateLoader->loadTemplate($_templateName);
        $posOptionPrefix = "template";
        if (! $_isTemplateOption) $posOptionPrefix = $_templateName;
        $templatePosX = ceil(($_board->width() - count($templateFields[0])) / 2);
        if ($_options->getOption($posOptionPrefix . "PosX") !== null)
        {
            $templatePosX = (int)$_options->getOption($posOptionPrefix . "PosX");
        }
        $templatePosY =  ceil(($_board->height() - count($templateFields)) / 2);
        if ($_options->getOption($posOptionPrefix . "PosY") !== null)
        {
            $templatePosY = (int)$_options->getOption($posOptionPrefix . "PosY");
        }
        $isDimensionsAdjustment = $this->isDimensionsAdjustment($_options, $_board, $templateFields, $posOptionPrefix);
        $this->templatePlacer->placeTemplate($templateFields, $_board, $templatePosX, $templatePosY, $isDimensionsAdjustment);
        if ($_options->getOption("invertTemplate") !== null) $_board->invertBoard();
    }
private function placeTemplate ( Board $ _board , Getopt $ _options , String $ _templateName , Bool $ _isTemplateOption ) { $ templateFields = $ this -> templateLoader -> loadTemplate ( $ _templateName ) ; $ posOptionPrefix = " template " ; if ( ! $ _isTemplateOption ) $ posOptionPrefix = $ _templateName ; $ templatePosX = ceil ( ( $ _board -> width ( ) - count ( $ templateFields [ 0 ] ) ) / 2 ) ; if ( $ _options -> getOption ( $ posOptionPrefix . " PosX " ) !== null ) { $ templatePosX = ( int ) $ _options -> getOption ( $ posOptionPrefix . " PosX " ) ; } $ templatePosY = ceil ( ( $ _board -> height ( ) - count ( $ templateFields ) ) / 2 ) ; if ( $ _options -> getOption ( $ posOptionPrefix . " PosY " ) !== null ) { $ templatePosY = ( int ) $ _options -> getOption ( $ posOptionPrefix . " PosY " ) ; } $ isDimensionsAdjustment = $ this -> isDimensionsAdjustment ( $ _options , $ _board , $ templateFields , $ posOptionPrefix ) ; $ this -> templatePlacer -> placeTemplate ( $ templateFields , $ _board , $ templatePosX , $ templatePosY , $ isDimensionsAdjustment ) ; if ( $ _options -> getOption ( " invertTemplate " ) !== null ) $ _board -> invertBoard ( ) ; }
Places the template on the board.
Places the template on the board .
// Get X position // Get Y position