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:
1 parent
0d1f73f19e
commit
2cc409f12a
3 files changed
+20
-7
No files matched your search
@@ -26,12 +26,17 @@ namespace Cthangover.LocaleAtlas
|
|||||||
/// <item>manifest — <c>mod_<id>_name</c>/<c>_desc</c> used by the mod manager
|
/// <item>manifest — <c>mod_<id>_name</c>/<c>_desc</c> used by the mod manager
|
||||||
/// (optional: the manifest text is the fallback).</item>
|
/// (optional: the manifest text is the fallback).</item>
|
||||||
/// </list>
|
/// </list>
|
||||||
/// Collection files (<c>collections/*.json</c>) are also checked for inline
|
/// Collection packages come as sources named <see cref="CollectionSourcePrefix"/>
|
||||||
/// <c>locale</c> entries: a literal <c>name</c>/<c>description</c> is the
|
/// + id: their <c>locale/</c> files are declarations like a mod's, and their
|
||||||
/// <c>en</c> text, every other project language needs a <c>locale</c> entry.
|
/// <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>
|
/// </summary>
|
||||||
public static class LocaleAtlasBuilder
|
public static class LocaleAtlasBuilder
|
||||||
{
|
{
|
||||||
|
/// <summary>Source id prefix of a collection package (<c>collection:<id></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>
|
/// <summary>Language of literal collection texts (fallback in <c>ModCollection.GetLocalizedName</c>).</summary>
|
||||||
public const string CollectionBaseLanguage = "en";
|
public const string CollectionBaseLanguage = "en";
|
||||||
|
|
||||||
@@ -66,6 +71,8 @@ namespace Cthangover.LocaleAtlas
|
|||||||
result.Mods.Add(modId);
|
result.Mods.Add(modId);
|
||||||
ScanLocaleFiles(modId, provider, result);
|
ScanLocaleFiles(modId, provider, result);
|
||||||
ScanReferences(modId, provider, result, collections, documents);
|
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}_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 });
|
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);
|
AddMatches(SceneText, text, file, modId, "scene", result);
|
||||||
break;
|
break;
|
||||||
case ".json":
|
case ".json":
|
||||||
var isCollection = file.StartsWith("collections/", StringComparison.Ordinal);
|
var isCollection = file == "collection.json" && modId.StartsWith(CollectionSourcePrefix, StringComparison.Ordinal);
|
||||||
if (!isCollection)
|
if (!isCollection)
|
||||||
AddMatches(JsonTextField, text, file, modId, "json", result);
|
AddMatches(JsonTextField, text, file, modId, "json", result);
|
||||||
AddMatches(JsonAtKey, text, file, modId, isCollection ? "collection" : "json", result);
|
AddMatches(JsonAtKey, text, file, modId, isCollection ? "collection" : "json", result);
|
||||||
|
|||||||
@@ -91,6 +91,12 @@ namespace Cthangover.LocaleAtlas
|
|||||||
result.Add((info.Id, info.FileProvider));
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -170,13 +170,13 @@ namespace Cthangover.LocaleAtlas.Tests
|
|||||||
[ModTest("map/collection_texts_need_every_language")]
|
[ModTest("map/collection_texts_need_every_language")]
|
||||||
static void CollectionTextsNeedEveryLanguage(ModTestContext ctx)
|
static void CollectionTextsNeedEveryLanguage(ModTestContext ctx)
|
||||||
{
|
{
|
||||||
var mod = new MemoryProvider("m")
|
var package = new MemoryProvider("c")
|
||||||
.Add("locale/en.properties", "x = X\n")
|
.Add("locale/en.properties", "x = X\n")
|
||||||
.Add("locale/ru.properties", "x = Икс\n")
|
.Add("locale/ru.properties", "x = Икс\n")
|
||||||
.Add("collections/c.json",
|
.Add("collection.json",
|
||||||
"{ \"id\": \"c\", \"name\": \"Game\", \"locale\": [ { \"lang\": \"ru\", \"name\": \"Игра\" } ],\n" +
|
"{ \"id\": \"c\", \"name\": \"Game\", \"locale\": [ { \"lang\": \"ru\", \"name\": \"Игра\" } ],\n" +
|
||||||
" \"mechanics\": [ { \"id\": \"m1\", \"name\": \"Story\" }, { \"id\": \"m2\", \"name\": \"@x\" } ] }");
|
" \"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();
|
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(1, missing.Count, "only the literal mechanic without ru: " + string.Join("; ", missing.Select(f => f.Message)));
|
||||||
ModAssert.Equal("m1", missing[0].Key, "mechanic id");
|
ModAssert.Equal("m1", missing[0].Key, "mechanic id");
|
||||||
|
|||||||
Reference in new issue
Block a user