-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathFabricModDependencyProblem.php
More file actions
136 lines (117 loc) · 4.87 KB
/
FabricModDependencyProblem.php
File metadata and controls
136 lines (117 loc) · 4.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
namespace Aternos\Codex\Minecraft\Analysis\Problem\Fabric;
use Aternos\Codex\Analysis\InsightInterface;
use Aternos\Codex\Minecraft\Analysis\Solution\Forge\ModInstallSolution;
use Aternos\Codex\Minecraft\Translator\Translator;
/**
* Class FabricModDependencyProblem
*
* @package Aternos\Codex\Minecraft\Analysis\Problem\Fabric
*/
class FabricModDependencyProblem extends FabricModProblem
{
protected ?string $dependency = null;
/**
* Get a human-readable message
*
* @return string
*/
public function getMessage(): string
{
$mods = "'" . $this->getDependency() . "'";
return Translator::getInstance()->getTranslation("mod-dependency-problem", ["mod-name" => $this->getModName(), "dependency-mod-name" => $mods]);
}
/**
* Get an array of possible patterns
*
* The array key of the pattern will be passed to setMatches()
*
* @return string[]
*/
public static function getPatterns(): array
{
return [
'short-error' => '/net\.fabricmc\.loader\.discovery\.ModResolutionException: Could not find required mod: ' . static::$modNamePattern . ' requires {' . static::$modNamePattern . ' @ \[([^\]]+)\]}/',
'any' => "/\s*- Mod " . static::$modNamePattern . "(?: [^ ]+)? requires any version of (?:mod )?" . static::$modNamePattern . ",/",
'minimum' => "/\s*- Mod " . static::$modNamePattern . "(?: [^ ]+)? requires version ([^ ]+) or later of (?:mod )?" . static::$modNamePattern . ",/",
'any-after' => "/\s*- Mod " . static::$modNamePattern . "(?: [^ ]+)? requires any version after ([^ ]+) of (?:mod )?" . static::$modNamePattern . ",/",
'any-before' => "/\s*- Mod " . static::$modNamePattern . "(?: [^ ]+)? requires any version before ([^ ]+) of (?:mod )?" . static::$modNamePattern . ",/",
'specific' => "/\s*- Mod " . static::$modNamePattern . "(?: [^ ]+)? requires version ([^ ]+) of (?:mod )?" . static::$modNamePattern . ",/",
'between' => "/\s*- Mod " . static::$modNamePattern . "(?: [^ ]+)? requires any version between ([^ ]+) \((inclusive|exclusive)\) and ([^ ]+) \((inclusive|exclusive)\) of (?:mod )?" . static::$modNamePattern . ",/"
];
}
/**
* Apply the matches from the pattern
*
* @param array $matches
* @param mixed $patternKey
* @return void
*/
public function setMatches(array $matches, mixed $patternKey): void
{
switch ($patternKey) {
case 'short-error':
$this->setModName($matches[2]);
$this->setDependency($matches[empty($matches[3]) ? 4 : 3]);
$solution = (new ModInstallSolution())->setModName($this->getDependency());
if ($matches[5] != '*') {
$solution->setModVersion($matches[5]);
}
$this->addSolution($solution);
return;
case 'any':
$this->setModName($matches[1]);
$this->setDependency($matches[empty($matches[3]) ? 4 : 3]);
$this->addSolution((new ModInstallSolution())->setModName($this->getDependency()));
return;
case 'minimum':
$symbol = ">=";
break;
case 'any-after':
$symbol = ">";
break;
case 'any-before':
$symbol = "<";
break;
case 'between':
$this->setModName($matches[1]);
$this->setDependency($matches[7]);
$firstSymbol = $matches[4] === "exclusive" ? ">" : ">=";
$secondSymbol = $matches[6] === "exclusive" ? "<" : "<=";
$this->addSolution((new ModInstallSolution())
->setModName($this->getDependency())
->setModVersion($firstSymbol . $matches[3] . ", " . $secondSymbol . $matches[5]));
return;
default:
$symbol = "";
break;
}
$this->setModName($matches[1]);
$this->setDependency($matches[empty($matches[4]) ? 5 : 4]);
$this->addSolution((new ModInstallSolution())->setModName($this->getDependency())->setModVersion($symbol . $matches[3]));
}
/**
* @return string|null
*/
public function getDependency(): ?string
{
return $this->dependency;
}
/**
* @param string $dependency
* @return $this
*/
protected function setDependency(string $dependency): static
{
$this->dependency = $this->getReplacedModName($dependency);
return $this;
}
/**
* @param InsightInterface $insight
* @return bool
*/
public function isEqual(InsightInterface $insight): bool
{
return $insight instanceof static && parent::isEqual($insight) && $this->getDependency() == $insight->getDependency();
}
}