Compare commits
118 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d83e437b4a | |||
| 99d554e5d7 | |||
| 75dd7494c3 | |||
| f7504bbb60 | |||
| 60a3a8bd2b | |||
| 147692d722 | |||
| 454248ed0f | |||
| 27347d0677 | |||
| 69434c7bbf | |||
| 2a3a3e7bc2 | |||
| 47693f6127 | |||
| e3534ea88d | |||
| 5dbe8fdca3 | |||
| 31387c1840 | |||
| dfd39cd1f8 | |||
| f25bab7af8 | |||
| c0ed663ef4 | |||
| b3b1c4af0a | |||
| 2153df5cc8 | |||
| 13dfab2321 | |||
| 29ad369c88 | |||
| a576bfd2a0 | |||
| aa5b32c03d | |||
| c2aaf025f6 | |||
| 9b60cc0ebb | |||
| eca1343b5f | |||
| 1fb2eb023e | |||
| 1a0b6dbe3e | |||
| 96feb12fb5 | |||
| 512d875609 | |||
| 0a2313b5e5 | |||
| c4634b90b7 | |||
| 6325b8bd36 | |||
| dd074a8bea | |||
| fdb53972d2 | |||
| ad3ea14bb2 | |||
| bb1ca987b5 | |||
| 57b8045c1a | |||
| f658b421f6 | |||
| 7ab55c1cb0 | |||
| 05d72a11bb | |||
| d006aa3ded | |||
| 147d449a27 | |||
| c18cdef3ff | |||
| 3eb538145e | |||
| 696a5f3305 | |||
| 765b65a9d2 | |||
| 96afd4b87e | |||
| ea6be63bb3 | |||
| 126fdee80e | |||
| 81c72ca91a | |||
| 29e5ced0f9 | |||
| c7dbf33f6e | |||
| d4124a71ef | |||
| 28c12a47f1 | |||
| 709b96ea52 | |||
| 363c4678d3 | |||
| d8b8fb69d9 | |||
| 0a20c8a968 | |||
| f051d72aea | |||
| af17f434d4 | |||
| 2680a41cee | |||
| c7d91230bd | |||
| 541748a168 | |||
| 42e3f22726 | |||
| 3c64492cde | |||
| 18ec30ede5 | |||
| 4e35fbd6b3 | |||
| 32305238d9 | |||
| 13082f7b9d | |||
| 272910c3a3 | |||
| 33a7812abe | |||
| a086fe4b9b | |||
| 557215bba3 | |||
| 81a6edc074 | |||
| 1cfe1cacba | |||
| f3fee8cc7d | |||
| 90f187dbf2 | |||
| 1a6079b270 | |||
| 17b704bec4 | |||
| f6df590cd6 | |||
| 3338a75f71 | |||
| 7fe81a9c5b | |||
| 3ecb7f8e95 | |||
| 0fcc6dc8b7 | |||
| 2376696101 | |||
| a52de33ed7 | |||
| cf99395ed3 | |||
| 1c53604244 | |||
| c6ecab6ce9 | |||
| ff154ccbd9 | |||
| fc73f86ffa | |||
| a375cb98cd | |||
| e18cdd21cc | |||
| c4ff330928 | |||
| e74dcbdfde | |||
| 8612a53538 | |||
| e8f2ea56bc | |||
| d0b2d48cc1 | |||
| 14d1c9d582 | |||
| 7725c7faed | |||
| 4ca81a3789 | |||
| 353c4251c4 | |||
| 248258a8fe | |||
| 4d1ab9e763 | |||
| d7229858cc | |||
| 14b1db8b82 | |||
| d7100deb0f | |||
| e260a1d661 | |||
| 2ff8d647e8 | |||
| 8d9a186b46 | |||
| 8f69527764 | |||
| 684f86aed6 | |||
| 55481c30b1 | |||
| 6b383be1cd | |||
| d609f981aa | |||
| 4ec84dfec3 | |||
| aa63259992 |
@@ -0,0 +1,39 @@
|
||||
name: Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Validate composer.json and composer.lock
|
||||
run: composer validate
|
||||
|
||||
- name: Cache Composer packages
|
||||
id: composer-cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: vendor
|
||||
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-php-
|
||||
|
||||
- name: Install dependencies
|
||||
if: steps.composer-cache.outputs.cache-hit != 'true'
|
||||
run: composer install --prefer-dist --no-progress --no-suggest
|
||||
|
||||
- name: Run test suite
|
||||
run: vendor/bin/phpunit --stop-on-failure
|
||||
|
||||
# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
|
||||
# Docs: https://getcomposer.org/doc/articles/scripts.md
|
||||
|
||||
# - name: Run test suite
|
||||
# run: composer run-script test
|
||||
@@ -0,0 +1,39 @@
|
||||
name: Package push
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
release:
|
||||
types: [ created ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Setup PHP with PECL extension
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '7.4'
|
||||
|
||||
- name: Set git credentials
|
||||
run: git config --global user.name "Vassyli" && git config --global user.email "basilius.sauter+automated@gmail.com" && git config --global user.password "${{ secrets.GH_TOKEN }}"
|
||||
|
||||
- name: Set composer token
|
||||
run: composer config -g github-oauth.github.com ${{ secrets.GH_TOKEN }}
|
||||
|
||||
- name: "Checkouts satis and packages"
|
||||
run: git clone https://github.com/composer/satis && git clone https://github.com/lotgd/packages
|
||||
|
||||
- name: "Install satis"
|
||||
run: cd satis && composer install && cd ..
|
||||
|
||||
- name: "Build satis"
|
||||
run: satis/bin/satis build packages/satis.json packages/build
|
||||
|
||||
- name: Set git url with credentials for pushing
|
||||
run: cd packages && git config remote.origin.url 'https://Vassyli:${{ secrets.GH_TOKEN }}@github.com/lotgd/packages.git' && cd ..
|
||||
|
||||
- name: "Commit changes and push to origin"
|
||||
run: cd packages && git add build/* && git commit -a -m "Updated packages" && git push origin master && cd ..
|
||||
@@ -228,3 +228,8 @@ pip-log.txt
|
||||
#Mr Developer
|
||||
.mr.developer.cfg
|
||||
dbconfig.php
|
||||
composer.phar
|
||||
clover.xml
|
||||
.phpunit.result.cache
|
||||
|
||||
.php_cs.cache
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
return PhpCsFixer\Config::create()
|
||||
->setRiskyAllowed(true)
|
||||
->setRules([
|
||||
'align_multiline_comment' => true,
|
||||
'array_indentation' => true,
|
||||
'array_syntax' => ['syntax' => 'short'],
|
||||
'binary_operator_spaces' => true,
|
||||
'blank_line_after_namespace' => true,
|
||||
'braces' => [
|
||||
'position_after_control_structures' => 'same',
|
||||
'position_after_functions_and_oop_constructs' => 'next',
|
||||
],
|
||||
'cast_spaces' => ['space' => 'none'],
|
||||
'class_definition' => true,
|
||||
'class_keyword_remove' => false,
|
||||
'combine_consecutive_issets' => true,
|
||||
'combine_consecutive_unsets' => true,
|
||||
'compact_nullable_typehint' => true,
|
||||
'declare_strict_types' => true,
|
||||
'declare_equal_normalize' => true,
|
||||
'dir_constant' => true,
|
||||
'doctrine_annotation_array_assignment' => true,
|
||||
'doctrine_annotation_braces' => true,
|
||||
'doctrine_annotation_indentation' => true,
|
||||
'doctrine_annotation_spaces' => [
|
||||
'after_array_assignments_colon' => false,
|
||||
'after_array_assignments_equals' => false,
|
||||
'before_argument_assignments' => false,
|
||||
'before_array_assignments_colon' => false,
|
||||
'before_array_assignments_equals' => false,
|
||||
],
|
||||
'elseif' => true,
|
||||
'encoding' => true,
|
||||
'ereg_to_preg' => true,
|
||||
'escape_implicit_backslashes' => true,
|
||||
'explicit_indirect_variable' => true,
|
||||
'explicit_string_variable' => true,
|
||||
'full_opening_tag' => true,
|
||||
'fully_qualified_strict_types' => true,
|
||||
'function_declaration' => true,
|
||||
'function_typehint_space' => true,
|
||||
'general_phpdoc_annotation_remove' => true,
|
||||
'indentation_type' => true,
|
||||
'line_ending' => true,
|
||||
'linebreak_after_opening_tag' => true,
|
||||
'list_syntax' => ['syntax' => 'short'],
|
||||
'lowercase_cast' => true,
|
||||
'lowercase_constants' => true,
|
||||
'lowercase_static_reference' => true,
|
||||
'magic_constant_casing' => true,
|
||||
'magic_method_casing' => true,
|
||||
'method_argument_space' => true,
|
||||
'method_chaining_indentation' => true,
|
||||
'multiline_comment_opening_closing' => true,
|
||||
'multiline_whitespace_before_semicolons' => ['strategy' => 'new_line_for_chained_calls'],
|
||||
'native_constant_invocation' => true,
|
||||
'native_function_invocation' => true,
|
||||
'native_function_type_declaration_casing' => true,
|
||||
'new_with_braces' => true,
|
||||
'no_alias_functions' => true,
|
||||
'no_alternative_syntax' => true,
|
||||
'no_blank_lines_after_phpdoc' => true,
|
||||
'no_break_comment' => true,
|
||||
'no_closing_tag' => true,
|
||||
'no_empty_comment' => true,
|
||||
'no_empty_phpdoc' => true,
|
||||
'no_empty_statement' => true,
|
||||
'no_extra_blank_lines' => true,
|
||||
'no_homoglyph_names' => true,
|
||||
'no_leading_import_slash' => true,
|
||||
'no_leading_namespace_whitespace' => true,
|
||||
'no_mixed_echo_print' => ["use" => "print"],
|
||||
'no_multiline_whitespace_around_double_arrow' => true,
|
||||
'no_php4_constructor' => true,
|
||||
'no_short_bool_cast' => true,
|
||||
'no_singleline_whitespace_before_semicolons' => true,
|
||||
'no_spaces_after_function_name' => true,
|
||||
'no_spaces_around_offset' => true,
|
||||
'no_spaces_inside_parenthesis' => true,
|
||||
'no_trailing_comma_in_list_call' => true,
|
||||
'no_trailing_comma_in_singleline_array' => true,
|
||||
'no_trailing_whitespace' => true,
|
||||
'no_trailing_whitespace_in_comment' => true,
|
||||
'no_unneeded_control_parentheses' => true,
|
||||
'no_unneeded_curly_braces' => true,
|
||||
'no_unneeded_final_method' => true,
|
||||
'no_unreachable_default_argument_value' => true,
|
||||
'no_unused_imports' => true,
|
||||
'no_useless_else' => true,
|
||||
'no_useless_return' => true,
|
||||
'no_whitespace_before_comma_in_array' => true,
|
||||
'non_printable_character' => true,
|
||||
'normalize_index_brace' => true,
|
||||
'object_operator_without_whitespace' => true,
|
||||
'ordered_imports' => true,
|
||||
'phpdoc_add_missing_param_annotation' => true,
|
||||
'phpdoc_indent' => true,
|
||||
'phpdoc_no_access' => true,
|
||||
'phpdoc_no_alias_tag' => true,
|
||||
'phpdoc_no_empty_return' => true,
|
||||
'phpdoc_no_package' => true,
|
||||
'phpdoc_no_useless_inheritdoc' => true,
|
||||
'phpdoc_order' => true,
|
||||
'phpdoc_scalar' => true,
|
||||
'phpdoc_single_line_var_spacing' => true,
|
||||
'phpdoc_summary' => true,
|
||||
'phpdoc_to_return_type' => true,
|
||||
'phpdoc_trim_consecutive_blank_line_separation' => true,
|
||||
'phpdoc_types' => true,
|
||||
'phpdoc_types_order' => ['null_adjustment' => 'always_last'],
|
||||
'phpdoc_var_annotation_correct_order' => true,
|
||||
'pow_to_exponentiation' => true,
|
||||
'psr4' => true,
|
||||
'random_api_migration' => true,
|
||||
'return_type_declaration' => true,
|
||||
'self_accessor' => true,
|
||||
'semicolon_after_instruction' => true,
|
||||
'set_type_to_cast' => true,
|
||||
'short_scalar_cast' => true,
|
||||
'single_blank_line_at_eof' => true,
|
||||
'single_blank_line_before_namespace' => true,
|
||||
'single_class_element_per_statement' => true,
|
||||
'single_import_per_statement' => true,
|
||||
'single_line_after_imports' => true,
|
||||
'standardize_not_equals' => true,
|
||||
'standardize_increment' => true,
|
||||
'switch_case_semicolon_to_colon' => true,
|
||||
'switch_case_space' => true,
|
||||
'ternary_to_null_coalescing' => true,
|
||||
'trailing_comma_in_multiline_array' => true,
|
||||
'trim_array_spaces' => false,
|
||||
'unary_operator_spaces' => true,
|
||||
'visibility_required' => true,
|
||||
'whitespace_after_comma_in_array' => true,
|
||||
'yoda_style' => false,
|
||||
])
|
||||
->setFinder(
|
||||
PhpCsFixer\Finder::create()
|
||||
->in(__DIR__."/src")
|
||||
);
|
||||
@@ -1,9 +0,0 @@
|
||||
sudo: false
|
||||
language: php
|
||||
php:
|
||||
- '7.1'
|
||||
- '7.2'
|
||||
install:
|
||||
- composer install
|
||||
script:
|
||||
- ./t
|
||||
@@ -1,6 +1,6 @@
|
||||
# Legend of the Green Dragon (Core)
|
||||
|
||||
[](https://travis-ci.org/lotgd/core)
|
||||

|
||||
|
||||
Legend of the Green Dragon is a text-based RPG originally developed by Eric Stevens and JT Traub as a remake of and homage to the classic BBS Door game,
|
||||
Legend of the Red Dragon, by Seth Able Robinson. You can play it at numerous sites, including http://www.lotgd.net/.
|
||||
|
||||
+17
-14
@@ -1,8 +1,7 @@
|
||||
{
|
||||
"name": "lotgd/core",
|
||||
"description": "Core functionality for Legend of the Green Dragon, a text-based RPG game.",
|
||||
"license": "AGPL-3.0",
|
||||
"version": "0.5.0",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"LotGD\\Core\\": "src/",
|
||||
@@ -13,15 +12,19 @@
|
||||
"bin/daenerys"
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.1.0",
|
||||
"composer/composer": "*",
|
||||
"gedmo/doctrine-extensions": "*",
|
||||
"doctrine/orm": "2.5.*",
|
||||
"monolog/monolog": "^1.12",
|
||||
"symfony/console": "^3.0",
|
||||
"symfony/yaml": "^3.0",
|
||||
"d11wtq/boris": "^1.0",
|
||||
"ramsey/uuid-doctrine": "^1.5"
|
||||
"php": "^8.0",
|
||||
"ext-pdo": "*",
|
||||
"composer/composer": "^1.10|^2.0",
|
||||
"gedmo/doctrine-extensions": "^2.3|^3.0",
|
||||
"doctrine/orm": "^2.8",
|
||||
"doctrine/common": "^3.0",
|
||||
"monolog/monolog": "^2.0",
|
||||
"symfony/console": "^5.0",
|
||||
"symfony/yaml": "^5.0",
|
||||
"twig/twig": "^3.0",
|
||||
"ramsey/uuid-doctrine": "^1.5",
|
||||
"jetbrains/phpstorm-attributes": "^1.0",
|
||||
"d11wtq/boris": "^1.0"
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
@@ -31,8 +34,8 @@
|
||||
|
||||
],
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^5.0",
|
||||
"phpunit/dbunit": "^2.0",
|
||||
"block8/php-docblock-checker": "2.0.0"
|
||||
"phpunit/phpunit": "*",
|
||||
"phpunit/php-code-coverage": "*",
|
||||
"friendsofphp/php-cs-fixer": "*"
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+3789
-1003
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,7 @@ database:
|
||||
name: daenerys
|
||||
user: root
|
||||
password:
|
||||
disableAutoSchemaUpdate: false
|
||||
game:
|
||||
epoch: 2016-07-01 00:00:00.0 -8
|
||||
offsetSeconds: 0
|
||||
|
||||
+14
-17
@@ -9,23 +9,20 @@ namespace LotGD\Core;
|
||||
*/
|
||||
class Action
|
||||
{
|
||||
protected $id;
|
||||
protected $destinationSceneId;
|
||||
protected $title = null;
|
||||
protected $parameters = [];
|
||||
protected string $id;
|
||||
|
||||
/**
|
||||
* Construct a new action with the specified Scene as its destination.
|
||||
* @param int $destinationSceneId
|
||||
* @param string $destinationSceneId
|
||||
* @param string|null $title
|
||||
* @param array $parameters
|
||||
*/
|
||||
public function __construct(string $destinationSceneId, ?string $title = null, array $parameters = [])
|
||||
{
|
||||
$this->id = bin2hex(random_bytes(8));
|
||||
$this->destinationSceneId = $destinationSceneId;
|
||||
$this->title = $title;
|
||||
$this->parameters = $parameters;
|
||||
public function __construct(
|
||||
protected string $destinationSceneId,
|
||||
protected ?string $title = null,
|
||||
protected array $parameters = []
|
||||
) {
|
||||
$this->id = \bin2hex(\random_bytes(8));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,7 +38,7 @@ class Action
|
||||
/**
|
||||
* Return the database ID of the destination scene, where the user will
|
||||
* go if they take this action.
|
||||
* @return int
|
||||
* @return string
|
||||
*/
|
||||
public function getDestinationSceneId(): string
|
||||
{
|
||||
@@ -49,7 +46,7 @@ class Action
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTitle(): ?string
|
||||
{
|
||||
@@ -57,15 +54,15 @@ class Action
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
* @param string|null $title
|
||||
*/
|
||||
public function setTitle(?string $title)
|
||||
public function setTitle(?string $title): void
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all parameters for this action
|
||||
* Returns all parameters for this action.
|
||||
* @return array
|
||||
*/
|
||||
public function getParameters(): array
|
||||
@@ -74,7 +71,7 @@ class Action
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets all parameters for this action
|
||||
* Sets all parameters for this action.
|
||||
* @param array $parameters
|
||||
*/
|
||||
public function setParameters(array $parameters): void
|
||||
|
||||
+9
-12
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core;
|
||||
|
||||
@@ -11,9 +11,6 @@ class ActionGroup implements \Countable
|
||||
const DefaultGroup = 'lotgd/core/default';
|
||||
const HiddenGroup = 'lotgd/core/hidden';
|
||||
|
||||
private $id;
|
||||
private $title;
|
||||
private $sortKey;
|
||||
private $actions;
|
||||
|
||||
/**
|
||||
@@ -22,11 +19,11 @@ class ActionGroup implements \Countable
|
||||
* @param string $title Title to display to the end user. Empty string means no title.
|
||||
* @param int $sortKey Navigation menus are displayed in the order sorted by this integer.
|
||||
*/
|
||||
public function __construct(string $id, string $title, int $sortKey)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->title = $title;
|
||||
$this->sortKey = $sortKey;
|
||||
public function __construct(
|
||||
private string $id,
|
||||
private string $title,
|
||||
private int $sortKey
|
||||
) {
|
||||
$this->actions = [];
|
||||
}
|
||||
|
||||
@@ -36,7 +33,7 @@ class ActionGroup implements \Countable
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->actions);
|
||||
return \count($this->actions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,7 +67,7 @@ class ActionGroup implements \Countable
|
||||
|
||||
/**
|
||||
* Returns the ordered array of actions.
|
||||
* @return array<Action>
|
||||
* @return Action[]
|
||||
*/
|
||||
public function getActions(): array
|
||||
{
|
||||
@@ -79,7 +76,7 @@ class ActionGroup implements \Countable
|
||||
|
||||
/**
|
||||
* Sets the ordered array of actions.
|
||||
* @param array<Action> $actions
|
||||
* @param Action[] $actions
|
||||
*/
|
||||
public function setActions(array $actions)
|
||||
{
|
||||
|
||||
+15
-17
@@ -3,24 +3,31 @@ declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core;
|
||||
|
||||
use Exception;
|
||||
use LotGD\Core\Models\Scene;
|
||||
|
||||
/**
|
||||
* An attachment to a scene. This is desigend to be subclasses by modules to
|
||||
* provide functinoality like forms or maybe image attachments to go along with a scene.
|
||||
*/
|
||||
abstract class Attachment
|
||||
abstract class Attachment implements AttachmentInterface
|
||||
{
|
||||
protected $id;
|
||||
protected $type;
|
||||
protected string $id;
|
||||
|
||||
/**
|
||||
* Construct a new attachment of the given type. Randomly assigns it an ID.
|
||||
* @param string $type Type of this attachment, in the vendor/module/type format.
|
||||
* @return Attachment
|
||||
* @param Game $game
|
||||
* @param Scene $scene
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct(string $type)
|
||||
public function __construct(Game $game, Scene $scene)
|
||||
{
|
||||
$this->id = bin2hex(random_bytes(8));
|
||||
$this->type = $type;
|
||||
$this->id = \bin2hex(\random_bytes(8));
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return "<Attachment#{$this->id} '{". static::class . "}'>";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,13 +39,4 @@ abstract class Attachment
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of this attachment, in vendor/module/type format.
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core;
|
||||
|
||||
use LotGD\Core\Models\Scene;
|
||||
|
||||
interface AttachmentInterface
|
||||
{
|
||||
/**
|
||||
* AttachmentInterface constructor.
|
||||
* @param Game $g Should not be saved internally.
|
||||
* @param Scene $scene Should not be saved internally.
|
||||
*/
|
||||
public function __construct(Game $g, Scene $scene);
|
||||
public function __toString(): string;
|
||||
public function getId(): string;
|
||||
|
||||
/**
|
||||
* Returns an array with attachment-specific fields.
|
||||
* @return array
|
||||
*/
|
||||
public function getData(): array;
|
||||
}
|
||||
+79
-90
@@ -3,21 +3,17 @@ declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core;
|
||||
|
||||
use Doctrine\Common\Collections\{
|
||||
ArrayCollection,
|
||||
Collection
|
||||
};
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
||||
use LotGD\Core\{
|
||||
DiceBag,
|
||||
Exceptions\ArgumentException,
|
||||
Exceptions\BattleIsOverException,
|
||||
Exceptions\BattleNotOverException,
|
||||
Models\FighterInterface
|
||||
};
|
||||
use LotGD\Core\Models\{
|
||||
Buff, BattleEvents\BuffMessageEvent, BattleEvents\CriticalHitEvent, BattleEvents\DamageEvent, BattleEvents\DeathEvent, Scene
|
||||
};
|
||||
use LotGD\Core\Exceptions\ArgumentException;
|
||||
use LotGD\Core\Exceptions\BattleIsOverException;
|
||||
use LotGD\Core\Exceptions\BattleNotOverException;
|
||||
use LotGD\Core\Models\BattleEvents\CriticalHitEvent;
|
||||
use LotGD\Core\Models\BattleEvents\DamageEvent;
|
||||
use LotGD\Core\Models\BattleEvents\DeathEvent;
|
||||
use LotGD\Core\Models\Buff;
|
||||
use LotGD\Core\Models\FighterInterface;
|
||||
|
||||
/**
|
||||
* Class for managing and running battles between 2 participants.
|
||||
@@ -34,18 +30,10 @@ class Battle
|
||||
const RESULT_PLAYERDEATH = 1;
|
||||
const RESULT_MONSTERDEATH = 2;
|
||||
|
||||
protected $player;
|
||||
protected $monster;
|
||||
protected $game;
|
||||
protected $events;
|
||||
protected $result = 0;
|
||||
protected $round = 0;
|
||||
|
||||
/**
|
||||
* Battle Configuration
|
||||
* @var array
|
||||
*/
|
||||
protected $configuration = [
|
||||
protected ArrayCollection $events;
|
||||
protected int $result = 0;
|
||||
protected int $round = 0;
|
||||
protected array $configuration = [
|
||||
"riposteEnabled" => true,
|
||||
"levelAdjustementEnabled" => true,
|
||||
"criticalHitEnabled" => true,
|
||||
@@ -53,15 +41,15 @@ class Battle
|
||||
|
||||
/**
|
||||
* Takes a game object and two participants (Player and Monster) to fight a battle.
|
||||
* @param \LotGD\Core\Game $game
|
||||
* @param Game $game
|
||||
* @param FighterInterface $player
|
||||
* @param FighterInterface $monster
|
||||
* @param FighterInterface|null $monster
|
||||
*/
|
||||
public function __construct(Game $game, FighterInterface $player, ?FighterInterface $monster)
|
||||
{
|
||||
$this->game = $game;
|
||||
$this->player = $player;
|
||||
$this->monster = $monster;
|
||||
public function __construct(
|
||||
protected Game $game,
|
||||
protected FighterInterface $player,
|
||||
protected ?FighterInterface $monster
|
||||
) {
|
||||
$this->events = new ArrayCollection();
|
||||
}
|
||||
|
||||
@@ -71,7 +59,7 @@ class Battle
|
||||
*/
|
||||
public function serialize(): string
|
||||
{
|
||||
return serialize([
|
||||
return \serialize([
|
||||
"monster" => $this->monster,
|
||||
"result" => $this->result,
|
||||
"round" => $this->round,
|
||||
@@ -83,14 +71,14 @@ class Battle
|
||||
* @param Game $game
|
||||
* @param FighterInterface $player
|
||||
* @param string $serialized
|
||||
* @return Battle
|
||||
* @return self
|
||||
*/
|
||||
public static function unserialize(Game $game, FighterInterface $player, string $serialized): self
|
||||
{
|
||||
$battle = new self($game, $player, null);
|
||||
$unserialized = unserialize($serialized);
|
||||
$unserialized = \unserialize($serialized);
|
||||
|
||||
$battle->monster = $unserialized["monster"];
|
||||
$battle->monster = $unserialized["monster"];
|
||||
$battle->result = $unserialized["result"];
|
||||
$battle->round = $unserialized["round"];
|
||||
$battle->configuration = $unserialized["configuration"];
|
||||
@@ -99,7 +87,7 @@ class Battle
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all battle events
|
||||
* Returns a list of all battle events.
|
||||
* @return Collection
|
||||
*/
|
||||
public function getEvents(): Collection
|
||||
@@ -108,23 +96,23 @@ class Battle
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables ripostes
|
||||
* Disables ripostes.
|
||||
*/
|
||||
public function disableRiposte()
|
||||
public function disableRiposte(): void
|
||||
{
|
||||
$this->configuration["riposteEnabled"] = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables ripostes
|
||||
* Enables ripostes.
|
||||
*/
|
||||
public function enableRiposte()
|
||||
public function enableRiposte(): void
|
||||
{
|
||||
$this->configuration["riposteEnabled"] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if ripostes are enabled
|
||||
* Returns true if ripostes are enabled.
|
||||
* @return bool
|
||||
*/
|
||||
public function isRiposteEnabled(): bool
|
||||
@@ -133,23 +121,23 @@ class Battle
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables level adjustement
|
||||
* Enables level adjustement.
|
||||
*/
|
||||
public function enableLevelAdjustement()
|
||||
public function enableLevelAdjustement(): void
|
||||
{
|
||||
$this->configuration["levelAdjustementEnabled"] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables level adjustement
|
||||
* Disables level adjustement.
|
||||
*/
|
||||
public function disableLevelAdjustement()
|
||||
public function disableLevelAdjustement(): void
|
||||
{
|
||||
$this->configuration["levelAdjustementEnabled"] = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if level adjustements are enabled
|
||||
* Returns true if level adjustements are enabled.
|
||||
* @return bool
|
||||
*/
|
||||
public function isLevelAdjustementEnabled(): bool
|
||||
@@ -158,7 +146,7 @@ class Battle
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if critical hit events are enabled
|
||||
* Returns true if critical hit events are enabled.
|
||||
* @return bool
|
||||
*/
|
||||
public function isCriticalHitEnabled(): bool
|
||||
@@ -167,17 +155,17 @@ class Battle
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable critical hits
|
||||
* Disable critical hits.
|
||||
*/
|
||||
public function disableCriticalHit()
|
||||
public function disableCriticalHit(): void
|
||||
{
|
||||
$this->configuration["criticalHitEnabled"] = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* enables critical hits
|
||||
* enables critical hits.
|
||||
*/
|
||||
public function enableCriticalHit()
|
||||
public function enableCriticalHit(): void
|
||||
{
|
||||
$this->configuration["criticalHitEnabled"] = true;
|
||||
}
|
||||
@@ -192,7 +180,7 @@ class Battle
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the player instance
|
||||
* Returns the player instance.
|
||||
* @return FighterInterface
|
||||
*/
|
||||
public function getPlayer(): FighterInterface
|
||||
@@ -201,7 +189,7 @@ class Battle
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the montser instance
|
||||
* Returns the montser instance.
|
||||
* @return FighterInterface
|
||||
*/
|
||||
public function getMonster(): FighterInterface
|
||||
@@ -210,9 +198,9 @@ class Battle
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the winner of this fight
|
||||
* @return FighterInterface
|
||||
* Returns the winner of this fight.
|
||||
* @throws BattleNotOverException if battle is not over.
|
||||
* @return FighterInterface
|
||||
*/
|
||||
public function getWinner(): FighterInterface
|
||||
{
|
||||
@@ -224,9 +212,9 @@ class Battle
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the loser of this fight
|
||||
* @return FighterInterface
|
||||
* Returns the loser of this fight.
|
||||
* @throws BattleNotOverException if battle is not over.
|
||||
* @return FighterInterface
|
||||
*/
|
||||
public function getLoser(): FighterInterface
|
||||
{
|
||||
@@ -241,10 +229,10 @@ class Battle
|
||||
* Fights the number of rounds given by the parameter $n and returns the number
|
||||
* of actual rounds fought.
|
||||
* @param int $n
|
||||
* @param bool $firstDamageRound Which damage rounds are calculated. Cannot be 0.
|
||||
* @return int Number of fights fought.
|
||||
* @param int $firstDamageRound Which damage rounds are calculated. Cannot be 0.
|
||||
* @throws ArgumentException if firstDamageRound is 0.
|
||||
* @throws BattleIsOverException
|
||||
* @return int Number of fights fought.
|
||||
*/
|
||||
public function fightNRounds(int $n = 1, int $firstDamageRound = self::DAMAGEROUND_BOTH): int
|
||||
{
|
||||
@@ -265,14 +253,14 @@ class Battle
|
||||
}
|
||||
}
|
||||
|
||||
return $count+1;
|
||||
return $count + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fights exactly 1 round
|
||||
* Fights exactly 1 round.
|
||||
* @param int $firstDamageRound
|
||||
*/
|
||||
protected function fightOneRound(int $firstDamageRound)
|
||||
protected function fightOneRound(int $firstDamageRound): void
|
||||
{
|
||||
$damageHasBeenDone = false;
|
||||
|
||||
@@ -285,7 +273,7 @@ class Battle
|
||||
$offenseTurnEvents = $firstDamageRound & self::DAMAGEROUND_PLAYER ? $this->turn($this->player, $this->monster) : new ArrayCollection();
|
||||
$defenseTurnEvents = $firstDamageRound & self::DAMAGEROUND_MONSTER ? $this->turn($this->monster, $this->player) : new ArrayCollection();
|
||||
|
||||
$events = new ArrayCollection(array_merge($offenseTurnEvents->toArray(), $defenseTurnEvents->toArray()));
|
||||
$events = new ArrayCollection([...$offenseTurnEvents->toArray(), ...$defenseTurnEvents->toArray()]);
|
||||
$eventsToAdd = new ArrayCollection();
|
||||
|
||||
foreach ($events as $event) {
|
||||
@@ -315,17 +303,17 @@ class Battle
|
||||
$monsterBuffExpiringEvents = $this->monster->getBuffs()->expireOneRound();
|
||||
|
||||
$this->events = new ArrayCollection(
|
||||
array_merge(
|
||||
$this->events->toArray(),
|
||||
$playerBuffStartEvents->toArray(),
|
||||
$monsterBuffStartEvents->toArray(),
|
||||
$eventsToAdd->toArray(),
|
||||
$playerBuffEndEvents->toArray(),
|
||||
$monsterBuffEndEvents->toArray(),
|
||||
$playerBuffExpiringEvents->toArray(),
|
||||
$monsterBuffExpiringEvents->toArray(),
|
||||
isset($deathEvent) ? [$deathEvent] : []
|
||||
)
|
||||
[
|
||||
...$this->events->toArray(),
|
||||
...$playerBuffStartEvents->toArray(),
|
||||
...$monsterBuffStartEvents->toArray(),
|
||||
...$eventsToAdd->toArray(),
|
||||
...$playerBuffEndEvents->toArray(),
|
||||
...$monsterBuffEndEvents->toArray(),
|
||||
...$playerBuffExpiringEvents->toArray(),
|
||||
...$monsterBuffExpiringEvents->toArray(),
|
||||
...isset($deathEvent) ? [$deathEvent] : [],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -333,6 +321,7 @@ class Battle
|
||||
* Runs one turn.
|
||||
* @param FighterInterface $attacker
|
||||
* @param FighterInterface $defender
|
||||
* @return ArrayCollection
|
||||
*/
|
||||
protected function turn(FighterInterface $attacker, FighterInterface $defender): ArrayCollection
|
||||
{
|
||||
@@ -384,8 +373,8 @@ class Battle
|
||||
}
|
||||
|
||||
// Conversion from float to int, since the random number generator takes int values.
|
||||
$attackersAttack = (int) round($attackersAttack, 0);
|
||||
$defendersDefense = (int) round($defendersDefense, 0);
|
||||
$attackersAttack = (int)\round($attackersAttack, 0);
|
||||
$defendersDefense = (int)\round($defendersDefense, 0);
|
||||
|
||||
// Lets roll the
|
||||
$attackersAtkRoll = $this->game->getDiceBag()->pseudoBell(0, $attackersAttack);
|
||||
@@ -413,10 +402,10 @@ class Battle
|
||||
$damage = 0;
|
||||
} elseif ($attackerIsInvulnurable) {
|
||||
// Attaker is invulnurable, damage is always > 0 (there is no riposte)
|
||||
$damage = abs($damage);
|
||||
$damage = \abs($damage);
|
||||
} elseif ($defenderIsInvulnurable) {
|
||||
// Defender is invulnurable, damage is always < 0 (defender always ripostes)
|
||||
$damage = - abs($damage);
|
||||
$damage = -\abs($damage);
|
||||
}
|
||||
|
||||
if ($damage < 0) {
|
||||
@@ -438,7 +427,7 @@ class Battle
|
||||
}
|
||||
|
||||
// Round the damage value and convert to int.
|
||||
$damage = (int)round($damage, 0);
|
||||
$damage = (int)\round($damage, 0);
|
||||
|
||||
// Add the damage event
|
||||
$events->add(new DamageEvent($attacker, $defender, $damage));
|
||||
@@ -454,15 +443,15 @@ class Battle
|
||||
$defendersDamageDependentBuffEvents = $defendersBuffs->processDamageDependentBuffs(Buff::ACTIVATE_DEFENSE, -$damage, $this->game, $defender, $attacker);
|
||||
|
||||
return new ArrayCollection(
|
||||
array_merge(
|
||||
$attackersBuffStartEvents->toArray(),
|
||||
$attackersDirectBuffEvents->toArray(),
|
||||
$defendersBuffStartEvents->toArray(),
|
||||
$defendersDirectBuffEvents->toArray(),
|
||||
$events->toArray(),
|
||||
$attackersDamageDependentBuffEvents->toArray(),
|
||||
$defendersDamageDependentBuffEvents->toArray()
|
||||
)
|
||||
[
|
||||
...$attackersBuffStartEvents->toArray(),
|
||||
...$attackersDirectBuffEvents->toArray(),
|
||||
...$defendersBuffStartEvents->toArray(),
|
||||
...$defendersDirectBuffEvents->toArray(),
|
||||
...$events->toArray(),
|
||||
...$attackersDamageDependentBuffEvents->toArray(),
|
||||
...$defendersDamageDependentBuffEvents->toArray(),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+45
-48
@@ -4,28 +4,21 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core;
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
||||
use Doctrine\Common\EventManager as DoctrineEventManager;
|
||||
use Doctrine\Common\Util\Debug;
|
||||
use Doctrine\DBAL\DBALException;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Events as DoctrineEvents;
|
||||
use Doctrine\ORM\ {
|
||||
EntityManager,
|
||||
EntityManagerInterface,
|
||||
Mapping\AnsiQuoteStrategy,
|
||||
Tools\Setup,
|
||||
Tools\SchemaTool
|
||||
};
|
||||
use Monolog\ {
|
||||
Logger,
|
||||
Handler\RotatingFileHandler
|
||||
};
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
use Doctrine\ORM\Tools\Setup;
|
||||
use LotGD\Core\Doctrine\EntityPostLoadEventListener;
|
||||
use LotGD\Core\Exceptions\InvalidConfigurationException;
|
||||
use Monolog\Handler\RotatingFileHandler;
|
||||
use Monolog\Logger;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
use LotGD\Core\{
|
||||
ComposerManager, BootstrapInterface, Doctrine\EntityPostLoadEventListener, Exceptions\InvalidConfigurationException
|
||||
};
|
||||
|
||||
/**
|
||||
* The entry point for constructing a properly configured LotGD Game object.
|
||||
*/
|
||||
@@ -33,24 +26,24 @@ class Bootstrap
|
||||
{
|
||||
private $logger;
|
||||
private $game;
|
||||
/** @var LibraryConfigurationManager */
|
||||
/** @var LibraryConfigurationManager */
|
||||
private $libraryConfigurationManager;
|
||||
private $annotationDirectories = [];
|
||||
|
||||
/**
|
||||
* Create a new Game object, with all the necessary configuration.
|
||||
* @param string $cwd
|
||||
* @param string|null $cwd
|
||||
* @return Game The newly created Game object.
|
||||
*/
|
||||
public static function createGame(string $cwd = null): Game
|
||||
{
|
||||
$game = new self();
|
||||
$cwd = $cwd ?? getcwd();
|
||||
$cwd = $cwd ?? \getcwd();
|
||||
return $game->getGame($cwd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the game kernel with the most important classes and returns the object
|
||||
* Starts the game kernel with the most important classes and returns the object.
|
||||
* @param string $cwd
|
||||
* @return Game
|
||||
*/
|
||||
@@ -64,16 +57,17 @@ class Bootstrap
|
||||
$composer = $this->createComposerManager($cwd);
|
||||
$this->libraryConfigurationManager = $this->createLibraryConfigurationManager($composer, $cwd);
|
||||
|
||||
list($dsn, $user, $password) = $config->getDatabaseConnectionDetails($cwd);
|
||||
[$dsn, $user, $password] = $config->getDatabaseConnectionDetails($cwd);
|
||||
$pdo = $this->connectToDatabase($dsn, $user, $password);
|
||||
$entityManager = $this->createEntityManager($pdo);
|
||||
$entityManager = $this->createEntityManager($pdo, $config);
|
||||
|
||||
$this->game = (new GameBuilder())
|
||||
->withConfiguration($config)
|
||||
->withLogger($this->logger)
|
||||
->withEntityManager($entityManager)
|
||||
->withCwd($cwd)
|
||||
->create();
|
||||
->create()
|
||||
;
|
||||
|
||||
// Add Event listener to entity manager
|
||||
$dem = $entityManager->getEventManager();
|
||||
@@ -86,10 +80,10 @@ class Bootstrap
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a library configuration manager
|
||||
* Creates a library configuration manager.
|
||||
* @param ComposerManager $composerManager
|
||||
* @param string $cwd
|
||||
* @return \LotGD\Core\LibraryConfigurationManager
|
||||
* @return LibraryConfigurationManager
|
||||
*/
|
||||
protected function createLibraryConfigurationManager(
|
||||
ComposerManager $composerManager,
|
||||
@@ -99,8 +93,10 @@ class Bootstrap
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to a database using pdo
|
||||
* @param \LotGD\Core\Configuration $config
|
||||
* Connects to a database using pdo.
|
||||
* @param string $dsn
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @return \PDO
|
||||
*/
|
||||
protected function connectToDatabase(string $dsn, string $user, string $password): \PDO
|
||||
@@ -109,7 +105,7 @@ class Bootstrap
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns an instance of ComposerManager
|
||||
* Creates and returns an instance of ComposerManager.
|
||||
* @param string $cwd
|
||||
* @return ComposerManager
|
||||
*/
|
||||
@@ -122,16 +118,16 @@ class Bootstrap
|
||||
/**
|
||||
* Returns a configuration object reading from the file located at the path stored in $cwd/config/lotgd.yml.
|
||||
* @param string $cwd
|
||||
* @return \LotGD\Core\Configuration
|
||||
* @throws InvalidConfigurationException
|
||||
* @return Configuration
|
||||
*/
|
||||
protected function createConfiguration(string $cwd): Configuration
|
||||
{
|
||||
if (empty($configFilePath)) {
|
||||
$configFilePath = implode(DIRECTORY_SEPARATOR, [$cwd, "config", "lotgd.yml"]);
|
||||
$configFilePath = \implode(\DIRECTORY_SEPARATOR, [$cwd, "config", "lotgd.yml"]);
|
||||
}
|
||||
|
||||
if ($configFilePath === false || strlen($configFilePath) == 0 || is_file($configFilePath) === false) {
|
||||
if ($configFilePath === false || \strlen($configFilePath) == 0 || \is_file($configFilePath) === false) {
|
||||
throw new InvalidConfigurationException("Invalid or missing configuration file: {$configFilePath}.");
|
||||
}
|
||||
|
||||
@@ -140,7 +136,7 @@ class Bootstrap
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a logger instance
|
||||
* Returns a logger instance.
|
||||
* @param Configuration $config
|
||||
* @param string $name
|
||||
* @return LoggerInterface
|
||||
@@ -149,40 +145,41 @@ class Bootstrap
|
||||
{
|
||||
$logger = new Logger($name);
|
||||
// Add lotgd as the prefix for the log filenames.
|
||||
$logger->pushHandler(new RotatingFileHandler($config->getLogPath() . DIRECTORY_SEPARATOR . $name, 14));
|
||||
$logger->pushHandler(new RotatingFileHandler($config->getLogPath() . \DIRECTORY_SEPARATOR . $name, 14));
|
||||
|
||||
return $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the EntityManager using the pdo connection given in it's argument
|
||||
* Creates the EntityManager using the pdo connection given in it's argument.
|
||||
* @param \PDO $pdo
|
||||
* @param Configuration
|
||||
* @return EntityManagerInterface
|
||||
*/
|
||||
protected function createEntityManager(\PDO $pdo): EntityManagerInterface
|
||||
protected function createEntityManager(\PDO $pdo, Configuration $config): EntityManagerInterface
|
||||
{
|
||||
$this->annotationDirectories = $this->generateAnnotationDirectories();
|
||||
$this->logger->addDebug("Adding annotation directories:");
|
||||
$this->logger->debug("Adding annotation directories:");
|
||||
foreach ($this->annotationDirectories as $d) {
|
||||
$this->logger->addDebug(" {$d}");
|
||||
$this->logger->debug(" {$d}");
|
||||
}
|
||||
$configuration = Setup::createAnnotationMetadataConfiguration($this->annotationDirectories, true);
|
||||
|
||||
// Set a quote
|
||||
$configuration->setQuoteStrategy(new AnsiQuoteStrategy());
|
||||
|
||||
// Create entity manager
|
||||
$entityManager = EntityManager::create(["pdo" => $pdo], $configuration);
|
||||
|
||||
// Register uuid type
|
||||
try {
|
||||
\Doctrine\DBAL\Types\Type::addType('uuid', 'Ramsey\Uuid\Doctrine\UuidType');
|
||||
} catch (DBALException $e) {}
|
||||
Type::addType('uuid', 'Ramsey\Uuid\Doctrine\UuidType');
|
||||
} catch (DBALException $e) {
|
||||
}
|
||||
|
||||
// Create Schema and update database if needed
|
||||
$metaData = $entityManager->getMetadataFactory()->getAllMetadata();
|
||||
$schemaTool = new SchemaTool($entityManager);
|
||||
$schemaTool->updateSchema($metaData);
|
||||
if ($config->getDatabaseAutoSchemaUpdate()) {
|
||||
$metaData = $entityManager->getMetadataFactory()->getAllMetadata();
|
||||
$schemaTool = new SchemaTool($entityManager);
|
||||
$schemaTool->updateSchema($metaData);
|
||||
}
|
||||
|
||||
return $entityManager;
|
||||
}
|
||||
@@ -194,12 +191,12 @@ class Bootstrap
|
||||
protected function generateAnnotationDirectories(): array
|
||||
{
|
||||
// Read db annotations from our own model files.
|
||||
$directories = [__DIR__ . DIRECTORY_SEPARATOR . 'Models'];
|
||||
$directories = [__DIR__ . \DIRECTORY_SEPARATOR . 'Models'];
|
||||
|
||||
// Get additional annotation directories from library configs.
|
||||
$libraryDirectories = $this->libraryConfigurationManager->getEntityDirectories();
|
||||
|
||||
return array_merge($directories, $libraryDirectories);
|
||||
return \array_merge($directories, $libraryDirectories);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+66
-82
@@ -3,73 +3,58 @@ declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core;
|
||||
|
||||
use Doctrine\Common\Collections\{
|
||||
ArrayCollection,
|
||||
Collection
|
||||
};
|
||||
|
||||
use LotGD\Core\Exceptions\{
|
||||
ArgumentException,
|
||||
BuffListAlreadyActivatedException
|
||||
};
|
||||
use LotGD\Core\Models\{
|
||||
Buff,
|
||||
Character,
|
||||
FighterInterface,
|
||||
BattleEvents\BuffMessageEvent,
|
||||
BattleEvents\DamageLifetapEvent,
|
||||
BattleEvents\DamageReflectionEvent,
|
||||
BattleEvents\RegenerationBuffEvent,
|
||||
BattleEvents\MinionDamageEvent
|
||||
};
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
||||
use LotGD\Core\Exceptions\ArgumentException;
|
||||
use LotGD\Core\Exceptions\BuffListAlreadyActivatedException;
|
||||
use LotGD\Core\Exceptions\BuffSlotOccupiedException;
|
||||
use LotGD\Core\Models\BattleEvents\BuffMessageEvent;
|
||||
use LotGD\Core\Models\BattleEvents\DamageLifetapEvent;
|
||||
use LotGD\Core\Models\BattleEvents\DamageReflectionEvent;
|
||||
use LotGD\Core\Models\BattleEvents\MinionDamageEvent;
|
||||
use LotGD\Core\Models\BattleEvents\RegenerationBuffEvent;
|
||||
use LotGD\Core\Models\Buff;
|
||||
use LotGD\Core\Models\FighterInterface;
|
||||
|
||||
/**
|
||||
* Description of BuffList
|
||||
* Description of BuffList.
|
||||
*/
|
||||
class BuffList
|
||||
{
|
||||
protected $buffs;
|
||||
protected $buffsBySlot;
|
||||
protected $activeBuffs = [];
|
||||
/** @var Doctrine\Common\Collections\ArrayCollection */
|
||||
protected $usedBuffs;
|
||||
protected array $buffsBySlot;
|
||||
protected array $activeBuffs = [];
|
||||
protected ArrayCollection $usedBuffs;
|
||||
|
||||
/** @var boolean True of the modifiers have already been calculated */
|
||||
protected $modifiersCalculated = false;
|
||||
/** @var boolean True if the badguy is invulnurable */
|
||||
protected $badguyInvulnurable = false;
|
||||
/** @var float */
|
||||
protected $badguyDamageModifier = 1.;
|
||||
/** @var float */
|
||||
protected $badguyAttackModifier = 1.;
|
||||
/** @var float */
|
||||
protected $badguyDefenseModifier = 1.;
|
||||
/** @var boolean True if the goodguy is invulnurable */
|
||||
protected $goodguyInvulnurable = false;
|
||||
/** @var float */
|
||||
protected $goodguyDamageModifier = 1.;
|
||||
/** @var float */
|
||||
protected $goodguyAttackModifier = 1.;
|
||||
/** @var float */
|
||||
protected $goodguyDefenseModifier = 1.;
|
||||
/** True of the modifiers have already been calculated */
|
||||
protected bool $modifiersCalculated = false;
|
||||
/** True if the badguy is invulnurable */
|
||||
protected bool $badguyInvulnurable = false;
|
||||
|
||||
protected $events;
|
||||
protected $loaded = false;
|
||||
protected float $badguyDamageModifier = 1.;
|
||||
protected float $badguyAttackModifier = 1.;
|
||||
protected float $badguyDefenseModifier = 1.;
|
||||
protected bool $goodguyInvulnurable = false;
|
||||
protected float $goodguyDamageModifier = 1.;
|
||||
protected float $goodguyAttackModifier = 1.;
|
||||
protected float $goodguyDefenseModifier = 1.;
|
||||
|
||||
protected ArrayCollection $events;
|
||||
protected bool $loaded = false;
|
||||
|
||||
/**
|
||||
* Initiates some variables
|
||||
* Initiates some variables.
|
||||
* @param Collection $buffs
|
||||
*/
|
||||
public function __construct(Collection $buffs)
|
||||
{
|
||||
$this->buffs = $buffs;
|
||||
public function __construct(
|
||||
protected Collection $buffs
|
||||
) {
|
||||
$this->events = new ArrayCollection();
|
||||
$this->usedBuffs = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all buffs (since it's a lazy correlation)
|
||||
* Loads all buffs (since it's a lazy correlation).
|
||||
*/
|
||||
public function loadBuffs()
|
||||
{
|
||||
@@ -97,7 +82,7 @@ class BuffList
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the given buff as used
|
||||
* Marks the given buff as used.
|
||||
* @param Buff $buff
|
||||
*/
|
||||
protected function useBuff(Buff $buff)
|
||||
@@ -106,7 +91,7 @@ class BuffList
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the buff's start or round message
|
||||
* Returns the buff's start or round message.
|
||||
* @param Buff $buff
|
||||
* @return string
|
||||
*/
|
||||
@@ -125,7 +110,7 @@ class BuffList
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the buff usage for a new round
|
||||
* Resets the buff usage for a new round.
|
||||
*/
|
||||
public function resetBuffUsage()
|
||||
{
|
||||
@@ -136,22 +121,23 @@ class BuffList
|
||||
|
||||
/**
|
||||
* Returns whether any buffs are in use.
|
||||
* @return bool
|
||||
*/
|
||||
public function hasBuffsInUse(): bool
|
||||
{
|
||||
return count($this->usedBuffs) > 0 ? true : false;
|
||||
return \count($this->usedBuffs) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates all buffs that activate upon the given activation parameter.
|
||||
* @param int $activation
|
||||
* @return Collection
|
||||
* @throws ArgumentException
|
||||
* @throws BuffListAlreadyActivatedException
|
||||
* @return Collection
|
||||
*/
|
||||
public function activate(int $activation): Collection
|
||||
{
|
||||
if ($activation%2 !== 0 && $activation !== 1) {
|
||||
if ($activation % 2 !== 0 && $activation !== 1) {
|
||||
throw new ArgumentException("You can only activate one activation type at a time.");
|
||||
}
|
||||
|
||||
@@ -186,7 +172,7 @@ class BuffList
|
||||
}
|
||||
|
||||
/**
|
||||
* Decreases the rounds left on all used buffs
|
||||
* Decreases the rounds left on all used buffs.
|
||||
* @return Collection A Collection containing expire messages (if there are any)
|
||||
*/
|
||||
public function expireOneRound(): Collection
|
||||
@@ -261,10 +247,9 @@ class BuffList
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates all total modifiers
|
||||
* @return type
|
||||
* Calculates all total modifiers.
|
||||
*/
|
||||
protected function calculateModifiers()
|
||||
protected function calculateModifiers(): void
|
||||
{
|
||||
if ($this->modifiersCalculated === true) {
|
||||
return;
|
||||
@@ -302,14 +287,13 @@ class BuffList
|
||||
// Only look at buffs that are activated in battle.
|
||||
if ($buff->getsActivatedAt(Buff::ACTIVATE_NONE)) {
|
||||
continue;
|
||||
} else {
|
||||
yield $buff;
|
||||
}
|
||||
yield $buff;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the badguy attack modifier calculated over the whole bufflist
|
||||
* Returns the badguy attack modifier calculated over the whole bufflist.
|
||||
* @return float
|
||||
*/
|
||||
public function getBadguyAttackModifier(): float
|
||||
@@ -318,8 +302,8 @@ class BuffList
|
||||
return $this->badguyAttackModifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the badguy defense modifier calculated over the whole bufflist
|
||||
/**
|
||||
* Returns the badguy defense modifier calculated over the whole bufflist.
|
||||
* @return float
|
||||
*/
|
||||
public function getBadguyDefenseModifier(): float
|
||||
@@ -329,7 +313,7 @@ class BuffList
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the badguy damage modifier calculated over the whole bufflist
|
||||
* Returns the badguy damage modifier calculated over the whole bufflist.
|
||||
* @return float
|
||||
*/
|
||||
public function getBadguyDamageModifier(): float
|
||||
@@ -339,7 +323,7 @@ class BuffList
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the badguy is invulnurable
|
||||
* Returns true if the badguy is invulnurable.
|
||||
* @return bool
|
||||
*/
|
||||
public function badguyIsInvulnurable(): bool
|
||||
@@ -349,7 +333,7 @@ class BuffList
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the badguy attack modifier calculated over the whole bufflist
|
||||
* Returns the badguy attack modifier calculated over the whole bufflist.
|
||||
* @return float
|
||||
*/
|
||||
public function getGoodguyAttackModifier(): float
|
||||
@@ -358,8 +342,8 @@ class BuffList
|
||||
return $this->goodguyAttackModifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the badguy defense modifier calculated over the whole bufflist
|
||||
/**
|
||||
* Returns the badguy defense modifier calculated over the whole bufflist.
|
||||
* @return float
|
||||
*/
|
||||
public function getGoodguyDefenseModifier(): float
|
||||
@@ -368,8 +352,8 @@ class BuffList
|
||||
return $this->goodguyDefenseModifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the badguy damage modifier calculated over the whole bufflist
|
||||
/**
|
||||
* Returns the badguy damage modifier calculated over the whole bufflist.
|
||||
* @return float
|
||||
*/
|
||||
public function getGoodguyDamageModifier(): float
|
||||
@@ -379,7 +363,7 @@ class BuffList
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the goodguy is invulnurable
|
||||
* Returns true if the goodguy is invulnurable.
|
||||
* @return bool
|
||||
*/
|
||||
public function goodguyIsInvulnurable(): bool
|
||||
@@ -389,9 +373,9 @@ class BuffList
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes buffs that do direct damage or regeneration
|
||||
* Processes buffs that do direct damage or regeneration.
|
||||
* @param int $activation
|
||||
* @param \LotGD\Core\Game $game
|
||||
* @param Game $game
|
||||
* @param FighterInterface $goodguy
|
||||
* @param FighterInterface $badguy
|
||||
* @return Collection
|
||||
@@ -477,7 +461,7 @@ class BuffList
|
||||
|
||||
$events[] = new MinionDamageEvent(
|
||||
$target,
|
||||
(int)round($damage, 0),
|
||||
(int)\round($damage, 0),
|
||||
$message
|
||||
);
|
||||
}
|
||||
@@ -490,10 +474,10 @@ class BuffList
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes buffs that are dependant on the damage done in one round
|
||||
* Processes buffs that are dependant on the damage done in one round.
|
||||
* @param int $activation
|
||||
* @param int $damage Positive damage is applied to the badguy, negative damage is applied to the goodguy
|
||||
* @param \LotGD\Core\Game $game
|
||||
* @param Game $game
|
||||
* @param FighterInterface $goodguy
|
||||
* @param FighterInterface $badguy
|
||||
* @return Collection
|
||||
@@ -518,7 +502,7 @@ class BuffList
|
||||
$reflectedDamage = 0;
|
||||
$message = $buff->getNoEffectMessage();
|
||||
} else {
|
||||
$reflectedDamage = (int)round($buff->getGoodguyDamageReflection() * $damage * -1, 0);
|
||||
$reflectedDamage = (int)\round($buff->getGoodguyDamageReflection() * $damage * -1, 0);
|
||||
if ($reflectedDamage === 0) {
|
||||
$message = $buff->getNoEffectMessage();
|
||||
} else {
|
||||
@@ -536,7 +520,7 @@ class BuffList
|
||||
if ($buff->getBadguyDamageReflection() !== 0.) {
|
||||
if ($damage > 0) {
|
||||
// Damage is > 0, so badguy takes damage, we can normally reflect
|
||||
$reflectedDamage = (int)round($buff->getBadguyDamageReflection() * $damage, 0);
|
||||
$reflectedDamage = (int)\round($buff->getBadguyDamageReflection() * $damage, 0);
|
||||
if ($reflectedDamage === 0) {
|
||||
$message = $buff->getNoEffectMessage();
|
||||
} else {
|
||||
@@ -565,7 +549,7 @@ class BuffList
|
||||
$message = $buff->getEffectFailsMessage();
|
||||
} elseif ($damage < 0) {
|
||||
// Damage is < 0, goodguy takes damage. We act upon this.
|
||||
$healAmount = (int)round($damage * -$buff->getBadguyLifetap(), 0);
|
||||
$healAmount = (int)\round($damage * -$buff->getBadguyLifetap(), 0);
|
||||
if ($healAmount === 0) {
|
||||
$message = $buff->getNoEffectMessage();
|
||||
} else {
|
||||
@@ -586,7 +570,7 @@ class BuffList
|
||||
if ($buff->getBadguyLifetap() !== 0.) {
|
||||
if ($damage > 0) {
|
||||
// Damage is > 0, badguy takes damage. We act upon this to heal goodguy.
|
||||
$healAmount = (int)round($damage * $buff->getBadguyLifetap(), 0);
|
||||
$healAmount = (int)\round($damage * $buff->getBadguyLifetap(), 0);
|
||||
if ($healAmount === 0) {
|
||||
$message = $buff->getNoEffectMessage();
|
||||
} else {
|
||||
|
||||
+38
-43
@@ -3,36 +3,29 @@ declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core;
|
||||
|
||||
use Composer\{
|
||||
Composer,
|
||||
Factory,
|
||||
IO\NullIO,
|
||||
Package\CompletePackageInterface
|
||||
};
|
||||
use Monolog\Logger;
|
||||
use Composer\Composer;
|
||||
use Composer\Factory;
|
||||
use Composer\IO\NullIO;
|
||||
use Composer\Package\CompletePackageInterface;
|
||||
use Composer\Package\PackageInterface;
|
||||
use Exception;
|
||||
|
||||
use LotGD\Core\{
|
||||
Exceptions\InvalidConfigurationException,
|
||||
Exceptions\LibraryDoesNotExistException
|
||||
};
|
||||
use LotGD\Core\Exceptions\InvalidConfigurationException;
|
||||
use LotGD\Core\Exceptions\LibraryDoesNotExistException;
|
||||
|
||||
/**
|
||||
* Helps perform tasks with the composer configuration.
|
||||
*/
|
||||
class ComposerManager
|
||||
{
|
||||
private $composer;
|
||||
private $cwd;
|
||||
private ?Composer $composer = null;
|
||||
|
||||
/**
|
||||
* Construct a manager with an optional working directory where composer.json
|
||||
* lives.
|
||||
* @param string $cwd
|
||||
*/
|
||||
public function __construct(string $cwd)
|
||||
{
|
||||
$this->cwd = $cwd;
|
||||
}
|
||||
public function __construct(private string $cwd) {}
|
||||
|
||||
/**
|
||||
* Returns a Composer instance to perform underlying operations on. Be careful.
|
||||
@@ -42,8 +35,8 @@ class ComposerManager
|
||||
{
|
||||
if ($this->composer === null) {
|
||||
// Verify location of composer.json.
|
||||
$composerConfigPath = $this->cwd . DIRECTORY_SEPARATOR . "composer.json";
|
||||
if (!file_exists($composerConfigPath)) {
|
||||
$composerConfigPath = $this->cwd . \DIRECTORY_SEPARATOR . "composer.json";
|
||||
if (!\file_exists($composerConfigPath)) {
|
||||
throw new InvalidConfigurationException("composer.json cannot be found at {$composerConfigPath}.");
|
||||
}
|
||||
|
||||
@@ -56,8 +49,9 @@ class ComposerManager
|
||||
|
||||
/**
|
||||
* Return the Composer package for the corresponding library, in vendor/module format.
|
||||
* @return PackageInterface Package corresponding to this library.
|
||||
* @param string $library
|
||||
* @throws LibraryDoesNotExistException
|
||||
* @return CompletePackageInterface Package corresponding to this library.
|
||||
*/
|
||||
public function getPackageForLibrary(string $library): CompletePackageInterface
|
||||
{
|
||||
@@ -73,27 +67,27 @@ class ComposerManager
|
||||
|
||||
/**
|
||||
* Return all the packages installed in the current setup.
|
||||
* @return array<Composer\PackageInterface>
|
||||
* @return PackageInterface[]
|
||||
*/
|
||||
public function getPackages(): array
|
||||
{
|
||||
return array_merge(
|
||||
[$this->getComposer()->getPackage()],
|
||||
$this->getComposer()->getRepositoryManager()->getLocalRepository()->getPackages()
|
||||
);
|
||||
return [
|
||||
$this->getComposer()->getPackage(),
|
||||
...$this->getComposer()->getRepositoryManager()->getLocalRepository()->getPackages(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of the configured packages which are LotGD modules (type = 'lotgd-module').
|
||||
* @return array Array of \Composer\PackageInterface.
|
||||
* @return PackageInterface[]
|
||||
*/
|
||||
public function getModulePackages(): array
|
||||
{
|
||||
$result = array();
|
||||
$result = [];
|
||||
$packages = $this->getComposer()->getRepositoryManager()->getLocalRepository()->getPackages();
|
||||
foreach ($packages as $p) {
|
||||
if ($p->getType() === 'lotgd-module') {
|
||||
array_push($result, $p);
|
||||
\array_push($result, $p);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +100,7 @@ class ComposerManager
|
||||
* @return string|null Path representing $namespace or null if $namespace
|
||||
* cannot be found or if the path does not exist.
|
||||
*/
|
||||
public function translateNamespaceToPath(string $namespace)
|
||||
public function translateNamespaceToPath(string $namespace): ?string
|
||||
{
|
||||
// Find the directory for this namespace by using the autoloader's
|
||||
// classmap.
|
||||
@@ -116,32 +110,32 @@ class ComposerManager
|
||||
// Standardize the namespace to remove any leading \ and add a trailing \
|
||||
$n = $namespace;
|
||||
if ('\\' == $n[0]) {
|
||||
$n = substr($n, 1);
|
||||
$n = \substr($n, 1);
|
||||
}
|
||||
if (strlen($n) > 0 && '\\' != $n[strlen($n) - 1]) {
|
||||
if (\strlen($n) > 0 && '\\' != $n[\strlen($n) - 1]) {
|
||||
$n .= '\\';
|
||||
}
|
||||
|
||||
$split = explode('\\', $n);
|
||||
$suffix = array_splice($split, -1, 1); // starts with ['']
|
||||
$split = \explode('\\', $n);
|
||||
$suffix = \array_splice($split, -1, 1); // starts with ['']
|
||||
$path = null;
|
||||
while (!empty($split)) {
|
||||
$key = implode('\\', $split) . '\\';
|
||||
$dir = implode(DIRECTORY_SEPARATOR, $suffix);
|
||||
$key = \implode('\\', $split) . '\\';
|
||||
$dir = \implode(\DIRECTORY_SEPARATOR, $suffix);
|
||||
// Prefix to directory mappings are arrays in Composer's
|
||||
// ClassLoader object. Not sure why. This might break in
|
||||
// some unforseen case.
|
||||
if (isset($prefixes[$key]) && is_dir($prefixes[$key][0] . DIRECTORY_SEPARATOR . $dir)) {
|
||||
$path = $prefixes[$key][0] . DIRECTORY_SEPARATOR . $dir;
|
||||
if (isset($prefixes[$key]) && \is_dir($prefixes[$key][0] . \DIRECTORY_SEPARATOR . $dir)) {
|
||||
$path = $prefixes[$key][0] . \DIRECTORY_SEPARATOR . $dir;
|
||||
break;
|
||||
}
|
||||
$suffix = array_merge($suffix, array_splice($split, -1, 1));
|
||||
$suffix = \array_merge($suffix, \array_splice($split, -1, 1));
|
||||
}
|
||||
|
||||
if ($path == null) {
|
||||
return null;
|
||||
}
|
||||
$path = realpath($path);
|
||||
$path = \realpath($path);
|
||||
if ($path == false) {
|
||||
return null;
|
||||
}
|
||||
@@ -151,19 +145,20 @@ class ComposerManager
|
||||
/**
|
||||
* Returns a path (could be relative) to the proper autoload.php file in
|
||||
* the current setup.
|
||||
* @return string
|
||||
*/
|
||||
public function findAutoloader(): string
|
||||
{
|
||||
// Dance to find the autoloader.
|
||||
// TOOD: change this to open up the Composer config and use $c['config']['vendor-dir'] instead of "vendor"
|
||||
$order = [
|
||||
implode(DIRECTORY_SEPARATOR, [$this->cwd, "vendor", "autoload.php"]),
|
||||
implode(DIRECTORY_SEPARATOR, [__DIR__, "..", "vendor", "autoload.php"]),
|
||||
implode(DIRECTORY_SEPARATOR, [__DIR__, "..", "autoload.php"]),
|
||||
\implode(\DIRECTORY_SEPARATOR, [$this->cwd, "vendor", "autoload.php"]),
|
||||
\implode(\DIRECTORY_SEPARATOR, [__DIR__, "..", "vendor", "autoload.php"]),
|
||||
\implode(\DIRECTORY_SEPARATOR, [__DIR__, "..", "autoload.php"]),
|
||||
];
|
||||
|
||||
foreach ($order as $path) {
|
||||
if (file_exists($path)) {
|
||||
if (\file_exists($path)) {
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
||||
+35
-18
@@ -5,10 +5,10 @@ namespace LotGD\Core;
|
||||
|
||||
use DateTime;
|
||||
|
||||
use Symfony\Component\Yaml\Exception\ParseException;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
use LotGD\Core\Exceptions\InvalidConfigurationException;
|
||||
use Symfony\Component\Yaml\Exception\ParseException;
|
||||
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
/**
|
||||
* The configuration information for a LotGD game. Configuration is read from
|
||||
@@ -16,14 +16,15 @@ use LotGD\Core\Exceptions\InvalidConfigurationException;
|
||||
*/
|
||||
class Configuration
|
||||
{
|
||||
private $databaseDSN;
|
||||
private $databaseName;
|
||||
private $databaseUser;
|
||||
private $databasePassword;
|
||||
private $logPath;
|
||||
private $gameEpoch;
|
||||
private $gameOffsetSeconds;
|
||||
private $gameDaysPerDay;
|
||||
private string $databaseDSN;
|
||||
private string $databaseName;
|
||||
private string $databaseUser;
|
||||
private string $databasePassword;
|
||||
private bool $databaseAutoSchemaUpdate;
|
||||
private string $logPath;
|
||||
private DateTime $gameEpoch;
|
||||
private int $gameOffsetSeconds;
|
||||
private int $gameDaysPerDay;
|
||||
|
||||
/**
|
||||
* Create the configuration object, reading from the specified path.
|
||||
@@ -41,8 +42,8 @@ class Configuration
|
||||
|
||||
// Log dir path is relative to config directory.
|
||||
$logPath = $rawConfig['logs']['path'] ?? '';
|
||||
$realLogPath = dirname($configFilePath) . DIRECTORY_SEPARATOR . $logPath;
|
||||
if ($realLogPath === false || strlen($realLogPath) == 0 || is_dir($realLogPath) === false) {
|
||||
$realLogPath = \dirname($configFilePath) . \DIRECTORY_SEPARATOR . $logPath;
|
||||
if ($realLogPath === false || \strlen($realLogPath) == 0 || \is_dir($realLogPath) === false) {
|
||||
throw new InvalidConfigurationException("Invalid or missing log path: {$realLogPath}");
|
||||
}
|
||||
$this->logPath = $realLogPath;
|
||||
@@ -52,10 +53,10 @@ class Configuration
|
||||
$passwd = $rawConfig['database']['password'] ?? '';
|
||||
$name = $rawConfig['database']['name'] ?? '';
|
||||
|
||||
if ($dsn === false || strlen($dsn) == 0) {
|
||||
if ($dsn === false || \strlen($dsn) == 0) {
|
||||
throw new InvalidConfigurationException("Invalid or missing data source name: {$dsn}");
|
||||
}
|
||||
if ($user === false || strlen($user) == 0) {
|
||||
if ($user === false || \strlen($user) == 0) {
|
||||
throw new InvalidConfigurationException("Invalid or missing database user: {$user}");
|
||||
}
|
||||
if ($passwd === false) {
|
||||
@@ -70,6 +71,12 @@ class Configuration
|
||||
$this->databasePassword = $passwd;
|
||||
$this->databaseName = $name;
|
||||
|
||||
if (empty($rawConfig['database']['disableAutoSchemaUpdate'])) {
|
||||
$this->databaseAutoSchemaUpdate = true;
|
||||
} else {
|
||||
$this->databaseAutoSchemaUpdate = false;
|
||||
}
|
||||
|
||||
$gameEpoch = $rawConfig['game']['epoch'];
|
||||
$gameOffsetSeconds = $rawConfig['game']['offsetSeconds'];
|
||||
$gameDaysPerDay = $rawConfig['game']['daysPerDay'];
|
||||
@@ -98,12 +105,12 @@ class Configuration
|
||||
*/
|
||||
protected function retrieveRawConfig(string $configFilePath): array
|
||||
{
|
||||
return Yaml::parse(file_get_contents($configFilePath));
|
||||
return Yaml::parse(\file_get_contents($configFilePath));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns database connection details needed for pdo to establish a connection.
|
||||
*
|
||||
*
|
||||
* This function takes optionally replaces the string %cwd% in the database dsn and
|
||||
* replaces it with the first parameter. This is important to normalize the database location
|
||||
* across different working directories. Alternatively, SQLite databse names can also directly
|
||||
@@ -114,7 +121,7 @@ class Configuration
|
||||
public function getDatabaseConnectionDetails(string $cwd = ""): array
|
||||
{
|
||||
return [
|
||||
str_replace("%cwd%", $cwd . DIRECTORY_SEPARATOR, $this->getDatabaseDSN()),
|
||||
\str_replace("%cwd%", $cwd . \DIRECTORY_SEPARATOR, $this->getDatabaseDSN()),
|
||||
$this->getDatabaseUser(),
|
||||
$this->getDatabasePassword(),
|
||||
];
|
||||
@@ -157,6 +164,15 @@ class Configuration
|
||||
return $this->databasePassword;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if doctrine should not auto update.
|
||||
* @return bool
|
||||
*/
|
||||
public function getDatabaseAutoSchemaUpdate(): bool
|
||||
{
|
||||
return $this->databaseAutoSchemaUpdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the path to the directory to store log files.
|
||||
* @return string The configured log directory path.
|
||||
@@ -197,6 +213,7 @@ class Configuration
|
||||
/**
|
||||
* Generate a textual representation of the configuration, for debugging
|
||||
* purposes.
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
|
||||
@@ -3,10 +3,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
use LotGD\Core\Game;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
/**
|
||||
* Parent class for daenerys tool commands.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command\Character;
|
||||
|
||||
use Exception;
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Models\Character;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Resets the viewpoint of a given character.
|
||||
*/
|
||||
class CharacterAddCommand extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('character:add')
|
||||
->setDescription('Add a character.')
|
||||
->setDefinition(
|
||||
new InputDefinition([
|
||||
new InputArgument(
|
||||
"name",
|
||||
mode: InputArgument::REQUIRED,
|
||||
description: "Character name",
|
||||
),
|
||||
new InputOption(
|
||||
"level",
|
||||
mode: InputOption::VALUE_OPTIONAL,
|
||||
description: "Character level",
|
||||
default: 1,
|
||||
),
|
||||
new InputOption(
|
||||
"maxHealth",
|
||||
mode: InputOption::VALUE_OPTIONAL,
|
||||
description: "Maximum health of the character. 10*level if not given.",
|
||||
default: null,
|
||||
),
|
||||
])
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$em = $this->game->getEntityManager();
|
||||
$logger = $this->game->getLogger();
|
||||
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$name = $input->getArgument("name");
|
||||
$level = intval($input->getOption("level"));
|
||||
$maxHealth = $input->getOption("maxHealth");
|
||||
|
||||
if ($level <= 0) {
|
||||
$io->error("Level must at least be 1.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// Set maxHealth in dependence of the level if not given.
|
||||
if ($maxHealth === null) {
|
||||
$maxHealth = $level*10;
|
||||
} else {
|
||||
$maxHealth = intval($maxHealth);
|
||||
}
|
||||
|
||||
$character = Character::createAtFullHealth([
|
||||
"name" => $name,
|
||||
"level" => $level,
|
||||
"maxHealth" => $maxHealth,
|
||||
]);
|
||||
|
||||
try {
|
||||
$em->persist($character);
|
||||
|
||||
// Commit changes
|
||||
$em->flush();
|
||||
} catch (Exception $e) {
|
||||
$io->error("Creating the character was not possible. Reason: {$e->getMessage()}.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$io->success("{$character} was successfully created.");
|
||||
$logger->info("{$character} was created.");
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command\Character;
|
||||
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Models\Character;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Command to list all characters.
|
||||
*/
|
||||
class CharacterListCommand extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('character:list')
|
||||
->setDescription('Lists all characters')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$em = $this->game->getEntityManager();
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$characters = $em->getRepository(Character::class)->findAll();
|
||||
|
||||
$table = [["id", "name", "level"], []];
|
||||
foreach ($characters as $character) {
|
||||
$table[1][] = [
|
||||
$character->getId(),
|
||||
$character->getDisplayName(),
|
||||
$character->getLevel(),
|
||||
];
|
||||
}
|
||||
|
||||
$io->table(...$table);
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command\Character;
|
||||
|
||||
use Exception;
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Models\Character;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Resets the viewpoint of a given character.
|
||||
*/
|
||||
class CharacterRemoveCommand extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('character:remove')
|
||||
->setDescription('Definitely removes a character (no soft delete).')
|
||||
->setDefinition(
|
||||
new InputDefinition([
|
||||
new InputArgument(
|
||||
"id",
|
||||
mode: InputArgument::REQUIRED,
|
||||
description: "Character ID",
|
||||
),
|
||||
])
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$em = $this->game->getEntityManager();
|
||||
$logger = $this->game->getLogger();
|
||||
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$id = $input->getArgument("id");
|
||||
|
||||
// Find character
|
||||
/** @var Character $character */
|
||||
$character = $em->getRepository(Character::class)->find($id);
|
||||
|
||||
if (!$character) {
|
||||
$io->error("The character with the id {$id} was not found.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
try {
|
||||
$em->remove($character);
|
||||
|
||||
// Commit changes
|
||||
$em->flush();
|
||||
} catch (Exception $e) {
|
||||
$io->error("Removing {$character} was not possible. Reason: {$e->getMessage()}.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$io->success("{$character} was successfully removed.");
|
||||
$logger->info("{$character} was removed.");
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command\Character;
|
||||
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Models\Character;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Resets the viewpoint of a given character.
|
||||
*/
|
||||
class CharacterResetViewpointCommand extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('character:resetViewpoint')
|
||||
->setDescription('Resets the viewpoint of a given character.')
|
||||
->setDefinition(
|
||||
new InputDefinition([
|
||||
new InputArgument("id", InputArgument::REQUIRED, "ID of the character"),
|
||||
])
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$em = $this->game->getEntityManager();
|
||||
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$id = $input->getArgument("id");
|
||||
|
||||
/* @var $character Character */
|
||||
$character = $em->getRepository(Character::class)->find($id);
|
||||
|
||||
if ($character === null) {
|
||||
$io->error("Character not found.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$em->remove($character->getViewpoint());
|
||||
$character->setViewpoint(null);
|
||||
|
||||
# Save
|
||||
$em->flush();
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command\Character;
|
||||
|
||||
use Exception;
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Models\Character;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Helper\TableSeparator;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Resets the viewpoint of a given character.
|
||||
*/
|
||||
class CharacterShowCommand extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('character:show')
|
||||
->setDescription('Shows details about character.')
|
||||
->setDefinition(
|
||||
new InputDefinition([
|
||||
new InputArgument(
|
||||
"id",
|
||||
mode: InputArgument::REQUIRED,
|
||||
description: "Character ID",
|
||||
),
|
||||
new InputOption(
|
||||
"onlyViewpoint",
|
||||
mode: InputOption::VALUE_NONE,
|
||||
description: "Set to true to only display viewpoint",
|
||||
)
|
||||
])
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$em = $this->game->getEntityManager();
|
||||
$logger = $this->game->getLogger();
|
||||
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$id = $input->getArgument("id");
|
||||
$onlyViewpoint = $input->getOption("onlyViewpoint");
|
||||
|
||||
// Find character
|
||||
/** @var Character $character */
|
||||
$character = $em->getRepository(Character::class)->find($id);
|
||||
|
||||
if (!$character) {
|
||||
$io->error("The character with the id {$id} was not found.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if (!$onlyViewpoint) {
|
||||
$io->title("About Character {$character->getName()}");
|
||||
|
||||
$io->listing([
|
||||
"ID: {$character->getId()}",
|
||||
"Display name: {$character->getDisplayName()}",
|
||||
"Level: {$character->getLevel()}",
|
||||
"Health: {$character->getHealth()}/{$character->getMaxHealth()}",
|
||||
"Alive: ".($character->isAlive()?"yes":"no"),
|
||||
"Attack: {$character->getAttack()}",
|
||||
"Defense: {$character->getDefense()}",
|
||||
]);
|
||||
|
||||
$io->section("Viewpoint");
|
||||
} else {
|
||||
$io->title("Viewpoint of {$character->getName()}");
|
||||
}
|
||||
|
||||
$viewpoint = $character->getViewpoint();
|
||||
|
||||
if (!$viewpoint) {
|
||||
$io->text("No viewpoint yet");
|
||||
} else {
|
||||
$io->text($viewpoint->getTitle() . "\n");
|
||||
$io->text($viewpoint->getDescription());
|
||||
|
||||
$io->section("Viewpoint actions");
|
||||
$actionGroups = $viewpoint->getActionGroups();
|
||||
|
||||
$rows = [];
|
||||
|
||||
foreach ($actionGroups as $actionGroup) {
|
||||
$rows[] = [$actionGroup->getId(), $actionGroup->getTitle(), "", "", ""];
|
||||
|
||||
foreach ($actionGroup->getActions() as $action) {
|
||||
$rows[] = ["", "", $action->getId(), $action->getTitle(), $action->getDestinationSceneId()];
|
||||
}
|
||||
|
||||
if (count($actionGroup->getActions())) {
|
||||
$rows[] = new TableSeparator();
|
||||
}
|
||||
}
|
||||
|
||||
$io->table(["Group id", "Group name", "Action id", "Action name", "Destination"], $rows);
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command;
|
||||
|
||||
use LotGD\Core\Game;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
@@ -17,26 +19,29 @@ class ConsoleCommand extends BaseCommand
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('console')
|
||||
->setDescription('Start a shell to interact with the game');
|
||||
->setDescription('Start a shell to interact with the game')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
print("Daenerys console, the dragon prompt. lotgd/core " . \LotGD\Core\Game::getVersion() . ".\n");
|
||||
print("Enter some PHP, but be careful, this is live and attached to your currently configured setup:\n\n");
|
||||
print($this->game->getConfiguration());
|
||||
print "Daenerys console, the dragon prompt. lotgd/core " . Game::getVersion() . ".\n";
|
||||
print "Enter some PHP, but be careful, this is live and attached to your currently configured setup:\n\n";
|
||||
print $this->game->getConfiguration();
|
||||
|
||||
print("\n");
|
||||
print("Try things like `\$g::getVersion()`. To quit, ^D or `exit();`.\n");
|
||||
print("\n");
|
||||
print "\n";
|
||||
print "Try things like `\$g::getVersion()`. To quit, ^D or `exit();`.\n";
|
||||
print "\n";
|
||||
|
||||
$boris = new \Boris\Boris('🐲 > ');
|
||||
$boris->setLocal(array(
|
||||
'g' => $this->game
|
||||
));
|
||||
$boris->setLocal([
|
||||
'g' => $this->game,
|
||||
]);
|
||||
$boris->start();
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-6
@@ -1,15 +1,13 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command;
|
||||
namespace LotGD\Core\Console\Command\Database;
|
||||
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use LotGD\Core\Console\Main;
|
||||
use LotGD\Core\Game;
|
||||
|
||||
/**
|
||||
* Danerys command to initiate the database with default values.
|
||||
*/
|
||||
@@ -21,14 +19,17 @@ class DatabaseInitCommand extends BaseCommand
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('database:init')
|
||||
->setDescription('Initiates database with default values.');
|
||||
->setDescription('Initiates database with default values.')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$this->game->getEntityManager()->flush();
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command\Database;
|
||||
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* Danerys command to initiate the database with default values.
|
||||
*/
|
||||
class DatabaseSchemaUpdateCommand extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('database:schemaUpdate')
|
||||
->setDescription('Updates the database schema manually.')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$entityManager = $this->game->getEntityManager();
|
||||
$metaData = $entityManager->getMetadataFactory()->getAllMetadata();
|
||||
$schemaTool = new SchemaTool($entityManager);
|
||||
$schemaTool->updateSchema($metaData);
|
||||
|
||||
$entityManager->flush();
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command\Module;
|
||||
|
||||
use Exception;
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Exceptions\ClassNotFoundException;
|
||||
use LotGD\Core\Exceptions\InvalidConfigurationException;
|
||||
use LotGD\Core\Exceptions\ModuleAlreadyExistsException;
|
||||
use LotGD\Core\Exceptions\WrongTypeException;
|
||||
use LotGD\Core\LibraryConfiguration;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Danerys command to register and initiate any newly installed modules.
|
||||
*/
|
||||
class ModuleRegisterCommand extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('module:register')
|
||||
->setDescription('Register and initialize any newly installed modules')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$modules = $this->game->getComposerManager()->getModulePackages();
|
||||
|
||||
$globalFlawless = true;
|
||||
$registered = [];
|
||||
foreach ($modules as $p) {
|
||||
$flawless = $this->registerModule($p->getName(), $io, $registered);
|
||||
|
||||
$globalFlawless &= $flawless;
|
||||
}
|
||||
|
||||
if (!$globalFlawless) {
|
||||
$io->warning("Some module were not registered properly.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a given package as a module if it is of type lotdg-module. Resolves dependencies and skips already registered packages.
|
||||
* @param string $packageName
|
||||
* @param SymfonyStyle $io
|
||||
* @param array $registered
|
||||
* @return bool True if registering was flawless
|
||||
* @throws InvalidConfigurationException
|
||||
* @throws WrongTypeException
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function registerModule(
|
||||
string $packageName,
|
||||
SymfonyStyle $io,
|
||||
array &$registered
|
||||
): bool {
|
||||
$composerRepository = $this->game->getComposerManager()->getComposer()
|
||||
->getRepositoryManager()->getLocalRepository();
|
||||
|
||||
$package = $composerRepository->findPackage($packageName, "*");
|
||||
|
||||
# Skip if not a lotgd-module
|
||||
if ($package->getType() !== "lotgd-module") {
|
||||
return true;
|
||||
}
|
||||
|
||||
# Skip if already registered
|
||||
if (!empty($registered[$packageName])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$io->text("Reading module {$packageName} {$package->getPrettyVersion()}");
|
||||
|
||||
# Try to load module configuration ($moduleRoot/lotgd.yml)
|
||||
try {
|
||||
$library = new LibraryConfiguration($this->game->getComposerManager(), $package, $this->game->getCWD());
|
||||
} catch (InvalidConfigurationException) {
|
||||
$io->error("\tModule {$packageName} does not have a valid lotgd.yml in its root.");
|
||||
return false;
|
||||
}
|
||||
|
||||
# Register dependencies first.
|
||||
$dependencyFlawless = true;
|
||||
$dependencies = $package->getRequires();
|
||||
foreach ($dependencies as $dependency) {
|
||||
$dependencyFlawless &= $this->registerModule($dependency->getTarget(), $io, $registered);
|
||||
}
|
||||
|
||||
# If $dependencyFlawless is not true anymore (as true & false == 0), we should abort as a dependency was not met.
|
||||
if (!$dependencyFlawless) {
|
||||
$io->warning("\t{$packageName} was not completely installed, as one of its dependencies had an "
|
||||
."error during registration.");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->game->getModuleManager()->register($library);
|
||||
$io->success("\tRegistered new module {$packageName}");
|
||||
} catch (ModuleAlreadyExistsException $e) {
|
||||
$io->note("\tSkipping already registered module {$packageName}");
|
||||
} catch (ClassNotFoundException $e) {
|
||||
$io->error("\tError installing module {$packageName}: {$e->getMessage()}");
|
||||
return false;
|
||||
}
|
||||
|
||||
$registered[$packageName] = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+12
-8
@@ -1,8 +1,10 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command;
|
||||
namespace LotGD\Core\Console\Command\Module;
|
||||
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
@@ -17,24 +19,26 @@ class ModuleValidateCommand extends BaseCommand
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('module:validate')
|
||||
->setDescription('Validate installed modules');
|
||||
->setDescription('Validate installed modules')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$results = $this->game->getModuleManager()->validate();
|
||||
|
||||
if (count($results) > 0) {
|
||||
if (\count($results) > 0) {
|
||||
foreach ($results as $r) {
|
||||
$output->writeln($r);
|
||||
}
|
||||
return 1;
|
||||
} else {
|
||||
$output->writeln("<info>LotGD modules validated</info>");
|
||||
return 0;
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
$output->writeln("<info>LotGD modules validated</info>");
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command;
|
||||
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use LotGD\Core\Exceptions\ClassNotFoundException;
|
||||
use LotGD\Core\Exceptions\ModuleAlreadyExistsException;
|
||||
use LotGD\Core\LibraryConfiguration;
|
||||
|
||||
/**
|
||||
* Danerys command to register and initiate any newly installed modules.
|
||||
*/
|
||||
class ModuleRegisterCommand extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('module:register')
|
||||
->setDescription('Register and initialize any newly installed modules');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$modules = $this->game->getComposerManager()->getModulePackages();
|
||||
|
||||
foreach ($modules as $p) {
|
||||
$library = new LibraryConfiguration($this->game->getComposerManager(), $p, $this->game->getCWD());
|
||||
$name = $library->getName();
|
||||
|
||||
try {
|
||||
$this->game->getModuleManager()->register($library);
|
||||
|
||||
$output->writeln("<info>Registered new module {$name}</info>");
|
||||
} catch (ModuleAlreadyExistsException $e) {
|
||||
$output->writeln("Skipping already registered module {$name}");
|
||||
} catch (ClassNotFoundException $e) {
|
||||
$output->writeln("<error>Error installing module {$name}: " . $e->getMessage() . "</error>");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command\Scene;
|
||||
|
||||
use Exception;
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use LotGD\Core\Models\SceneTemplate;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Resets the viewpoint of a given character.
|
||||
*/
|
||||
class SceneAddCommand extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('scene:add')
|
||||
->setDescription('Add a scene.')
|
||||
->setDefinition(
|
||||
new InputDefinition([
|
||||
new InputArgument(
|
||||
"title",
|
||||
mode: InputArgument::REQUIRED,
|
||||
description: "Scene title",
|
||||
),
|
||||
new InputArgument(
|
||||
"description",
|
||||
mode: InputArgument::OPTIONAL,
|
||||
description: "Scene description",
|
||||
default: "",
|
||||
),
|
||||
new InputOption(
|
||||
"template",
|
||||
mode: InputOption::VALUE_OPTIONAL,
|
||||
description: "A valid, user-assignable scene template. Check sceneTemplate:list to get all available scenes.",
|
||||
default: null,
|
||||
)
|
||||
])
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$em = $this->game->getEntityManager();
|
||||
$logger = $this->game->getLogger();
|
||||
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$title = $input->getArgument("title");
|
||||
$description = $input->getArgument("description");
|
||||
$templateClass = $input->getOption("template");
|
||||
|
||||
/* @var $template SceneTemplate */
|
||||
if ($templateClass) {
|
||||
$template = $em->getRepository(SceneTemplate::class)->find($templateClass);
|
||||
|
||||
if (!$template) {
|
||||
$io->warning("Template '$template' has not been found. Set to NULL instead.");
|
||||
}
|
||||
} else {
|
||||
$template = $templateClass;
|
||||
}
|
||||
|
||||
$scene = Scene::create([
|
||||
"title" => $title,
|
||||
"description" => $description,
|
||||
"template" => $template,
|
||||
]);
|
||||
|
||||
try {
|
||||
$em->persist($scene);
|
||||
|
||||
// Commit changes
|
||||
$em->flush();
|
||||
} catch (Exception $e) {
|
||||
$io->error("Persisting of the scene was not possible. Reason: {$e->getMessage()}.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$io->success("Scene was successfully created. ID: {$scene->getId()}.");
|
||||
$logger->info("{$scene} was created.");
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command\Scene;
|
||||
|
||||
use Exception;
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Exceptions\ArgumentException;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use LotGD\Core\Models\SceneConnectionGroup;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Resets the viewpoint of a given character.
|
||||
*/
|
||||
class SceneAddConnectionGroupCommand extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('scene:addConnectionGroup')
|
||||
->setDescription('Add a connection group to an existing scene.')
|
||||
->setDefinition(
|
||||
new InputDefinition([
|
||||
new InputArgument("id", InputArgument::REQUIRED, "ID of the scene"),
|
||||
new InputArgument("groupName", InputArgument::REQUIRED, "Internal id of the group."),
|
||||
new InputArgument("groupTitle", InputArgument::REQUIRED, "Title of the group (what the character can see"),
|
||||
]),
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$em = $this->game->getEntityManager();
|
||||
$logger = $this->game->getLogger();
|
||||
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$sceneId = $input->getArgument("id");
|
||||
$groupName = $input->getArgument("groupName");
|
||||
$groupTitle = $input->getArgument("groupTitle");
|
||||
|
||||
// Search scene
|
||||
/** @var ?Scene $scene */
|
||||
$scene = $em->getRepository(Scene::class)->find($sceneId);
|
||||
|
||||
if (!$scene) {
|
||||
$io->error("The requested scene with the ID {$sceneId} was not found");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// Make scene connection group
|
||||
$connectionGroup = new SceneConnectionGroup($groupName, $groupTitle);
|
||||
|
||||
// Add
|
||||
try {
|
||||
$scene->addConnectionGroup($connectionGroup);
|
||||
|
||||
// Commit changes
|
||||
$em->flush();
|
||||
} catch(ArgumentException $e) {
|
||||
$io->error($e->getMessage());
|
||||
return Command::FAILURE;
|
||||
} catch (Exception $e) {
|
||||
$io->error("An unknown error occured: {$e->getMessage()}");
|
||||
}
|
||||
|
||||
$io->success("{$connectionGroup} successfully added.");
|
||||
$logger->info("{$connectionGroup} was added to {$scene}.");
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command\Scene;
|
||||
|
||||
use Exception;
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Exceptions\ArgumentException;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use LotGD\Core\Models\SceneConnectable;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Resets the viewpoint of a given character.
|
||||
*/
|
||||
class SceneConnectCommand extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('scene:connect')
|
||||
->setDescription('Connects two scenes.')
|
||||
->setDefinition(
|
||||
new InputDefinition([
|
||||
new InputArgument(
|
||||
"outgoing",
|
||||
mode: InputArgument::REQUIRED,
|
||||
description: "Outgoing scene ID",
|
||||
),
|
||||
new InputArgument(
|
||||
"incoming",
|
||||
mode: InputArgument::REQUIRED,
|
||||
description: "Incoming scene ID",
|
||||
),
|
||||
new InputOption(
|
||||
"outgoingGroupName",
|
||||
shortcut: "o",
|
||||
mode: InputOption::VALUE_OPTIONAL,
|
||||
description: "A valid, user-assignable scene template. Check sceneTemplate:list to get all available scenes.",
|
||||
default: null,
|
||||
),
|
||||
new InputOption(
|
||||
"incomingGroupName",
|
||||
shortcut: "i",
|
||||
mode: InputOption::VALUE_OPTIONAL,
|
||||
description: "A valid, user-assignable scene template. Check sceneTemplate:list to get all available scenes.",
|
||||
default: null,
|
||||
),
|
||||
new InputOption(
|
||||
"directionality",
|
||||
shortcut: "d",
|
||||
mode: InputOption::VALUE_OPTIONAL,
|
||||
description: "0 for bidirectional, 1 for unidirectional (outgoing->incoming)",
|
||||
default: 0,
|
||||
)
|
||||
])
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$em = $this->game->getEntityManager();
|
||||
$logger = $this->game->getLogger();
|
||||
$sceneRepository = $em->getRepository(Scene::class);
|
||||
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
/** @var ?Scene $outgoingScene */
|
||||
$outgoingScene = $sceneRepository->find($input->getArgument("outgoing"));
|
||||
/** @var ?Scene $incomingScene */
|
||||
$incomingScene = $sceneRepository->find($input->getArgument("incoming"));
|
||||
|
||||
// Check of scenes actually exist
|
||||
if (!$outgoingScene) {
|
||||
$io->error("The outgoing scene was not found.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if (!$incomingScene) {
|
||||
$io->error("The incoming scene was not found");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// Get group names
|
||||
$outgoingGroupName = $input->getOption("outgoingGroupName");
|
||||
$incomingGroupName = $input->getOption("incomingGroupName");
|
||||
|
||||
/** @var SceneConnectable $outgoing */
|
||||
$outgoing = null;
|
||||
/** @var SceneConnectable $outgoing */
|
||||
$incoming = null;
|
||||
|
||||
// Determine the outgoing Connectable
|
||||
if ($outgoingGroupName) {
|
||||
if (!$outgoingScene->hasConnectionGroup($outgoingGroupName)) {
|
||||
$io->error("The outgoing scene does not have a connection group with the id {$outgoingGroupName}");
|
||||
return Command::FAILURE;
|
||||
} else {
|
||||
$outgoing = $outgoingScene->getConnectionGroup($outgoingGroupName);
|
||||
}
|
||||
} else {
|
||||
$outgoing = $outgoingScene;
|
||||
}
|
||||
|
||||
// Determine the incoming Connectable
|
||||
if ($incomingGroupName) {
|
||||
if (!$incomingScene->hasConnectionGroup($incomingGroupName)) {
|
||||
$io->error("The incoming scene does not have a connection group with the id {$incomingGroupName}");
|
||||
return Command::FAILURE;
|
||||
} else {
|
||||
$incoming = $incomingScene->getConnectionGroup($incomingGroupName);
|
||||
}
|
||||
} else {
|
||||
$incoming = $incomingScene;
|
||||
}
|
||||
|
||||
// Get directionality
|
||||
$directionality = intval($input->getOption("directionality"));
|
||||
|
||||
if ($directionality < 0 or $directionality > 1) {
|
||||
$io->warning("Directionality was not either 0 or 1. It was forced to 0.");
|
||||
$directionality = 0;
|
||||
}
|
||||
|
||||
// Connect the connectables
|
||||
try {
|
||||
$outgoing->connect($incoming, $directionality);
|
||||
|
||||
// Commit changes
|
||||
$em->flush();
|
||||
} catch (ArgumentException $e) {
|
||||
$io->error("Scenes were not connected. Reason: {$e}.");
|
||||
return Command::FAILURE;
|
||||
} catch (Exception $e) {
|
||||
$io->error("An unknown error occured: {$e->getMessage()}");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$io->success("The two scenes were successfully connected.");
|
||||
$logger->info("Connected {$outgoingScene} to {$incomingScene}.");
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command\Scene;
|
||||
|
||||
use Exception;
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Resets the viewpoint of a given character.
|
||||
*/
|
||||
class SceneDisconnectCommand extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('scene:disconnect')
|
||||
->setDescription('Disconnects two scenes.')
|
||||
->setDefinition(
|
||||
new InputDefinition([
|
||||
new InputArgument(
|
||||
"scene1",
|
||||
mode: InputArgument::REQUIRED,
|
||||
description: "Outgoing scene ID",
|
||||
),
|
||||
new InputArgument(
|
||||
"scene2",
|
||||
mode: InputArgument::REQUIRED,
|
||||
description: "Incoming scene ID",
|
||||
),
|
||||
])
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$em = $this->game->getEntityManager();
|
||||
$logger = $this->game->getLogger();
|
||||
$sceneRepository = $em->getRepository(Scene::class);
|
||||
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
/** @var Scene $scene1 */
|
||||
$scene1 = $sceneRepository->find($input->getArgument("scene1"));
|
||||
/** @var Scene $scene2 */
|
||||
$scene2 = $sceneRepository->find($input->getArgument("scene2"));
|
||||
|
||||
if (!$scene1) {
|
||||
$io->error("Scene with id {$input->getArgument('scene1')} was not found.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if (!$scene2) {
|
||||
$io->error("Scene with id {$input->getArgument('scene2')} was not found.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$connection = $scene1->getConnectionTo($scene2);
|
||||
|
||||
if (!$connection) {
|
||||
$io->error("The to given scenes do not share a connection.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
try {
|
||||
// Commit changes
|
||||
$em->remove($connection);
|
||||
$em->flush();
|
||||
} catch (Exception $e) {
|
||||
$io->error("An unknown error occured: {$e->getMessage()}");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$io->success("The connections between the two given scenes was removed.");
|
||||
$logger->info("Disconnected {$connection->getOutgoingScene()} and {$connection->getIncomingScene()}.");
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command\Scene;
|
||||
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class SceneListCommand extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('scene:list')
|
||||
->setDescription('Lists all scenes')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$em = $this->game->getEntityManager();
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
/** @var Scene[] $scenes */
|
||||
$scenes = $em->getRepository(Scene::class)->findAll();
|
||||
|
||||
$table = [["id", "title", "connections"], []];
|
||||
foreach ($scenes as $scene) {
|
||||
$table[1][] = [
|
||||
$scene->getId(),
|
||||
$scene->getTitle(),
|
||||
count($scene->getConnectedScenes()),
|
||||
];
|
||||
}
|
||||
|
||||
$io->table(...$table);
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command\Scene;
|
||||
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Resets the viewpoint of a given character.
|
||||
*/
|
||||
class SceneRemoveCommand extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('scene:remove')
|
||||
->setDescription('Removes a scene.')
|
||||
->setDefinition(
|
||||
new InputDefinition([
|
||||
new InputArgument(
|
||||
"id",
|
||||
mode: InputArgument::REQUIRED,
|
||||
description: "Scene ID",
|
||||
),
|
||||
])
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$em = $this->game->getEntityManager();
|
||||
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$sceneId = $input->getArgument("id");
|
||||
|
||||
// Get scene
|
||||
/** @var Scene $scene */
|
||||
$scene = $em->getRepository(Scene::class)->find($sceneId);
|
||||
|
||||
if (!$scene) {
|
||||
$io->error("The scene with the ID {$sceneId} was not found.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if (!$scene->isRemovable()) {
|
||||
$io->error("The scene with the ID {$sceneId} was marked as not removable. Please remove the responsible");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// Mark for removal and flush
|
||||
try {
|
||||
$em->remove($scene);
|
||||
$em->flush();
|
||||
} catch (\Exception $e) {
|
||||
$io->error("Removal of {$sceneId} was not possible: {$e->getMessage()}");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$io->success("{$scene} was successfully removed.");
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command\Scene;
|
||||
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use LotGD\Core\Models\SceneConnection;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Resets the viewpoint of a given character.
|
||||
*/
|
||||
class SceneRemoveConnectionGroupCommand extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('scene:removeConnectionGroup')
|
||||
->setDescription('Removes a connection group from an existing scene.')
|
||||
->setDefinition(
|
||||
new InputDefinition([
|
||||
new InputArgument("id", InputArgument::REQUIRED, "ID of the scene"),
|
||||
new InputArgument("groupName", InputArgument::REQUIRED, "Internal id of the group."),
|
||||
]),
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$em = $this->game->getEntityManager();
|
||||
$logger = $this->game->getLogger();
|
||||
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$sceneId = $input->getArgument("id");
|
||||
$groupName = $input->getArgument("groupName");
|
||||
|
||||
// Search scene
|
||||
/** @var ?Scene $scene */
|
||||
$scene = $em->getRepository(Scene::class)->find($sceneId);
|
||||
|
||||
if (!$scene) {
|
||||
$io->error("The requested scene with the ID {$sceneId} was not found");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if (!$scene->hasConnectionGroup($groupName)) {
|
||||
$io->error("The scene {$sceneId} oes not have a connection group with the name {$groupName}");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$connectionGroup = $scene->getConnectionGroup($groupName);
|
||||
|
||||
# Mark for removal
|
||||
$em->remove($connectionGroup);
|
||||
|
||||
# Update outgoing connections if they refer to the deleted connectionGroup
|
||||
$connections = $scene->getConnections();
|
||||
/** @var SceneConnection $connection */
|
||||
foreach ($connections as $connection) {
|
||||
if ($connection->getIncomingScene() === $scene and $connection->getIncomingConnectionGroupName() === $groupName) {
|
||||
$connection->setIncomingConnectionGroupName(null);
|
||||
$io->comment("Updated connection to {$connection->getOutgoingScene()->getTitle()}");
|
||||
}
|
||||
|
||||
if ($connection->getOutgoingScene() === $scene and $connection->getOutgoingConnectionGroupName() === $groupName) {
|
||||
$connection->setOutgoingConnectionGroupName(null);
|
||||
$io->comment("Updated connection to {$connection->getIncomingScene()->getTitle()}");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$em->flush();
|
||||
} catch (\Exception $e) {
|
||||
$io->error("An unknown error occured: {$e->getMessage()}");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$io->success("{$connectionGroup} was successfully removed");
|
||||
$logger->info("Removed {$connectionGroup} from {$scene}.");
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command\Scene;
|
||||
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use LotGD\Core\Models\SceneConnectable;
|
||||
use LotGD\Core\Models\SceneConnection;
|
||||
use LotGD\Core\Models\SceneConnectionGroup;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Resets the viewpoint of a given character.
|
||||
*/
|
||||
class SceneShowCommand extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('scene:show')
|
||||
->setDescription('Show details about a specific scene.')
|
||||
->setDefinition(
|
||||
new InputDefinition([
|
||||
new InputArgument("id", InputArgument::REQUIRED, "ID of the scene"),
|
||||
])
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$em = $this->game->getEntityManager();
|
||||
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$id = $input->getArgument("id");
|
||||
|
||||
/* @var $scene Scene */
|
||||
$scene = $em->getRepository(Scene::class)->find($id);
|
||||
|
||||
if ($scene === null) {
|
||||
$io->error("Scene not found.");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$io->title("About scene '{$scene->getTitle()}'");
|
||||
$io->listing([
|
||||
"ID: {$scene->getId()}",
|
||||
"Title: {$scene->getTitle()}",
|
||||
"Template: {$scene->getTemplate()->getClass()}",
|
||||
]);
|
||||
|
||||
$io->text($scene->getDescription());
|
||||
|
||||
$io->section("Connection groups");
|
||||
|
||||
/** @var SceneConnectionGroup[] $connectionGroups */
|
||||
$connectionGroups = $scene->getConnectionGroups();
|
||||
$list = [];
|
||||
foreach ($connectionGroups as $connectionGroup) {
|
||||
$list[] = "{$connectionGroup->getTitle()} (id={$connectionGroup->getName()})";
|
||||
}
|
||||
$io->listing($list);
|
||||
|
||||
$io->section("Connected Scenes");
|
||||
|
||||
/** @var SceneConnection[] $connections */
|
||||
$connections = $scene->getConnections();
|
||||
$list = [];
|
||||
foreach ($connections as $connection) {
|
||||
# Get formatting for outgoing scene connection group name
|
||||
$outgoingSceneConnectionGroup = $connection->getOutgoingConnectionGroupName();
|
||||
if ($outgoingSceneConnectionGroup) {
|
||||
$outgoingSceneConnectionGroup = "(on $outgoingSceneConnectionGroup)";
|
||||
} else {
|
||||
$outgoingSceneConnectionGroup = "";
|
||||
}
|
||||
|
||||
# Get formatting for incoming scene connection group name
|
||||
$incomingSceneConnectionGroup = $connection->getIncomingConnectionGroupName();
|
||||
if ($incomingSceneConnectionGroup) {
|
||||
$incomingSceneConnectionGroup = " (on $incomingSceneConnectionGroup)";
|
||||
} else {
|
||||
$incomingSceneConnectionGroup = " ";
|
||||
}
|
||||
|
||||
# Treat outgoing and incoming connections slightly differently
|
||||
if ($connection->getOutgoingScene() === $scene) {
|
||||
$other = $connection->getIncomingScene();
|
||||
|
||||
# Check if the connection is bidirectional (only out (this)->in)
|
||||
if ($connection->isDirectionality(SceneConnectable::Bidirectional)) {
|
||||
$list[] = "this$outgoingSceneConnectionGroup <=> {$other->getTitle()}$incomingSceneConnectionGroup (id={$other->getId()})";
|
||||
} else {
|
||||
$list[] = "this$outgoingSceneConnectionGroup => {$other->getTitle()}$incomingSceneConnectionGroup (id={$other->getId()})";
|
||||
}
|
||||
} else {
|
||||
$other = $connection->getOutgoingScene();
|
||||
|
||||
# Check if the connection is bidirectional (only out->in (this))
|
||||
if ($connection->isDirectionality(SceneConnectable::Bidirectional)) {
|
||||
$list[] = "this$incomingSceneConnectionGroup <=> {$other->getTitle()}$outgoingSceneConnectionGroup (id={$other->getId()})";
|
||||
} else {
|
||||
$list[] = "this$incomingSceneConnectionGroup <= {$other->getTitle()}$outgoingSceneConnectionGroup (id={$other->getId()})";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$io->listing($list);
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console\Command\SceneTemplates;
|
||||
|
||||
use LotGD\Core\Console\Command\BaseCommand;
|
||||
use LotGD\Core\Models\SceneTemplate;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class SceneTemplateListCommand extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('sceneTemplate:list')
|
||||
->setDescription('Lists all registered scene templates')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$em = $this->game->getEntityManager();
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
/** @var SceneTemplate[] $templates */
|
||||
$templates = $em->getRepository(SceneTemplate::class)->findAll();
|
||||
|
||||
$table = [["class", "module", "assignable", "# scenes", "# viewpoints"], []];
|
||||
foreach ($templates as $template) {
|
||||
$table[1][] = [
|
||||
$template->getClass(),
|
||||
$template->getModule(),
|
||||
$template->isUserAssignable()?"X":"-",
|
||||
count($template->getOwningScenes()),
|
||||
count($template->getOwningViewpoints()),
|
||||
];
|
||||
}
|
||||
|
||||
$io->table(...$table);
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
+50
-12
@@ -3,25 +3,38 @@ declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Console;
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
use LotGD\Core\Bootstrap;
|
||||
|
||||
use LotGD\Core\Console\Command\Character\CharacterAddCommand;
|
||||
use LotGD\Core\Console\Command\Character\CharacterListCommand;
|
||||
use LotGD\Core\Console\Command\Character\CharacterRemoveCommand;
|
||||
use LotGD\Core\Console\Command\Character\CharacterResetViewpointCommand;
|
||||
use LotGD\Core\Console\Command\Character\CharacterShowCommand;
|
||||
use LotGD\Core\Console\Command\ConsoleCommand;
|
||||
use LotGD\Core\Console\Command\Database\DatabaseInitCommand;
|
||||
use LotGD\Core\Console\Command\Database\DatabaseSchemaUpdateCommand;
|
||||
use LotGD\Core\Console\Command\Module\ModuleRegisterCommand;
|
||||
use LotGD\Core\Console\Command\Module\ModuleValidateCommand;
|
||||
use LotGD\Core\Console\Command\Scene\SceneAddCommand;
|
||||
use LotGD\Core\Console\Command\Scene\SceneRemoveCommand;
|
||||
use LotGD\Core\Console\Command\Scene\SceneAddConnectionGroupCommand;
|
||||
use LotGD\Core\Console\Command\Scene\SceneConnectCommand;
|
||||
use LotGD\Core\Console\Command\Scene\SceneListCommand;
|
||||
use LotGD\Core\Console\Command\Scene\SceneDisconnectCommand;
|
||||
use LotGD\Core\Console\Command\Scene\SceneRemoveConnectionGroupCommand;
|
||||
use LotGD\Core\Console\Command\Scene\SceneShowCommand;
|
||||
use LotGD\Core\Console\Command\SceneTemplates\SceneTemplateListCommand;
|
||||
use LotGD\Core\Game;
|
||||
use LotGD\Core\Console\Command\{
|
||||
DatabaseInitCommand,
|
||||
ModuleValidateCommand,
|
||||
ModuleRegisterCommand,
|
||||
ConsoleCommand
|
||||
};
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
/**
|
||||
* Main execution class for the daenerys tool.
|
||||
*/
|
||||
class Main
|
||||
{
|
||||
private $application;
|
||||
private $bootstrap;
|
||||
private $game;
|
||||
private Application $application;
|
||||
private Bootstrap $bootstrap;
|
||||
private Game $game;
|
||||
|
||||
/**
|
||||
* Construct a new daenerys tool instance.
|
||||
@@ -42,8 +55,33 @@ class Main
|
||||
$this->application->add(new ModuleValidateCommand($this->game));
|
||||
$this->application->add(new ModuleRegisterCommand($this->game));
|
||||
$this->application->add(new DatabaseInitCommand($this->game));
|
||||
$this->application->add(new DatabaseSchemaUpdateCommand($this->game));
|
||||
$this->application->add(new ConsoleCommand($this->game));
|
||||
|
||||
// Character commands
|
||||
$this->application->add(new CharacterAddCommand($this->game));
|
||||
$this->application->add(new CharacterListCommand($this->game));
|
||||
$this->application->add(new CharacterRemoveCommand($this->game));
|
||||
$this->application->add(new CharacterResetViewpointCommand($this->game));
|
||||
$this->application->add(new CharacterShowCommand($this->game));
|
||||
|
||||
// Scene commands
|
||||
$this->application->add(new SceneListCommand($this->game));
|
||||
$this->application->add(new SceneAddCommand($this->game));
|
||||
$this->application->add(new SceneRemoveCommand($this->game));
|
||||
$this->application->add(new SceneShowCommand($this->game));
|
||||
|
||||
// Scene connections
|
||||
$this->application->add(new SceneConnectCommand($this->game));
|
||||
$this->application->add(new SceneDisconnectCommand($this->game));
|
||||
|
||||
// Scene connection group
|
||||
$this->application->add(new SceneAddConnectionGroupCommand($this->game));
|
||||
$this->application->add(new SceneRemoveConnectionGroupCommand($this->game));
|
||||
|
||||
// Scene templates
|
||||
$this->application->add(new SceneTemplateListCommand($this->game));
|
||||
|
||||
// Add additional ones
|
||||
$this->bootstrap->addDaenerysCommands($this->application);
|
||||
}
|
||||
@@ -55,7 +93,7 @@ class Main
|
||||
{
|
||||
// Bootstrap application
|
||||
$this->bootstrap = new Bootstrap();
|
||||
$this->game = $this->bootstrap->getGame(getcwd());
|
||||
$this->game = $this->bootstrap->getGame(\getcwd());
|
||||
|
||||
// Add commands
|
||||
$this->addCommands();
|
||||
|
||||
+15
-16
@@ -28,7 +28,7 @@ class DiceBag
|
||||
*/
|
||||
public function uniform(float $min, float $max): float
|
||||
{
|
||||
return (mt_rand(0, 100) / 100.0) * ($max - $min) + $min;
|
||||
return (\mt_rand(0, 100) / 100.0) * ($max - $min) + $min;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,7 +49,7 @@ class DiceBag
|
||||
$max = $a;
|
||||
}
|
||||
|
||||
return mt_rand($min, $max);
|
||||
return \mt_rand($min, $max);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,9 +71,9 @@ class DiceBag
|
||||
$mean = ($max - $min) / 2;
|
||||
$r = 0;
|
||||
do {
|
||||
$u1 = mt_rand() / mt_getrandmax();
|
||||
$u2 = mt_rand() / mt_getrandmax();
|
||||
$r = sqrt(-2 * log($u1)) * cos(2 * pi() * $u2) + $mean;
|
||||
$u1 = \mt_rand() / \mt_getrandmax();
|
||||
$u2 = \mt_rand() / \mt_getrandmax();
|
||||
$r = \sqrt(-2 * \log($u1)) * \cos(2 * \pi() * $u2) + $mean;
|
||||
} while ($r < $min || $r > $max);
|
||||
|
||||
return $r;
|
||||
@@ -82,31 +82,30 @@ class DiceBag
|
||||
/**
|
||||
* This function has uniform distribution except for the extreme values, which are
|
||||
* half as likely to happen.
|
||||
* The code for this function was taken from LotGD in version 0.9.7
|
||||
* The code for this function was taken from LotGD in version 0.9.7.
|
||||
* @author MightyE, JT
|
||||
* @param int $min
|
||||
* @param int $max
|
||||
* @param int|null $min
|
||||
* @param int|null $max
|
||||
* @return int
|
||||
*/
|
||||
public function pseudoBell(int $min = null, int $max = null): int
|
||||
{
|
||||
if (is_null($min)) {
|
||||
return mt_rand();
|
||||
if (\is_null($min)) {
|
||||
return \mt_rand();
|
||||
}
|
||||
|
||||
$min *= 1000;
|
||||
|
||||
if (is_null($max)) {
|
||||
return (int)round(mt_rand($min)/1000, 0);
|
||||
if (\is_null($max)) {
|
||||
return (int)\round(\mt_rand($min) / 1000, 0);
|
||||
}
|
||||
$max *= 1000;
|
||||
|
||||
if ($min === $max) {
|
||||
return (int)round($min/1000, 0);
|
||||
return (int)\round($min / 1000, 0);
|
||||
} elseif ($min < $max) {
|
||||
return (int)round(mt_rand($min, $max)/1000, 0);
|
||||
} else {
|
||||
return (int)round(mt_rand($max, $min)/1000, 0);
|
||||
return (int)\round(\mt_rand($min, $max) / 1000, 0);
|
||||
}
|
||||
return (int)\round(\mt_rand($max, $min) / 1000, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,38 +4,37 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Doctrine\Annotations;
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation;
|
||||
use Doctrine\Common\Annotations\Annotation\Attributes;
|
||||
use Doctrine\Common\Annotations\Annotation\Attribute;
|
||||
use Doctrine\Common\Annotations\Annotation\Attributes;
|
||||
use LotGD\Core\Exceptions\ArgumentException;
|
||||
use LotGD\Core\Models\ExtendableModelInterface;
|
||||
|
||||
/**
|
||||
* Annotation that is used to flag which entity a class extends.
|
||||
* @package LotGD\Core\Doctrine
|
||||
* @Annotation
|
||||
* @Target("CLASS")
|
||||
* @Attributes({
|
||||
* @Attribute("of", type = "string")
|
||||
* @Attribute("of", type="string")
|
||||
* })
|
||||
*/
|
||||
class Extension
|
||||
{
|
||||
/** @var string */
|
||||
private $modelClass;
|
||||
private string $modelClass;
|
||||
|
||||
/**
|
||||
* Extension constructor.
|
||||
* @param array $attributes
|
||||
* @throws ArgumentException
|
||||
*/
|
||||
public function __construct(array $attributes) {
|
||||
public function __construct(array $attributes)
|
||||
{
|
||||
$this->modelClass = $attributes["of"];
|
||||
|
||||
if (!class_exists($this->modelClass)) {
|
||||
if (!\class_exists($this->modelClass)) {
|
||||
throw new ArgumentException("The class given in of must be a valid class.");
|
||||
}
|
||||
|
||||
if (!in_array(ExtendableModelInterface::class, class_implements($this->modelClass))) {
|
||||
if (!\in_array(ExtendableModelInterface::class, \class_implements($this->modelClass))) {
|
||||
throw new ArgumentException("The class given in of must implement the ExtendableModelInterface.");
|
||||
}
|
||||
}
|
||||
@@ -48,4 +47,4 @@ class Extension
|
||||
{
|
||||
return $this->modelClass;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,37 +4,36 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Doctrine\Annotations;
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation;
|
||||
use Doctrine\Common\Annotations\Annotation\Attributes;
|
||||
use Doctrine\Common\Annotations\Annotation\Attribute;
|
||||
use Doctrine\Common\Annotations\Annotation\Attributes;
|
||||
use LotGD\Core\Exceptions\ArgumentException;
|
||||
|
||||
/**
|
||||
* Annotation that is used to link a static method to a model entity.
|
||||
* @package LotGD\Core\Doctrine\Annotations
|
||||
* @Annotation
|
||||
* @Target("METHOD")
|
||||
* @Attributes({
|
||||
* @Attribute("as", type = "string")
|
||||
* @Attribute("as", type="string")
|
||||
* })
|
||||
*/
|
||||
class ExtensionMethod
|
||||
{
|
||||
/** @var string */
|
||||
private $methodName = "";
|
||||
private string $methodName = "";
|
||||
|
||||
/**
|
||||
* ExtensionMethod constructor.
|
||||
* @param array $attributes
|
||||
* @throws ArgumentException
|
||||
*/
|
||||
public function __construct(array $attributes) {
|
||||
public function __construct(array $attributes)
|
||||
{
|
||||
$this->methodName = $attributes["as"];
|
||||
|
||||
if (!is_string($this->methodName)) {
|
||||
if (!\is_string($this->methodName)) {
|
||||
throw new ArgumentException("Property 'as' must be a string.");
|
||||
}
|
||||
|
||||
if (strlen($this->methodName) == 0) {
|
||||
if (\strlen($this->methodName) == 0) {
|
||||
throw new ArgumentException("Property 'as' must not be an empty string.");
|
||||
}
|
||||
}
|
||||
@@ -47,4 +46,4 @@ class ExtensionMethod
|
||||
{
|
||||
return $this->methodName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,28 +3,21 @@ declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Doctrine;
|
||||
|
||||
use Doctrine\Common\Util\Debug;
|
||||
use Doctrine\ORM\Event\LifecycleEventArgs;
|
||||
use LotGD\Core\Game;
|
||||
use LotGD\Core\GameAwareInterface;
|
||||
|
||||
/**
|
||||
* Class EntityPostLoadEventListener
|
||||
* @package LotGD\Core\Doctrine
|
||||
* Class EntityPostLoadEventListener.
|
||||
*/
|
||||
class EntityPostLoadEventListener
|
||||
{
|
||||
/** @var Game $game */
|
||||
private $game;
|
||||
|
||||
/**
|
||||
* EntityPostLoadEventListener constructor.
|
||||
* @param Game $g
|
||||
* @param Game $game
|
||||
*/
|
||||
public function __construct(Game $g)
|
||||
{
|
||||
$this->game = $g;
|
||||
}
|
||||
public function __construct(private Game $game) {}
|
||||
|
||||
/**
|
||||
* Called upon event postLoad.
|
||||
@@ -37,4 +30,4 @@ class EntityPostLoadEventListener
|
||||
$entity->setGame($this->game);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core;
|
||||
|
||||
use LotGD\Core\Events\EventContext;
|
||||
|
||||
interface EventHandler
|
||||
@@ -10,9 +11,8 @@ interface EventHandler
|
||||
* Called when an event is published that is handled by this class.
|
||||
*
|
||||
* @param Game $g The game.
|
||||
* @param string $event Name of this event.
|
||||
* @param array $context Arbitrary dictionary representing context around this event.
|
||||
* @return array|null Return an array if you want to make changes to the $context before
|
||||
* @param EventContext $context Arbitrary dictionary representing context around this event.
|
||||
* @return EventContext Return an array if you want to make changes to the $context before
|
||||
* the next handler is called. Otherwise, return null. Any changes made will be propogated
|
||||
* to the event publisher as well.
|
||||
*/
|
||||
|
||||
+14
-21
@@ -3,31 +3,23 @@ declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use LotGD\Core\Events\EventContext;
|
||||
use LotGD\Core\Models\EventSubscription;
|
||||
use LotGD\Core\EventHandler;
|
||||
use LotGD\Core\Events\EventContextData;
|
||||
use LotGD\Core\Exceptions\ClassNotFoundException;
|
||||
use LotGD\Core\Exceptions\SubscriptionNotFoundException;
|
||||
use LotGD\Core\Exceptions\WrongTypeException;
|
||||
use LotGD\Core\Events\EventContextData;
|
||||
use LotGD\Core\Models\EventSubscription;
|
||||
|
||||
/**
|
||||
* Manages a simple publish/subscribe system based on regular expressions
|
||||
* matching event names and running a fixed
|
||||
* matching event names and running a fixed.
|
||||
*/
|
||||
class EventManager
|
||||
{
|
||||
private $g;
|
||||
|
||||
/**
|
||||
* @param Game $g The game.
|
||||
*/
|
||||
public function __construct(Game $g)
|
||||
{
|
||||
$this->g = $g;
|
||||
}
|
||||
public function __construct(private Game $g) {}
|
||||
|
||||
/**
|
||||
* Publish an event. Will immediately cause handleEvent() to be called on all
|
||||
@@ -46,13 +38,13 @@ class EventManager
|
||||
// TODO: Add an in-memory cache here. Will likely only be in the 1000s of
|
||||
// patterns, so no need to go to the remote key-value store.
|
||||
|
||||
$this->g->getLogger()->addDebug("Publishing event {$event}.");
|
||||
$this->g->getLogger()->debug("Publishing event {$event}.");
|
||||
|
||||
$subscriptions = $this->getSubscriptions();
|
||||
foreach ($subscriptions as $s) {
|
||||
if (preg_match($s->getPattern(), $event)) {
|
||||
if (\preg_match($s->getPattern(), $event)) {
|
||||
$class = $s->getClass();
|
||||
$this->g->getLogger()->addDebug(" Handling with {$class}.");
|
||||
$this->g->getLogger()->debug(" Handling with {$class}.");
|
||||
|
||||
$eventContext = new EventContext($event, $s->getPattern(), $contextData);
|
||||
|
||||
@@ -82,7 +74,7 @@ class EventManager
|
||||
*/
|
||||
public function subscribe(string $pattern, string $class, string $library)
|
||||
{
|
||||
$this->g->getLogger()->addDebug("Subscribing event pattern={$pattern} class={$class} library={$library}");
|
||||
$this->g->getLogger()->debug("Subscribing event pattern={$pattern} class={$class} library={$library}");
|
||||
|
||||
try {
|
||||
// Can we resolve this class?
|
||||
@@ -102,14 +94,14 @@ class EventManager
|
||||
}
|
||||
|
||||
// Validate the regular expression.
|
||||
if (@preg_match($pattern, '') === false) {
|
||||
if (@\preg_match($pattern, '') === false) {
|
||||
throw new WrongTypeException("Invalid regular expression: {$pattern}");
|
||||
}
|
||||
|
||||
$e = EventSubscription::create([
|
||||
'pattern' => $pattern,
|
||||
'class' => $class,
|
||||
'library' => $library
|
||||
'library' => $library,
|
||||
]);
|
||||
|
||||
$this->g->getEntityManager()->persist($e);
|
||||
@@ -122,15 +114,16 @@ class EventManager
|
||||
* @param string $pattern Regular expression, in PHP format, to match against
|
||||
* published event names.
|
||||
* @param string $class Fully qualified class name.
|
||||
* @param string $library
|
||||
* @throws SubscriptionNotFoundException if the specified subscription does not exist.
|
||||
*/
|
||||
public function unsubscribe(string $pattern, string $class, string $library)
|
||||
{
|
||||
$e = $this->g->getEntityManager()->getRepository(EventSubscription::class)->find(array(
|
||||
$e = $this->g->getEntityManager()->getRepository(EventSubscription::class)->find([
|
||||
'pattern' => $pattern,
|
||||
'class' => $class,
|
||||
'library' => $library
|
||||
));
|
||||
'library' => $library,
|
||||
]);
|
||||
if (!$e) {
|
||||
throw new SubscriptionNotFoundException("Subscription not found with pattern={$pattern} class={$class} library={$library}.");
|
||||
}
|
||||
|
||||
@@ -1,19 +1,28 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Events;
|
||||
|
||||
|
||||
use LotGD\Core\Exceptions\ArgumentException;
|
||||
use JetBrains\PhpStorm\ArrayShape;
|
||||
use LotGD\Core\Models\Character;
|
||||
|
||||
/**
|
||||
* Class CharacterEventData
|
||||
* @package LotGD\Core\Events
|
||||
* Class CharacterEventData.
|
||||
*/
|
||||
class CharacterEventData extends EventContextData
|
||||
{
|
||||
protected static $argumentConfig = [
|
||||
#[ArrayShape([
|
||||
"character" => [
|
||||
"type" => Character::class,
|
||||
"required" => "bool",
|
||||
],
|
||||
"value" => [
|
||||
"type" => "mixed",
|
||||
"required" => "bool",
|
||||
],
|
||||
])]
|
||||
protected static ?array $argumentConfig = [
|
||||
"character" => ["type" => Character::class, "required" => true],
|
||||
"value" => ["type" => "mixed", "required" => false]
|
||||
"value" => ["type" => "mixed", "required" => false],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,18 +3,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Events;
|
||||
|
||||
|
||||
/**
|
||||
* Class EventContext
|
||||
* @package LotGD\Core
|
||||
* Class EventContext.
|
||||
* @immutable
|
||||
*/
|
||||
class EventContext
|
||||
{
|
||||
private $matchingPattern;
|
||||
private $event;
|
||||
private $data;
|
||||
|
||||
/**
|
||||
* EventContext constructor.
|
||||
* @param string $event The published event
|
||||
@@ -22,13 +16,10 @@ class EventContext
|
||||
* @param EventContextData $data
|
||||
*/
|
||||
public function __construct(
|
||||
string $event,
|
||||
string $matchingPattern,
|
||||
EventContextData $data
|
||||
private string $event,
|
||||
private string $matchingPattern,
|
||||
private EventContextData $data
|
||||
) {
|
||||
$this->event = $event;
|
||||
$this->matchingPattern = $matchingPattern;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +60,7 @@ class EventContext
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a data field
|
||||
* Returns a data field.
|
||||
* @param $field
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -79,7 +70,7 @@ class EventContext
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a data field
|
||||
* Sets a data field.
|
||||
* @param $field
|
||||
* @param $value
|
||||
*/
|
||||
@@ -106,4 +97,4 @@ class EventContext
|
||||
{
|
||||
return $this->data === $originalData ? false : true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,12 +9,18 @@ use LotGD\Core\Exceptions\ArgumentException;
|
||||
* EventContextData to provide a basic structure for managing contextual data of an event.
|
||||
*
|
||||
* This class must be immutable and returns always a new instance of itself for any change.
|
||||
* @package LotGD\Core\Events
|
||||
* @immutable
|
||||
*/
|
||||
class EventContextData
|
||||
{
|
||||
private $data;
|
||||
protected static ?array $argumentConfig = null;
|
||||
|
||||
/**
|
||||
* protected constructor..
|
||||
* @see self::create
|
||||
* @param array $data
|
||||
*/
|
||||
protected function __construct(private array $data) {}
|
||||
|
||||
/**
|
||||
* Creates a new instance of a data container.
|
||||
@@ -34,53 +40,53 @@ class EventContextData
|
||||
|
||||
/**
|
||||
* Checks a field configuration given in self::$argumentConfig.
|
||||
* @param $data
|
||||
* @param array $data
|
||||
* @throws ArgumentException
|
||||
*/
|
||||
public static function checkConfiguration($data)
|
||||
public static function checkConfiguration(array $data)
|
||||
{
|
||||
$configuration = static::$argumentConfig;
|
||||
$types = [
|
||||
"mixed" => function ($x) {return true;},
|
||||
"int" => function ($x) {return is_int($x);},
|
||||
"float" => function ($x) {return is_float($x);},
|
||||
"numeric" => function($x) {return is_numeric($x);},
|
||||
"string" => function($x) {return is_string($x);},
|
||||
"mixed" => function ($x) {
|
||||
return true;
|
||||
},
|
||||
"int" => function ($x) {
|
||||
return \is_int($x);
|
||||
},
|
||||
"float" => function ($x) {
|
||||
return \is_float($x);
|
||||
},
|
||||
"numeric" => function ($x) {
|
||||
return \is_numeric($x);
|
||||
},
|
||||
"string" => function ($x) {
|
||||
return \is_string($x);
|
||||
},
|
||||
];
|
||||
|
||||
$keys = array_keys($data);
|
||||
$keys = \array_keys($data);
|
||||
foreach ($keys as $key) {
|
||||
if (!isset($configuration[$key])) {
|
||||
throw new ArgumentException(sprintf("%s does not accept a field called %s", static::class, $key));
|
||||
throw new ArgumentException(\sprintf("%s does not accept a field called %s", static::class, $key));
|
||||
}
|
||||
}
|
||||
foreach ($configuration as $key => $config) {
|
||||
if ($config["required"] === true and !isset($data[$key])) {
|
||||
throw new ArgumentException(sprintf("%s must have a field called %s.", static::class, $key));
|
||||
throw new ArgumentException(\sprintf("%s must have a field called %s.", static::class, $key));
|
||||
}
|
||||
|
||||
if (isset($types[$config["type"]])) {
|
||||
if ($types[$config["type"]]($data[$key]) === false) {
|
||||
throw new ArgumentException(sprintf("The field %s of %s must be of type %s.", $key, static::class, $config["type"]));
|
||||
throw new ArgumentException(\sprintf("The field %s of %s must be of type %s.", $key, static::class, $config["type"]));
|
||||
}
|
||||
} else {
|
||||
if (!$data[$key] instanceof $config["type"]) {
|
||||
throw new ArgumentException(sprintf("The field %s of %s must be of type %s", $key, static::class, $config["type"]));
|
||||
throw new ArgumentException(\sprintf("The field %s of %s must be of type %s", $key, static::class, $config["type"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* protected constructor..
|
||||
* @see self::create
|
||||
* @param array $data
|
||||
*/
|
||||
protected function __construct(array $data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if container has a certain field.
|
||||
* @param string $field
|
||||
@@ -88,7 +94,7 @@ class EventContextData
|
||||
*/
|
||||
public function has(string $field): bool
|
||||
{
|
||||
return array_key_exists($field, $this->data);
|
||||
return \array_key_exists($field, $this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,31 +106,29 @@ class EventContextData
|
||||
{
|
||||
if ($this->has($field)) {
|
||||
return $this->data[$field];
|
||||
} else {
|
||||
$this->throwException($field);
|
||||
}
|
||||
$this->throwException($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a field to a new value and returns a new data container
|
||||
* Sets a field to a new value and returns a new data container.
|
||||
* @param string $field
|
||||
* @param $value
|
||||
* @param mixed $value
|
||||
* @return EventContextData
|
||||
*/
|
||||
public function set(string $field, $value): self
|
||||
public function set(string $field, mixed $value): self
|
||||
{
|
||||
if ($this->has($field)) {
|
||||
$data = $this->data;
|
||||
$data[$field] = $value;
|
||||
|
||||
return new static($data);
|
||||
} else {
|
||||
$this->throwException($field);
|
||||
}
|
||||
$this->throwException($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets multiple fields at once
|
||||
* Sets multiple fields at once.
|
||||
* @param array $data array of $field=>$value pairs
|
||||
* @return EventContextData
|
||||
*/
|
||||
@@ -144,12 +148,12 @@ class EventContextData
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of fields in this context
|
||||
* Returns a list of fields in this context.
|
||||
* @return array
|
||||
*/
|
||||
private function getListOfFields(): array
|
||||
{
|
||||
return array_keys($this->data);
|
||||
return \array_keys($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,8 +162,8 @@ class EventContextData
|
||||
*/
|
||||
private function getFormattedListOfFields(): string
|
||||
{
|
||||
return substr(
|
||||
implode(", ", $this->getListOfFields()),
|
||||
return \substr(
|
||||
\implode(", ", $this->getListOfFields()),
|
||||
0,
|
||||
-2
|
||||
);
|
||||
|
||||
@@ -3,15 +3,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Events;
|
||||
|
||||
|
||||
use Doctrine\Common\Util\Debug;
|
||||
use Doctrine\DBAL\Schema\View;
|
||||
use JetBrains\PhpStorm\ArrayShape;
|
||||
use LotGD\Core\Exceptions\ArgumentException;
|
||||
use LotGD\Core\Models\Character;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use LotGD\Core\Models\Viewpoint;
|
||||
|
||||
|
||||
/**
|
||||
* NavigateToScene data container which can be used for navigational events.
|
||||
*
|
||||
@@ -21,7 +17,6 @@ use LotGD\Core\Models\Viewpoint;
|
||||
* scene Scene
|
||||
* parameters array
|
||||
* redirect Scene|null
|
||||
* @package LotGD\Core\Events
|
||||
*/
|
||||
class NavigateToSceneData extends EventContextData
|
||||
{
|
||||
@@ -30,40 +25,49 @@ class NavigateToSceneData extends EventContextData
|
||||
* @param array $data Must contain fields referrer, viewpoint, scene, parameters and redirect; none more.
|
||||
* @throws ArgumentException
|
||||
*/
|
||||
protected function __construct(array $data)
|
||||
{
|
||||
protected function __construct(
|
||||
#[ArrayShape([
|
||||
"referrer" => Scene::class . "|null",
|
||||
"viewpoint" => Viewpoint::class,
|
||||
"scene" => Scene::class,
|
||||
"parameters" => "array",
|
||||
"reddirect" => Scene::class . "|null",
|
||||
])]
|
||||
array $data,
|
||||
) {
|
||||
$mustHaveForm = ["referrer", "viewpoint", "scene", "parameters", "redirect"];
|
||||
$doesHaveForm = array_keys($data);
|
||||
sort($mustHaveForm); sort($doesHaveForm);
|
||||
$doesHaveForm = \array_keys($data);
|
||||
\sort($mustHaveForm);
|
||||
\sort($doesHaveForm);
|
||||
|
||||
if ($doesHaveForm !== $mustHaveForm) {
|
||||
throw new ArgumentException("A new NavigateToScene event must have referrer, viewpoint, scene, parameters and redirect.");
|
||||
}
|
||||
|
||||
if ($data["referrer"] instanceof Scene === false and $data["referrer"] !== null) {
|
||||
throw new ArgumentException(sprintf(
|
||||
throw new ArgumentException(\sprintf(
|
||||
"data[referrer] must be an instance of %s, %s given.",
|
||||
Scene::class,
|
||||
get_class($data["referrer"])
|
||||
\get_class($data["referrer"])
|
||||
));
|
||||
}
|
||||
|
||||
if ($data["scene"] instanceof Scene === false) {
|
||||
throw new ArgumentException(sprintf(
|
||||
throw new ArgumentException(\sprintf(
|
||||
"data[scene] must be an instance of %s, %s given.",
|
||||
Scene::class,
|
||||
get_class($data["scene"])
|
||||
\get_class($data["scene"])
|
||||
));
|
||||
}
|
||||
|
||||
if ($data["viewpoint"] instanceof Viewpoint === false) {
|
||||
throw new ArgumentException(sprintf(
|
||||
throw new ArgumentException(\sprintf(
|
||||
"data[viewpoint] must be an instance of %s, %s given.",
|
||||
Viewpoint::class,
|
||||
get_class($data["viewpoint"])
|
||||
\get_class($data["viewpoint"])
|
||||
));
|
||||
}
|
||||
|
||||
parent::__construct($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Events;
|
||||
|
||||
|
||||
use JetBrains\PhpStorm\ArrayShape;
|
||||
use LotGD\Core\Exceptions\ArgumentException;
|
||||
use LotGD\Core\Models\Character;
|
||||
use LotGD\Core\Models\Scene;
|
||||
@@ -14,7 +14,6 @@ use LotGD\Core\Models\Scene;
|
||||
* Fields are:
|
||||
* character Character
|
||||
* scene Scene|null
|
||||
* @package LotGD\Core\Events
|
||||
*/
|
||||
class NewViewpointData extends EventContextData
|
||||
{
|
||||
@@ -23,28 +22,33 @@ class NewViewpointData extends EventContextData
|
||||
* @param array $data
|
||||
* @throws ArgumentException In case $data contains invalid data.
|
||||
*/
|
||||
protected function __construct(array $data)
|
||||
{
|
||||
if (array_keys($data) !== ["character", "scene"]) {
|
||||
protected function __construct(
|
||||
#[ArrayShape([
|
||||
"character" => Character::class,
|
||||
"scene" => Scene::class . "|null",
|
||||
])]
|
||||
array $data,
|
||||
) {
|
||||
if (\array_keys($data) !== ["character", "scene"]) {
|
||||
throw new ArgumentException("A NewViewpoint event must have only character and scene.");
|
||||
}
|
||||
|
||||
if (!$data["character"] instanceof Character) {
|
||||
throw new ArgumentException(sprintf(
|
||||
throw new ArgumentException(\sprintf(
|
||||
"NewViewpoint data[character] must be an instance of %s, %s given.",
|
||||
Character::class,
|
||||
get_class($data)
|
||||
\get_class($data)
|
||||
));
|
||||
}
|
||||
|
||||
if ($data["scene"] !== null and !$data["scene"] instanceof Scene) {
|
||||
throw new ArgumentException(sprintf(
|
||||
throw new ArgumentException(\sprintf(
|
||||
"NewViewpoint data[scene] must be an instance of %s or null, %s given.",
|
||||
Scene::class,
|
||||
get_class($data)
|
||||
\get_class($data)
|
||||
));
|
||||
}
|
||||
|
||||
parent::__construct($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,16 +3,21 @@ declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Events;
|
||||
|
||||
use LotGD\Core\Exceptions\ArgumentException;
|
||||
use JetBrains\PhpStorm\ArrayShape;
|
||||
use LotGD\Core\Models\Viewpoint;
|
||||
|
||||
/**
|
||||
* Class ViewpointDecorationEventData
|
||||
* @package LotGD\Core\Events
|
||||
* Class ViewpointDecorationEventData.
|
||||
*/
|
||||
class ViewpointDecorationEventData extends EventContextData
|
||||
{
|
||||
protected static $argumentConfig = [
|
||||
"viewpoint" => ["type" => Viewpoint::class, "required" => true]
|
||||
#[ArrayShape([
|
||||
"viewpoint" => [
|
||||
"type" => Viewpoint::class,
|
||||
"required" => "bool",
|
||||
],
|
||||
])]
|
||||
protected static ?array $argumentConfig = [
|
||||
"viewpoint" => ["type" => Viewpoint::class, "required" => true],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,5 +8,4 @@ namespace LotGD\Core\Exceptions;
|
||||
*/
|
||||
class ActionNotFoundException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,8 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* Exception if a specific, required argument is missing
|
||||
* Exception if a specific, required argument is missing.
|
||||
*/
|
||||
class ArgumentEmptyException extends ArgumentException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,8 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* Exception if a specific, required argument is missing
|
||||
* Exception if a specific, required argument is missing.
|
||||
*/
|
||||
class ArgumentException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,8 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* Exception if a specific, required argument is missing
|
||||
* Exception if a specific, required argument is missing.
|
||||
*/
|
||||
class AttributeMissingException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,8 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* Exception if a specific, required argument is missing
|
||||
* Exception if a specific, required argument is missing.
|
||||
*/
|
||||
class BattleEventException extends BattleException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,8 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* Exception if a specific, required argument is missing
|
||||
* Exception if a specific, required argument is missing.
|
||||
*/
|
||||
class BattleException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,8 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* Exception if a specific, required argument is missing
|
||||
* Exception if a specific, required argument is missing.
|
||||
*/
|
||||
class BattleIsOverException extends BattleException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,8 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* Exception if a specific, required argument is missing
|
||||
* Exception if a specific, required argument is missing.
|
||||
*/
|
||||
class BattleNotOverException extends BattleException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,8 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* Exception if a specific, required argument is missing
|
||||
* Exception if a specific, required argument is missing.
|
||||
*/
|
||||
class BuffListAlreadyActivatedException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,8 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* Exception if a specific, required argument is missing
|
||||
* Exception if a specific, required argument is missing.
|
||||
*/
|
||||
class BuffSlotOccupiedException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,8 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* Exception if a builder is missing an argument
|
||||
* Exception if a builder is missing an argument.
|
||||
*/
|
||||
class BuilderException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -8,5 +8,4 @@ namespace LotGD\Core\Exceptions;
|
||||
*/
|
||||
class CharacterNotFoundException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* Class CharacterStatException.
|
||||
*/
|
||||
class CharacterStatException extends CoreException
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* Class CharacterStatExistsException.
|
||||
*/
|
||||
class CharacterStatExistsException extends CharacterStatException
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* Class CharacterStatGroupExistsException.
|
||||
*/
|
||||
class CharacterStatGroupExistsException extends CharacterStatException
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* Class CharacterStatGroupNotFoundException.
|
||||
*/
|
||||
class CharacterStatGroupNotFoundException extends CharacterStatException
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* Class CharacterStatNotFoundException.
|
||||
*/
|
||||
class CharacterStatNotFoundException extends CharacterStatException
|
||||
{
|
||||
}
|
||||
@@ -4,9 +4,8 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* Exception if a specific, required argument is missing
|
||||
* Exception if a specific, required argument is missing.
|
||||
*/
|
||||
class ClassNotFoundException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -8,5 +8,4 @@ namespace LotGD\Core\Exceptions;
|
||||
*/
|
||||
class CoreException extends \Exception
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -8,5 +8,4 @@ namespace LotGD\Core\Exceptions;
|
||||
*/
|
||||
class EntityAlreadyExistsException extends EntityException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -8,5 +8,4 @@ namespace LotGD\Core\Exceptions;
|
||||
*/
|
||||
class EntityDoesNotExistException extends EntityException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,8 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* A basic entity exception
|
||||
* A basic entity exception.
|
||||
*/
|
||||
class EntityException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
class InsecureTwigTemplateError extends CoreException
|
||||
{
|
||||
}
|
||||
@@ -8,5 +8,4 @@ namespace LotGD\Core\Exceptions;
|
||||
*/
|
||||
class InvalidConfigurationException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -8,5 +8,4 @@ namespace LotGD\Core\Exceptions;
|
||||
*/
|
||||
class InvalidModelException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,8 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* Exception if a specific, required argument is missing
|
||||
* Exception if a specific, required argument is missing.
|
||||
*/
|
||||
class IsNullException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,8 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* Exception if a specific, required argument is missing
|
||||
* Exception if a specific, required argument is missing.
|
||||
*/
|
||||
class KeyNotFoundException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -8,5 +8,4 @@ namespace LotGD\Core\Exceptions;
|
||||
*/
|
||||
class LibraryDoesNotExistException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -8,5 +8,4 @@ namespace LotGD\Core\Exceptions;
|
||||
*/
|
||||
class ModuleAlreadyExistsException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -8,5 +8,4 @@ namespace LotGD\Core\Exceptions;
|
||||
*/
|
||||
class ModuleDoesNotExistException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,8 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* Exception if a specific, required argument is missing
|
||||
* Exception if a specific, required argument is missing.
|
||||
*/
|
||||
class NotImplementedException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,8 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* Exception if a specific, required argument is missing
|
||||
* Exception if a specific, required argument is missing.
|
||||
*/
|
||||
class ParentAlreadySetException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -8,5 +8,4 @@ namespace LotGD\Core\Exceptions;
|
||||
*/
|
||||
class PermissionAlreadyExistsException extends EntityAlreadyExistsException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -8,5 +8,4 @@ namespace LotGD\Core\Exceptions;
|
||||
*/
|
||||
class PermissionDoesNotExistException extends EntityDoesNotExistException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -8,5 +8,4 @@ namespace LotGD\Core\Exceptions;
|
||||
*/
|
||||
class PermissionIdNotFoundException extends EntityDoesNotExistException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -8,5 +8,4 @@ namespace LotGD\Core\Exceptions;
|
||||
*/
|
||||
class SceneNotFoundException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -8,5 +8,4 @@ namespace LotGD\Core\Exceptions;
|
||||
*/
|
||||
class SubscriptionNotFoundException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,8 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* Gets thrown if a array containts an unexpected array key
|
||||
* Gets thrown if a array containts an unexpected array key.
|
||||
*/
|
||||
class UnexpectedArrayKeyException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -8,5 +8,4 @@ namespace LotGD\Core\Exceptions;
|
||||
*/
|
||||
class WrongTypeException extends CoreException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
+90
-54
@@ -1,39 +1,39 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core;
|
||||
|
||||
use DateTime;
|
||||
use Doctrine\Common\Util\Debug;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use LotGD\Core\Events\NavigateToSceneData;
|
||||
use LotGD\Core\Events\NewViewpointData;
|
||||
use LotGD\Core\Exceptions\ActionNotFoundException;
|
||||
use LotGD\Core\Exceptions\CharacterNotFoundException;
|
||||
use LotGD\Core\Exceptions\InvalidConfigurationException;
|
||||
use LotGD\Core\Exceptions\SceneNotFoundException;
|
||||
use LotGD\Core\Models\Character;
|
||||
use LotGD\Core\Models\Scene;
|
||||
use LotGD\Core\Models\SceneConnectable;
|
||||
use LotGD\Core\Models\SceneConnection;
|
||||
use LotGD\Core\Models\Viewpoint;
|
||||
use LotGD\Core\SceneTemplates\BasicSceneTemplate;
|
||||
use LotGD\Core\SceneTemplates\SceneTemplateInterface;
|
||||
use LotGD\Core\Services\TwigSceneRenderer;
|
||||
use Monolog\Logger;
|
||||
|
||||
use LotGD\Core\Models\{
|
||||
Character, SceneConnectable, Viewpoint, Scene, SceneConnection
|
||||
};
|
||||
use LotGD\Core\Exceptions\ {
|
||||
ActionNotFoundException, CharacterNotFoundException, InvalidConfigurationException, SceneNotFoundException
|
||||
};
|
||||
|
||||
/**
|
||||
* The main game class.
|
||||
*/
|
||||
class Game
|
||||
{
|
||||
private $entityManager;
|
||||
private $eventManager;
|
||||
private $composerManager;
|
||||
private $moduleManager;
|
||||
private $messageManager;
|
||||
private $logger;
|
||||
private $configuration;
|
||||
private $character;
|
||||
private $diceBag;
|
||||
private $cwd;
|
||||
private $timeKeeper;
|
||||
|
||||
private EventManager $eventManager;
|
||||
private ComposerManager $composerManager;
|
||||
private ModuleManager $moduleManager;
|
||||
private MessageManager $messageManager;
|
||||
private ?Character $character = null;
|
||||
private DiceBag $diceBag;
|
||||
private ?TimeKeeper $timeKeeper = null;
|
||||
private TwigSceneRenderer $sceneRenderer;
|
||||
|
||||
/**
|
||||
* Construct a game. You probably want to use Bootstrap to do this.
|
||||
@@ -43,15 +43,11 @@ class Game
|
||||
* @param string $cwd
|
||||
*/
|
||||
public function __construct(
|
||||
Configuration $configuration,
|
||||
Logger $logger,
|
||||
EntityManagerInterface $entityManager,
|
||||
string $cwd
|
||||
private Configuration $configuration,
|
||||
private Logger $logger,
|
||||
private EntityManagerInterface $entityManager,
|
||||
private string $cwd
|
||||
) {
|
||||
$this->configuration = $configuration;
|
||||
$this->logger = $logger;
|
||||
$this->entityManager = $entityManager;
|
||||
$this->cwd = $cwd;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,7 +184,7 @@ class Game
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Message manager
|
||||
* Returns the Message manager.
|
||||
* @return MessageManager
|
||||
*/
|
||||
public function getMessageManager(): MessageManager
|
||||
@@ -197,7 +193,7 @@ class Game
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Message Manager
|
||||
* Sets the Message Manager.
|
||||
* @param MessageManager $messageManager
|
||||
*/
|
||||
public function setMessageManager(MessageManager $messageManager): void
|
||||
@@ -205,10 +201,28 @@ class Game
|
||||
$this->messageManager = $messageManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default scene renderer.
|
||||
* @return TwigSceneRenderer
|
||||
*/
|
||||
public function getSceneRenderer(): TwigSceneRenderer
|
||||
{
|
||||
return $this->sceneRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a scene renderer.
|
||||
* @param TwigSceneRenderer $sceneRenderer
|
||||
*/
|
||||
public function setSceneRenderer(TwigSceneRenderer $sceneRenderer): void
|
||||
{
|
||||
$this->sceneRenderer = $sceneRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently configured user character.
|
||||
* @return Character
|
||||
* @throws CharacterNotFoundException
|
||||
* @return Character
|
||||
*/
|
||||
public function getCharacter(): Character
|
||||
{
|
||||
@@ -230,7 +244,7 @@ class Game
|
||||
/**
|
||||
* Return the viewpoint for the current user.
|
||||
* @return Viewpoint
|
||||
* @throws InvalidConfigurationException
|
||||
* @throws InvalidConfigurationException|CharacterNotFoundException
|
||||
*/
|
||||
public function getViewpoint(): Viewpoint
|
||||
{
|
||||
@@ -241,7 +255,7 @@ class Game
|
||||
// scene.
|
||||
$contextData = NewViewpointData::create([
|
||||
'character' => $this->getCharacter(),
|
||||
'scene' => null
|
||||
'scene' => null,
|
||||
]);
|
||||
|
||||
$contextData = $this->getEventManager()->publish('h/lotgd/core/default-scene', $contextData);
|
||||
@@ -269,6 +283,7 @@ class Game
|
||||
* by the hook.
|
||||
* @param Scene $scene
|
||||
* @param array $parameters
|
||||
* @throws CharacterNotFoundException
|
||||
*/
|
||||
private function navigateToScene(Scene $scene, array $parameters)
|
||||
{
|
||||
@@ -278,21 +293,21 @@ class Game
|
||||
|
||||
$id = $scene->getId();
|
||||
$referrerId = $referrer ? $referrer->getId() : 'null';
|
||||
$this->getLogger()->addDebug("Navigating to sceneId={$id} from referrer sceneId={$referrerId}");
|
||||
$this->getLogger()->debug("Navigating to sceneId={$id} from referrer sceneId={$referrerId}");
|
||||
|
||||
// Copy over the basic structure from the scene database.
|
||||
$viewpoint->changeFromScene($scene);
|
||||
$viewpoint->changeFromScene($scene, $this->getSceneRenderer());
|
||||
|
||||
// Generate the default set of actions: the default group with
|
||||
// all children.
|
||||
$this->getLogger()->addDebug("Building default action group...");
|
||||
$this->getLogger()->debug("Building default action group...");
|
||||
$actionGroups = [
|
||||
ActionGroup::DefaultGroup => new ActionGroup(ActionGroup::DefaultGroup, '', 0),
|
||||
];
|
||||
|
||||
// Iterates through all connections and adds an action to the connected scene to the action group. If the connection
|
||||
// belongs to a new connection Group, it creates a new ActionGroup.
|
||||
$scene->getConnections()->map(function(SceneConnection $connection) use ($scene, &$actionGroups) {
|
||||
$scene->getConnections()->map(function (SceneConnection $connection) use ($scene, &$actionGroups) {
|
||||
if ($connection->getOutgoingScene() === $scene) {
|
||||
// current scene is outgoing, use incoming.
|
||||
$connectedScene = $connection->getIncomingScene();
|
||||
@@ -309,8 +324,8 @@ class Game
|
||||
}
|
||||
}
|
||||
|
||||
$this->getLogger()->addDebug(" Adding navigation action for child sceneId={$connectedScene->getId()}");
|
||||
$action = new Action($connectedScene->getId());
|
||||
$this->getLogger()->debug(" Adding navigation action for child sceneId={$connectedScene->getId()}");
|
||||
$action = new Action($connectedScene->getId(), $connectedScene->getTitle());
|
||||
|
||||
if ($connectionGroupName === null) {
|
||||
$actionGroups[ActionGroup::DefaultGroup]->addAction($action);
|
||||
@@ -327,15 +342,34 @@ class Game
|
||||
}
|
||||
});
|
||||
|
||||
// Logging
|
||||
$counts = implode(", ", array_map(function($k, $v) {
|
||||
return $k .count($v);
|
||||
}, array_keys($actionGroups), array_values($actionGroups)));
|
||||
$this->getLogger()->addDebug("Total actions: {$counts}");
|
||||
|
||||
// Create hidden group
|
||||
$actionGroups[ActionGroup::HiddenGroup] = new ActionGroup(ActionGroup::HiddenGroup, '', 100);
|
||||
|
||||
$viewpoint->setActionGroups(array_values($actionGroups));
|
||||
// Iterates over all SceneAttachments and creates the corresponding attachment objects, adding them to the
|
||||
// viewpoint. Additionally, all actions from the Attachments are added here to the hidden ActionGroup.
|
||||
$sceneAttachments = $scene->getSceneAttachments();
|
||||
foreach ($sceneAttachments as $sceneAttachment) {
|
||||
/** @var AttachmentInterface $attachment */
|
||||
$attachment = new ($sceneAttachment->getClass())($this, $scene);
|
||||
$viewpoint->addAttachment($attachment);
|
||||
|
||||
$this->getLogger()->debug("Adding attachment {$attachment}");
|
||||
}
|
||||
|
||||
// Logging
|
||||
$counts = \implode(", ", \array_map(function ($k, $v) {
|
||||
return $k .\count($v);
|
||||
}, \array_keys($actionGroups), \array_values($actionGroups)));
|
||||
$this->getLogger()->debug("Total actions: {$counts}");
|
||||
|
||||
$viewpoint->setActionGroups(\array_values($actionGroups));
|
||||
|
||||
$sceneTemplate = $scene->getTemplate();
|
||||
$templateClass = $sceneTemplate ? $sceneTemplate->getClass() : BasicSceneTemplate::class;
|
||||
|
||||
if (!\is_a($templateClass, SceneTemplateInterface::class, true)) {
|
||||
throw new \Exception("Scene template must implement ".SceneTemplateInterface::class);
|
||||
}
|
||||
|
||||
// Let and installed listeners (ie modules) make modifications to the
|
||||
// new viewpoint, including the ability to redirect the user to
|
||||
@@ -345,10 +379,10 @@ class Game
|
||||
'viewpoint' => $viewpoint,
|
||||
'scene' => $scene,
|
||||
'parameters' => $parameters,
|
||||
'redirect' => null
|
||||
'redirect' => null,
|
||||
]);
|
||||
|
||||
$hook = 'h/lotgd/core/navigate-to/' . $scene->getTemplate();
|
||||
$hook = "h/lotgd/core/navigate-to/".$templateClass::getNavigationEvent();
|
||||
$contextData = $this->getEventManager()->publish($hook, $contextData);
|
||||
|
||||
$scene = $contextData->get('redirect');
|
||||
@@ -356,7 +390,7 @@ class Game
|
||||
$id = $scene->getId();
|
||||
$this->getLogger()->debug("Redirecting to sceneId={$id}");
|
||||
}
|
||||
} while($scene !== null);
|
||||
} while ($scene !== null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -378,18 +412,20 @@ class Game
|
||||
if ($action === null) {
|
||||
throw new ActionNotFoundException("Invalid actionId={$actionId} for current viewpoint.");
|
||||
}
|
||||
$actionParameters = $action->getParameters();
|
||||
|
||||
$actionParameters = $action->getParameters();
|
||||
$sceneId = $action->getDestinationSceneId();
|
||||
|
||||
/** @var Scene $scene */
|
||||
$scene = $this->getEntityManager()->getRepository(Scene::class)->find([
|
||||
'id' => $sceneId
|
||||
'id' => $sceneId,
|
||||
]);
|
||||
if ($scene == null) {
|
||||
if ($scene === null) {
|
||||
throw new SceneNotFoundException("Cannot find sceneId={$sceneId} specified by actionId={$actionId}.");
|
||||
}
|
||||
|
||||
// action parameters overwrite other parameters since the former cannot be changed by the user
|
||||
$parameters = array_merge($parameters, $actionParameters);
|
||||
$parameters = \array_merge($parameters, $actionParameters);
|
||||
|
||||
$this->navigateToScene($scene, $parameters);
|
||||
|
||||
|
||||
@@ -4,11 +4,10 @@ declare(strict_types=1);
|
||||
namespace LotGD\Core;
|
||||
|
||||
/**
|
||||
* Interface for classes that are aware of the game
|
||||
* @package LotGD\Core
|
||||
* Interface for classes that are aware of the game.
|
||||
*/
|
||||
interface GameAwareInterface
|
||||
{
|
||||
public function setGame(Game $g);
|
||||
public function getGame(): Game;
|
||||
}
|
||||
}
|
||||
|
||||
+35
-20
@@ -3,36 +3,36 @@ declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core;
|
||||
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Monolog\Logger;
|
||||
|
||||
use LotGD\Core\Exceptions\BuilderException;
|
||||
|
||||
use LotGD\Core\Services\TwigSceneRenderer;
|
||||
use Monolog\Logger;
|
||||
|
||||
/**
|
||||
* The GameBuilder class is used to build a Game object with all dependencies that are needed.
|
||||
*
|
||||
* You must provide $cwd, $configuration, $entityManager and a logger instance using the with* methods.
|
||||
* You can provide additional class *names* for additional dependency injections using the use* methods.
|
||||
* @package LotGD\Core
|
||||
*/
|
||||
class GameBuilder
|
||||
{
|
||||
private $cwd;
|
||||
private $configuration;
|
||||
private $entityManager;
|
||||
private $logger;
|
||||
private string $cwd;
|
||||
private Configuration $configuration;
|
||||
private EntityManagerInterface $entityManager;
|
||||
private Logger $logger;
|
||||
|
||||
private $moduleManagerClass;
|
||||
private $composerManagerClass;
|
||||
private $eventManagerClass;
|
||||
private $diceBagClass;
|
||||
private $messageManagerClass;
|
||||
private string $moduleManagerClass;
|
||||
private string $composerManagerClass;
|
||||
private string$eventManagerClass;
|
||||
private string $diceBagClass;
|
||||
private string $messageManagerClass;
|
||||
private string $sceneRendererClass;
|
||||
|
||||
/**
|
||||
* Creates the game instance with the prepared parameters.
|
||||
* @return Game
|
||||
* @throws BuilderException if at least one of cwd, configuration, entityManager or logger as not been set.
|
||||
* @return Game
|
||||
*/
|
||||
public function create(): Game
|
||||
{
|
||||
@@ -63,13 +63,17 @@ class GameBuilder
|
||||
$diceBag = $this->diceBagClass ?? DiceBag::class;
|
||||
$game->setDiceBag(new $diceBag());
|
||||
|
||||
$messageManager=$this->messageManagerClass ?? MessageManager::class;
|
||||
$messageManager = $this->messageManagerClass ?? MessageManager::class;
|
||||
$game->setMessageManager(new $messageManager());
|
||||
|
||||
$sceneRenderer = $this->sceneRendererClass ?? TwigSceneRenderer::class;
|
||||
$game->setSceneRenderer(new $sceneRenderer($game));
|
||||
|
||||
return $game;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds current working directory argument
|
||||
* Adds current working directory argument.
|
||||
* @param string $cwd
|
||||
* @return self
|
||||
*/
|
||||
@@ -80,7 +84,7 @@ class GameBuilder
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration
|
||||
* Configuration.
|
||||
* @param Configuration $conf
|
||||
* @return self
|
||||
*/
|
||||
@@ -113,13 +117,13 @@ class GameBuilder
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the fqcn for the message manager to be used
|
||||
* Sets the fqcn for the message manager to be used.
|
||||
* @param string $messageManagerFqcn
|
||||
* @return self
|
||||
*/
|
||||
public function withMessageManager(string $messageManagerFqcn): self
|
||||
{
|
||||
$this->messageManagerClass=$messageManagerFqcn;
|
||||
$this->messageManagerClass = $messageManagerFqcn;
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -166,4 +170,15 @@ class GameBuilder
|
||||
$this->diceBagClass = $diceBagFqcn;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the class name for the scene renderer to be used.
|
||||
* @param string $sceneRendererFqcn
|
||||
* @return $this
|
||||
*/
|
||||
public function useSceneRenderer(string $sceneRendererFqcn): self
|
||||
{
|
||||
$this->sceneRendererClass = $sceneRendererFqcn;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core;
|
||||
|
||||
use Composer\Package\PackageInterface;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
use LotGD\Core\ComposerManager;
|
||||
|
||||
/**
|
||||
* Represents the configuration of a LotGD library (like the core, crate or module),
|
||||
* with its configuration parameters.
|
||||
@@ -15,17 +13,11 @@ use LotGD\Core\ComposerManager;
|
||||
*/
|
||||
class LibraryConfiguration
|
||||
{
|
||||
/** @var ComposerManager */
|
||||
private $composerManager;
|
||||
/** @var PackageInterface */
|
||||
private $package;
|
||||
/** @var string */
|
||||
private $rootNamespace;
|
||||
/** @var array */
|
||||
private $subscriptionPatterns;
|
||||
/** @var array */
|
||||
private $rawConfig;
|
||||
private $daenerysCommands;
|
||||
private string $rootNamespace;
|
||||
private ?string $entityDirectory;
|
||||
private array $subscriptionPatterns;
|
||||
private array $rawConfig;
|
||||
private array $daenerysCommands;
|
||||
|
||||
/**
|
||||
* Construct a configuration.
|
||||
@@ -33,17 +25,17 @@ class LibraryConfiguration
|
||||
* @param PackageInterface $package
|
||||
* @param string $cwd
|
||||
*/
|
||||
public function __construct(ComposerManager $composerManager, PackageInterface $package, string $cwd)
|
||||
{
|
||||
$this->composerManager = $composerManager;
|
||||
$this->package = $package;
|
||||
|
||||
public function __construct(
|
||||
private ComposerManager $composerManager,
|
||||
private PackageInterface $package,
|
||||
string $cwd,
|
||||
) {
|
||||
$path = '';
|
||||
$basePackage = $composerManager->getComposer()->getPackage();
|
||||
if ($basePackage && $basePackage->getName() === $package->getName()) {
|
||||
// Whatever the base package is in this repo is at $cwd.
|
||||
$path = $cwd;
|
||||
} elseif (in_array($package->getType(), ["lotgd-module", "lotgd-crate"])) {
|
||||
} elseif (\in_array($package->getType(), ["lotgd-module", "lotgd-crate"])) {
|
||||
// lotgd-modules are installed in the vendor directory.
|
||||
$installationManager = $composerManager->getComposer()->getInstallationManager();
|
||||
$path = $installationManager->getInstallPath($package);
|
||||
@@ -52,15 +44,15 @@ class LibraryConfiguration
|
||||
$path = $cwd;
|
||||
}
|
||||
|
||||
$confFile = $path . DIRECTORY_SEPARATOR . 'lotgd.yml';
|
||||
$confFile = $path . \DIRECTORY_SEPARATOR . 'lotgd.yml';
|
||||
|
||||
$this->rootNamespace = $this->findRootNamespace($package);
|
||||
if (file_exists($confFile)) {
|
||||
$this->rawConfig = Yaml::parse(file_get_contents($confFile));
|
||||
if (\file_exists($confFile)) {
|
||||
$this->rawConfig = Yaml::parse(\file_get_contents($confFile));
|
||||
} else {
|
||||
$name = $package->getName();
|
||||
$type = $package->getType();
|
||||
throw new \Exception("Library {$name} of type {$type} does not have a lotgd.yml in it's root ($confFile).");
|
||||
throw new \Exception("Library {$name} of type {$type} does not have a lotgd.yml in it's root (${confFile}).");
|
||||
}
|
||||
|
||||
$this->findEntityDirectory();
|
||||
@@ -87,25 +79,25 @@ class LibraryConfiguration
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for a root namespace
|
||||
* Searches for a root namespace.
|
||||
*
|
||||
* This function searches the package's configuration to find it's root namespace.
|
||||
* For this, it uses the following order:
|
||||
* - check psr-4 autoload configuration. If used, it takes the first element
|
||||
* - check psr-0 autoload configuration. If used, it takes the first element
|
||||
* @param PackageInterface $package
|
||||
* @return string
|
||||
* @throws \Exception if no namespace has been found
|
||||
* @return string
|
||||
*/
|
||||
protected function findRootNamespace(PackageInterface $package): string
|
||||
{
|
||||
$autoload = $package->getAutoload();
|
||||
if (isset($autoload["psr-4"]) && count($autoload["psr-4"]) > 0) {
|
||||
return key($autoload["psr-4"]);
|
||||
if (isset($autoload["psr-4"]) && \count($autoload["psr-4"]) > 0) {
|
||||
return \key($autoload["psr-4"]);
|
||||
}
|
||||
|
||||
if (isset($autoload["psr-0"]) && count($autoload["psr-0"]) > 0) {
|
||||
return key($autoload["psr-0"]);
|
||||
if (isset($autoload["psr-0"]) && \count($autoload["psr-0"]) > 0) {
|
||||
return \key($autoload["psr-0"]);
|
||||
}
|
||||
|
||||
$name = $package->getName();
|
||||
@@ -142,14 +134,14 @@ class LibraryConfiguration
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to iterate an array element given by the arguments
|
||||
* @param scalar $argument1,... array keys, by increasing depth
|
||||
* Tries to iterate an array element given by the arguments.
|
||||
* @param bool|int|float|string|bool[]|int[]|float[]|string[] $arguments array keys, by increasing depth
|
||||
*/
|
||||
public function iterateKey(...$arguments)
|
||||
public function iterateKey(array|bool|int|float|string ...$arguments)
|
||||
{
|
||||
$result = $this->getSubKeyIfItExists($arguments);
|
||||
|
||||
if (is_array($result)) {
|
||||
if (\is_array($result)) {
|
||||
foreach ($result as $key => $val) {
|
||||
yield $key => $val;
|
||||
}
|
||||
@@ -157,11 +149,11 @@ class LibraryConfiguration
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a subkey of an array if it exists or null
|
||||
* @param scalar $argument1,... array keys, by increasing depth
|
||||
* @return type
|
||||
* Returns a subkey of an array if it exists or null.
|
||||
* @param mixed ...$arguments
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getConfig(...$arguments)
|
||||
protected function getConfig(mixed ...$arguments)
|
||||
{
|
||||
$result = $this->getSubKeyIfItExists($arguments);
|
||||
return $result;
|
||||
@@ -177,12 +169,12 @@ class LibraryConfiguration
|
||||
|
||||
$entityNamespace = $this->getConfig("entityNamespace");
|
||||
|
||||
if (is_null($entityNamespace) === false) {
|
||||
if (\is_null($entityNamespace) === false) {
|
||||
$entityDirectory = $this->composerManager->translateNamespaceToPath($entityNamespace);
|
||||
|
||||
if ($entityDirectory === null) {
|
||||
throw new \Exception("Could not translate namespace {$entityNamespace} into a directory.");
|
||||
} else if (is_dir($entityDirectory) === false) {
|
||||
} elseif (\is_dir($entityDirectory) === false) {
|
||||
throw new \Exception("Path {$entityDirectory}, translated from namespace {$entityNamespace}, is not a valid directory.");
|
||||
}
|
||||
|
||||
@@ -192,7 +184,7 @@ class LibraryConfiguration
|
||||
|
||||
/**
|
||||
* Returns true if there are any models to add.
|
||||
* @return type
|
||||
* @return bool
|
||||
*/
|
||||
public function hasEntityDirectory(): bool
|
||||
{
|
||||
@@ -209,7 +201,7 @@ class LibraryConfiguration
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches the config file for daenerys commands and, if found, adds the class name to a list
|
||||
* Searches the config file for daenerys commands and, if found, adds the class name to a list.
|
||||
*/
|
||||
protected function findDaenerysCommands()
|
||||
{
|
||||
@@ -222,16 +214,16 @@ class LibraryConfiguration
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this configuration has daenerys commands
|
||||
* Returns true if this configuration has daenerys commands.
|
||||
* @return bool
|
||||
*/
|
||||
public function hasDaenerysCommands(): bool
|
||||
{
|
||||
return count($this->daenerysCommands) > 0 ? true : false;
|
||||
return \count($this->daenerysCommands) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of daenerys commands
|
||||
* Returns a list of daenerys commands.
|
||||
*/
|
||||
public function getDaenerysCommands(): array
|
||||
{
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core;
|
||||
|
||||
use Composer\Package\PackageInterface;
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
use LotGD\Core\ComposerManager;
|
||||
|
||||
/**
|
||||
* Handle the library configurations for the installed core, crate and modules.
|
||||
*/
|
||||
class LibraryConfigurationManager
|
||||
{
|
||||
/** @var array<LibraryConfiguration> */
|
||||
private $configurations = null;
|
||||
/** @var LibraryConfiguration[] */
|
||||
private array $configurations = [];
|
||||
|
||||
/**
|
||||
* Construct a manager.
|
||||
@@ -23,7 +19,6 @@ class LibraryConfigurationManager
|
||||
public function __construct(ComposerManager $composerManager, string $cwd)
|
||||
{
|
||||
$packages = $composerManager->getPackages();
|
||||
$this->configurations = [];
|
||||
|
||||
foreach ($packages as $package) {
|
||||
if ($package->getType() === "lotgd-crate" || $package->getType() === "lotgd-module") {
|
||||
@@ -36,9 +31,10 @@ class LibraryConfigurationManager
|
||||
/**
|
||||
* Return a library configuration for the specified library, in 'vendor/library'
|
||||
* format.
|
||||
* @param string $library
|
||||
* @return LibraryConfiguration|null
|
||||
*/
|
||||
public function getConfigurationForLibrary(string $library)
|
||||
public function getConfigurationForLibrary(string $library): ?LibraryConfiguration
|
||||
{
|
||||
$configs = $this->getConfigurations();
|
||||
|
||||
@@ -54,7 +50,8 @@ class LibraryConfigurationManager
|
||||
* Return an array of the library configurations.
|
||||
* @return LibraryConfiguration[]
|
||||
*/
|
||||
public function getConfigurations(): array {
|
||||
public function getConfigurations(): array
|
||||
{
|
||||
return $this->configurations;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,45 +10,44 @@ use LotGD\Core\Models\SystemCharacter;
|
||||
|
||||
/**
|
||||
* Manages the message system overall
|
||||
* Class MessageManager
|
||||
* @package LotGD\Core
|
||||
* Class MessageManager.
|
||||
*/
|
||||
class MessageManager
|
||||
{
|
||||
/**
|
||||
* Sends a message to a MessageThread
|
||||
* Sends a message to a MessageThread.
|
||||
* @param \LotGD\Core\Models\Character $from
|
||||
* @param string $message
|
||||
* @param \LotGD\Core\Models\MessageThread $thread
|
||||
* @param bool $systemMessage
|
||||
* @return \LotGD\Core\Models\Message
|
||||
* @throws Exceptions\CoreException
|
||||
* @return \LotGD\Core\Models\Message
|
||||
*/
|
||||
public function send(
|
||||
Character $from,
|
||||
string $message,
|
||||
MessageThread $thread,
|
||||
bool $systemMessage = false
|
||||
) {
|
||||
): Message {
|
||||
$message = new Message($from, $message, $thread, $systemMessage);
|
||||
$thread->addMessage($message);
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a system message to a MessageThread
|
||||
* Sends a system message to a MessageThread.
|
||||
* @param string $message
|
||||
* @param \LotGD\Core\Models\MessageThread $thread
|
||||
* @return \LotGD\Core\Models\Message
|
||||
* @throws Exceptions\ArgumentException
|
||||
* @throws Exceptions\CoreException
|
||||
* @return \LotGD\Core\Models\Message
|
||||
*/
|
||||
public function sendSystemMessage(
|
||||
string $message,
|
||||
MessageThread $thread
|
||||
) {
|
||||
): Message {
|
||||
$message = new Message(SystemCharacter::getInstance(), $message, $thread, true);
|
||||
$thread->addMessage($message);
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,16 +3,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core;
|
||||
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
use LotGD\Core\Doctrine\Annotations\Extension;
|
||||
use LotGD\Core\Doctrine\Annotations\ExtensionMethod;
|
||||
use LotGD\Core\Exceptions\ArgumentException;
|
||||
use ReflectionClass;
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
use LotGD\Core\Doctrine\Annotations\Extension;
|
||||
|
||||
/**
|
||||
* Contains method to help the extension of a model.
|
||||
* @package LotGD\Core
|
||||
*/
|
||||
class ModelExtender
|
||||
{
|
||||
@@ -32,8 +30,9 @@ class ModelExtender
|
||||
/**
|
||||
* @param string[] $classes
|
||||
*/
|
||||
public function addMore(array $classes): void {
|
||||
foreach($classes as $class) {
|
||||
public function addMore(array $classes): void
|
||||
{
|
||||
foreach ($classes as $class) {
|
||||
$this->add($class);
|
||||
}
|
||||
}
|
||||
@@ -49,7 +48,7 @@ class ModelExtender
|
||||
$extensionAnnotation = $this->reader->getClassAnnotation($reflectionClass, Extension::class);
|
||||
|
||||
if ($extensionAnnotation === null) {
|
||||
throw new ArgumentException(sprintf("Class %s must have the class Annotation %s", $class, Extension::class));
|
||||
throw new ArgumentException(\sprintf("Class %s must have the class Annotation %s", $class, Extension::class));
|
||||
}
|
||||
|
||||
$modelClass = $extensionAnnotation->getModelClass();
|
||||
@@ -63,7 +62,7 @@ class ModelExtender
|
||||
|
||||
foreach ($reflectionMethods as $method) {
|
||||
if ($method->isStatic() === false) {
|
||||
throw new ArgumentException(sprintf("Method %s must be static.", $method->getName()));
|
||||
throw new ArgumentException(\sprintf("Method %s must be static.", $method->getName()));
|
||||
}
|
||||
|
||||
/** @var ExtensionMethod $extensionMethodAnnotation */
|
||||
@@ -92,4 +91,4 @@ class ModelExtender
|
||||
|
||||
return self::$classes[$modelClassName][$methodName];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ use Generator;
|
||||
|
||||
use LotGD\Core\Exceptions\PermissionAlreadyExistsException;
|
||||
use LotGD\Core\Exceptions\PermissionDoesNotExistException;
|
||||
use LotGD\Core\Models\Permission;
|
||||
use LotGD\Core\Models\PermissionAssociationInterface;
|
||||
|
||||
/**
|
||||
* This abtract class provides functionality for user entities that crates might
|
||||
@@ -38,7 +36,7 @@ abstract class Actor
|
||||
*/
|
||||
protected function loadPermissions()
|
||||
{
|
||||
if (class_exists($this->getPermissionAssociationClass()) === false) {
|
||||
if (\class_exists($this->getPermissionAssociationClass()) === false) {
|
||||
throw new PermissionAssociationEntityMissingException(
|
||||
"The method getPermissionAssociationClass does not return a valid class name."
|
||||
);
|
||||
@@ -104,13 +102,12 @@ abstract class Actor
|
||||
if ($this->hasPermissionSet($permission->getId())) {
|
||||
$permissionId = $permission->getId();
|
||||
throw new PermissionAlreadyExistsException("The permission with the id {$permissionId} has already been set on this actor.");
|
||||
} else {
|
||||
$associationEntity = $this->getPermissionAssociationClass();
|
||||
|
||||
$permissionAssoc = new $associationEntity($this, $permission, $state);
|
||||
$this->permissions->add($permissionAssoc);
|
||||
$this->permissionIdToAssociation[$permissionAssoc->getId()] = $permissionAssoc;
|
||||
}
|
||||
$associationEntity = $this->getPermissionAssociationClass();
|
||||
|
||||
$permissionAssoc = new $associationEntity($this, $permission, $state);
|
||||
$this->permissions->add($permissionAssoc);
|
||||
$this->permissionIdToAssociation[$permissionAssoc->getId()] = $permissionAssoc;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,12 +25,13 @@ abstract class BasicEnemy implements FighterInterface
|
||||
* BasicEnemy constructor. Sets uuid upon creation.
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
$this->id = Uuid::uuid4();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the enemy's id
|
||||
* Returns the enemy's id.
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): UuidInterface
|
||||
@@ -39,7 +40,7 @@ abstract class BasicEnemy implements FighterInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the enemy's name
|
||||
* Returns the enemy's name.
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
@@ -66,7 +67,7 @@ abstract class BasicEnemy implements FighterInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the enemy's current health
|
||||
* Returns the enemy's current health.
|
||||
* @return int
|
||||
*/
|
||||
public function getHealth(): int
|
||||
@@ -79,7 +80,7 @@ abstract class BasicEnemy implements FighterInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the enemy's current health
|
||||
* Sets the enemy's current health.
|
||||
* @param int $health
|
||||
*/
|
||||
public function setHealth(int $health)
|
||||
@@ -105,7 +106,7 @@ abstract class BasicEnemy implements FighterInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Heals the enemy
|
||||
* Heals the enemy.
|
||||
* @param int $heal
|
||||
* @param type $overheal True if healing bigger than maxhealth is desired.
|
||||
*/
|
||||
@@ -126,8 +127,7 @@ abstract class BasicEnemy implements FighterInterface
|
||||
{
|
||||
if ($this->getHealth() > 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user