Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Space Merchant Realms open-source game engine

License

NotificationsYou must be signed in to change notification settings

smrealms/smr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Run TestsTest CoveragePHPStan LevelBuild Live

Installation

Dependencies

Make sure the following software is installed:

  • docker (version 19.03.0+)
  • docker compose plugin (v2)

To run unit tests on your machine:

  • Composer (2.0.5+)

Setup

First, you will need to clone this repository. Then inside the clone, youwill need to create installation-specific copies of the following files:

  • .env.sample.env
  • .my.cnf.sample.my.cnf
  • config/config.specific.sample.phpconfig/config.specific.php

The sample versions have sensible defaults, but update the copies as necessary.The options must be consistent between the various configuration files.

Populate the mysql database

To initialize the database or update it with new patches, run:

docker compose run --rm flyway

To modify the database, add a file calledV<VERSION_NUMBER>__<NAME>.sql intodb/patches and rerun the command.

You can optionally start upphpMyAdmin toinspect your mysql database in a web browser athttp://localhost/pma/:

docker compose up --build -d pma

Start up the services

Then you can start up the persistent game services

docker compose up --build -d traefik smr

Runtime

Permissions

In order to create an admin account you should first create a standard accountvia the register form, then run the following command to give that accountadmin permissions:

db/init_admin.sh

The account should now have an "Admin Tools" link on the left whilst logged in,which will allow you to assign any extra permissions to yourself and others.

Creating a Game

To create a game you will have to have assigned yourself the "1.6 Universe Generator" and then access this link via the admin tools to create the game.Once you are happy with the game you need to edit the "game" table and set the "enabled" flag for your game to 'TRUE' in order for it to appear in the list of games to join.

Coding Style

This is the coding style that should be used for any new code, although currently not all code currently follows these guidelines (the guidelines are also likely to require extension).

  • Opening races should be placed on the same line with a single space before

  • Single line if statements should still include braces

    if (true) { }
  • Variable names should be camelCase normally, except when in templates when they should be UpperCamelCase (to enforce some mental separation between the two contexts).

    $applicationVar ='value';$TemplateVar ='value';
  • Function names should be camelCase, class names should be UpperCamelCase

    functionexampleFunction() { }class ExampleClass {publicfunctionexampleMethod() { } }
  • Associative array indices should be UpperCamelCase

    $container['SectorID'] =$sectorID;

SMR-isms

File inclusion

Classes should be added tosrc/lib/Smr to take advantage of the PSR-4 autoloader.Engine files and their associated templates should be placed insrc/engine andsrc/templates respectively (seePage::process for how they will be included).

Links

If possible use a function fromGlobals or a relevant object to generate links (e.g.Globals::getCurrentSectorHREF() or$otherPlayer->getExamineTraderHREF()).This is usually clearer and allows hooking into the hotkey system.To create a link you first create a "container" using aPage class, e.g.:

$container =newCurrentSector();

You can then call$container->href() to get a HREF, which will give a link thatcan be displayed on the page. In this example, clicking the link will load the"Current Sector" page next.

You can also call$container->go(), which will immediately forward to this pagewithin the same HTTP request.

Request variables

For any page which takes input through POST or GET, these values may be accessedusingSmr\Session::getRequestVar() and relatives, which will store the valuein the session. When a page is auto-refreshed with AJAX, these inputs are notresent, but they are still required to render the page correctly.

Abstract vs normal classes

This initially started out to be used in the "standard" way for NPCs but that idea has since been discarded.Now all core/shared "Default" code should be in the abstract version, with the normal class child implementing game type specific functionality/overrides, for instance "lib/Semi Wars/Account" which is used to make every account appear to be a "vet" account when playing semi wars.

Unit testing

SMR usesPHPUnit to run unit tests.

Setup

  1. Ensure the MySQL container is running, and ready for any integration tests that touch the database:
    • composer start:test-services
  2. Runcomposer phpunit to execute the full suite of PHPUnit tests.
  3. Add new tests as needed in the/test directory.

Setting up your IDE to run tests

This information applies to IDEA-based IDEs, e.g.IntelliJ,PHPStorm. For other vendors, please refer to your vendor's documentation for running PHPUnit tests against a remote container.

  • In order to perform these next steps inIntelliJ, you must have the following Jetbrains-provided plugins installed:
  • PHP
  • PHP Docker
Configure a remote PHP interpreter for the project
  1. File > Settings > Languages & Frameworks > PHP. In theCLI Interpreter area, click the... button
  2. Press the "+" button in the top left, and selectFrom Docker, Vagrant, VM, WSL, Remote...
  3. In the new window, chooseDocker Compose, and in theService area, selectphpunit. Press "OK".
  4. It will check the configuration by starting up the Docker container, and gathering PHP information. Once that's finished, you should be on a configuration screen for the new interpreter. It should have the PHP information from the Docker container, and also theXdebug information.
  5. In theEnvironment variables box on the new intepreter's screen, paste in the values from/test/env in the project directory.
  6. The rest of the default settings should be fine, so you can press "Apply".
  7. On the settings navigation tree, underneath PHP, click theComposer item: In theCLI Interpreter drop down, select the new interpreter you've created. Press "Apply".
  8. On the settings navigation tree, underneath PHP, click theTest Frameworks item.
  9. Click the+ button to create an entry, select the newly created interpreter from the drop down, and press "OK".
  10. In thePHPUnit library section, set thePath to script value to/smr/vendor/autoload.php
  11. In theTest Runner section, set theDefault configuration file to/smr/phpunit.xml
  12. Press "OK", and you should be good to go for executing tests inside the IDE.

Writing integration tests

  1. To create an integration test that uses the database, your test should extendSmrTest\BaseIntegrationSpec. This will ensure that any test data that gets written to the database will be cleaned up after each test.
  • The SMR database uses MyISAM for a storage engine, so we cannot simply rollback transactions after each test. Instead, theBaseIntegrationSpec will check for any tables that are populated from theflyway migration during startup, and truncate all other tables after your test.

About

Space Merchant Realms open-source game engine

Topics

Resources

License

Stars

Watchers

Forks


[8]ページ先頭

©2009-2025 Movatter.jp