Add resolveCollection task: resolves config.toml like server startup and prints results.
This commit is contained in:
1 parent
8484d6c20c
commit
e07e946a87
8 files changed
+122
-18
No files matched your search
@@ -62,18 +62,23 @@ record Resolution(List<Resolution.Item> items, List<Resolution.Item> excluded, L
|
||||
modIds = Math.max(modIds, Resolution.modIds(item).length());
|
||||
}
|
||||
|
||||
lines.add("# Mod list");
|
||||
lines.add("Mod List:");
|
||||
|
||||
for (int i = 0; i < this.items.size(); i++)
|
||||
{
|
||||
Item item = this.items.get(i);
|
||||
lines.add(("# %" + number + "d. %-" + title + "s %10s %-" + modIds + "s").formatted(i + 1, item.title(), item.id(), Resolution.modIds(item)).stripTrailing());
|
||||
//noinspection StringConcatenationInFormatCall
|
||||
lines.add(
|
||||
("%" + number + "d. %-" + title + "s %10s %-" + modIds + "s").formatted(
|
||||
i + 1, item.title(), item.id(), Resolution.modIds(item)
|
||||
).stripTrailing()
|
||||
);
|
||||
}
|
||||
|
||||
if (!this.excluded.isEmpty())
|
||||
{
|
||||
lines.add("# Excluded");
|
||||
for (Item item : this.excluded) lines.add("# %s %s".formatted(item.title(), item.id()));
|
||||
lines.add("Excluded:");
|
||||
for (Item item : this.excluded) lines.add(" %s %s".formatted(item.title(), item.id()));
|
||||
}
|
||||
|
||||
return lines;
|
||||
|
||||
@@ -190,13 +190,13 @@ class CollectionResolverTest
|
||||
List<String> modList = CollectionResolver.resolve(CollectionResolverTest.COLLECTION, CollectionResolverTest.DEFAULT_ORDER, items).modList();
|
||||
|
||||
assertEquals(List.of(
|
||||
"# Mod list",
|
||||
"# 1. A Map 300 MapMod",
|
||||
"# 2. Framework 200 Frame",
|
||||
"# 3. Misc One 100 MiscOne",
|
||||
"# 4. Misc Two 400 MiscTwo, MiscTwoExtra",
|
||||
"# Excluded",
|
||||
"# Misc Three 500"
|
||||
"Mod List:",
|
||||
"1. A Map 300 MapMod",
|
||||
"2. Framework 200 Frame",
|
||||
"3. Misc One 100 MiscOne",
|
||||
"4. Misc Two 400 MiscTwo, MiscTwoExtra",
|
||||
"Excluded:",
|
||||
" Misc Three 500"
|
||||
), modList);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package dev.overlord.luamodautomator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Resolves a collection like the server does at startup, without the server: binds the shipped
|
||||
* defaults with a {@code config.toml} on top, asks Steam, and prints the mod list,
|
||||
* {@code Mods=}, {@code WorkshopItems=}, {@code Map=}, and every warning. Run through
|
||||
* {@code ./gradlew resolveCollection --args=<config.toml>}.
|
||||
*/
|
||||
public final class ResolveCollection
|
||||
{
|
||||
private ResolveCollection() {}
|
||||
|
||||
public static void main(String[] args) throws IOException
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
System.err.println("Usage: ./gradlew resolveCollection --args=<config.toml>");
|
||||
System.exit(2);
|
||||
}
|
||||
|
||||
Path config = Path.of(args[0]);
|
||||
|
||||
if (!Files.isRegularFile(config))
|
||||
{
|
||||
System.err.println("'" + config.toAbsolutePath() + "' does not exist.");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
List<String> warnings = new ArrayList<>();
|
||||
Settings settings = SettingsTest.bind(Files.readString(config, StandardCharsets.UTF_8), warnings);
|
||||
String id = SteamWorkshopApi.collectionId(settings.collection()).orElse("");
|
||||
|
||||
if (id.isEmpty())
|
||||
{
|
||||
System.err.println("'collection' in '" + args[0] + "' holds no collection id.");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
try (SteamWorkshopApi api = new SteamWorkshopApi(SteamWorkshopApi.BASE, Duration.ofSeconds(settings.steam().timeoutS()), "LuaModAutomator/resolveCollection"))
|
||||
{
|
||||
Resolution resolution = CollectionResolver.resolve(api.collection(id, warnings), settings.order(), settings.items());
|
||||
ServerValues values = resolution.values(settings.ini().baseMap());
|
||||
|
||||
warnings.addAll(resolution.warnings());
|
||||
|
||||
resolution.modList().forEach(System.out::println);
|
||||
System.out.println();
|
||||
System.out.println("Mods=" + values.mods());
|
||||
System.out.println();
|
||||
System.out.println("WorkshopItems=" + values.workshopItems());
|
||||
System.out.println();
|
||||
System.out.println("Map=" + values.map());
|
||||
|
||||
for (String warning : warnings) System.err.println("WARNING: " + warning);
|
||||
}
|
||||
catch (SteamException | ConfigurationException e)
|
||||
{
|
||||
System.err.println(e.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,9 +109,9 @@ class SteamWorkshopApiTest
|
||||
Settings settings = SettingsTest.bind("");
|
||||
Resolution resolution = CollectionResolver.resolve(this.api.collection(SteamWorkshopApiTest.recordedId(), new ArrayList<>()), settings.order(), settings.items());
|
||||
ServerValues values = resolution.values(settings.ini().baseMap());
|
||||
List<String> expected = SteamWorkshopApiTest.resource("script-output.txt").lines().toList();
|
||||
List<String> expected = SteamWorkshopApiTest.withoutCommentPrefix(SteamWorkshopApiTest.resource("script-output.txt").lines().toList());
|
||||
|
||||
List<String> actual = new ArrayList<>(resolution.modList());
|
||||
List<String> actual = new ArrayList<>(resolution.modList().subList(1, resolution.modList().size()));
|
||||
actual.add("Mods=" + values.mods());
|
||||
actual.add("WorkshopItems=" + values.workshopItems());
|
||||
|
||||
@@ -207,6 +207,9 @@ class SteamWorkshopApiTest
|
||||
assertFalse(items.get(0).found());
|
||||
}
|
||||
|
||||
/** The script's output without its mod list header, and the mod list lines without their {@code "# "}. */
|
||||
private static List<String> withoutCommentPrefix(List<String> output) { return output.stream().skip(1).map(line -> line.startsWith("# ") ? line.substring(2) : line).toList(); }
|
||||
|
||||
/** Details for every even id of the request: title {@code Item <id>}, Mod ID {@code Mod<id>}. */
|
||||
private static Response details(Map<String, String> form)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user