mistralys/cyberpunk-mod-db-php

用于处理《赛博朋克2077》数据库的PHP类。

1.1.0 2024-09-22 17:03 UTC

This package is auto-updated.

Last update: 2024-09-22 17:28:33 UTC


README

PHP类,用于访问《赛博朋克2077》服装模数据库

要求

  • PHP 8.2或更高版本
  • Composer
  • 支持PHP的Web服务器

安装

  1. 使用Composer要求此包
  2. 确保通过Web服务器可以访问vendor目录。
composer require mistralys/cyberpunk-mod-db-php

使用方法

创建集合实例

use CPMDB\Mods\Collection\ModCollection;

// Create a collection instance
$collection = ModCollection::create(
    __DIR__.'/vendor', // Absolute path to the composer vendor directory
    __DIR__.'/cache', // Path to a writable directory to store cache files
    'http://127.0.0.1/your-app/vendor' // Absolute URL to the composer vendor directory
);

// Get all mods
$mods = $collection->getAll();

// Get only clothing mods
$clothing = $collection->categoryClothing()->getAll();

// Get a mod by its UUID (unique identifier, category ID + mod ID)
$catsuit = $collection->getByID('clothing.catsuit');

// Get the screenshot URL for a mod
if($catsuit->hasImage()) {
    echo '<img src"'.$catsuit->getImageURL().'">';
}

缓存

默认情况下,集合将缓存指定的缓存目录中的模数据。这样做是为了性能原因,因为模数据是从文件系统中读取的单独文件中读取的。

第一次创建集合实例时将自动创建缓存。

关闭缓存

如果需要,可以关闭缓存

use CPMDB\Mods\Collection\DataWriter\CacheDataWriter;

CacheDataWriter::setCacheEnabled(false);

性能测试

要检查您系统中缓存的性能,可以运行性能测试

php tests/performance/performance-test.php

标签

标签用于对模进行分类,使用在模文件中定义的简单字符串(例如,CET表示《赛博引擎调整》模)。所有在模数据库中使用的已知标签都已包含在包中。

标签也具有额外的元数据,例如标签和类别。

标签名称常量

可以使用匹配的标签类在代码中引用标签,这些类都有一个带有标签名称的常量。这使得避免拼写错误变得更加容易。

$cetTag = \CPMDB\Mods\Tags\Types\CyberEngineTweaks::TAG_NAME;
$clothingTag = \CPMDB\Mods\Tags\Types\Clothing::TAG_NAME;

获取所有已知标签

所有已知标签都可通过TagCollection类获得,该类具有访问它们的方法。

use CPMDB\Mods\Tags\TagCollection;
use CPMDB\Mods\Tags\Types\CyberEngineTweaks;

$collection = TagCollection::getInstance();

// Get all tags
$all = $collection->getAll();

// Get a specific tag
$cet = $collection->getByID(CyberEngineTweaks::TAG_NAME);

// Additional tag meta data
echo 'Full label: '.$cet->getLabel();
echo 'Tag category: '.$cet->getCategory();