Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entities filtering for forks #5473

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Resources/EnginePrototypes/entityCategory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@
description: entity-category-desc-hide
hideSpawnMenu: true
inheritable: false

# Entity prototypes added by the fork. With CVar you can hide all entities without this category
- type: entityCategory
id: ForkFiltered
name: entity-category-name-fork
description: entity-category-desc-fork
3 changes: 3 additions & 0 deletions Resources/Locale/en-US/entity-category.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ entity-category-desc-spawner = Entity prototypes that spawn other entities.

entity-category-name-hide = Hidden
entity-category-desc-hide = Entity prototypes that should be hidden from entity spawn menus

entity-category-name-fork = Fork Filtered
entity-category-desc-fork = Entity prototypes added by the fork. With CVar you can hide all entities without this category
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared;
using Robust.Shared.Configuration;
using Robust.Shared.Enums;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
Expand All @@ -19,6 +21,7 @@ namespace Robust.Client.UserInterface.Controllers.Implementations;

public sealed class EntitySpawningUIController : UIController
{
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IPlacementManager _placement = default!;
[Dependency] private readonly IPrototypeManager _prototypes = default!;

Expand Down Expand Up @@ -192,6 +195,9 @@ private void BuildEntityList(string? searchStr = null)
_window.SelectedButton = null;
searchStr = searchStr?.ToLowerInvariant();

var categoryFilter = _cfg.GetCVar(CVars.EntitiesCategoryFilter);
_prototypes.TryIndex<EntityCategoryPrototype>(categoryFilter, out var filter);

foreach (var prototype in _prototypes.EnumeratePrototypes<EntityPrototype>())
{
if (prototype.Abstract)
Expand All @@ -204,6 +210,11 @@ private void BuildEntityList(string? searchStr = null)
continue;
}

if (filter is not null && !prototype.Categories.Contains(filter))
{
continue;
}

if (searchStr != null && !DoesEntityMatchSearch(prototype, searchStr))
{
continue;
Expand Down
7 changes: 7 additions & 0 deletions Robust.Shared/CVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,13 @@ protected CVars()
public static readonly CVarDef<string> BuildManifestHash =
CVarDef.Create("build.manifest_hash", "");

/// <summary>
/// Allows you to disable the display of all entities in the spawn menu that are not labeled with the ShowSpawnMenu category.
/// This is useful for forks that just want to disable the standard upstream content
/// </summary>
public static readonly CVarDef<string> EntitiesCategoryFilter =
CVarDef.Create("build.entities_category_filter", "");

/*
* WATCHDOG
*/
Expand Down
Loading