Enhance school creation and map management features by updating the API to support mod packs and map layouts. Introduce a new map snapshot protocol for efficient data handling during school sessions. Revise documentation to reflect these changes, including updates to the protocol and architecture documents. Improve UI components for mod selection and map editing, ensuring a better user experience. Update tests to validate new functionalities and ensure robustness.
This commit is contained in:
@@ -29,6 +29,50 @@ internal sealed class ModContent
|
||||
|
||||
public bool PackExists(string packId) => Directory.Exists(PackPath(packId));
|
||||
|
||||
/// <summary>
|
||||
/// Pack folder names are identifiers, not paths. Anything that could escape <see cref="Root"/>
|
||||
/// is rejected before it reaches the disk.
|
||||
/// </summary>
|
||||
public static bool IsSafePackId(string packId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(packId) || packId.Length > 64)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var ch in packId)
|
||||
{
|
||||
if (!char.IsAsciiLetterOrDigit(ch) && ch is not '-' and not '_')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public IReadOnlyList<ModPackInfo> ListPacks()
|
||||
{
|
||||
var packs = new List<ModPackInfo> { new(CatalogLoader.CorePackId, Required: true) };
|
||||
if (!Directory.Exists(Root))
|
||||
{
|
||||
return packs;
|
||||
}
|
||||
|
||||
foreach (var directory in Directory.GetDirectories(Root).OrderBy(path => path, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
var id = Path.GetFileName(directory);
|
||||
if (id.Equals(CatalogLoader.CorePackId, StringComparison.OrdinalIgnoreCase) || !IsSafePackId(id))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
packs.Add(new ModPackInfo(id, Required: false));
|
||||
}
|
||||
|
||||
return packs;
|
||||
}
|
||||
|
||||
public IReadOnlyList<string> NormalizePackIds(IReadOnlyList<string>? extraModIds) =>
|
||||
CatalogLoader.NormalizePackOrder(extraModIds ?? []);
|
||||
|
||||
@@ -90,5 +134,9 @@ internal sealed class ModContent
|
||||
return map;
|
||||
}
|
||||
|
||||
public DefCatalog LoadCatalog(IReadOnlyList<string> packIds) => LoadCatalog(packIds, _logger);
|
||||
|
||||
private string PackPath(string packId) => Path.Combine(Root, packId);
|
||||
}
|
||||
|
||||
internal sealed record ModPackInfo(string Id, bool Required);
|
||||
|
||||
Reference in New Issue
Block a user