Skip to content

Game.PSI.ModTags

Assembly: Assembly-CSharp (game's main assembly)
Namespace: Game.PSI

Type: public static class ModTags

Base: static class (no instance base)

Summary:
Utility used by the game to generate "mod tags" for assets (maps, saves, prefabs and generic AssetData). ModTags inspects the asset type hierarchy, prefab/component types and any explicit modTags on assets/components, filters those tags by a provided set of valid tags, and enforces a maximum tag count (kMaxTags). It also provides helpers for extracting tags from enum flags and for determining whether a prefab should be treated as a "prop" (static object) by excluding certain object types. Note: GetEnumFlagTags contains an implementation detail that causes it to yield value.ToString() inside the loop instead of the iterated enum member's name — this looks like a bug (reported below).


Fields

  • private static ILog sLog = LogManager.GetLogger("Platforms")
    Logger used to emit warnings when generated tags exceed the maximum allowed. Used in GetTags when tags are removed to trim the set.

  • public static readonly int kMaxTags = 10
    Maximum number of tags allowed for an asset. If more tags are generated, non-type tags are preferentially removed until the limit is satisfied; when forced, type tags will be removed as well.

  • private static readonly Type[] sExcludePropTypes = new Type[4] { typeof(PillarObject), typeof(TreeObject), typeof(PlantObject), typeof(NetObject) }
    Types that exclude a StaticObjectPrefab from being classified as a "prop". Used by IsProp to check prefab components.

Properties

  • (none)
    This class is static and exposes no properties.

Constructors

  • (none)
    Static classes do not define instance constructors. There is no explicit static initializer in the source.

Methods

  • public static void GetTags(AssetData asset, HashSet<string> tags, HashSet<string> typeTags, HashSet<string> validTags)
    Main entry point. Populates the provided sets:
  • Calls GetAssetTypeTags to extract type-level tags from the asset type hierarchy and from assetData.modTags.
  • If the asset is MapMetadata or SaveGameMetadata, calls GetMapTags/GetSaveTags which add the asset theme if it is in validTags.
  • If the asset is a PrefabAsset and the prefab is loaded, calls GetPrefabTags to extract tags from the prefab and its components.
  • Merges typeTags into tags, then if the combined tags exceed kMaxTags, trims tags down to kMaxTags. Trimming prefers removing tags not present in typeTags; if necessary it removes typeTags too. Logs a warning for each removed tag.

  • private static void GetMapTags(MapMetadata map, HashSet<string> tags, HashSet<string> typeTags, HashSet<string> validTags)
    Adds map.target.theme to tags if validTags contains it.

  • private static void GetSaveTags(SaveGameMetadata save, HashSet<string> tags, HashSet<string> typeTags, HashSet<string> validTags)
    Adds save.target.theme to tags if validTags contains it.

  • private static void GetPrefabTags(PrefabBase prefab, HashSet<string> tags, HashSet<string> typeTags, HashSet<string> validTags)
    Extracts tags from the prefab type (as typeTags) and from each component on the prefab (as tags). Uses GetComponentTags to get tags from a component/type hierarchy and from explicit component.modTags.

  • private static IEnumerable<string> GetComponentTags(ComponentBase component, HashSet<string> validTags, Type terminateAtType)
    Yields tags derived from the component's type hierarchy up to but not including terminateAtType:

  • For each type in the hierarchy (stopping at terminateAtType), if the type is not marked with ExcludeGeneratedModTagAttribute, a tag name is generated by stripping "Prefab" and "Object" from the type name; if that text is in validTags it is yielded.
  • After processing the type hierarchy, the method yields any strings from component.modTags that are present in validTags. This is an iterator (yield return).

  • private static void GetAssetTypeTags(AssetData assetData, HashSet<string> tags, HashSet<string> typeTags, HashSet<string> validTags)
    Walks the assetData type hierarchy up to AssetData and, for each non-excluded type, yields a tag formed by removing "Metadata" and "Asset" from the type name (if present in validTags) and adds it to typeTags. Also adds assetData.modTags entries present in validTags.

  • public static IEnumerable<string> GetEnumFlagTags<T>(T value, T defaultValue) where T : Enum
    Helper for flags enums: iterates all enum values and yields the string representation of values that are set in the provided value. If no flags are set, yields the defaultValue.ToString(). Note: the implementation yields value.ToString() inside the loop rather than the iterated enum member's name — this appears to be a bug and will produce the same string repeatedly (the full value) instead of each matched flag name.

  • public static bool IsProp(PrefabBase prefab)
    Determines whether a prefab should be considered a "prop":

  • Returns true only if prefab.GetType() == typeof(StaticObjectPrefab).
  • If so, the method checks whether the prefab has any components of types listed in sExcludePropTypes (PillarObject, TreeObject, PlantObject, NetObject). If any such component exists, returns false; otherwise true.
  • For non-StaticObjectPrefab types, returns false.

Usage Example

// Example: collect tags for an asset
var tags = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
var typeTags = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
var validTags = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
    "Residential", "Commercial", "Industrial", "MapTheme", "Park", "Road", // etc.
};

AssetData asset = /* obtain asset, e.g. from AssetDatabase */;
ModTags.GetTags(asset, tags, typeTags, validTags);

// 'tags' now contains generated tags (including typeTags merged in), trimmed to ModTags.kMaxTags

Notes and implementation caveats: - The trimming strategy in GetTags tries to preserve type-derived tags (typeTags) and remove other tags first; if the limit still isn't met, it will remove type tags too. - GetEnumFlagTags appears to have an implementation mistake: in its loop it yields value.ToString() instead of the matched enum member's ToString() — this should be corrected to yield the iterated member's name. - IsProp checks exact prefab type equality to StaticObjectPrefab; subclasses of StaticObjectPrefab will not be treated as props by this method. - The class relies on asset.modTags and component.modTags properties to supply explicit tags; these strings are only accepted if present in validTags.