Collections are packages of their own

A collection is no longer a file inside a mod: it is a package (folder or zip)
named after its id with collection.json, cover and optional locale/, shipped in
collections/ next to the mods or kept by the player in user://collections/.
Covers and texts come from the package; mods do not ship collections.
This commit is contained in:
cthangover committed 2026-10-18 19:21:34 +02:00
1 parent 0d1f73f19e
commit 2cc409f12a
3 files changed
+20 -7

No files matched your search

+11 -4
View File
@@ -26,12 +26,17 @@ namespace Cthangover.LocaleAtlas
/// <item>manifest — <c>mod_&lt;id&gt;_name</c>/<c>_desc</c> used by the mod manager
/// (optional: the manifest text is the fallback).</item>
/// </list>
/// Collection files (<c>collections/*.json</c>) are also checked for inline
/// <c>locale</c> entries: a literal <c>name</c>/<c>description</c> is the
/// <c>en</c> text, every other project language needs a <c>locale</c> entry.
/// Collection packages come as sources named <see cref="CollectionSourcePrefix"/>
/// + id: their <c>locale/</c> files are declarations like a mod's, and their
/// <c>collection.json</c> is checked for inline <c>locale</c> entries — a
/// literal <c>name</c>/<c>description</c> is the <c>en</c> text, every other
/// project language needs a <c>locale</c> entry.
/// </summary>
public static class LocaleAtlasBuilder
{
/// <summary>Source id prefix of a collection package (<c>collection:&lt;id&gt;</c>), as opposed to a mod.</summary>
public const string CollectionSourcePrefix = "collection:";
/// <summary>Language of literal collection texts (fallback in <c>ModCollection.GetLocalizedName</c>).</summary>
public const string CollectionBaseLanguage = "en";
@@ -66,6 +71,8 @@ namespace Cthangover.LocaleAtlas
result.Mods.Add(modId);
ScanLocaleFiles(modId, provider, result);
ScanReferences(modId, provider, result, collections, documents);
if (modId.StartsWith(CollectionSourcePrefix, StringComparison.Ordinal))
continue;
result.References.Add(new LocaleReference { Key = $"mod_{modId}_name", ModId = modId, File = "manifest.json", Via = "manifest", Optional = true });
result.References.Add(new LocaleReference { Key = $"mod_{modId}_desc", ModId = modId, File = "manifest.json", Via = "manifest", Optional = true });
}
@@ -229,7 +236,7 @@ namespace Cthangover.LocaleAtlas
AddMatches(SceneText, text, file, modId, "scene", result);
break;
case ".json":
var isCollection = file.StartsWith("collections/", StringComparison.Ordinal);
var isCollection = file == "collection.json" && modId.StartsWith(CollectionSourcePrefix, StringComparison.Ordinal);
if (!isCollection)
AddMatches(JsonTextField, text, file, modId, "json", result);
AddMatches(JsonAtKey, text, file, modId, isCollection ? "collection" : "json", result);
+6
View File
@@ -91,6 +91,12 @@ namespace Cthangover.LocaleAtlas
result.Add((info.Id, info.FileProvider));
}
foreach (var collection in ModCollectionStore.LoadAll())
{
if (collection.Package != null)
result.Add((LocaleAtlasBuilder.CollectionSourcePrefix + collection.Id, collection.Package));
}
return result;
}
+3 -3
View File
@@ -170,13 +170,13 @@ namespace Cthangover.LocaleAtlas.Tests
[ModTest("map/collection_texts_need_every_language")]
static void CollectionTextsNeedEveryLanguage(ModTestContext ctx)
{
var mod = new MemoryProvider("m")
var package = new MemoryProvider("c")
.Add("locale/en.properties", "x = X\n")
.Add("locale/ru.properties", "x = Икс\n")
.Add("collections/c.json",
.Add("collection.json",
"{ \"id\": \"c\", \"name\": \"Game\", \"locale\": [ { \"lang\": \"ru\", \"name\": \"Игра\" } ],\n" +
" \"mechanics\": [ { \"id\": \"m1\", \"name\": \"Story\" }, { \"id\": \"m2\", \"name\": \"@x\" } ] }");
var result = LocaleAtlasBuilder.Build(new[] { ("m", (IModFileProvider)mod) });
var result = LocaleAtlasBuilder.Build(new[] { (LocaleAtlasBuilder.CollectionSourcePrefix + "c", (IModFileProvider)package) });
var missing = result.Findings.Where(f => f.Code == "collection_text_missing").ToList();
ModAssert.Equal(1, missing.Count, "only the literal mechanic without ru: " + string.Join("; ", missing.Select(f => f.Message)));
ModAssert.Equal("m1", missing[0].Key, "mechanic id");