chg: dev: change the code style to fit the current standard #4
This commit is contained in:
@@ -175,7 +175,7 @@ class MineSeeker extends React.Component {
|
|||||||
// ------------------------------------------------------------------ //
|
// ------------------------------------------------------------------ //
|
||||||
|
|
||||||
handleMercureMessage(payload) {
|
handleMercureMessage(payload) {
|
||||||
let isTopicEvent = 'undefined' !== typeof payload.data;
|
let isTopicEvent = 'undefined' !== typeof payload.data;
|
||||||
let isNotUnsubscribe = 'undefined' === typeof payload.msg;
|
let isNotUnsubscribe = 'undefined' === typeof payload.msg;
|
||||||
|
|
||||||
if (isTopicEvent) {
|
if (isTopicEvent) {
|
||||||
@@ -197,9 +197,9 @@ class MineSeeker extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
openEventSource() {
|
openEventSource() {
|
||||||
const wrapper = document.getElementById('mine-wrapper');
|
const wrapper = document.getElementById('mine-wrapper');
|
||||||
const hubUrl = wrapper.dataset.mercureHubUrl;
|
const hubUrl = wrapper.dataset.mercureHubUrl;
|
||||||
const subscriberJwt = wrapper.dataset.mercureSubscriberJwt;
|
const subscriberJwt = wrapper.dataset.mercureSubscriberJwt;
|
||||||
|
|
||||||
const url = new URL(hubUrl, window.location.origin);
|
const url = new URL(hubUrl, window.location.origin);
|
||||||
url.searchParams.append('topic', this.state.channel);
|
url.searchParams.append('topic', this.state.channel);
|
||||||
@@ -324,8 +324,8 @@ class MineSeeker extends React.Component {
|
|||||||
try {
|
try {
|
||||||
if (this.state.gameInherited) {
|
if (this.state.gameInherited) {
|
||||||
/** Fetch existing player info and previously revealed cells */
|
/** Fetch existing player info and previously revealed cells */
|
||||||
const resp = await fetch('/api/game/connect/' + this.state.gameAssoc);
|
const resp = await fetch('/api/game/connect/' + this.state.gameAssoc);
|
||||||
const b64 = await resp.text();
|
const b64 = await resp.text();
|
||||||
const serverData = JSON.parse(window.atob(b64));
|
const serverData = JSON.parse(window.atob(b64));
|
||||||
|
|
||||||
if ('undefined' === typeof serverData.users || null === serverData.users) {
|
if ('undefined' === typeof serverData.users || null === serverData.users) {
|
||||||
@@ -393,7 +393,7 @@ class MineSeeker extends React.Component {
|
|||||||
let dataPack = {
|
let dataPack = {
|
||||||
coords: coords,
|
coords: coords,
|
||||||
player: activePlayer,
|
player: activePlayer,
|
||||||
bomb: this.refs.gridControl.refs.userControl.state.bombSelected,
|
bomb: this.refs.gridControl.refs.userControl.state.bombSelected,
|
||||||
resign: null,
|
resign: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -403,7 +403,7 @@ class MineSeeker extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resp = await this.publishStep(dataPack);
|
const resp = await this.publishStep(dataPack);
|
||||||
const result = await resp.json();
|
const result = await resp.json();
|
||||||
|
|
||||||
this.refs.gridControl.applyStep(result);
|
this.refs.gridControl.applyStep(result);
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
framework:
|
framework:
|
||||||
assets:
|
assets:
|
||||||
json_manifest_path: '%kernel.project_dir%/public/build/manifest.json'
|
json_manifest_path: '%kernel.project_dir%/public/build/manifest.json'
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
monolog:
|
monolog:
|
||||||
handlers:
|
handlers:
|
||||||
main:
|
main:
|
||||||
type: stream
|
type: stream
|
||||||
path: "%kernel.logs_dir%/%kernel.environment%.log"
|
path: "%kernel.logs_dir%/%kernel.environment%.log"
|
||||||
level: error
|
level: error
|
||||||
channels: ["!event"]
|
channels: [ "!event" ]
|
||||||
# uncomment to get logging in your browser
|
# uncomment to get logging in your browser
|
||||||
# you may have to allow bigger header sizes in your Web server configuration
|
# you may have to allow bigger header sizes in your Web server configuration
|
||||||
#firephp:
|
#firephp:
|
||||||
# type: firephp
|
# type: firephp
|
||||||
# level: info
|
# level: info
|
||||||
#chromephp:
|
#chromephp:
|
||||||
# type: chromephp
|
# type: chromephp
|
||||||
# level: info
|
# level: info
|
||||||
console:
|
console:
|
||||||
type: console
|
type: console
|
||||||
process_psr_3_messages: false
|
process_psr_3_messages: false
|
||||||
channels: ["!event", "!doctrine", "!console"]
|
channels: [ "!event", "!doctrine", "!console" ]
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
framework:
|
framework:
|
||||||
router:
|
router:
|
||||||
strict_requirements: true
|
strict_requirements: true
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
web_profiler:
|
web_profiler:
|
||||||
toolbar: true
|
toolbar: true
|
||||||
intercept_redirects: false
|
intercept_redirects: false
|
||||||
|
|
||||||
framework:
|
framework:
|
||||||
profiler: { only_exceptions: false }
|
profiler: { only_exceptions: false }
|
||||||
|
|||||||
@@ -1,30 +1,30 @@
|
|||||||
parameters:
|
parameters:
|
||||||
# Adds a fallback DATABASE_URL if the env var is not set.
|
# Adds a fallback DATABASE_URL if the env var is not set.
|
||||||
# This allows you to run cache:warmup even if your
|
# This allows you to run cache:warmup even if your
|
||||||
# environment variables are not available yet.
|
# environment variables are not available yet.
|
||||||
# You should not need to change this value.
|
# You should not need to change this value.
|
||||||
env(DATABASE_URL): ''
|
env(DATABASE_URL): ''
|
||||||
|
|
||||||
doctrine:
|
doctrine:
|
||||||
dbal:
|
dbal:
|
||||||
# configure these for your database server
|
# configure these for your database server
|
||||||
driver: 'pdo_mysql'
|
driver: 'pdo_mysql'
|
||||||
server_version: '5.7'
|
server_version: '5.7'
|
||||||
charset: utf8mb4
|
charset: utf8mb4
|
||||||
default_table_options:
|
default_table_options:
|
||||||
charset: utf8mb4
|
charset: utf8mb4
|
||||||
collate: utf8mb4_unicode_ci
|
collate: utf8mb4_unicode_ci
|
||||||
|
|
||||||
url: '%env(resolve:DATABASE_URL)%'
|
url: '%env(resolve:DATABASE_URL)%'
|
||||||
|
|
||||||
orm:
|
orm:
|
||||||
auto_generate_proxy_classes: '%kernel.debug%'
|
auto_generate_proxy_classes: '%kernel.debug%'
|
||||||
naming_strategy: doctrine.orm.naming_strategy.underscore
|
naming_strategy: doctrine.orm.naming_strategy.underscore
|
||||||
auto_mapping: true
|
auto_mapping: true
|
||||||
mappings:
|
mappings:
|
||||||
App:
|
App:
|
||||||
is_bundle: false
|
is_bundle: false
|
||||||
type: attribute
|
type: attribute
|
||||||
dir: '%kernel.project_dir%/src/Entity'
|
dir: '%kernel.project_dir%/src/Entity'
|
||||||
prefix: 'App\Entity'
|
prefix: 'App\Entity'
|
||||||
alias: App
|
alias: App
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
doctrine_migrations:
|
doctrine_migrations:
|
||||||
migrations_paths:
|
migrations_paths:
|
||||||
'App\Migrations': '%kernel.project_dir%/src/Migrations'
|
'App\Migrations': '%kernel.project_dir%/src/Migrations'
|
||||||
organize_migrations: BY_YEAR_AND_MONTH
|
organize_migrations: BY_YEAR_AND_MONTH
|
||||||
|
|||||||
@@ -1,29 +1,29 @@
|
|||||||
framework:
|
framework:
|
||||||
secret: '%env(APP_SECRET)%'
|
secret: '%env(APP_SECRET)%'
|
||||||
#default_locale: en
|
#default_locale: en
|
||||||
#csrf_protection: true
|
#csrf_protection: true
|
||||||
#http_method_override: true
|
#http_method_override: true
|
||||||
# Enables session support. Note that the session will ONLY be started if you read or write from it.
|
# Enables session support. Note that the session will ONLY be started if you read or write from it.
|
||||||
# Remove or comment this section to explicitly disable session support.
|
# Remove or comment this section to explicitly disable session support.
|
||||||
session:
|
session:
|
||||||
handler_id: ~
|
handler_id: ~
|
||||||
|
|
||||||
#esi: true
|
#esi: true
|
||||||
#fragments: true
|
#fragments: true
|
||||||
php_errors:
|
php_errors:
|
||||||
log: true
|
log: true
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
# Put the unique name of your app here: the prefix seed
|
# Put the unique name of your app here: the prefix seed
|
||||||
# is used to compute stable namespaces for cache keys.
|
# is used to compute stable namespaces for cache keys.
|
||||||
#prefix_seed: your_vendor_name/app_name
|
#prefix_seed: your_vendor_name/app_name
|
||||||
|
|
||||||
# The app cache caches to the filesystem by default.
|
# The app cache caches to the filesystem by default.
|
||||||
# Other options include:
|
# Other options include:
|
||||||
|
|
||||||
# Redis
|
# Redis
|
||||||
#app: cache.adapter.redis
|
#app: cache.adapter.redis
|
||||||
#default_redis_provider: redis://localhost
|
#default_redis_provider: redis://localhost
|
||||||
|
|
||||||
# APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
|
# APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
|
||||||
#app: cache.adapter.apcu
|
#app: cache.adapter.apcu
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
framework:
|
framework:
|
||||||
mailer:
|
mailer:
|
||||||
dsn: '%env(MAILER_DSN)%'
|
dsn: '%env(MAILER_DSN)%'
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
doctrine:
|
doctrine:
|
||||||
orm:
|
orm:
|
||||||
metadata_cache_driver:
|
metadata_cache_driver:
|
||||||
type: pool
|
type: pool
|
||||||
pool: doctrine.system_cache_pool
|
pool: doctrine.system_cache_pool
|
||||||
query_cache_driver:
|
query_cache_driver:
|
||||||
type: pool
|
type: pool
|
||||||
pool: doctrine.system_cache_pool
|
pool: doctrine.system_cache_pool
|
||||||
result_cache_driver:
|
result_cache_driver:
|
||||||
type: pool
|
type: pool
|
||||||
pool: doctrine.result_cache_pool
|
pool: doctrine.result_cache_pool
|
||||||
|
|
||||||
framework:
|
framework:
|
||||||
cache:
|
cache:
|
||||||
pools:
|
pools:
|
||||||
doctrine.result_cache_pool:
|
doctrine.result_cache_pool:
|
||||||
adapter: cache.app
|
adapter: cache.app
|
||||||
doctrine.system_cache_pool:
|
doctrine.system_cache_pool:
|
||||||
adapter: cache.system
|
adapter: cache.system
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
monolog:
|
monolog:
|
||||||
handlers:
|
handlers:
|
||||||
main:
|
main:
|
||||||
type: fingers_crossed
|
type: fingers_crossed
|
||||||
action_level: error
|
action_level: error
|
||||||
handler: nested
|
handler: nested
|
||||||
excluded_http_codes: [404, 405]
|
excluded_http_codes: [ 404, 405 ]
|
||||||
nested:
|
nested:
|
||||||
type: stream
|
type: stream
|
||||||
path: "%kernel.logs_dir%/%kernel.environment%.log"
|
path: "%kernel.logs_dir%/%kernel.environment%.log"
|
||||||
level: debug
|
level: debug
|
||||||
console:
|
console:
|
||||||
type: console
|
type: console
|
||||||
process_psr_3_messages: false
|
process_psr_3_messages: false
|
||||||
channels: ["!event", "!doctrine"]
|
channels: [ "!event", "!doctrine" ]
|
||||||
deprecation:
|
deprecation:
|
||||||
type: stream
|
type: stream
|
||||||
path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log"
|
path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log"
|
||||||
deprecation_filter:
|
deprecation_filter:
|
||||||
type: filter
|
type: filter
|
||||||
handler: deprecation
|
handler: deprecation
|
||||||
max_level: info
|
max_level: info
|
||||||
channels: ["php"]
|
channels: [ "php" ]
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#webpack_encore:
|
#webpack_encore:
|
||||||
# Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes)
|
# Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes)
|
||||||
# Available in version 1.2
|
# Available in version 1.2
|
||||||
#cache: true
|
#cache: true
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
framework:
|
framework:
|
||||||
router:
|
router:
|
||||||
strict_requirements: ~
|
strict_requirements: ~
|
||||||
|
|||||||
@@ -1,27 +1,27 @@
|
|||||||
security:
|
security:
|
||||||
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
|
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
|
||||||
providers:
|
providers:
|
||||||
app_user_provider:
|
app_user_provider:
|
||||||
entity:
|
entity:
|
||||||
class: App\Entity\User
|
class: App\Entity\User
|
||||||
property: username
|
property: username
|
||||||
firewalls:
|
firewalls:
|
||||||
dev:
|
dev:
|
||||||
pattern: ^/(_(profiler|wdt)|css|images|js)/
|
pattern: ^/(_(profiler|wdt)|css|images|js)/
|
||||||
security: false
|
security: false
|
||||||
main:
|
main:
|
||||||
lazy: true
|
lazy: true
|
||||||
|
|
||||||
# activate different ways to authenticate
|
# activate different ways to authenticate
|
||||||
|
|
||||||
# http_basic: true
|
# http_basic: true
|
||||||
# https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate
|
# https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate
|
||||||
|
|
||||||
# form_login: true
|
# form_login: true
|
||||||
# https://symfony.com/doc/current/security/form_login_setup.html
|
# https://symfony.com/doc/current/security/form_login_setup.html
|
||||||
|
|
||||||
# Easy way to control access for large sections of your site
|
# Easy way to control access for large sections of your site
|
||||||
# Note: Only the *first* access control that matches will be used
|
# Note: Only the *first* access control that matches will be used
|
||||||
access_control:
|
access_control:
|
||||||
# - { path: ^/admin, roles: ROLE_ADMIN }
|
# - { path: ^/admin, roles: ROLE_ADMIN }
|
||||||
# - { path: ^/profile, roles: ROLE_USER }
|
# - { path: ^/profile, roles: ROLE_USER }
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
framework:
|
framework:
|
||||||
test: true
|
test: true
|
||||||
session:
|
session:
|
||||||
storage_id: session.storage.mock_file
|
storage_id: session.storage.mock_file
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
monolog:
|
monolog:
|
||||||
handlers:
|
handlers:
|
||||||
main:
|
main:
|
||||||
type: stream
|
type: stream
|
||||||
path: "%kernel.logs_dir%/%kernel.environment%.log"
|
path: "%kernel.logs_dir%/%kernel.environment%.log"
|
||||||
level: debug
|
level: debug
|
||||||
channels: ["!event"]
|
channels: [ "!event" ]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
web_profiler:
|
web_profiler:
|
||||||
toolbar: false
|
toolbar: false
|
||||||
intercept_redirects: false
|
intercept_redirects: false
|
||||||
|
|
||||||
framework:
|
framework:
|
||||||
profiler: { collect: false }
|
profiler: { collect: false }
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
framework:
|
framework:
|
||||||
default_locale: '%locale%'
|
default_locale: '%locale%'
|
||||||
translator:
|
translator:
|
||||||
paths:
|
paths:
|
||||||
- '%kernel.project_dir%/translations'
|
- '%kernel.project_dir%/translations'
|
||||||
fallbacks:
|
fallbacks:
|
||||||
- '%locale%'
|
- '%locale%'
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
twig:
|
twig:
|
||||||
paths: ['%kernel.project_dir%/templates']
|
paths: [ '%kernel.project_dir%/templates' ]
|
||||||
debug: '%kernel.debug%'
|
debug: '%kernel.debug%'
|
||||||
strict_variables: '%kernel.debug%'
|
strict_variables: '%kernel.debug%'
|
||||||
globals:
|
globals:
|
||||||
version: "%jotunheimr.version%"
|
version: "%jotunheimr.version%"
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
services:
|
services:
|
||||||
_defaults:
|
_defaults:
|
||||||
public: false
|
public: false
|
||||||
autowire: true
|
autowire: true
|
||||||
autoconfigure: true
|
autoconfigure: true
|
||||||
|
|
||||||
#Twig\Extensions\ArrayExtension: ~
|
#Twig\Extensions\ArrayExtension: ~
|
||||||
#Twig\Extensions\DateExtension: ~
|
#Twig\Extensions\DateExtension: ~
|
||||||
#Twig\Extensions\IntlExtension: ~
|
#Twig\Extensions\IntlExtension: ~
|
||||||
#Twig\Extensions\TextExtension: ~
|
#Twig\Extensions\TextExtension: ~
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
webpack_encore:
|
webpack_encore:
|
||||||
# The path where Encore is building the assets.
|
# The path where Encore is building the assets.
|
||||||
# This should match Encore.setOutputPath() in webpack.config.js.
|
# This should match Encore.setOutputPath() in webpack.config.js.
|
||||||
output_path: '%kernel.project_dir%/public/build'
|
output_path: '%kernel.project_dir%/public/build'
|
||||||
# If multiple builds are defined (as shown below), you can disable the default build:
|
# If multiple builds are defined (as shown below), you can disable the default build:
|
||||||
# output_path: false
|
# output_path: false
|
||||||
|
|
||||||
# if using Encore.enableIntegrityHashes() specify the crossorigin attribute value (default: false, or use 'anonymous' or 'use-credentials')
|
# if using Encore.enableIntegrityHashes() specify the crossorigin attribute value (default: false, or use 'anonymous' or 'use-credentials')
|
||||||
# crossorigin: 'anonymous'
|
# crossorigin: 'anonymous'
|
||||||
|
|
||||||
# Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes).
|
# Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes).
|
||||||
# To enable caching for the production environment, creating a webpack_encore.yaml in the config/packages/prod directory with this value set to true
|
# To enable caching for the production environment, creating a webpack_encore.yaml in the config/packages/prod directory with this value set to true
|
||||||
# Available in version 1.2
|
# Available in version 1.2
|
||||||
#cache: false
|
#cache: false
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class MercureController extends AbstractController
|
|||||||
#[Route('/api/game/start', name: 'MineSeekerBundle_api_game_start', methods: ['POST'])]
|
#[Route('/api/game/start', name: 'MineSeekerBundle_api_game_start', methods: ['POST'])]
|
||||||
public function start(Request $request): JsonResponse
|
public function start(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
$data = $request->toArray();
|
$data = $request->toArray();
|
||||||
$result = $this->rpcManager->saveGrid($data['gameAssoc']);
|
$result = $this->rpcManager->saveGrid($data['gameAssoc']);
|
||||||
|
|
||||||
return $this->json(['success' => $result]);
|
return $this->json(['success' => $result]);
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ class RpcManager implements RpcManagerInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$users = $this->getUserCollection($playedGame);
|
$users = $this->getUserCollection($playedGame);
|
||||||
$revealedCells = $this->aggregateRevealedCells($playedGame);
|
$revealedCells = $this->aggregateRevealedCells($playedGame);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -85,9 +85,9 @@ class RpcManager implements RpcManagerInterface
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$grid2d = $this->generateGrid();
|
$grid2d = $this->generateGrid();
|
||||||
$playedGame = new PlayedGame();
|
$playedGame = new PlayedGame();
|
||||||
$grid = new Grid();
|
$grid = new Grid();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
foreach ($grid2d as $row) {
|
foreach ($grid2d as $row) {
|
||||||
@@ -127,7 +127,7 @@ class RpcManager implements RpcManagerInterface
|
|||||||
|
|
||||||
// Fisher-Yates shuffle
|
// Fisher-Yates shuffle
|
||||||
for ($i = count($set) - 1; $i > 0; $i--) {
|
for ($i = count($set) - 1; $i > 0; $i--) {
|
||||||
$j = random_int(0, $i);
|
$j = random_int(0, $i);
|
||||||
[$set[$i], $set[$j]] = [$set[$j], $set[$i]];
|
[$set[$i], $set[$j]] = [$set[$j], $set[$i]];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,10 +180,10 @@ class RpcManager implements RpcManagerInterface
|
|||||||
private function getUserCollection(PlayedGame $playedGame): array
|
private function getUserCollection(PlayedGame $playedGame): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'red' => null !== $playedGame->getRed() ? $playedGame->getRed()->getUsername() : '',
|
'red' => null !== $playedGame->getRed() ? $playedGame->getRed()->getUsername() : '',
|
||||||
'blue' => null !== $playedGame->getBlue() ? $playedGame->getBlue()->getUsername() : '',
|
'blue' => null !== $playedGame->getBlue() ? $playedGame->getBlue()->getUsername() : '',
|
||||||
'redAnon' => null !== $playedGame->getRedAnon() ? $playedGame->getRedAnon()->getUserName() : '',
|
'redAnon' => null !== $playedGame->getRedAnon() ? $playedGame->getRedAnon()->getUserName() : '',
|
||||||
'blueAnon' => null !== $playedGame->getBlueAnon()? $playedGame->getBlueAnon()->getUserName(): '',
|
'blueAnon' => null !== $playedGame->getBlueAnon() ? $playedGame->getBlueAnon()->getUserName() : '',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,9 +19,9 @@ use App\Interfaces\TopicManagerInterface;
|
|||||||
use DateTime;
|
use DateTime;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Exception;
|
use Exception;
|
||||||
use RuntimeException;
|
|
||||||
use JsonException;
|
use JsonException;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use RuntimeException;
|
||||||
use Symfony\Component\Mercure\HubInterface;
|
use Symfony\Component\Mercure\HubInterface;
|
||||||
use Symfony\Component\Mercure\Update;
|
use Symfony\Component\Mercure\Update;
|
||||||
use Symfony\Component\Security\Core\User\UserInterface;
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
@@ -52,8 +52,8 @@ class TopicManager implements TopicManagerInterface
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$users = $this->getUserCollection($playedGame);
|
$users = $this->getUserCollection($playedGame);
|
||||||
$count = $this->getPlayerCount($users);
|
$count = $this->getPlayerCount($users);
|
||||||
$isKnown = in_array($userName, array_filter(array_values($users)), true);
|
$isKnown = in_array($userName, array_filter(array_values($users)), true);
|
||||||
|
|
||||||
/** Reject a third player who is not a reconnecting player */
|
/** Reject a third player who is not a reconnecting player */
|
||||||
@@ -105,9 +105,9 @@ class TopicManager implements TopicManagerInterface
|
|||||||
$this->saveResignToDb($gameAssoc, $event['resign']);
|
$this->saveResignToDb($gameAssoc, $event['resign']);
|
||||||
|
|
||||||
$playedGame = $this->getPlayedGame($gameAssoc);
|
$playedGame = $this->getPlayedGame($gameAssoc);
|
||||||
$users = $this->getUserCollection($playedGame);
|
$users = $this->getUserCollection($playedGame);
|
||||||
$count = $this->getPlayerCount($users);
|
$count = $this->getPlayerCount($users);
|
||||||
$topic = 'mineseeker/channel/' . $gameAssoc;
|
$topic = 'mineseeker/channel/' . $gameAssoc;
|
||||||
|
|
||||||
$data = ['resign' => $event['resign'], 'coords' => null];
|
$data = ['resign' => $event['resign'], 'coords' => null];
|
||||||
|
|
||||||
@@ -134,10 +134,10 @@ class TopicManager implements TopicManagerInterface
|
|||||||
// ------------------------------------------------------------------ //
|
// ------------------------------------------------------------------ //
|
||||||
$coords = $event['coords'];
|
$coords = $event['coords'];
|
||||||
$player = $event['player']; // 'red' | 'blue'
|
$player = $event['player']; // 'red' | 'blue'
|
||||||
$isBomb = (bool) $event['bomb'];
|
$isBomb = (bool)$event['bomb'];
|
||||||
|
|
||||||
$playedGame = $this->getPlayedGame($gameAssoc);
|
$playedGame = $this->getPlayedGame($gameAssoc);
|
||||||
$grid = $this->loadGrid($gameAssoc);
|
$grid = $this->loadGrid($gameAssoc);
|
||||||
|
|
||||||
// Cells already revealed by previous steps (as "row,col" => true map)
|
// Cells already revealed by previous steps (as "row,col" => true map)
|
||||||
$alreadyRevealed = $this->buildRevealedMap($playedGame);
|
$alreadyRevealed = $this->buildRevealedMap($playedGame);
|
||||||
@@ -152,10 +152,10 @@ class TopicManager implements TopicManagerInterface
|
|||||||
$revealedCells = $this->floodFill($grid, $coords[0], $coords[1], $alreadyRevealed);
|
$revealedCells = $this->floodFill($grid, $coords[0], $coords[1], $alreadyRevealed);
|
||||||
}
|
}
|
||||||
|
|
||||||
$minesFound = count(array_filter($revealedCells, static fn($c) => 'm' === $c['value']));
|
$minesFound = count(array_filter($revealedCells, static fn($c) => 'm' === $c['value']));
|
||||||
$redPoints = ($playedGame->getRedPoints() ?? 0) + ('red' === $player ? $minesFound : 0);
|
$redPoints = ($playedGame->getRedPoints() ?? 0) + ('red' === $player ? $minesFound : 0);
|
||||||
$bluePoints = ($playedGame->getBluePoints() ?? 0) + ('blue' === $player ? $minesFound : 0);
|
$bluePoints = ($playedGame->getBluePoints() ?? 0) + ('blue' === $player ? $minesFound : 0);
|
||||||
$gameOver = $redPoints > 25 || $bluePoints > 25;
|
$gameOver = $redPoints > 25 || $bluePoints > 25;
|
||||||
|
|
||||||
// Reveal remaining mines when the game ends
|
// Reveal remaining mines when the game ends
|
||||||
$leftMines = [];
|
$leftMines = [];
|
||||||
@@ -232,13 +232,13 @@ class TopicManager implements TopicManagerInterface
|
|||||||
* Reveals the clicked cell plus all connected zero-value cells and their non-mine borders.
|
* Reveals the clicked cell plus all connected zero-value cells and their non-mine borders.
|
||||||
* Mines are never added to the result.
|
* Mines are never added to the result.
|
||||||
*
|
*
|
||||||
* @param array<string, true> $visited Map of "row,col" already revealed; updated in-place.
|
* @param array<string, true> $visited Map of "row,col" already revealed; updated in-place.
|
||||||
*/
|
*/
|
||||||
private function floodFill(array $grid, int $row, int $col, array &$visited): array
|
private function floodFill(array $grid, int $row, int $col, array &$visited): array
|
||||||
{
|
{
|
||||||
$cells = [];
|
$cells = [];
|
||||||
$queue = [[$row, $col]];
|
$queue = [[$row, $col]];
|
||||||
$dirs = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]];
|
$dirs = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]];
|
||||||
|
|
||||||
while (!empty($queue)) {
|
while (!empty($queue)) {
|
||||||
[$r, $c] = array_shift($queue);
|
[$r, $c] = array_shift($queue);
|
||||||
@@ -265,8 +265,8 @@ class TopicManager implements TopicManagerInterface
|
|||||||
// Only expand neighbours for zero-cells
|
// Only expand neighbours for zero-cells
|
||||||
if (0 === $value) {
|
if (0 === $value) {
|
||||||
foreach ($dirs as [$dr, $dc]) {
|
foreach ($dirs as [$dr, $dc]) {
|
||||||
$nr = $r + $dr;
|
$nr = $r + $dr;
|
||||||
$nc = $c + $dc;
|
$nc = $c + $dc;
|
||||||
$nKey = $nr . ',' . $nc;
|
$nKey = $nr . ',' . $nc;
|
||||||
if (!isset($visited[$nKey]) && isset($grid[$nr][$nc])) {
|
if (!isset($visited[$nKey]) && isset($grid[$nr][$nc])) {
|
||||||
$queue[] = [$nr, $nc];
|
$queue[] = [$nr, $nc];
|
||||||
@@ -290,12 +290,12 @@ class TopicManager implements TopicManagerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
[$row, $col ], [$row - 2, $col - 2], [$row - 2, $col ], [$row - 2, $col + 2],
|
[$row, $col], [$row - 2, $col - 2], [$row - 2, $col], [$row - 2, $col + 2],
|
||||||
[$row, $col - 2], [$row, $col + 2], [$row + 2, $col - 2], [$row + 2, $col ],
|
[$row, $col - 2], [$row, $col + 2], [$row + 2, $col - 2], [$row + 2, $col],
|
||||||
[$row + 2, $col + 2], [$row - 2, $col + 1], [$row - 2, $col - 1],
|
[$row + 2, $col + 2], [$row - 2, $col + 1], [$row - 2, $col - 1],
|
||||||
[$row - 1, $col - 2], [$row - 1, $col - 1], [$row - 1, $col ], [$row - 1, $col + 1], [$row - 1, $col + 2],
|
[$row - 1, $col - 2], [$row - 1, $col - 1], [$row - 1, $col], [$row - 1, $col + 1], [$row - 1, $col + 2],
|
||||||
[$row, $col - 1], [$row, $col + 1],
|
[$row, $col - 1], [$row, $col + 1],
|
||||||
[$row + 1, $col - 2], [$row + 1, $col - 1], [$row + 1, $col ], [$row + 1, $col + 1], [$row + 1, $col + 2],
|
[$row + 1, $col - 2], [$row + 1, $col - 1], [$row + 1, $col], [$row + 1, $col + 1], [$row + 1, $col + 2],
|
||||||
[$row + 2, $col - 1], [$row + 2, $col + 1],
|
[$row + 2, $col - 1], [$row + 2, $col + 1],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -307,8 +307,8 @@ class TopicManager implements TopicManagerInterface
|
|||||||
private function getBombRevealedCells(array $grid, int $row, int $col, array $alreadyRevealed): array
|
private function getBombRevealedCells(array $grid, int $row, int $col, array $alreadyRevealed): array
|
||||||
{
|
{
|
||||||
$bombCells = $this->getBombRadius($row, $col);
|
$bombCells = $this->getBombRadius($row, $col);
|
||||||
$visited = $alreadyRevealed;
|
$visited = $alreadyRevealed;
|
||||||
$cells = [];
|
$cells = [];
|
||||||
|
|
||||||
foreach ($bombCells as [$r, $c]) {
|
foreach ($bombCells as [$r, $c]) {
|
||||||
$key = $r . ',' . $c;
|
$key = $r . ',' . $c;
|
||||||
@@ -318,11 +318,11 @@ class TopicManager implements TopicManagerInterface
|
|||||||
|
|
||||||
if ('m' === $grid[$r][$c]) {
|
if ('m' === $grid[$r][$c]) {
|
||||||
$visited[$key] = true;
|
$visited[$key] = true;
|
||||||
$cells[] = ['row' => $r, 'col' => $c, 'value' => 'm'];
|
$cells[] = ['row' => $r, 'col' => $c, 'value' => 'm'];
|
||||||
} else {
|
} else {
|
||||||
// flood-fill handles the zero-cascade and deduplication via $visited
|
// flood-fill handles the zero-cascade and deduplication via $visited
|
||||||
$newCells = $this->floodFill($grid, $r, $c, $visited);
|
$newCells = $this->floodFill($grid, $r, $c, $visited);
|
||||||
$cells = array_merge($cells, $newCells);
|
$cells = array_merge($cells, $newCells);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,7 +376,7 @@ class TopicManager implements TopicManagerInterface
|
|||||||
|
|
||||||
private function getPlayerCount(array $users): int
|
private function getPlayerCount(array $users): int
|
||||||
{
|
{
|
||||||
$red = '' !== $users['red'] || '' !== $users['redAnon'] ? 1 : 0;
|
$red = '' !== $users['red'] || '' !== $users['redAnon'] ? 1 : 0;
|
||||||
$blue = '' !== $users['blue'] || '' !== $users['blueAnon'] ? 1 : 0;
|
$blue = '' !== $users['blue'] || '' !== $users['blueAnon'] ? 1 : 0;
|
||||||
|
|
||||||
return $red + $blue;
|
return $red + $blue;
|
||||||
@@ -404,7 +404,7 @@ class TopicManager implements TopicManagerInterface
|
|||||||
$step = new Step();
|
$step = new Step();
|
||||||
$step->setRow($event['coords'][0]);
|
$step->setRow($event['coords'][0]);
|
||||||
$step->setCol($event['coords'][1]);
|
$step->setCol($event['coords'][1]);
|
||||||
$step->setWBomb((bool) $event['bomb']);
|
$step->setWBomb((bool)$event['bomb']);
|
||||||
$step->setPlayer($player);
|
$step->setPlayer($player);
|
||||||
$step->setRevealedCells($revealedCells);
|
$step->setRevealedCells($revealedCells);
|
||||||
$step->setPlayedGame($playedGame);
|
$step->setPlayedGame($playedGame);
|
||||||
@@ -413,8 +413,8 @@ class TopicManager implements TopicManagerInterface
|
|||||||
|
|
||||||
$playedGame->setRedPoints($redPoints);
|
$playedGame->setRedPoints($redPoints);
|
||||||
$playedGame->setBluePoints($bluePoints);
|
$playedGame->setBluePoints($bluePoints);
|
||||||
$playedGame->setRedExplodedBomb((bool) $event['bomb'] && 'red' === $player ? true : null);
|
$playedGame->setRedExplodedBomb((bool)$event['bomb'] && 'red' === $player ? true : null);
|
||||||
$playedGame->setBlueExplodedBomb((bool) $event['bomb'] && 'blue' === $player ? true : null);
|
$playedGame->setBlueExplodedBomb((bool)$event['bomb'] && 'blue' === $player ? true : null);
|
||||||
$playedGame->setUpdated(new DateTime());
|
$playedGame->setUpdated(new DateTime());
|
||||||
$this->entityManager->persist($playedGame);
|
$this->entityManager->persist($playedGame);
|
||||||
|
|
||||||
@@ -483,9 +483,9 @@ class TopicManager implements TopicManagerInterface
|
|||||||
private function getUserCollection(PlayedGame $playedGame): array
|
private function getUserCollection(PlayedGame $playedGame): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'red' => null !== $playedGame->getRed() ? $playedGame->getRed()->getUsername() : '',
|
'red' => null !== $playedGame->getRed() ? $playedGame->getRed()->getUsername() : '',
|
||||||
'blue' => null !== $playedGame->getBlue() ? $playedGame->getBlue()->getUsername() : '',
|
'blue' => null !== $playedGame->getBlue() ? $playedGame->getBlue()->getUsername() : '',
|
||||||
'redAnon' => null !== $playedGame->getRedAnon() ? $playedGame->getRedAnon()->getUserName() : '',
|
'redAnon' => null !== $playedGame->getRedAnon() ? $playedGame->getRedAnon()->getUserName() : '',
|
||||||
'blueAnon' => null !== $playedGame->getBlueAnon() ? $playedGame->getBlueAnon()->getUserName() : '',
|
'blueAnon' => null !== $playedGame->getBlueAnon() ? $playedGame->getBlueAnon()->getUserName() : '',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user