Skip to content

Commit 53beba1

Browse files
committed
Warning when :FOR and :NEEDS use the same "tag" (modName).
1 parent 60a903b commit 53beba1

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

Source/ModuleManager/ModListGenerator.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ public static IEnumerable<string> GenerateModList(IEnumerable<ModAddedByAssembly
123123
mods.Add(dependency);
124124
modListInfo.AppendFormat(" {0}\n", dependency);
125125
}
126+
127+
if (name.Contains(":NEEDS["))
128+
{
129+
string needs = (name.Substring(name.IndexOf(":NEEDS[") + 7));
130+
needs = needs.Substring(0, needs.IndexOf(']'));
131+
needs = needs.Replace("!", "").Replace('&', ',').Replace('|', ',');
132+
foreach (string s in needs.Split(',')) if (dependency.Equals(s))
133+
progress.ForWithInvalidNeedsWarning(dependency, cfgmod);
134+
}
126135
}
127136
catch (ArgumentOutOfRangeException)
128137
{

Source/ModuleManager/Progress/IPatchProgress.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public interface IPatchProgress
2626
EventData<IPass> OnPassStarted { get; }
2727

2828
void Warning(UrlDir.UrlConfig url, string message, params object[] @params);
29+
void ForWithInvalidNeedsWarning(string modName, UrlDir.UrlConfig cfgmod);
2930
void Error(UrlDir.UrlConfig url, string message, params object[] @params);
3031
void Error(string message, params object[] @params);
3132
void Exception(Exception exception, string message, params object[] @params);

Source/ModuleManager/Progress/PatchProgress.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ public void Warning(UrlDir.UrlConfig url, string message, params object[] @param
130130
RecordWarningFile(url);
131131
}
132132

133+
public void ForWithInvalidNeedsWarning(string tag, UrlDir.UrlConfig url)
134+
{
135+
Counter.warnings.Increment();
136+
logger.Warning("Name {0} shouldn't be used both on :FOR and :NEEDS, as :FOR takes precedence rendering :NEEDS innocuous. Check file {1} node: {2}", tag, url.parent.url, url.type);
137+
RecordWarningFile(url);
138+
}
139+
133140
public void Error(UrlDir.UrlConfig url, string message, params object[] @params)
134141
{
135142
Counter.errors.Increment();

Tests/ForNeedsSameName.cfg

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@PART[HeatShield0]:FOR[forneedstest]:NEEDS[forneedstest]
2+
{
3+
}
4+
5+
@PART[HeatShield0]:FOR[forneedstest]:NEEDS[forneedstest,Squad,Something,Else]
6+
{
7+
}
8+
9+
@PART[HeatShield0]:FOR[forneedstest]:NEEDS[!forneedstest&Squad|Something,!Else]
10+
{
11+
}
12+
13+
@PART[HeatShield0]:FOR[forneedstest]:NEEDS[Squad|!Something]
14+
{
15+
}

0 commit comments

Comments
 (0)