Files
h-school/src/HSchool.People/NativeLanguages.cs
T
Leonid Pershin 5a00ad7746
ci / server (push) Failing after 3m44s
ci / client (push) Successful in 14s
Enhance school creation and staffing management with native language support
- Updated protocol documentation to include `nativeLanguages` in `nameSets` and added `nativeLanguage` to school creation options.
- Enhanced the UI for school creation to allow selection of native languages, improving user experience.
- Revised API interfaces to accommodate new native language features, ensuring proper data handling.
- Improved localization strings to support new native language functionalities in both English and Russian.
- Updated tests to validate the new native language features and ensure robust functionality in staffing scenarios.
2026-08-19 22:22:31 +03:00

39 lines
1.3 KiB
C#

namespace HSchool.People;
/// <summary>
/// A name set can speak several native languages; the school picks one. Empty request rolls from
/// the school seed so the same create always lands on the same tongue.
/// </summary>
public static class NativeLanguages
{
public static bool Allows(NameSetDef names, string skill) =>
names.Spoken.Contains(skill, StringComparer.Ordinal);
/// <summary>
/// <paramref name="requested"/> must already be in the set, or empty. Invalid ids return
/// null so the create path can 400. When omitted, a new school rolls; a reload without a
/// saved pick takes the first listed language so old saves do not reshuffle intake.
/// </summary>
public static string? Pick(NameSetDef names, int schoolSeed, string? requested, bool rollIfOmitted)
{
var spoken = names.Spoken;
if (spoken.Count == 0)
{
return null;
}
if (!string.IsNullOrWhiteSpace(requested))
{
return Allows(names, requested) ? requested : null;
}
if (!rollIfOmitted || spoken.Count == 1)
{
return spoken[0];
}
var rng = new Random(Seed.ForSchool(schoolSeed, Seed.NativeLanguageSalt));
return spoken[rng.Next(spoken.Count)];
}
}