railShape = $stateMeta; } protected function writeStateToMeta() : int{ //TODO: railShape won't be plain metadata in future return $this->railShape; } public function getStateBitmask() : int{ return 0b1111; } protected function setShapeFromConnections(array $connections) : void{ $railShape = self::searchState($connections, RailConnectionInfo::CONNECTIONS) ?? self::searchState($connections, RailConnectionInfo::CURVE_CONNECTIONS); if($railShape === null){ throw new \InvalidArgumentException("No rail shape matches these connections"); } $this->railShape = $railShape; } protected function getCurrentShapeConnections() : array{ return RailConnectionInfo::CURVE_CONNECTIONS[$this->railShape] ?? RailConnectionInfo::CONNECTIONS[$this->railShape]; } protected function getPossibleConnectionDirectionsOneConstraint(int $constraint) : array{ $possible = parent::getPossibleConnectionDirectionsOneConstraint($constraint); if(($constraint & RailConnectionInfo::FLAG_ASCEND) === 0){ foreach([ Facing::NORTH, Facing::SOUTH, Facing::WEST, Facing::EAST ] as $d){ if($constraint !== $d){ $possible[$d] = true; } } } return $possible; } public function getShape() : int{ return $this->railShape; } /** @return $this */ public function setShape(int $shape) : self{ if(!isset(RailConnectionInfo::CONNECTIONS[$shape]) && !isset(RailConnectionInfo::CURVE_CONNECTIONS[$shape])){ throw new \InvalidArgumentException("Invalid shape, must be one of " . implode(", ", [...array_keys(RailConnectionInfo::CONNECTIONS), ...array_keys(RailConnectionInfo::CURVE_CONNECTIONS)])); } $this->railShape = $shape; return $this; } }