Add HSchool.Content project for JSONC definitions, catalog, and map validation. Update solution structure to include new content and tests projects. Enhance school management to support mod packs and map instances, ensuring proper loading and validation. Revise documentation to reflect these changes and update tests for new functionality.
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
namespace HSchool.Content;
|
||||
|
||||
internal static class PackPaths
|
||||
{
|
||||
public static string Normalize(string relativePath) => relativePath.Replace('\\', '/').TrimStart('/');
|
||||
|
||||
public static bool IsJsonc(string relativePath)
|
||||
{
|
||||
var path = Normalize(relativePath);
|
||||
return path.EndsWith(".jsonc", StringComparison.OrdinalIgnoreCase)
|
||||
|| path.EndsWith(".json", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public static bool TryGetDefKind(string relativePath, out DefKind kind)
|
||||
{
|
||||
kind = default;
|
||||
var parts = Normalize(relativePath).Split('/');
|
||||
if (parts.Length < 3 || !parts[0].Equals("defs", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return TryMapFolder(parts[1], out kind);
|
||||
}
|
||||
|
||||
public static bool IsPatch(string relativePath)
|
||||
{
|
||||
var path = Normalize(relativePath);
|
||||
return path.StartsWith("patches/", StringComparison.OrdinalIgnoreCase) && IsJsonc(path);
|
||||
}
|
||||
|
||||
public static bool TryGetLocaleLanguage(string relativePath, out string language)
|
||||
{
|
||||
language = string.Empty;
|
||||
var path = Normalize(relativePath);
|
||||
if (!path.StartsWith("localizations/", StringComparison.OrdinalIgnoreCase) || !IsJsonc(path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var file = Path.GetFileNameWithoutExtension(path);
|
||||
if (file.Equals("ru", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
language = "ru";
|
||||
return true;
|
||||
}
|
||||
|
||||
if (file.Equals("en", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
language = "en";
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsDefaultMap(string relativePath) =>
|
||||
Normalize(relativePath).Equals("maps/default.jsonc", StringComparison.OrdinalIgnoreCase)
|
||||
|| Normalize(relativePath).Equals("maps/default.json", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
private static bool TryMapFolder(string folder, out DefKind kind)
|
||||
{
|
||||
switch (folder.ToLowerInvariant())
|
||||
{
|
||||
case "actions":
|
||||
kind = DefKind.Action;
|
||||
return true;
|
||||
case "things":
|
||||
kind = DefKind.Thing;
|
||||
return true;
|
||||
case "positions":
|
||||
kind = DefKind.Position;
|
||||
return true;
|
||||
case "works":
|
||||
kind = DefKind.Work;
|
||||
return true;
|
||||
case "rooms":
|
||||
kind = DefKind.Room;
|
||||
return true;
|
||||
case "buildings":
|
||||
kind = DefKind.Building;
|
||||
return true;
|
||||
case "floors":
|
||||
kind = DefKind.Floor;
|
||||
return true;
|
||||
case "territories":
|
||||
kind = DefKind.Territory;
|
||||
return true;
|
||||
default:
|
||||
kind = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user