-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4cc0eff
Showing
7 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Mods.txt | ||
Both.txt | ||
WorkshopItems.txt | ||
composer.lock | ||
/vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# PZConfigHelper | ||
|
||
PZConfigHelper is a PHP tool designed to generate mod lists for Project Zomboid from a specified directory structure. It scans directories to create lists of mod IDs and workshop items, and saves these lists to text files. | ||
|
||
## Installation | ||
|
||
Clone the repository to your local machine: | ||
|
||
```sh | ||
git clone https://github.com/yourusername/PZConfigHelper.git | ||
``` | ||
|
||
Navigate to the project directory: | ||
|
||
```sh | ||
cd PZConfigHelper | ||
``` | ||
|
||
## Usage | ||
|
||
Run the script with the `--path` option to specify the directory containing the mods: | ||
|
||
```sh | ||
php src/PZConfigHelper/PZConfigHelper.php --path='D:\\SteamLibrary\\steamapps\\workshop\\content\\108600' | ||
``` | ||
|
||
This will generate three files in the current working directory: | ||
- `Mods.txt`: Contains a list of mod names. | ||
- `WorkshopItems.txt`: Contains a list of workshop item IDs. | ||
- `Both.txt`: Contains a combined list of mod names and workshop item IDs. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. | ||
|
||
## Author | ||
|
||
Valithor Obsidion <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "valgorithms/pzconfighelper", | ||
"description": "PZConfigHelper is a PHP tool designed to generate mod lists for Project Zomboid.", | ||
"keywords": ["project-zomboid", "mod-list", "workshop-items"], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Valithor Obsidion", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=7.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"PZConfigHelper\\": "src/PZConfigHelper/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
require_once 'vendor/autoload.php'; | ||
|
||
use PZConfigHelper\PZConfigHelper; | ||
|
||
$options = getopt("", ["path:"]); | ||
if (!isset($options['path'])) die("Usage: php example.php --path='D:\\SteamLibrary\\steamapps\\workshop\\content\\108600'"); | ||
|
||
$helper = new PZConfigHelper($options['path']); | ||
$helper->saveToFile(getcwd()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
/* | ||
* This file is a part of the PZConfigHelper project. | ||
* | ||
* Copyright (c) 2024-present Valithor Obsidion <[email protected]> | ||
*/ | ||
|
||
namespace PZConfigHelper; | ||
|
||
class PZConfigHelper | ||
{ | ||
use PZConfigHelperTrait; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is a part of the PZConfigHelper project. | ||
* | ||
* Copyright (c) 2024-present Valithor Obsidion <[email protected]> | ||
*/ | ||
|
||
namespace PZConfigHelper; | ||
|
||
interface PZConfigHelperInterface | ||
{ | ||
public function __construct(string $path = __DIR__); | ||
public function generateModLists(?string $directory = null, bool $isRootDirectory = true): void; | ||
public function saveToFile(string $directory = __DIR__): void; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
/* | ||
* This file is a part of the PZConfigHelper project. | ||
* | ||
* Copyright (c) 2024-present Valithor Obsidion <[email protected]> | ||
*/ | ||
|
||
namespace PZConfigHelper; | ||
|
||
trait PZConfigHelperTrait | ||
{ | ||
private string $mods = ''; | ||
private string $ids = ''; | ||
private string $both = ''; | ||
|
||
public function __construct(private string $path = __DIR__) { | ||
$this->generateModLists(); | ||
} | ||
|
||
public function generateModLists(?string $directory = null, bool $isRootDirectory = true): void | ||
{ | ||
$directory = $directory ?? $this->path; | ||
|
||
foreach (scandir($directory) as $file) { | ||
if ($file === '.' || $file === '..') continue; | ||
if (!is_dir($filePath = $directory . '/' . $file)) continue; | ||
if ($isRootDirectory) { // Root level directory, should contain Mod IDs | ||
$this->ids .= $file . ';'; | ||
$this->both .= $file . '='; | ||
$this->generateModLists($filePath, false); | ||
$this->both .= PHP_EOL; | ||
} else { | ||
// Nested directory, should contain Workshop Item names | ||
if (basename($filePath) === 'mods') { | ||
foreach (scandir($filePath) as $modFile) { | ||
if ($modFile === '.' || $modFile === '..') continue; | ||
if (is_dir($filePath . '/' . $modFile)) { | ||
$this->mods .= $modFile . ';'; | ||
$this->both .= $modFile . ';'; | ||
} | ||
} | ||
} else { | ||
$this->generateModLists($filePath, false); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public function saveToFile(string $directory = __DIR__): void | ||
{ | ||
file_put_contents($directory . '/Mods.txt', $this->mods); | ||
file_put_contents($directory . '/WorkshopItems.txt', $this->ids); | ||
file_put_contents($directory . '/Both.txt', $this->both); | ||
} | ||
|
||
public function __get(string $name) | ||
{ | ||
return $this->$name ?? null; | ||
} | ||
|
||
public function serialize(): string | ||
{ | ||
return serialize($this->__toArray()); | ||
} | ||
|
||
public function unserialize($data): void | ||
{ | ||
$array = unserialize($data); | ||
$this->mods = $array['mods']; | ||
$this->ids = $array['ids']; | ||
$this->both = $array['both']; | ||
} | ||
|
||
public function __toArray(): array | ||
{ | ||
return [ | ||
'mods' => $this->mods, | ||
'ids' => $this->ids, | ||
'both' => $this->both, | ||
]; | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return "$this->both"; | ||
} | ||
|
||
public function __debugInfo(): array | ||
{ | ||
return $this->__toArray(); | ||
} | ||
} |