CatStation/Content.Shared/Chemistry/EntitySystems/SharedSolutionContainerSystem.Capabilities.cs
Princess Cheeseballs ef3a0ecc2a
Solutions Refactor Part 1 - Solution Prototypes (#43412)
* Everything except the YAML slop...

* She solution on my manager till I sajfslkahfsjakfhaskjfshajksafhfsakhfasjfas

* another 1000 lines

* fix chem dispenser size

* go my shnelf

* Implicit ass

* rider is being mean for some reason

* dasdas

* borger

* better formatting go!

* clothes/bloodstream

* Cartons

* cups and bottles

* mmm soder

* bar drinks

* Spray bottles and some size tweaks with hindsight

* 99 bottles of beer on the wall I hate YAML

* push that shit

* mmm burger

* Sneed

* sheets

* condiments

* mmm yummy

* fridge yummyfood

* meat...

* sub 300

* burger...

* bready

* let them eat cake

* does she know how to make a grilled cheese?

* pizza pie!

* misc shit

* soup or salad

* Food and drinks, vanquished

* the cubes!!!

* Almost free from YAML...

* fix test fails and some yaml issues

* fix prediction, almost done

* fix all test fails

* remove master merge artifacts and undo autonetworking

* review and compatibility

* graaah

* unfuck master merge I hate github

* merg conflicts

* sfsa

* ehoop

* sadas

* afsafsaasf

* merge conflicts

* fucked up the merge conflicts

* merge conflict is fucked I might need to completely redo this branch

* test fail

* no calcium????

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
2026-04-25 02:00:34 +00:00

191 lines
6.7 KiB
C#

using Content.Shared.Chemistry.Components;
using Content.Shared.Kitchen.Components;
using Content.Shared.Chemistry.Components.SolutionManager;
using Content.Shared.FixedPoint;
using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace Content.Shared.Chemistry.EntitySystems;
public abstract partial class SharedSolutionContainerSystem
{
#region Solution Accessors
public bool TryGetRefillableSolution(Entity<RefillableSolutionComponent?, SolutionManagerComponent?> entity, [NotNullWhen(true)] out Entity<SolutionComponent>? soln, [NotNullWhen(true)] out Solution? solution)
{
if (!Resolve(entity, ref entity.Comp1, logMissing: false))
{
(soln, solution) = (default!, null);
return false;
}
return TryGetSolution((entity.Owner, entity.Comp2), entity.Comp1.Solution, out soln, out solution);
}
public bool TryGetDrainableSolution(Entity<DrainableSolutionComponent?, SolutionManagerComponent?> entity, [NotNullWhen(true)] out Entity<SolutionComponent>? soln, [NotNullWhen(true)] out Solution? solution)
{
if (!Resolve(entity, ref entity.Comp1, logMissing: false))
{
(soln, solution) = (default!, null);
return false;
}
return TryGetSolution((entity.Owner, entity.Comp2), entity.Comp1.Solution, out soln, out solution);
}
public bool TryGetExtractableSolution(Entity<ExtractableComponent?, SolutionManagerComponent?> entity, [NotNullWhen(true)] out Entity<SolutionComponent>? soln, [NotNullWhen(true)] out Solution? solution)
{
if (!Resolve(entity, ref entity.Comp1, logMissing: false) || entity.Comp1.GrindableSolutionName == null)
{
(soln, solution) = (default!, null);
return false;
}
return TryGetSolution((entity.Owner, entity.Comp2), entity.Comp1.GrindableSolutionName, out soln, out solution);
}
public bool TryGetDumpableSolution(Entity<DumpableSolutionComponent?, SolutionManagerComponent?> entity, [NotNullWhen(true)] out Entity<SolutionComponent>? soln, [NotNullWhen(true)] out Solution? solution)
{
if (!Resolve(entity, ref entity.Comp1, logMissing: false))
{
(soln, solution) = (default!, null);
return false;
}
return TryGetSolution((entity.Owner, entity.Comp2), entity.Comp1.Solution, out soln, out solution);
}
public bool TryGetDrawableSolution(Entity<DrawableSolutionComponent?, SolutionManagerComponent?> entity, [NotNullWhen(true)] out Entity<SolutionComponent>? soln, [NotNullWhen(true)] out Solution? solution)
{
if (!Resolve(entity, ref entity.Comp1, logMissing: false))
{
(soln, solution) = (default!, null);
return false;
}
return TryGetSolution((entity.Owner, entity.Comp2), entity.Comp1.Solution, out soln, out solution);
}
public bool TryGetInjectableSolution(Entity<InjectableSolutionComponent?, SolutionManagerComponent?> entity, [NotNullWhen(true)] out Entity<SolutionComponent>? soln, [NotNullWhen(true)] out Solution? solution)
{
if (!Resolve(entity, ref entity.Comp1, logMissing: false))
{
(soln, solution) = (default!, null);
return false;
}
return TryGetSolution((entity.Owner, entity.Comp2), entity.Comp1.Solution, out soln, out solution);
}
public bool TryGetFitsInDispenser(Entity<FitsInDispenserComponent?, SolutionManagerComponent?> entity, [NotNullWhen(true)] out Entity<SolutionComponent>? soln, [NotNullWhen(true)] out Solution? solution)
{
if (!Resolve(entity, ref entity.Comp1, logMissing: false))
{
(soln, solution) = (default!, null);
return false;
}
return TryGetSolution((entity.Owner, entity.Comp2), entity.Comp1.Solution, out soln, out solution);
}
public bool TryGetMixableSolution(Entity<MixableSolutionComponent?, SolutionManagerComponent?> entity, [NotNullWhen(true)] out Entity<SolutionComponent>? soln, [NotNullWhen(true)] out Solution? solution)
{
if (!Resolve(entity, ref entity.Comp1, logMissing: false))
{
(soln, solution) = (default!, null);
return false;
}
return TryGetSolution((entity.Owner, entity.Comp2), entity.Comp1.Solution, out soln, out solution);
}
#endregion Solution Accessors
#region Solution Modifiers
public void Refill(Entity<RefillableSolutionComponent?> entity, Entity<SolutionComponent> soln, Solution refill)
{
if (!Resolve(entity, ref entity.Comp, logMissing: false))
return;
AddSolution(soln, refill);
}
public void Inject(Entity<InjectableSolutionComponent?> entity, Entity<SolutionComponent> soln, Solution inject)
{
if (!Resolve(entity, ref entity.Comp, logMissing: false))
return;
AddSolution(soln, inject);
}
public Solution Drain(Entity<DrainableSolutionComponent?> entity, Entity<SolutionComponent> soln, FixedPoint2 quantity)
{
if (!Resolve(entity, ref entity.Comp, logMissing: false))
return new();
return SplitSolution(soln, quantity);
}
public Solution Draw(Entity<DrawableSolutionComponent?> entity, Entity<SolutionComponent> soln, FixedPoint2 quantity)
{
if (!Resolve(entity, ref entity.Comp, logMissing: false))
return new();
return SplitSolution(soln, quantity);
}
#endregion Solution Modifiers
/// <returns>A value between 0 and 100 inclusive.</returns>
public float PercentFull(EntityUid uid)
{
if (!TryGetDrainableSolution(uid, out _, out var solution))
return 0;
return PercentFull(solution);
}
#region Static Methods
public static string ToPrettyString(SolutionComponent solution)
{
var sb = new StringBuilder($"{solution.Id}:");
sb.Append(ToPrettyString(solution.Solution));
return sb.ToString();
}
public static string ToPrettyString(Solution solution)
{
var sb = new StringBuilder();
sb.Append("[");
var first = true;
foreach (var (id, quantity) in solution.Contents)
{
if (first)
{
first = false;
}
else
{
sb.Append(", ");
}
sb.AppendFormat("{0}: {1}u", id, quantity);
}
sb.Append(']');
return sb.ToString();
}
/// <returns>A value between 0 and 100 inclusive.</returns>
public static float PercentFull(Solution sol)
{
if (sol.MaxVolume.Equals(FixedPoint2.Zero))
return 0;
return sol.FillFraction * 100;
}
#endregion Static Methods
}