String Resources
Namespaces:
RisingV.Shared.Strings
Stunlock.Core
(for PrefabGUID & Unit enums)RisingV.Shared.Prefabs
(forUnit
enum lookup)ProjectM.Terrain
(forWorldRegionType
enum lookup)
Assembly: RisingV.Shared
This document describes four “string‐helper” classes that centralize human‐readable names (long and short) for various game objects—items, prefabs, units, and world regions. Each class exposes static lookups or methods so that, given a numeric ID (GUID or enum), you can obtain a display name without scattering string literals throughout your code.
1. ItemStrings
namespace RisingV.Shared.Strings;
/// <summary>
/// Provides methods to retrieve strings (such as display names or tooltips) for items.
/// </summary>
public class ItemStrings
{
// (Currently empty; intended for future expansion.)
}
Purpose
A placeholder/resolver for future item‐related string lookups (e.g., “Iron Sword”, “Health Potion”).
Since no members are defined yet, you can extend this class with your own dictionaries or methods to map an item’s internal ID to a localized/long/short name.Usage Example
// eventually, you might write: string displayName = ItemStrings.GetLongName(itemPrefab.Guid); string tooltip = ItemStrings.GetDescription(itemPrefab.Guid);
Note:
As soon as you add item‐metadata (e.g., in JSON or a static dictionary), implement and exposestatic
lookup methods here.
2. PrefabStrings
using Stunlock.Core;
namespace RisingV.Shared.Strings;
/// <summary>
/// Provides methods to retrieve string names for “prefab” GUIDs,
/// re‐using the UnitStrings lookup under the hood.
/// </summary>
public static class PrefabStrings
{
/// <summary>
/// Attempts to resolve the “long” name for a given PrefabGUID (game object).
/// Delegates to UnitStrings.GetName if the GUID corresponds to a Unit.
/// </summary>
/// <param name="prefabGuid">The GUID (integer ID) of a prefab.</param>
/// <returns>
/// The human‐readable name for that prefab (e.g., “Vampire Boss”),
/// or null if no matching entry exists.
/// </returns>
public static string? GetName(PrefabGUID prefabGuid)
{
// Since some prefabs correspond to “Units” in the game, this method
// simply casts to the Unit enum and calls UnitStrings.GetName.
return UnitStrings.GetName(prefabGuid);
}
}
Purpose
To provide a unified “GetName” method for any prefab GUID, regardless of whether it’s a character/unit, an item, or a world object. Currently, it forwards requests toUnitStrings.GetName
. You can extend it later if other prefab types (e.g., buildings, interfaces) require dedicated lookups.Key Member
static string? GetName(PrefabGUID prefabGuid)
Returns astring?
(nullable) if the GUID exists in the underlyingUnitStrings
dictionary; otherwise returnsnull
.
Usage Example
PrefabGUID someGuid = /* some GUID from game data */; string? name = PrefabStrings.GetName(someGuid); if (!string.IsNullOrEmpty(name)) Log.Info($"Spawned prefab: {name}"); else Log.Warn($"Unknown prefab GUID: {someGuid}");
3. UnitStrings
using RisingV.Shared.Prefabs;
using Stunlock.Core;
namespace RisingV.Shared.Strings;
/// <summary>
/// Provides a mapping of “Unit”‐type prefab GUIDs (longs) to their long and short names.
/// </summary>
public static class UnitStrings
{
/// <summary>
/// The core lookup dictionary. Maps each Unit enum value to a (Long, Short) tuple.
/// For example:
/// Unit.VampireBoss → (“Vampire Boss Lord”, “Vampire Boss”)
/// Unit.VampireMinion → (“Vampire Minion”, “Minion”)
/// </summary>
private static readonly Dictionary<Unit, (string Long, string Short)> PrefabToNames = new()
{
// Example entries (the real file contains all Unit enum values):
{ Unit.VampireBoss, ("Vampire Boss Lord", "Vampire Boss") },
{ Unit.VampireMinion, ("Vampire Minion", "Minion") },
{ Unit.SkeletonWarrior, ("Skeleton Warrior", "Skeleton") },
// … (many more entries) …
};
/// <summary>
/// Gets the long‐form name for a given prefab GUID (as a long).
/// </summary>
/// <param name="prefabGuid">The numeric GUID of the unit prefab.</param>
/// <returns>
/// The “Long” name (e.g., “Vampire Boss Lord”), or null if not found.
/// </returns>
public static string? GetName(long prefabGuid)
=> GetName((Unit) prefabGuid);
/// <summary>
/// Gets the long‐form name for a given Unit enum value.
/// </summary>
/// <param name="unit">The Unit enum key.</param>
/// <returns>
/// The “Long” name (e.g., “Skeleton Warrior”), or null if not found.
/// </returns>
public static string? GetName(Unit unit)
{
return PrefabToNames.TryGetValue(unit, out var names)
? names.Long
: null;
}
/// <summary>
/// Gets the short‐form name for a given prefab GUID (as a long).
/// </summary>
/// <param name="prefabGuid">The numeric GUID of the unit prefab.</param>
/// <returns>
/// The “Short” name (e.g., “Vampire Boss”), or null if not found.
/// </returns>
public static string? GetShortName(long prefabGuid)
=> GetShortName((Unit) prefabGuid);
/// <summary>
/// Gets the short‐form name for a given Unit enum value.
/// </summary>
/// <param name="unit">The Unit enum key.</param>
/// <returns>
/// The “Short” name (e.g., “Minion”), or null if not found.
/// </returns>
public static string? GetShortName(Unit unit)
{
return PrefabToNames.TryGetValue(unit, out var names)
? names.Short
: null;
}
}
Purpose
A central dictionary that associates everyUnit
enum (which itself represents underlying prefab GUIDs) with two human‐readable strings:- Long name: typically a fully descriptive title.
- Short name: a brief label for UI.
Key Members
private static readonly Dictionary<Unit, (string Long, string Short)> PrefabToNames
Holds the entire mapping ofUnit
→ (Long, Short).public static string? GetName(long prefabGuid)
andGetName(Unit unit)
Return the “Long” name, ornull
if the unit isn’t in the dictionary.public static string? GetShortName(long prefabGuid)
andGetShortName(Unit unit)
Return the “Short” name, ornull
if not found.
Usage Examples
long bossGuid = (long) Unit.VampireBoss; string? longName = UnitStrings.GetName(bossGuid); // “Vampire Boss Lord” string? shortName = UnitStrings.GetShortName(bossGuid); // “Vampire Boss” Unit someUnit = Unit.SkeletonWarrior; Log.Info($"Spawning: {UnitStrings.GetShortName(someUnit)}");
4. WorldStrings
using ProjectM.Terrain;
namespace RisingV.Shared.Strings;
/// <summary>
/// Provides string representations for world “region” types in the game.
/// </summary>
public static class WorldStrings
{
/// <summary>
/// Maps each WorldRegionType enum to a (Long, Short) tuple.
/// For example:
/// WorldRegionType.Forest → (“The Darkwood Forest”, “Forest”)
/// WorldRegionType.Swamp → (“Mordregahm’s Swamp”, “Swamp”)
/// </summary>
public static readonly Dictionary<WorldRegionType, (string Long, string Short)> WorldRegionToName = new()
{
{ WorldRegionType.Forest, ("The Darkwood Forest", "Forest") },
{ WorldRegionType.Swamp, ("Mordregahm’s Swamp", "Swamp") },
{ WorldRegionType.CrystalCaves, ("Crystal Caves", "Caves") },
// … (many more region entries) …
};
/// <summary>
/// Gets the long‐form region name for a given region enum.
/// </summary>
/// <param name="region">The WorldRegionType key.</param>
/// <returns>
/// The “Long” name (e.g., “The Darkwood Forest”), or throws if `region` isn’t in the dictionary.
/// </returns>
public static string GetRegionName(WorldRegionType region)
=> WorldRegionToName[region].Long;
/// <summary>
/// Gets the short‐form region name for a given prefab GUID (as an int).
/// </summary>
/// <param name="prefabGuid">The integer GUID corresponding to a WorldRegionType.</param>
/// <returns>
/// The “Short” name (e.g., “Forest”), or throws if the GUID isn’t in the dictionary.
/// </returns>
public static string GetRegionShortName(int prefabGuid)
=> WorldRegionToName[(WorldRegionType) prefabGuid].Short;
}
Purpose
Converts betweenWorldRegionType
(enum values that correspond to in‐game terrain/region identifiers) and human‐readable location names. Each entry pairs a “Long” descriptive string (for tooltips, lore screens) with a “Short” label (for UI elements, minimaps).Key Members
public static readonly Dictionary<WorldRegionType, (string Long, string Short)> WorldRegionToName
Contains every mapping from the game’sWorldRegionType
enum to a (Long, Short) name tuple.public static string GetRegionName(WorldRegionType region)
Returns the “Long” string. ThrowsKeyNotFoundException
if the region is absent.public static string GetRegionShortName(int prefabGuid)
Casts the numeric GUID →WorldRegionType
and returns the “Short” string. Throws if missing.
Usage Example
WorldRegionType someRegion = WorldRegionType.Swamp; Log.Info($"Entering region: {WorldStrings.GetRegionName(someRegion)}"); // “Mordregahm’s Swamp” int regionGuid = (int) WorldRegionType.Forest; string shortLabel = WorldStrings.GetRegionShortName(regionGuid); // “Forest”
5. Integration & Best Practices
Single Source of Truth
By centralizing all “string lookups” into these four static classes, you avoid scattering literals or duplicating mappings across plugins. If a name changes (e.g., you rename “Vampire Boss Lord” → “Vampire Overlord”), update onlyUnitStrings
(orWorldStrings
), and every plugin sees the new name immediately.Nullable Return Conventions
PrefabStrings.GetName
andUnitStrings.GetShortName
returnstring?
.- If a lookup fails (key not found), you get
null
rather than an exception—make sure to check fornull
before using the result. - In contrast,
WorldStrings.GetRegionName
andGetRegionShortName
assume the region exists and will throw if it doesn’t. UseWorldRegionToName.ContainsKey(...)
if you need to guard against missing entries.
Enum Casting
- All underlying lookups rely on an integer‐to‐enum cast (
(Unit) prefabGuid
,(WorldRegionType) prefabGuid
). Ensure that the numeric GUIDs passed into these methods actually correspond to valid enum values. Invalid casts will lead to runtime exceptions or unexpected behavior.
- All underlying lookups rely on an integer‐to‐enum cast (
Extending for New Types
- If your mod introduces custom “prefab” categories (for example, new building types or unique items), implement similar static dictionaries in
ItemStrings
or create a new helper underRisingV.Shared.Strings
. - You can also overload
PrefabStrings.GetName
to internally route to the correct specialized class (e.g.,ItemStrings
,StructureStrings
, etc.) based on a GUID‐range or prefix convention.
- If your mod introduces custom “prefab” categories (for example, new building types or unique items), implement similar static dictionaries in
Localization
- Currently, these classes are English‐only. If you plan to support multiple languages, consider changing each dictionary to map
(Unit, LanguageCode)
→(string Long, string Short)
, or wrap the lookup in aLocalizationManager
that returns translated strings based on the player’s locale.
- Currently, these classes are English‐only. If you plan to support multiple languages, consider changing each dictionary to map
Summary
Collectively, these four classes provide a concise, type‐safe way to retrieve display names for:
- Items (future expansion via
ItemStrings
) - Prefabs (generic façade via
PrefabStrings.GetName
) - Units (names of creatures, NPCs, bosses via
UnitStrings
) - World Regions (terrain zones, biomes via
WorldStrings
)
By referencing these helpers, your gameplay code can remain clean (no hard‐coded string literals) and maintainable (single location for all in‐game English names). Whenever you introduce new game assets or regions, simply add the corresponding enum entry and update the dictionary in one of these classes—every plugin that uses them will automatically pick up the changes.
End of documentation for RisingV.Shared.Strings
helper classes.