Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 586a9469cb | |||
| db8958a33b | |||
| 127abf136e | |||
| e29b45ce39 | |||
| a9dae2e958 |
Generated
+84
-14
@@ -189,20 +189,21 @@
|
||||
},
|
||||
{
|
||||
"name": "composer/composer",
|
||||
"version": "2.0.12",
|
||||
"version": "2.0.13",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/composer/composer.git",
|
||||
"reference": "6c12ce263da71641903e399c3ce8ecb08fd375fb"
|
||||
"reference": "986e8b86b7b570632ad0a905c3726c33dd4c0efb"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/composer/composer/zipball/6c12ce263da71641903e399c3ce8ecb08fd375fb",
|
||||
"reference": "6c12ce263da71641903e399c3ce8ecb08fd375fb",
|
||||
"url": "https://api.github.com/repos/composer/composer/zipball/986e8b86b7b570632ad0a905c3726c33dd4c0efb",
|
||||
"reference": "986e8b86b7b570632ad0a905c3726c33dd4c0efb",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"composer/ca-bundle": "^1.0",
|
||||
"composer/metadata-minifier": "^1.0",
|
||||
"composer/semver": "^3.0",
|
||||
"composer/spdx-licenses": "^1.2",
|
||||
"composer/xdebug-handler": "^1.1",
|
||||
@@ -266,7 +267,7 @@
|
||||
"support": {
|
||||
"irc": "irc://irc.freenode.org/composer",
|
||||
"issues": "https://github.com/composer/composer/issues",
|
||||
"source": "https://github.com/composer/composer/tree/2.0.12"
|
||||
"source": "https://github.com/composer/composer/tree/2.0.13"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -282,7 +283,76 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-04-01T08:14:59+00:00"
|
||||
"time": "2021-04-27T11:11:08+00:00"
|
||||
},
|
||||
{
|
||||
"name": "composer/metadata-minifier",
|
||||
"version": "1.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/composer/metadata-minifier.git",
|
||||
"reference": "c549d23829536f0d0e984aaabbf02af91f443207"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/composer/metadata-minifier/zipball/c549d23829536f0d0e984aaabbf02af91f443207",
|
||||
"reference": "c549d23829536f0d0e984aaabbf02af91f443207",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^5.3.2 || ^7.0 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"composer/composer": "^2",
|
||||
"phpstan/phpstan": "^0.12.55",
|
||||
"symfony/phpunit-bridge": "^4.2 || ^5"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "1.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Composer\\MetadataMinifier\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jordi Boggiano",
|
||||
"email": "j.boggiano@seld.be",
|
||||
"homepage": "http://seld.be"
|
||||
}
|
||||
],
|
||||
"description": "Small utility library that handles metadata minification and expansion.",
|
||||
"keywords": [
|
||||
"composer",
|
||||
"compression"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/composer/metadata-minifier/issues",
|
||||
"source": "https://github.com/composer/metadata-minifier/tree/1.0.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://packagist.com",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/composer",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/composer/composer",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-04-07T13:37:33+00:00"
|
||||
},
|
||||
{
|
||||
"name": "composer/package-versions-deprecated",
|
||||
@@ -3193,21 +3263,21 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/service-contracts",
|
||||
"version": "v2.2.0",
|
||||
"version": "v2.4.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/service-contracts.git",
|
||||
"reference": "d15da7ba4957ffb8f1747218be9e1a121fd298a1"
|
||||
"reference": "f040a30e04b57fbcc9c6cbcf4dbaa96bd318b9bb"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/service-contracts/zipball/d15da7ba4957ffb8f1747218be9e1a121fd298a1",
|
||||
"reference": "d15da7ba4957ffb8f1747218be9e1a121fd298a1",
|
||||
"url": "https://api.github.com/repos/symfony/service-contracts/zipball/f040a30e04b57fbcc9c6cbcf4dbaa96bd318b9bb",
|
||||
"reference": "f040a30e04b57fbcc9c6cbcf4dbaa96bd318b9bb",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.2.5",
|
||||
"psr/container": "^1.0"
|
||||
"psr/container": "^1.1"
|
||||
},
|
||||
"suggest": {
|
||||
"symfony/service-implementation": ""
|
||||
@@ -3215,7 +3285,7 @@
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.2-dev"
|
||||
"dev-main": "2.4-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/contracts",
|
||||
@@ -3252,7 +3322,7 @@
|
||||
"standards"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/service-contracts/tree/master"
|
||||
"source": "https://github.com/symfony/service-contracts/tree/v2.4.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -3268,7 +3338,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2020-09-07T11:33:47+00:00"
|
||||
"time": "2021-04-01T10:43:52+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/string",
|
||||
|
||||
@@ -273,6 +273,8 @@ class Game
|
||||
$v->save($this->getEntityManager());
|
||||
}
|
||||
|
||||
$v->setTwigSceneRenderer($this->getSceneRenderer());
|
||||
|
||||
return $v;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ use Doctrine\ORM\Mapping\JoinColumn;
|
||||
use Doctrine\ORM\Mapping\ManyToOne;
|
||||
use Doctrine\ORM\Mapping\OneToOne;
|
||||
use Doctrine\ORM\Mapping\Table;
|
||||
use Doctrine\ORM\Mapping\PostLoad;
|
||||
use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
|
||||
|
||||
use LotGD\Core\Action;
|
||||
use LotGD\Core\ActionGroup;
|
||||
@@ -28,6 +30,7 @@ use LotGD\Core\Tools\SceneDescription;
|
||||
* all changes from modules included.
|
||||
* @Entity
|
||||
* @Table(name="viewpoints")
|
||||
* @HasLifecycleCallbacks
|
||||
*/
|
||||
class Viewpoint implements CreateableInterface
|
||||
{
|
||||
@@ -69,6 +72,16 @@ class Viewpoint implements CreateableInterface
|
||||
"owner",
|
||||
];
|
||||
|
||||
/**
|
||||
* @PostLoad
|
||||
*/
|
||||
public function onLoad()
|
||||
{
|
||||
foreach ($this->actionGroups as $actionGroup) {
|
||||
$actionGroup->setViewpoint($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the owner.
|
||||
* @return Character
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Services;
|
||||
|
||||
|
||||
use Doctrine\DBAL\Exception as DBALException;
|
||||
use LotGD\Core\Action;
|
||||
use LotGD\Core\Events\EventContextData;
|
||||
use LotGD\Core\Exceptions\CharacterNotFoundException;
|
||||
@@ -35,8 +36,14 @@ class TwigSceneRenderer
|
||||
// the viewpoint itself.
|
||||
$eventManager = $this->game->getEventManager();
|
||||
$contextData = EventContextData::create(["templateValues" => []]);
|
||||
$newContextData = $eventManager->publish("h/lotgd/core/scene-renderer/templateValues", $contextData);
|
||||
$this->templateValues = $newContextData->get("templateValues") ?? [];
|
||||
|
||||
// Use try-catch here in case no database has yet been created. See #162
|
||||
try {
|
||||
$newContextData = $eventManager->publish("h/lotgd/core/scene-renderer/templateValues", $contextData);
|
||||
$this->templateValues = $newContextData->get("templateValues") ?? [];
|
||||
} catch (DBALException) {
|
||||
$this->templateValues = [];
|
||||
}
|
||||
|
||||
// Add Sandbox extension
|
||||
$securityPolicy = $this->getSecurityPolicy();
|
||||
@@ -62,11 +69,15 @@ class TwigSceneRenderer
|
||||
// throwing an exception.
|
||||
try {
|
||||
$template = $this->twig->createTemplate($string);
|
||||
} catch (SecurityError $e) {
|
||||
} catch (SecurityError | SyntaxError $e) {
|
||||
if ($ignoreErrors) {
|
||||
return $string;
|
||||
} else {
|
||||
throw new InsecureTwigTemplateError("Template contains illegal calls: {$e->getMessage()}");
|
||||
if ($e instanceof SecurityError) {
|
||||
throw new InsecureTwigTemplateError("Template contains illegal calls: {$e->getMessage()}");
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +98,11 @@ class TwigSceneRenderer
|
||||
if ($ignoreErrors) {
|
||||
return $string;
|
||||
} else {
|
||||
throw new InsecureTwigTemplateError("Template contains illegal calls: {$e->getMessage()}");
|
||||
if ($e instanceof SecurityError) {
|
||||
throw new InsecureTwigTemplateError("Template contains illegal calls: {$e->getMessage()}");
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +117,7 @@ class TwigSceneRenderer
|
||||
public function getSecurityPolicy(): SecurityPolicy
|
||||
{
|
||||
$tags = ["if"];
|
||||
$filters = ["lower", "upper", "escape", "round"];
|
||||
$filters = ["lower", "upper", "escape", "round", "abs"];
|
||||
$functions = ["range"];
|
||||
$methods = [
|
||||
Character::class => ["getDisplayName", "getLevel", "isAlive", "getHealth", "getMaxHealth", "getProperty"],
|
||||
@@ -125,7 +140,13 @@ class TwigSceneRenderer
|
||||
"methods" => $methods,
|
||||
"properties" => $properties,
|
||||
]);
|
||||
$newContextData = $eventManager->publish("h/lotgd/core/scene-renderer/securityPolicy", $contextData);
|
||||
|
||||
// Use try-catch here in case no database has yet been created. See #162
|
||||
try {
|
||||
$newContextData = $eventManager->publish("h/lotgd/core/scene-renderer/securityPolicy", $contextData);
|
||||
} catch (DBALException) {
|
||||
$this->templateValues = [];
|
||||
}
|
||||
|
||||
// Set changed values from the event.
|
||||
$tags = $newContextData->get("tags");
|
||||
|
||||
@@ -126,6 +126,8 @@ class ViewpointTest extends CoreModelTestCase
|
||||
$this->assertSame($should->getTitle(), $is->getTitle());
|
||||
$this->assertSame($should->getSortKey(), $is->getSortKey());
|
||||
$this->assertSame(count($should->getActions()), count($is->getActions()));
|
||||
|
||||
$this->assertSame($output, $is->getViewpoint());
|
||||
}
|
||||
|
||||
$this->assertEquals($ag2->getTitle(), $input->findActionGroupById('id2')->getTitle());
|
||||
|
||||
@@ -26,6 +26,9 @@ class TwigSceneRendererTest extends LotGDTestCase
|
||||
$character->method("getHealth")->willReturn(10);
|
||||
$character->method("getMaxHealth")->willReturn(100);
|
||||
$character->method("isAlive")->willReturn(true);
|
||||
$character->method("getProperty")->willReturnCallback(function ($name, $default=null) {
|
||||
return $default;
|
||||
});
|
||||
|
||||
# Get mock game
|
||||
$game = $this->getMockBuilder(Game::class)
|
||||
@@ -104,6 +107,46 @@ class TwigSceneRendererTest extends LotGDTestCase
|
||||
$this->assertSame($result, $renderResult);
|
||||
}
|
||||
|
||||
public function testIfTwigSceneRendererParsesStringsWithCharacterProperty()
|
||||
{
|
||||
[$game, $viewpoint, $character, $eventManager] = $this->getMockeries();
|
||||
$eventManager->method("publish")->willReturnArgument(1);
|
||||
|
||||
# Get renderer
|
||||
$renderer = new TwigSceneRenderer($game);
|
||||
|
||||
# Prepare the template string.
|
||||
$template = "Character has {{ Character.getProperty('a/goldiNBank', -10) }} gold in bank.";
|
||||
|
||||
$result = "Character has -10 gold in bank.";
|
||||
|
||||
# Create the result
|
||||
$renderResult = $renderer->render($template, $viewpoint);
|
||||
|
||||
# Assert result
|
||||
$this->assertSame($result, $renderResult);
|
||||
}
|
||||
|
||||
public function testIfTwigSceneRendererAccepsAbsFIlter()
|
||||
{
|
||||
[$game, $viewpoint, $character, $eventManager] = $this->getMockeries();
|
||||
$eventManager->method("publish")->willReturnArgument(1);
|
||||
|
||||
# Get renderer
|
||||
$renderer = new TwigSceneRenderer($game);
|
||||
|
||||
# Prepare the template string.
|
||||
$template = "Character has a debt of {{ Character.getProperty('a/goldiNBank', -10)|abs }} gold.";
|
||||
|
||||
$result = "Character has a debt of 10 gold.";
|
||||
|
||||
# Create the result
|
||||
$renderResult = $renderer->render($template, $viewpoint);
|
||||
|
||||
# Assert result
|
||||
$this->assertSame($result, $renderResult);
|
||||
}
|
||||
|
||||
public function testIfViewpointDataCanBeAccessed()
|
||||
{
|
||||
[$game, $viewpoint, $character, $eventManager] = $this->getMockeries();
|
||||
|
||||
Reference in New Issue
Block a user