Skip to content

add module system#1304

Open
rbardtke wants to merge 4 commits into
lanedirt:mainfrom
rbardtke:feature/1303-module-system
Open

add module system#1304
rbardtke wants to merge 4 commits into
lanedirt:mainfrom
rbardtke:feature/1303-module-system

Conversation

@rbardtke

Copy link
Copy Markdown
Contributor

Description

This PR introduces a modular extension system for OGameX, allowing features to be distributed as standalone Composer packages and installed on demand without modifying core files.

What was added:

  • ModuleServiceProvider (app/Modules/ModuleServiceProvider.php) — abstract base class all modules must extend. Handles automatic loading of routes, views, migrations, and translations from the package directory. Maintains a static discovery registry so the admin UI can list all installed modules regardless of how they were registered.
  • ModuleSlotService (app/Services/ModuleSlotService.php) — allows modules to inject rendered HTML fragments into named slots in core Blade templates via a @moduleSlot directive. Core views remain untouched; modules hook in declaratively.
  • config/modules.php — opt-in list of module provider classes to activate. A module must be Composer-installed AND listed here (or auto-discovered) to be active.
  • AppServiceProvider — updated to register providers from config/modules.php and skip any listed in storage/app/modules-disabled.json, which is readable before the DB boots.
  • Admin Modules page (/admin/modules) — lists all discovered modules with name, version, description, and enabled/disabled status. Supports toggling modules on/off at runtime without code changes.
  • Module contracts (app/Contracts/Modules/) — interfaces for modules that extend core services: ProvidesGameObjects, ProvidesQueueProcessor, ProvidesHighscoreCategory, ExtendsPlanetService, ExtendsPlayerService.
  • Documentation (docs/modules.md) — full developer guide covering package structure, available contracts, the slot system, and the module manifest format.

Showcase module: ogamex/admin-panel is provided as a reference implementation — a standalone Composer package installable via composer require ogamex/admin-panel that adds a dedicated admin panel at /admin-panel/. It is not bundled in this repo; it demonstrates the system works end-to-end with real Composer-based installation and auto-discovery.

Type of Change:

  • Bug fix
  • Feature enhancement
  • Documentation update
  • Other (please describe):

Related Issues

Fixes #1303

Checklist

Before submitting this pull request, ensure all following requirements as outlined in CONTRIBUTING.md are met:

  • Automated Refactoring: Rector has been run and no outstanding issues remain.
  • Code Standards: Code adheres to PSR-12 coding standards. Verified with Laravel Pint.
  • Static Analysis: Code passes PHPStan static code analysis.
  • Testing:
    • Relevant unit and feature tests are included or updated.
    • Tests successfully run locally.
  • CSS & JS Build: No CSS/JS changes — not applicable.
  • Documentation: docs/modules.md added with full developer guide.

Additional Information

Enable/disable without DB: Module state is stored in storage/app/modules-disabled.json (plain file, no database). This is intentional — service providers are registered before Eloquent is available, so a DB-based registry would cause boot-order failures.

Auto-discovery: Modules that declare their provider under extra.laravel.providers in their composer.json are picked up by Laravel's standard package discovery. No manual config/modules.php entry is required for Composer-installed modules; the admin UI will show them automatically.

No breaking changes: All additions are additive. Existing core behaviour is unchanged. The @moduleSlot calls added to overview/index.blade.php and resources/index.blade.php render nothing if no module has registered a handler for that slot.


How to test the showcase module (ogamex/admin-panel)

The admin-panel module is a standalone Composer package hosted at https://github.com/rbardtke/admin-panel. Follow these steps to install and verify it:

1. Add the VCS repository and install the package:

# Add to composer.json repositories array:
"repositories": [
        { "type": "vcs", "url": "https://github.com/rbardtke/admin-panel" }
],

composer require ogamex/admin-panel:@dev

2. Verify auto-discovery:

Navigate to /admin/modules while logged in as an admin. The Admin Panel module should appear in the list with status Enabled.

3. Verify the nav slot:

Open the classic admin panel at /admin. The sidebar should show an Advanced Panel link injected by the module without any core template changes.

4. Verify the dedicated panel:

Navigate to /admin-panel/. You should see the standalone dark-themed admin dashboard showing universe stats (total players, planets, active fleets) and a universe config summary.

5. Verify module pages:

  • /admin-panel/server-settings — edit and save a server setting, confirm it persists
  • /admin-panel/rules — edit a rules tab, confirm it saves
  • /admin-panel/developer-shortcuts — add units to a planet, confirm they appear in-game

6. Test disable/enable:

On /admin/modules, click Disable next to the Admin Panel module. Reload the page — the Advanced Panel link should disappear from the admin sidebar and /admin-panel/ should no longer be accessible. Click Enable to restore it.

…rovider::class)

  in ModulesController toggle() and index() to prevent arbitrary class instantiation
- Tests: add 11 unit tests covering module discovery registry, slot rendering,
  multi-renderer concatenation, data passing, and slot isolation
- Static state: add resetDiscovered() and resetSlots() methods to prevent test pollution
- JS safety: move @moduleSlot(layout.resources_bar_js) to after }); closing so modules
  cannot silently break the JS object literal
- Docs: clarify that auto-discovery is the primary installation path; manual
  config/modules.php entry is the fallback for packages without extra.laravel.providers
- Style: fix 2 Pint issues in AppServiceProvider and ModuleSystemTest
@github-actions

Copy link
Copy Markdown

Preview deployment

Preview environment for this PR is ready for functional testing. Use one of the test accounts below to log in.

Status URL Commit Last deployed
✅ Live https://pr-1304.preview.ogamex.dev e57b044 2026-03-29 19:02:15 UTC
Test accounts (click to expand)
Email (login) Password Role Class Planets Description
test1@ogamex.dev test admin Collector 2 Admin, high resources, mining focus
test2@ogamex.dev test player General 1 Military focus, ships & fleet
test3@ogamex.dev test player Discoverer 1 Exploration, probes & cargo ships
test4@ogamex.dev test player None 1 New player, no class selected yet
test5@ogamex.dev test moderator Collector 1 Moderator, balanced setup
test6@ogamex.dev test player General 1 Vacation mode enabled
test7@ogamex.dev test player General 3 Heavy defense across planets
test8@ogamex.dev test player Discoverer 1 Fleet focus, inactive (i) 8 days
test9@ogamex.dev test player Collector 1 Beginner, long inactive (I) 40 days
test10@ogamex.dev test player General 5 Endgame, 90 unread messages

This preview will be automatically destroyed when the PR is closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Module System

1 participant