Table of Contents

String Resources

Namespaces:

  • RisingV.Shared.Strings
  • Stunlock.Core (for PrefabGUID & Unit enums)
  • RisingV.Shared.Prefabs (for Unit enum lookup)
  • ProjectM.Terrain (for WorldRegionType 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 expose static 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 to UnitStrings.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 a string? (nullable) if the GUID exists in the underlying UnitStrings dictionary; otherwise returns null.
  • 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 every Unit enum (which itself represents underlying prefab GUIDs) with two human‐readable strings:

    1. Long name: typically a fully descriptive title.
    2. Short name: a brief label for UI.
  • Key Members

    • private static readonly Dictionary<Unit, (string Long, string Short)> PrefabToNames
      Holds the entire mapping of Unit → (Long, Short).
    • public static string? GetName(long prefabGuid) and GetName(Unit unit)
      Return the “Long” name, or null if the unit isn’t in the dictionary.
    • public static string? GetShortName(long prefabGuid) and GetShortName(Unit unit)
      Return the “Short” name, or null 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 between WorldRegionType (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’s WorldRegionType enum to a (Long, Short) name tuple.
    • public static string GetRegionName(WorldRegionType region)
      Returns the “Long” string. Throws KeyNotFoundException 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

  1. 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 only UnitStrings (or WorldStrings), and every plugin sees the new name immediately.

  2. Nullable Return Conventions

    • PrefabStrings.GetName and UnitStrings.GetShortName return string?.
    • If a lookup fails (key not found), you get null rather than an exception—make sure to check for null before using the result.
    • In contrast, WorldStrings.GetRegionName and GetRegionShortName assume the region exists and will throw if it doesn’t. Use WorldRegionToName.ContainsKey(...) if you need to guard against missing entries.
  3. 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.
  4. 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 under RisingV.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.
  5. 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 a LocalizationManager that returns translated strings based on the player’s locale.

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.