src/GameOfLife/Inputs/BoardEditor/Options/CopySelectionOption.php
/**
     * Copies the fields in the current selection area.
     *
     * @return bool Indicates whether the board editing is finished
     *
     * @throws \Exception The exception when the selection coordinates are empty
     */
Copies the fields in the current selection area.
@return bool Indicates whether the board editing is finished

@throws \Exception The exception when the selection coordinates are empty
Copies the fields in the current selection area . @return bool Indicates whether the board editing is finished @throws \ Exception The exception when the selection coordinates are empty
public function copySelection(): Bool
    {
        $selectionCoordinates = $this->parentBoardEditor->selectionCoordinates();
        if ($selectionCoordinates == array()) throw new \Exception("There are no fields selected at the moment.");
        $copiedFields = array();
        for ($y = $selectionCoordinates["A"]["y"]; $y <= $selectionCoordinates["B"]["y"]; $y++)
        {
            for ($x = $selectionCoordinates["A"]["x"]; $x <= $selectionCoordinates["B"]["x"]; $x++)
            {
                $field = clone $this->parentBoardEditor->board()->fields()[$y][$x];
                $field->setX($x - $selectionCoordinates["A"]["x"]);
                $field->setY($y - $selectionCoordinates["A"]["y"]);
                $copiedFields[$field->y()][$field->x()] = $field;
            }
        }
        $this->parentBoardEditor->setCopiedFields($copiedFields);
        $this->parentBoardEditor->outputBoard("Fields successfully copied.");
        return false;
    }
public function copySelection ( ) : Bool { $ selectionCoordinates = $ this -> parentBoardEditor -> selectionCoordinates ( ) ; if ( $ selectionCoordinates == array ( ) ) throw new \ Exception ( " There are no fields selected at the moment. " ) ; $ copiedFields = array ( ) ; for ( $ y = $ selectionCoordinates [ " A " ] [ " y " ] ; $ y <= $ selectionCoordinates [ " B " ] [ " y " ] ; $ y ++ ) { for ( $ x = $ selectionCoordinates [ " A " ] [ " x " ] ; $ x <= $ selectionCoordinates [ " B " ] [ " x " ] ; $ x ++ ) { $ field = clone $ this -> parentBoardEditor -> board ( ) -> fields ( ) [ $ y ] [ $ x ] ; $ field -> setX ( $ x - $ selectionCoordinates [ " A " ] [ " x " ] ) ; $ field -> setY ( $ y - $ selectionCoordinates [ " A " ] [ " y " ] ) ; $ copiedFields [ $ field -> y ( ) ] [ $ field -> x ( ) ] = $ field ; } } $ this -> parentBoardEditor -> setCopiedFields ( $ copiedFields ) ; $ this -> parentBoardEditor -> outputBoard ( " Fields successfully copied. " ) ; return false ; }
Copies the fields in the current selection area.
Copies the fields in the current selection area .
/** @var Field $field */