Remove GalacticMarket component (#7914)

This commit is contained in:
20kdc
2022-05-04 03:51:25 +01:00
committed by GitHub
parent 10847e004f
commit 2e0fcbab5a
9 changed files with 47 additions and 353 deletions

View File

@@ -19,9 +19,6 @@ namespace Content.Client.Cargo
[ViewVariables]
private CargoConsoleOrderMenu? _orderMenu;
[ViewVariables]
public GalacticMarketComponent? Market { get; private set; }
[ViewVariables]
public CargoOrderDatabaseComponent? Orders { get; private set; }
@@ -51,10 +48,8 @@ namespace Content.Client.Cargo
base.Open();
var entMan = IoCManager.Resolve<IEntityManager>();
if (!entMan.TryGetComponent(Owner.Owner, out GalacticMarketComponent? market) ||
!entMan.TryGetComponent(Owner.Owner, out CargoOrderDatabaseComponent? orders)) return;
if (!entMan.TryGetComponent(Owner.Owner, out CargoOrderDatabaseComponent? orders)) return;
Market = market;
Orders = orders;
_menu = new CargoConsoleMenu(this);
@@ -64,8 +59,6 @@ namespace Content.Client.Cargo
_menu.Populate();
Market.OnDatabaseUpdated += _menu.PopulateProducts;
Market.OnDatabaseUpdated += _menu.PopulateCategories;
Orders.OnDatabaseUpdated += _menu.PopulateOrders;
_menu.CallShuttleButton.OnPressed += (_) =>
@@ -121,12 +114,6 @@ namespace Content.Client.Cargo
if (!disposing) return;
if (Market != null && _menu != null)
{
Market.OnDatabaseUpdated -= _menu.PopulateProducts;
Market.OnDatabaseUpdated -= _menu.PopulateCategories;
}
if (Orders != null && _menu != null)
{
Orders.OnDatabaseUpdated -= _menu.PopulateOrders;

View File

@@ -1,36 +0,0 @@
using System;
using Content.Shared.Cargo;
using Content.Shared.Cargo.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
namespace Content.Client.Cargo.Components
{
[RegisterComponent]
public sealed class GalacticMarketComponent : SharedGalacticMarketComponent
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
/// <summary>
/// Event called when the database is updated.
/// </summary>
public event Action? OnDatabaseUpdated;
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
base.HandleComponentState(curState, nextState);
if (curState is not GalacticMarketState state)
return;
_productIds.Clear();
foreach (var productId in state.Products)
{
if (!_prototypeManager.TryIndex(productId, out CargoProductPrototype? product))
continue;
_products.Add(product);
}
OnDatabaseUpdated?.Invoke();
}
}
}

View File

@@ -9,6 +9,7 @@ using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Client.Utility;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Maths;
@@ -21,6 +22,9 @@ namespace Content.Client.Cargo.UI
[GenerateTypedNameReferences]
public sealed partial class CargoConsoleMenu : DefaultWindow
{
[Dependency]
private IPrototypeManager _prototypeManager = default!;
public CargoConsoleBoundUserInterface Owner { get; private set; }
public event Action<ButtonEventArgs>? OnItemSelected;
@@ -66,6 +70,8 @@ namespace Content.Client.Cargo.UI
Categories.SelectId(id);
}
public IEnumerable<CargoProductPrototype> ProductPrototypes => _prototypeManager.EnumeratePrototypes<CargoProductPrototype>();
/// <summary>
/// Populates the list of products that will actually be shown, using the current filters.
/// </summary>
@@ -73,13 +79,8 @@ namespace Content.Client.Cargo.UI
{
Products.RemoveAllChildren();
if (Owner.Market == null)
{
return;
}
var search = SearchBar.Text.Trim().ToLowerInvariant();
foreach (var prototype in Owner.Market.Products)
foreach (var prototype in ProductPrototypes)
{
// if no search or category
// else if search
@@ -112,14 +113,9 @@ namespace Content.Client.Cargo.UI
_categoryStrings.Clear();
Categories.Clear();
if (Owner.Market == null)
{
return;
}
_categoryStrings.Add(Loc.GetString("cargo-console-menu-populate-categories-all-text"));
foreach (var prototype in Owner.Market.Products)
foreach (var prototype in ProductPrototypes)
{
if (!_categoryStrings.Contains(prototype.Category))
{
@@ -141,26 +137,26 @@ namespace Content.Client.Cargo.UI
Orders.RemoveAllChildren();
Requests.RemoveAllChildren();
if (Owner.Orders == null || Owner.Market == null)
if (Owner.Orders == null)
{
return;
}
foreach (var order in Owner.Orders.Orders)
{
var productName = Owner.Market.GetProduct(order.ProductId)?.Name;
if (productName == null)
if (!_prototypeManager.TryIndex<CargoProductPrototype>(order.ProductId, out CargoProductPrototype? product))
{
DebugTools.Assert(false);
Logger.ErrorS("cargo", $"Unable to find product name for {order.ProductId}");
continue;
}
var productName = product.Name;
var row = new CargoOrderRow
{
Order = order,
Icon = { Texture = Owner.Market.GetProduct(order.ProductId)?.Icon.Frame0() },
Icon = { Texture = product.Icon.Frame0() },
ProductName =
{
Text = Loc.GetString(

View File

@@ -68,7 +68,6 @@ namespace Content.Server.Cargo.Components
{
base.Initialize();
Owner.EnsureComponentWarn(out GalacticMarketComponent _);
Owner.EnsureComponentWarn(out CargoOrderDatabaseComponent _);
if (UserInterface != null)

View File

@@ -1,15 +0,0 @@
using Content.Shared.Cargo.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Players;
namespace Content.Server.Cargo.Components
{
[RegisterComponent]
public sealed class GalacticMarketComponent : SharedGalacticMarketComponent
{
public override ComponentState GetComponentState()
{
return new GalacticMarketState(GetProductIdList());
}
}
}

View File

@@ -1,106 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
namespace Content.Shared.Cargo.Components
{
[NetworkedComponent()]
public abstract class SharedGalacticMarketComponent : Component, IEnumerable<CargoProductPrototype>, ISerializationHooks
{
[DataField("products", customTypeSerializer: typeof(PrototypeIdListSerializer<CargoProductPrototype>))]
protected List<string> _productIds = new();
protected readonly List<CargoProductPrototype> _products = new();
/// <summary>
/// A read-only list of products.
/// </summary>
public IReadOnlyList<CargoProductPrototype> Products => _products;
void ISerializationHooks.AfterDeserialization()
{
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
_products.Clear();
foreach (var id in _productIds)
{
if (!prototypeManager.TryIndex(id, out CargoProductPrototype? product))
{
Logger.ErrorS("cargo", $"Unable to find {nameof(CargoProductPrototype)} for {id}");
continue;
}
_products.Add(product);
}
}
void ISerializationHooks.BeforeSerialization()
{
_productIds.Clear();
foreach (var product in _products)
{
_productIds.Add(product.ID);
}
}
public IEnumerator<CargoProductPrototype> GetEnumerator()
{
return _products.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
/// <summary>
/// Returns a product from the string id;
/// </summary>
/// <returns>Product</returns>
public CargoProductPrototype? GetProduct(string productId)
{
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
if (!prototypeManager.TryIndex(productId, out CargoProductPrototype? product) || !_products.Contains(product))
{
return null;
}
return product;
}
/// <summary>
/// Returns a list with the IDs of all products.
/// </summary>
/// <returns>A list of product IDs</returns>
public List<string> GetProductIdList()
{
var productIds = new List<string>();
foreach (var product in _products)
{
productIds.Add(product.ID);
}
return productIds;
}
}
[Serializable, NetSerializable]
public sealed class GalacticMarketState : ComponentState
{
public List<string> Products;
public GalacticMarketState(List<string> technologies)
{
Products = technologies;
}
}
}

View File

@@ -46,38 +46,38 @@
category: Atmospherics
group: market
- type: cargoProduct
name: "water vapor canister"
id: AtmosphericsWaterVapor
description: "Water vapor canister"
icon:
sprite: Structures/Storage/canister.rsi
state: water_vapor
product: WaterVaporCanister
cost: 1000
category: Atmospherics
group: market
#- type: cargoProduct
# name: "water vapor canister"
# id: AtmosphericsWaterVapor
# description: "Water vapor canister"
# icon:
# sprite: Structures/Storage/canister.rsi
# state: water_vapor
# product: WaterVaporCanister
# cost: 1000
# category: Atmospherics
# group: market
- type: cargoProduct
name: "plasma canister"
id: AtmosphericsPlasma
description: "Plasma canister"
icon:
sprite: Structures/Storage/canister.rsi
state: orange
product: PlasmaCanister
cost: 2000
category: Atmospherics
group: market
#- type: cargoProduct
# name: "plasma canister"
# id: AtmosphericsPlasma
# description: "Plasma canister"
# icon:
# sprite: Structures/Storage/canister.rsi
# state: orange
# product: PlasmaCanister
# cost: 2000
# category: Atmospherics
# group: market
- type: cargoProduct
name: "tritium canister"
id: AtmosphericsTritium
description: "Tritium canister"
icon:
sprite: Structures/Storage/canister.rsi
state: green
product: TritiumCanister
cost: 2000
category: Atmospherics
group: market
#- type: cargoProduct
# name: "tritium canister"
# id: AtmosphericsTritium
# description: "Tritium canister"
# icon:
# sprite: Structures/Storage/canister.rsi
# state: green
# product: TritiumCanister
# cost: 2000
# category: Atmospherics
# group: market

View File

@@ -100,69 +100,6 @@
- type: RadarConsole
- type: CargoConsole
- type: CargoOrderDatabase
- type: GalacticMarket # wow this kinda sucks.
products:
- MedicalSupplies
- MedicalChemistrySupplies
- EmergencyExplosive
- EmergencyFire
- EmergencyInternals
- EmergencyRadiation
- EmergencyInflatablewall
- ArmorySmg
- ArmoryShotgun
- SecurityArmor
- SecurityRiot
- SecurityLaser
- SecurityHelmet
- SecuritySupplies
- SecurityNonLethal
- SecurityRestraints
- HydroponicsTools
- HydroponicsSeeds
- HydroponicsSeedsExotic
- LivestockMonkeyCube
- LivestockCow
- LivestockChicken
- LivestockDuck
- LivestockGoat
- FoodPizza
- ServiceJanitorial
- ServiceLightsReplacement
- ServiceSmokeables
- ServiceCustomSmokable
- ServiceBureaucracy
- ServicePersonnel
- EngineeringCableLv
- EngineeringCableMv
- EngineeringCableHv
- EngineeringCableBulk
- EngineAmeShielding
- EngineAmeJar
- EngineAmeControl
- EngineSolar
- FunPlushies
- FunArtSupplies
- FunInstruments
- FunBoardGames
- FunATV
- MaterialSteel
- MaterialGlass
- MaterialPlastic
- MaterialPlasteel
- MaterialPlasma
- EngineSingularityEmitter
- EngineSingularityCollector
- EngineSingularityGenerator
- EngineSingularityContainment
- EngineParticleAccelerator
- ShuttleThruster
- ShuttleGyroscope
- AtmosphericsAir
- AtmosphericsOxygen
- AtmosphericsNitrogen
- AtmosphericsCarbonDioxide
- ArtifactContainer
- type: CrewMonitoringConsole
snap: false
precision: 3

View File

@@ -349,74 +349,6 @@
screen: supply
- type: CargoConsole
- type: CargoOrderDatabase
- type: GalacticMarket
products:
- MedicalSupplies
- MedicalChemistrySupplies
- EmergencyExplosive
- EmergencyFire
- EmergencyInternals
- EmergencyRadiation
- EmergencyInflatablewall
- ArmorySmg
- ArmoryShotgun
- SecurityArmor
- SecurityRiot
- SecurityLaser
- SecurityHelmet
- SecuritySupplies
- SecurityNonLethal
- SecurityRestraints
- HydroponicsTools
- HydroponicsSeeds
- HydroponicsSeedsExotic
- LivestockMonkeyCube
- LivestockCow
- LivestockChicken
- LivestockDuck
- LivestockGoat
- FoodPizza
- FoodMRE
- ServiceJanitorial
- ServiceLightsReplacement
- ServiceSmokeables
- ServiceCustomSmokable
- ServiceBureaucracy
- ServicePersonnel
- EngineeringCableLv
- EngineeringCableMv
- EngineeringCableHv
- EngineeringCableBulk
- EngineAmeShielding
- EngineAmeJar
- EngineAmeControl
- EngineSolar
- FunPlushies
- FunArtSupplies
- FunInstruments
- FunBrass
- FunBoardGames
- FunATV
- MaterialSteel
- MaterialGlass
- MaterialPlastic
- MaterialPlasteel
- MaterialPlasma
- EngineSingularityEmitter
- EngineSingularityCollector
- EngineSingularityGenerator
- EngineSingularityContainment
- EngineParticleAccelerator
- ShuttleThruster
- ShuttleGyroscope
- AtmosphericsAir
- AtmosphericsOxygen
- AtmosphericsNitrogen
- AtmosphericsCarbonDioxide
- ArtifactContainer
# - AtmosphericsWaterVapor
# - AtmosphericsPlasma
# - AtmosphericsTritium
- type: ActivatableUI
key: enum.CargoConsoleUiKey.Key
- type: ActivatableUIRequiresPower