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.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
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)];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user