Handle Mod IDs with spaces; warn and recommend confirmation in overrides.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
389b5b19d7
commit
0763730a24
5 files changed
+56
-30
No files matched your search
@@ -45,10 +45,11 @@ replaces those values at every start anyway.
|
||||
|
||||
For every item of the collection, Steam's Web API returns its title, tags, and description.
|
||||
|
||||
- **Mod IDs** come from description lines such as `Mod ID: Foo` or `ModID = Foo; Bar`; IDs may
|
||||
also be separated by `/`, `or`, or `and`, and a dash between spaces (`Foo - B42 only`) ends
|
||||
the list. An item without one stays in `WorkshopItems=` (so the server downloads it) but is
|
||||
left out of `Mods=`, with a warning; `[items.<id>] mod_ids` supplies it. The same applies to
|
||||
- **Mod IDs** come from description lines such as `Mod ID: Foo` or `ModID = Foo; Bar`. A Mod
|
||||
ID may contain spaces (`Mod ID: Nicks Moveable Workstations - Furniture Fix`); `Mods=` then
|
||||
lists it as written, with a warning until `[items.<id>] mod_ids` confirms or corrects it. An
|
||||
item without one stays in `WorkshopItems=` (so the server downloads it) but is left out of
|
||||
`Mods=`, with a warning; `[items.<id>] mod_ids` supplies it. The same applies to
|
||||
items Steam returns no details for (private, unlisted, or removed items inside the
|
||||
collection).
|
||||
- **Buckets** decide the load order: `map` (a `Map Folder:` line in the description),
|
||||
|
||||
@@ -66,6 +66,16 @@ final class CollectionResolver
|
||||
warnings.add("Steam returns no details for " + item.id() + " (private, unlisted, or removed); it stays in WorkshopItems= but not in Mods=. Set [items." + item.id() + "] mod_ids to load it.");
|
||||
}
|
||||
|
||||
// Mod IDs may contain spaces, but "Mod ID: Foo Bar" may also mean two of them.
|
||||
if (override.modIds().isEmpty())
|
||||
{
|
||||
for (String modId : result.modIds())
|
||||
{
|
||||
if (modId.chars().anyMatch(Character::isWhitespace))
|
||||
warnings.add("'" + result.title() + "' (" + item.id() + ") names the Mod ID '" + modId + "', which contains spaces; Mods= lists it as written. Set [items." + item.id() + "] mod_ids to confirm or correct it.");
|
||||
}
|
||||
}
|
||||
|
||||
if (item.map() && item.mapFolders().isEmpty())
|
||||
warnings.add("'" + result.title() + "' (" + item.id() + ") has a Map Folder line without a folder name; it adds nothing to Map=.");
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package dev.overlord.luamodautomator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -19,22 +18,22 @@ final class DescriptionParser
|
||||
private static final Pattern MOD_IDS = Pattern.compile("(?im)^\\s*Mod\\s*IDs?\\h*[:=]\\h*(.+)$");
|
||||
private static final Pattern MAP_LINE = Pattern.compile("(?im)^\\s*Map\\s*Folder\\h*[:=]");
|
||||
private static final Pattern MAP_FOLDER = Pattern.compile("(?im)^\\s*Map\\s*Folder\\h*[:=]\\h*(.+)$");
|
||||
private static final Pattern COMMENT = Pattern.compile("\\h+[-–—]\\h.*$");
|
||||
private static final Pattern SEPARATOR = Pattern.compile("[\\s,;/]+");
|
||||
private static final Pattern MOD_ID = Pattern.compile("[A-Za-z0-9_.\\-]*[A-Za-z0-9][A-Za-z0-9_.\\-]*");
|
||||
private static final Pattern SEPARATOR = Pattern.compile("[,;]");
|
||||
private static final Pattern WHITESPACE = Pattern.compile("\\s+");
|
||||
|
||||
/** Words between Mod IDs, as in {@code Mod ID: Foo or Foo_Lite}. */
|
||||
private static final Set<String> CONJUNCTIONS = Set.of("or", "and");
|
||||
/** Words of letters, digits, {@code _}, {@code .}, and {@code -}, separated by spaces; with at least one letter or digit. */
|
||||
private static final Pattern MOD_ID = Pattern.compile("(?=.*[A-Za-z0-9])[A-Za-z0-9_.\\-]+(?:\\h+[A-Za-z0-9_.\\-]+)*");
|
||||
|
||||
private DescriptionParser() {}
|
||||
|
||||
static String stripBbcode(String description) { return DescriptionParser.BBCODE.matcher(description).replaceAll(""); }
|
||||
|
||||
/**
|
||||
* Every Mod ID of every {@code Mod ID} line, each once, in order of appearance. Mod IDs are
|
||||
* separated by spaces, {@code ,}, {@code ;}, {@code /}, {@code or}, or {@code and}; a dash
|
||||
* between spaces ({@code Foo - B42 only}) starts a comment that ends the line; tokens
|
||||
* without a letter or digit, or with other characters, are skipped.
|
||||
* Every Mod ID of every {@code Mod ID} line, each once, in order of appearance. Mod IDs on
|
||||
* one line are separated by {@code ,} or {@code ;}, and may contain spaces
|
||||
* ({@code Nicks Moveable Workstations - Furniture Fix}, as in its {@code mod.info}). A part
|
||||
* with other characters ({@code Foo (B41)}) yields those of its words that are Mod IDs; parts
|
||||
* without a letter or digit yield none.
|
||||
*/
|
||||
static List<String> modIds(String description)
|
||||
{
|
||||
@@ -43,11 +42,20 @@ final class DescriptionParser
|
||||
|
||||
while (matcher.find())
|
||||
{
|
||||
String line = DescriptionParser.COMMENT.matcher(matcher.group(1)).replaceFirst("");
|
||||
|
||||
for (String token : DescriptionParser.SEPARATOR.split(line.strip()))
|
||||
for (String part : DescriptionParser.SEPARATOR.split(matcher.group(1)))
|
||||
{
|
||||
if (DescriptionParser.MOD_ID.matcher(token).matches() && !DescriptionParser.CONJUNCTIONS.contains(token.toLowerCase(Locale.ROOT))) modIds.add(token);
|
||||
String modId = part.strip();
|
||||
|
||||
if (DescriptionParser.MOD_ID.matcher(modId).matches())
|
||||
{
|
||||
modIds.add(modId);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (String token : DescriptionParser.WHITESPACE.split(modId))
|
||||
{
|
||||
if (DescriptionParser.MOD_ID.matcher(token).matches()) modIds.add(token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -196,6 +196,18 @@ class CollectionResolverTest
|
||||
assertEquals(List.of("Mod IDs 'Shared' of 'One' (100) and 'shared' of 'Two' (200) differ only in case; Mods= lists both."), resolution.warnings());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modIdWithSpacesIsListedWithAWarningUntilAnOverrideConfirmsIt() throws ConfigurationException
|
||||
{
|
||||
List<WorkshopItem> collection = List.of(CollectionResolverTest.item("3809993153", "Furniture Fix", "Mod ID: Nicks Moveable Workstations - Furniture Fix"));
|
||||
Resolution parsed = CollectionResolver.resolve(collection, CollectionResolverTest.DEFAULT_ORDER, Map.of());
|
||||
Resolution confirmed = CollectionResolver.resolve(collection, CollectionResolverTest.DEFAULT_ORDER, Map.of("3809993153", CollectionResolverTest.modIds("Nicks Moveable Workstations - Furniture Fix")));
|
||||
|
||||
assertEquals("\\Nicks Moveable Workstations - Furniture Fix", parsed.values(List.of()).mods());
|
||||
assertEquals(List.of("'Furniture Fix' (3809993153) names the Mod ID 'Nicks Moveable Workstations - Furniture Fix', which contains spaces; Mods= lists it as written. Set [items.3809993153] mod_ids to confirm or correct it."), parsed.warnings());
|
||||
assertEquals(List.of(), confirmed.warnings());
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapFoldersThenBaseMapEachOnce() throws ConfigurationException
|
||||
{
|
||||
|
||||
@@ -44,27 +44,22 @@ class DescriptionParserTest
|
||||
}
|
||||
|
||||
@Test
|
||||
void modIdsSkipTokensWithoutLetterOrDigit()
|
||||
void modIdsSkipPartsWithoutLetterOrDigit()
|
||||
{
|
||||
assertEquals(List.of("Foo", "Bar"), DescriptionParser.modIds("Mod ID: Foo -- Bar ..."));
|
||||
assertEquals(List.of("Foo", "Bar"), DescriptionParser.modIds("Mod ID: Foo; --; Bar, ..."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void modIdsSeparatedByWords()
|
||||
void modIdWithSpacesStaysWhole()
|
||||
{
|
||||
assertEquals(List.of("Foo", "Foo_Lite", "Bar", "Baz"), DescriptionParser.modIds("Mod ID: Foo or Foo_Lite\nMod IDs: Bar AND Baz"));
|
||||
// 3809993153: mod.info has id=Nicks Moveable Workstations - Furniture Fix
|
||||
assertEquals(List.of("Nicks Moveable Workstations - Furniture Fix"), DescriptionParser.modIds("Mod id: Nicks Moveable Workstations - Furniture Fix\nid=3809993153"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void modIdsSeparatedBySlashes()
|
||||
void modIdsWithSpacesSeparatedBySemicolons()
|
||||
{
|
||||
assertEquals(List.of("Foo", "FooLite"), DescriptionParser.modIds("Mod ID: Foo/FooLite"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void spacedDashStartsAComment()
|
||||
{
|
||||
assertEquals(List.of("Bar", "Baz-Lite"), DescriptionParser.modIds("Mod ID: Bar - B42 only\nMod ID: Baz-Lite – optional"));
|
||||
assertEquals(List.of("Foo Bar", "Baz"), DescriptionParser.modIds("Mod IDs: Foo Bar ; Baz"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user