Move SolutionRegenerationSwitcherSystem to Shared (#1700)
This commit is contained in:
parent
e10844ed8b
commit
bb9d23d3bf
5 changed files with 146 additions and 83 deletions
|
|
@ -0,0 +1,20 @@
|
|||
using Content.Shared._Sunrise.SolutionRegenerationSwitcher;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
|
||||
namespace Content.Client._Sunrise.SolutionRegenerationSwitcher;
|
||||
|
||||
public sealed class ClientSolutionRegenerationSwitcherSystem : SharedSolutionRegenerationSwitcherSystem
|
||||
{
|
||||
protected override void SwitchToNextReagent(EntityUid uid,
|
||||
SolutionRegenerationSwitcherComponent component,
|
||||
EntityUid user)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void SwitchReagent(EntityUid uid,
|
||||
ReagentQuantity reagent,
|
||||
SolutionRegenerationSwitcherComponent component,
|
||||
EntityUid user)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
using Content.Shared.Chemistry.Reagent;
|
||||
|
||||
namespace Content.Server._Sunrise.SolutionRegenerationSwitcher
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed partial class SolutionRegenerationSwitcherComponent : Component
|
||||
{
|
||||
[DataField("options", required: true), ViewVariables(VVAccess.ReadWrite)]
|
||||
public List<ReagentQuantity> Options = default!;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int CurrentIndex;
|
||||
|
||||
[DataField("keepSolution"), ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool KeepSolution;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,89 +1,38 @@
|
|||
using Content.Server.Chemistry.Components;
|
||||
using Content.Server.Popups;
|
||||
using Content.Shared._Sunrise.SolutionRegenerationSwitcher;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server._Sunrise.SolutionRegenerationSwitcher
|
||||
{
|
||||
public sealed class SolutionRegenerationSwitcherSystem : EntitySystem
|
||||
public sealed class SolutionRegenerationSwitcherSystem : SharedSolutionRegenerationSwitcherSystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly SharedSolutionContainerSystem _solutionSystem = default!;
|
||||
[Dependency] private readonly PopupSystem _popups = default!;
|
||||
[Dependency] private readonly SharedSolutionContainerSystem _solutionSystem = null!;
|
||||
[Dependency] private readonly PopupSystem _popups = null!;
|
||||
|
||||
private ISawmill _sawmill = default!;
|
||||
private ISawmill _sawmill = null!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_sawmill = Logger.GetSawmill("chemistry");
|
||||
|
||||
SubscribeLocalEvent<SolutionRegenerationSwitcherComponent, GetVerbsEvent<Verb>>(AddSwitchVerb);
|
||||
SubscribeLocalEvent<SolutionRegenerationSwitcherComponent, GetVerbsEvent<AlternativeVerb>>(AddAlternateSwitchVerb);
|
||||
}
|
||||
|
||||
private void AddSwitchVerb(EntityUid uid, SolutionRegenerationSwitcherComponent component, GetVerbsEvent<Verb> args)
|
||||
{
|
||||
if (!args.CanInteract || !args.CanAccess)
|
||||
return;
|
||||
|
||||
for (var i = 0; i < component.Options.Count; i++)
|
||||
{
|
||||
var componentOption = component.Options[i];
|
||||
if (!_prototypeManager.TryIndex(componentOption.Reagent.Prototype, out ReagentPrototype? proto))
|
||||
{
|
||||
_sawmill.Error($"Can't get reagent prototype {componentOption.Reagent.Prototype} for {ToPrettyString(uid)}");
|
||||
return;
|
||||
}
|
||||
|
||||
var index = i;
|
||||
Verb reagent = new()
|
||||
{
|
||||
Text = proto.LocalizedName,
|
||||
Category = VerbCategory.ReagentSwitch,
|
||||
Act = () =>
|
||||
{
|
||||
component.CurrentIndex = index;
|
||||
SwitchReagent(uid, componentOption, component, args.User);
|
||||
},
|
||||
Priority = 2,
|
||||
Message = Loc.GetString("solution-regeneration-switcher-switch-verb-text"),
|
||||
};
|
||||
args.Verbs.Add(reagent);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddAlternateSwitchVerb(EntityUid uid, SolutionRegenerationSwitcherComponent component, GetVerbsEvent<AlternativeVerb> args)
|
||||
{
|
||||
if (!args.CanInteract || !args.CanAccess)
|
||||
return;
|
||||
|
||||
if (component.Options.Count <= 1)
|
||||
return;
|
||||
|
||||
AlternativeVerb verb = new()
|
||||
{
|
||||
Act = () =>
|
||||
{
|
||||
SwitchToNextReagent(uid, component, args.User);
|
||||
},
|
||||
Text = Loc.GetString("solution-regeneration-switcher-switch-reagent-alt"),
|
||||
Priority = 2
|
||||
};
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
private void SwitchToNextReagent(EntityUid uid, SolutionRegenerationSwitcherComponent component, EntityUid user)
|
||||
protected override void SwitchToNextReagent(EntityUid uid,
|
||||
SolutionRegenerationSwitcherComponent component,
|
||||
EntityUid user)
|
||||
{
|
||||
component.CurrentIndex = (component.CurrentIndex + 1) % component.Options.Count;
|
||||
var nextReagent = component.Options[component.CurrentIndex];
|
||||
SwitchReagent(uid, nextReagent, component, user);
|
||||
}
|
||||
|
||||
private void SwitchReagent(EntityUid uid, ReagentQuantity reagent, SolutionRegenerationSwitcherComponent component, EntityUid user)
|
||||
protected override void SwitchReagent(EntityUid uid,
|
||||
ReagentQuantity reagent,
|
||||
SolutionRegenerationSwitcherComponent component,
|
||||
EntityUid user)
|
||||
{
|
||||
if (!TryComp<SolutionRegenerationComponent>(uid, out var solutionRegenerationComponent))
|
||||
{
|
||||
|
|
@ -115,13 +64,17 @@ namespace Content.Server._Sunrise.SolutionRegenerationSwitcher
|
|||
|
||||
solutionRegeneration.ChangeGenerated(reagent);
|
||||
|
||||
if (!_prototypeManager.TryIndex(reagent.Reagent.Prototype, out ReagentPrototype? proto))
|
||||
if (!PrototypeManager.TryIndex(reagent.Reagent.Prototype, out ReagentPrototype? proto))
|
||||
{
|
||||
_sawmill.Error($"Can't get get reagent prototype {reagent.Reagent.Prototype} for {ToPrettyString(uid)}");
|
||||
_sawmill.Error(
|
||||
$"Can't get get reagent prototype {reagent.Reagent.Prototype} for {ToPrettyString(uid)}");
|
||||
return;
|
||||
}
|
||||
|
||||
_popups.PopupEntity(Loc.GetString("solution-regeneration-switcher-switched", ("reagent", proto.LocalizedName)), user, user);
|
||||
_popups.PopupEntity(
|
||||
Loc.GetString("solution-regeneration-switcher-switched", ("reagent", proto.LocalizedName)),
|
||||
user,
|
||||
user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,90 @@
|
|||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared._Sunrise.SolutionRegenerationSwitcher
|
||||
{
|
||||
public abstract class SharedSolutionRegenerationSwitcherSystem : EntitySystem
|
||||
{
|
||||
[Dependency] protected readonly IPrototypeManager PrototypeManager = null!;
|
||||
|
||||
private ISawmill _sawmill = null!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_sawmill = Logger.GetSawmill("chemistry");
|
||||
|
||||
SubscribeLocalEvent<SolutionRegenerationSwitcherComponent, GetVerbsEvent<Verb>>(AddSwitchVerb);
|
||||
SubscribeLocalEvent<SolutionRegenerationSwitcherComponent, GetVerbsEvent<AlternativeVerb>>(
|
||||
AddAlternateSwitchVerb);
|
||||
}
|
||||
|
||||
private void AddSwitchVerb(EntityUid uid,
|
||||
SolutionRegenerationSwitcherComponent component,
|
||||
GetVerbsEvent<Verb> args)
|
||||
{
|
||||
if (!args.CanInteract || !args.CanAccess)
|
||||
return;
|
||||
|
||||
for (var i = 0; i < component.Options.Count; i++)
|
||||
{
|
||||
var componentOption = component.Options[i];
|
||||
if (!PrototypeManager.TryIndex(componentOption.Reagent.Prototype, out ReagentPrototype? proto))
|
||||
{
|
||||
_sawmill.Error(
|
||||
$"Can't get reagent prototype {componentOption.Reagent.Prototype} for {ToPrettyString(uid)}");
|
||||
return;
|
||||
}
|
||||
|
||||
var index = i;
|
||||
Verb reagent = new()
|
||||
{
|
||||
Text = proto.LocalizedName,
|
||||
Category = VerbCategory.ReagentSwitch,
|
||||
Act = () =>
|
||||
{
|
||||
component.CurrentIndex = index;
|
||||
SwitchReagent(uid, componentOption, component, args.User);
|
||||
},
|
||||
Priority = 2,
|
||||
Message = Loc.GetString("solution-regeneration-switcher-switch-verb-text"),
|
||||
};
|
||||
args.Verbs.Add(reagent);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddAlternateSwitchVerb(EntityUid uid,
|
||||
SolutionRegenerationSwitcherComponent component,
|
||||
GetVerbsEvent<AlternativeVerb> args)
|
||||
{
|
||||
if (!args.CanInteract || !args.CanAccess)
|
||||
return;
|
||||
|
||||
if (component.Options.Count <= 1)
|
||||
return;
|
||||
|
||||
AlternativeVerb verb = new()
|
||||
{
|
||||
Act = () =>
|
||||
{
|
||||
SwitchToNextReagent(uid, component, args.User);
|
||||
},
|
||||
Text = Loc.GetString("solution-regeneration-switcher-switch-reagent-alt"),
|
||||
Priority = 2,
|
||||
};
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
protected abstract void SwitchToNextReagent(EntityUid uid,
|
||||
SolutionRegenerationSwitcherComponent component,
|
||||
EntityUid user);
|
||||
|
||||
|
||||
protected abstract void SwitchReagent(EntityUid uid,
|
||||
ReagentQuantity reagent,
|
||||
SolutionRegenerationSwitcherComponent component,
|
||||
EntityUid user);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
using Content.Shared.Chemistry.Reagent;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared._Sunrise.SolutionRegenerationSwitcher
|
||||
{
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
public sealed partial class SolutionRegenerationSwitcherComponent : Component
|
||||
{
|
||||
[DataField(required: true), ViewVariables, AutoNetworkedField]
|
||||
public List<ReagentQuantity> Options = [];
|
||||
|
||||
public int CurrentIndex;
|
||||
|
||||
[DataField, ViewVariables]
|
||||
public bool KeepSolution;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue