PHP code example of mistralys / x4-core

1. Go to this page and download the library: Download mistralys/x4-core library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mistralys / x4-core example snippets


use Mistralys\X4\Database\Factions\FactionDefs;

echo "Available factions:" . PHP_EOL;

foreach(FactionDefs::getInstance()->getAll() as $faction) {
    echo $faction->getLabel() . PHP_EOL;
}

use Mistralys\X4\Database\Factions\KnownFactions;

$argon = KnownFactions::getInstance()->getArgon();

echo $argon->getLabel(); // Outputs "Argon"

use Mistralys\X4\Database\Wares\WareDefs;

echo "Available wares:" . PHP_EOL;

foreach(WareDefs::getInstance()->getAll() as $ware) {
    echo $ware->getLabel() . PHP_EOL;
}

use Mistralys\X4\Database\Wares\WareDefs;

$advancedElectronics = WareDefs::getInstance()
    ->getByID('module_gen_prod_advancedelectronics_01');

use Mistralys\X4\Database\Wares\WareDefs;
use Mistralys\X4\Database\Wares\WareGroups;
use Mistralys\X4\Database\DataSources\KnownDataSources;

$boronEngines = WareDefs::getInstance()
    ->findWares()
    ->selectDataSource(KnownDataSources::DATA_SOURCE_KINGDOM_END)
    ->selectGroup(WareGroups::GROUP_ENGINES)
    ->getAll();

use Mistralys\X4\Database\Ships\ShipDefs;

echo "Available ships:" . PHP_EOL;

foreach(ShipDefs::getInstance()->getAll() as $ship) {
    echo $ship->getLabel() . PHP_EOL;
}

use Mistralys\X4\Database\Translations\Languages;

$english = Languages::getInstance()->getEnglish();

$shipName = $english->t('{20101,20604}');