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

View File

@@ -68,7 +68,6 @@ namespace Content.Server.Cargo.Components
{ {
base.Initialize(); base.Initialize();
Owner.EnsureComponentWarn(out GalacticMarketComponent _);
Owner.EnsureComponentWarn(out CargoOrderDatabaseComponent _); Owner.EnsureComponentWarn(out CargoOrderDatabaseComponent _);
if (UserInterface != null) 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 category: Atmospherics
group: market group: market
- type: cargoProduct #- type: cargoProduct
name: "water vapor canister" # name: "water vapor canister"
id: AtmosphericsWaterVapor # id: AtmosphericsWaterVapor
description: "Water vapor canister" # description: "Water vapor canister"
icon: # icon:
sprite: Structures/Storage/canister.rsi # sprite: Structures/Storage/canister.rsi
state: water_vapor # state: water_vapor
product: WaterVaporCanister # product: WaterVaporCanister
cost: 1000 # cost: 1000
category: Atmospherics # category: Atmospherics
group: market # group: market
- type: cargoProduct #- type: cargoProduct
name: "plasma canister" # name: "plasma canister"
id: AtmosphericsPlasma # id: AtmosphericsPlasma
description: "Plasma canister" # description: "Plasma canister"
icon: # icon:
sprite: Structures/Storage/canister.rsi # sprite: Structures/Storage/canister.rsi
state: orange # state: orange
product: PlasmaCanister # product: PlasmaCanister
cost: 2000 # cost: 2000
category: Atmospherics # category: Atmospherics
group: market # group: market
- type: cargoProduct #- type: cargoProduct
name: "tritium canister" # name: "tritium canister"
id: AtmosphericsTritium # id: AtmosphericsTritium
description: "Tritium canister" # description: "Tritium canister"
icon: # icon:
sprite: Structures/Storage/canister.rsi # sprite: Structures/Storage/canister.rsi
state: green # state: green
product: TritiumCanister # product: TritiumCanister
cost: 2000 # cost: 2000
category: Atmospherics # category: Atmospherics
group: market # group: market

View File

@@ -100,69 +100,6 @@
- type: RadarConsole - type: RadarConsole
- type: CargoConsole - type: CargoConsole
- type: CargoOrderDatabase - 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 - type: CrewMonitoringConsole
snap: false snap: false
precision: 3 precision: 3

View File

@@ -349,74 +349,6 @@
screen: supply screen: supply
- type: CargoConsole - type: CargoConsole
- type: CargoOrderDatabase - 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 - type: ActivatableUI
key: enum.CargoConsoleUiKey.Key key: enum.CargoConsoleUiKey.Key
- type: ActivatableUIRequiresPower - type: ActivatableUIRequiresPower