Download the PHP package pierstoval/character-manager without Composer
On this page you can find all versions of the php package pierstoval/character-manager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pierstoval/character-manager
More information about pierstoval/character-manager
Files in pierstoval/character-manager
Package character-manager
Short Description Skeleton of a character manager for games
License MIT
Homepage https://github.com/Pierstoval/CharacterManagerBundle
Informations about the package character-manager
Character manager bundle
This bundle is here to provide a customizable skeleton to create characters based on a list of actions representing each step of character creation.
You can configure your steps both from configuration and services.
Setup
- Install the bundle
If you are using Symfony with Flex, all you have to do iscomposer require pierstoval/character-manager
.
If you do not have Flex, please refer to the next steps. -
Add it to your Kernel:
-
Create a
Character
class, for your first character manager: - Pro tip: You can also extend the abstract class
Pierstoval\Bundle\CharacterManagerBundle\Entity\Character
, which already implements the different methods AND is already a Doctrine ORM Entity for which you just have to add your ownid
property. -
Load the routing file:
This routing file is important because it is the place where character generation will be handled.
Note: You can add the{manager}
route option to your url prefix, when using multiple character managers. - You're set for the base setup!
Now you have to create your Step actions, for you to be able to generate a character
Character generation
Step actions
To generate characters, you need what are called Step Action classes.
One generation step = one class.
Each class must implement StepActionInterface
, but you can also extend the abstract class AbstractStepAction
which
implements the interface and adds cool logic, so you just have to implement the execute()
method.
You can define it at a simple class like this:
You can also refer to an already existing service:
💯 Note: You should know that all action classes that are not set as service will be defined as service,
autowired and set private, because it is mandatory for the ActionRegistry
to have them as services.
However, your services will be untouched, to keep consistency with your own logic.
💠 Magic
Important things about steps
Step configuration reference:
- Step name must be unique for each character manager. You can refer to it in the application, so be sure it is verbose enough for you, and more informative than just "Step 1", "Step 2", etc.
- Steps order matter! The step number starts at 1 and if you change the order of a step, the whole order will change.
Keep this in mind when using the
AbstractStepAction::goToStep($stepNumber)
method (see below). - The
onchange_clear
parameter is only handled in the abstractAbstractStepAction
class, but you can implement it manually in yourStepActionInterface::execute()
method for example.
AbstractStepAction
class
This is an example of a basic action:
What is injected in the AbstractStepAction class
When you have defined all your character managers configurations, the StepsPass
will process them and execute certain
actions:
-
Check if your action is an existing class extending
StepActionInterface
.
If it exists and is not defined as a service, it will:- Define it as a service
- Make the service
private
,autowired
andlazy
.
If it is already defined as a service, it will not do something else than the next steps:
- For all actions, now they should be defined as services, so the compiler pass will process them:
- If it extends the
AbstractStepAction
class, it will also inject: - The router if available (via the
RouterInterface
) - The entity manager if available (it actually injects the
ObjectManager
, so works with both ORM and ODM). - The translator (it should already be available via
TranslatorInterface
, even if not enabled in the framework). - The Twig environment, if available.
- It will inject the step configuration:
- The
character_class
option - The
Step
object, retrieved from theStepActionResolver
- All steps from this manager, again retrieved from the
StepActionResolver
. They're mostly used to manage thegoToStep()
andnextStep()
methods in the abstract action class. - Add the action to the
ActionRegistryInterface
service registered in the container.
- If it extends the
And the abstract class has cool new methods, too.
Constructor
First, you must know that the AbstractStepAction has no constructor.
Then, you're free to have your own constructor without being forced to rely on the parent's logic, and inject all your necessary services and parameters in the constructor, via autowiring.
The abstract class only adds some nice stuff to use (and if someone don't extend it, send me a message, I'd like to hear why you don't want to extend it), and this cool logic resides in other methods.
So you're free to implement your own constructor, especially if you define your action as a service
Injected services
If you define the step action as a service and extend the abstract class, you will have access to four services:
Most of the time, you don't need many other things, but if you need other things, just add the arguments:
or calls:
options to your service definition.
The cool methods of the AbstractStepAction class
The abstract class adds cool methods to manage your steps:
Roadmap
A list of "todos":
- Add a factory, a service, or whatever, which goal will be to handle converting the final step submission into a
proper
Character
object. Abstract, obviously, because it has to be implemented manually by the user. - Try to find a way to reduce the size of the controller class
- Create lots of character managers for different games so we find the flaws of this bundle and rip them off! (help appreciated 😁 )
License
The project is published under MIT license. See the license file for more information.
All versions of character-manager with dependencies
symfony/config Version ^6.2|^7.1
symfony/dependency-injection Version ^6.2|^7.1
symfony/framework-bundle Version ^6.2|^7.1
symfony/http-kernel Version ^6.2|^7.1
symfony/http-foundation Version ^6.2|^7.1
symfony/routing Version ^6.2|^7.1