A modular Drupal RPG and Trading Game engine - Wk 2 of 4

From the single behat feature I created a game loop with 2 variables: health and strength, with attack being computed on the fly based on dice rolls.

I've built out the player profile for testing. I've experimented with players having weapons as paragraphs, which in turn are made of materials as paragraphs (to enable crafting).

I have introduced a simple ajax routine to avoid reloading the page for each battle. So wanting to add some more attributes meant adding vueJS immediately to avoid having to mess with updating individual variables.
I moved my single Ajax form to a Vue component. This meant a bit of confusion as I created and deleted controllers.

(Php)

Strategy Pattern:

Having originally created a simple player, I used the strategy pattern to expand the player using solid principles to allow for games of different complexity.
https://refactoring.guru/design-patterns/strategy/php/example

 

$this->simplePlayer = new Player($his->user->field_health->value,
$this->user->field_strength->value ); $this->faction = new Faction(7);
$this->weapon = new Weapon(6); $this->complexPlayer = new WeaponDecorator(new FactionDecorator
($this->simplePlayer, $this->faction), $this->weapon);

 

Symfony Entities:

I built out the player and dice as entities with getters and setters.

Drupal Entites:

I spent a lot of time trying to add user fields using hooks to no avail. I came to the conclusion that hooks are used for pages and other entites/nodes. but a user object would not go through the same hooks, listeners etc.
So I used yaml files in the config/install directory to build out the player. The Drupal user is coneected to the player entity in the game controller.

(Js)

Vue:

Each of the attributes are now reactive and belong to a player object. I need to build out the same for a game object and a buildings object. (I think). AxiosJs handles ajax calls
https://www.koderhq.com/tutorial/vue/http-axios/

PhaserJs:

I added the game framework by injecting it into a div, but it is not connected to Drupal, Vue or the backend. I now have three different js/public folders, with js being injected by the libraries yaml file as well as in the twig template. It's a bit messy.