ViewpointDescription now ignores empty lines
This commit is contained in:
@@ -71,6 +71,14 @@ class Viewpoint implements CreateableInterface
|
|||||||
$this->_description = new SceneDescription($description);
|
$this->_description = new SceneDescription($description);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the description
|
||||||
|
*/
|
||||||
|
public function clearDescription(): void
|
||||||
|
{
|
||||||
|
$this->description = "";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current description as a string
|
* Returns the current description as a string
|
||||||
* @return string
|
* @return string
|
||||||
|
|||||||
@@ -61,6 +61,13 @@ class SceneDescription
|
|||||||
$input = str_replace("\r\n", "\n", $input);
|
$input = str_replace("\r\n", "\n", $input);
|
||||||
$input = str_replace("\r", "\n", $input);
|
$input = str_replace("\r", "\n", $input);
|
||||||
|
|
||||||
return explode("\n\n", $input);
|
$parts = explode("\n\n", $input);
|
||||||
|
foreach ($parts as $key => $part) {
|
||||||
|
if (strlen($part) === 0) {
|
||||||
|
unset($parts[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $parts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -197,4 +197,17 @@ class ViewpointTest extends CoreModelTestCase
|
|||||||
$characterScene->addDescriptionParagraph("You enjoy being here.");
|
$characterScene->addDescriptionParagraph("You enjoy being here.");
|
||||||
$this->assertSame("This is the village.\n\nYou enjoy being here.", $characterScene->getDescription());
|
$this->assertSame("This is the village.\n\nYou enjoy being here.", $characterScene->getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testClearingSceneDescription()
|
||||||
|
{
|
||||||
|
$em = $this->getEntityManager();
|
||||||
|
$testCharacter = $em->getRepository(Character::class)->find(2);
|
||||||
|
$characterScene = $testCharacter->getViewpoint();
|
||||||
|
|
||||||
|
$characterScene->clearDescription();
|
||||||
|
$this->assertSame("", $characterScene->getDescription());
|
||||||
|
|
||||||
|
$characterScene->addDescriptionParagraph("You enjoy being here.");
|
||||||
|
$this->assertSame("You enjoy being here.", $characterScene->getDescription());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user