Get support for p-chess/chess-bundle
If you're new to LTH, please see our FAQ for more information on what it is we do.
Support Options
Unfortunately, there are currently no active helpers for this repository on the platform. Until they become available, we reccomend the following actions:
View Open IssuesTake a look to see if anyone else has experienced the same issue as you and if they managed to solve it.
Open an IssueMake sure to read any relevant guidelines for opening issues on this repo before posting a new issue.
Sponsor directlyCheck out the page and see if there are any options to sponsor this project or it's developers directly.
p-chess/chess-bundle
ChessBundle
Installation
Run composer require p-chess/chess-bundle
Configuration
Create a service that extends PChess\ChessBundle\HtmlOutput
and
implements required methods.
You probably want to inject Symfony's router service here, and use it
to return required URLs.
Note that each route can be provided with an identifier for your game.
Create a configuration file, and use a content like the following:
# config/packages/chess.yaml
chess:
output_service: App\YourOutputService
This is an example of how routes can be defined (using an "id" parameter as identifier):
# config/routes.yaml
move_start:
path: /{id}/move/{from}
methods: GET
controller: ... # your controller action
move_cancel:
path: /{id}
methods: GET
controller: ... # your controller action
move_promotion:
path: /{id}/promote/{from}/{to}
methods: GET
controller: ... # your controller action
move_end:
path: /{id}/move/{from}/{to}/{promotion}
methods: GET
controller: ... # your controller action
defaults:
promotion: ~
Usage
You can inject a service implementing \PChess\ChessBundle\ChessProviderInterface
in your controller, then
implement different actions, using provided \PChess\Chess\Chess
object.
In your template, you can use Twig function chess_render(chess)
to render the board.
If you need to pass an identifier, use chess_render(chess, identifier)
instead.
The main service you can use is \PChess\ChessBundle\SessionChessProvider
.
This service allows you to keep chess games in session, providing following methods:
-
getChess($identifier, $fen)
to get main\PChess\Chess\Chess
instance (as provided by interface) -
restart($identifier)
to restart the game -
save($identifier)
to save the game in session -
reverse($identifier)
to switch sides -
getAllowedMoves($chess, $from)
to get a list of currently allowed moves (optionally limited to$from
square)
Using $identifier
is not mandatory.
Styling
You can use provided _board.scss
file to style the board:
@import '~@p-chess/chess-bundle/scss/board';
Don't forget to update your frontend files, using npm or yarn.
The final result should be something like this:
Persisting a Chess object
You can easily save a Chess
object into Doctrine (or other kind of mapping libraries), using two fields/properties:
fen
, and history
.
The first one is a simple string. The second one can be a simple_array
(for Doctrine), where you should put
the result of Mover::getHistoryStrings()
method.
When retrieving an object, you should use fen
and the result of Mover::getHistoryEntries()
to build back your
Chess
object.
Our Mission
We want to make open source more sustainable. The entire platform was born from this and everything we do is in aid of this.
From the Blog
Interesting Articles
-
Generating income from open source
Jun 23 • 8 min read
-
2023 State of OSS
Apr 23 • 45 min read ★
-
A funding experiment...
Aug 19 • 10 min read
-
But You Said I could
Aug 19 • 2 min read
Thank you for checking out LiveTechHelper |
2025 © lth-dev incorporated
p-e622a1a2