small food slicing cleanup (#22291)
* component cleanup * slice system cleanup * thank you entprotoid * webedit 1 * webedit 2 * bruh this shitcode has sliceable food with no slice * ok no persistence --------- Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -1,24 +1,31 @@
|
|||||||
using Content.Server.Nutrition.EntitySystems;
|
using Content.Server.Nutrition.EntitySystems;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
|
|
||||||
namespace Content.Server.Nutrition.Components
|
namespace Content.Server.Nutrition.Components;
|
||||||
|
|
||||||
|
[RegisterComponent, Access(typeof(SliceableFoodSystem))]
|
||||||
|
public sealed partial class SliceableFoodComponent : Component
|
||||||
{
|
{
|
||||||
[RegisterComponent, Access(typeof(SliceableFoodSystem))]
|
/// <summary>
|
||||||
internal sealed partial class SliceableFoodComponent : Component
|
/// Prototype to spawn after slicing.
|
||||||
{
|
/// If null then it can't be sliced.
|
||||||
[DataField("slice")]
|
/// </summary>
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public string Slice = string.Empty;
|
public EntProtoId? Slice;
|
||||||
|
|
||||||
[DataField("sound")]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
public SoundSpecifier Sound = new SoundPathSpecifier("/Audio/Items/Culinary/chop.ogg");
|
||||||
public SoundSpecifier Sound = new SoundPathSpecifier("/Audio/Items/Culinary/chop.ogg");
|
|
||||||
|
|
||||||
[DataField("count")]
|
/// <summary>
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
/// Number of slices the food starts with.
|
||||||
public ushort TotalCount = 5;
|
/// </summary>
|
||||||
|
[DataField("count"), ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public ushort TotalCount = 5;
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
/// <summary>
|
||||||
public ushort Count;
|
/// Number of slices left.
|
||||||
}
|
/// </summary>
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public ushort Count;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var sliceUid = Spawn(component.Slice, transform.Coordinates);
|
var sliceUid = Slice(uid, user, component, transform);
|
||||||
|
|
||||||
var lostSolution = _solutionContainerSystem.SplitSolution(uid, solution,
|
var lostSolution = _solutionContainerSystem.SplitSolution(uid, solution,
|
||||||
solution.Volume / FixedPoint2.New(component.Count));
|
solution.Volume / FixedPoint2.New(component.Count));
|
||||||
@@ -65,18 +65,6 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
// Fill new slice
|
// Fill new slice
|
||||||
FillSlice(sliceUid, lostSolution);
|
FillSlice(sliceUid, lostSolution);
|
||||||
|
|
||||||
var inCont = _containerSystem.IsEntityInContainer(component.Owner);
|
|
||||||
if (inCont)
|
|
||||||
{
|
|
||||||
_handsSystem.PickupOrDrop(user, sliceUid);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var xform = Transform(sliceUid);
|
|
||||||
_containerSystem.AttachParentToContainerOrGrid((sliceUid, xform));
|
|
||||||
xform.LocalRotation = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
_audio.PlayPvs(component.Sound, transform.Coordinates, AudioParams.Default.WithVolume(-2));
|
_audio.PlayPvs(component.Sound, transform.Coordinates, AudioParams.Default.WithVolume(-2));
|
||||||
|
|
||||||
// Decrease size of item based on count - Could implement in the future
|
// Decrease size of item based on count - Could implement in the future
|
||||||
@@ -99,11 +87,26 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
if (component.Count > 1)
|
if (component.Count > 1)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
sliceUid = Spawn(component.Slice, transform.Coordinates);
|
sliceUid = Slice(uid, user, component, transform);
|
||||||
|
|
||||||
// Fill last slice with the rest of the solution
|
// Fill last slice with the rest of the solution
|
||||||
FillSlice(sliceUid, solution);
|
FillSlice(sliceUid, solution);
|
||||||
|
|
||||||
|
DeleteFood(uid, user);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new slice in the world and returns its entity.
|
||||||
|
/// The solutions must be set afterwards.
|
||||||
|
/// </summary>
|
||||||
|
public EntityUid Slice(EntityUid uid, EntityUid user, SliceableFoodComponent? comp = null, TransformComponent? transform = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(uid, ref comp, ref transform))
|
||||||
|
return EntityUid.Invalid;
|
||||||
|
|
||||||
|
var sliceUid = Spawn(comp.Slice, transform.Coordinates);
|
||||||
|
var inCont = _containerSystem.IsEntityInContainer(uid);
|
||||||
if (inCont)
|
if (inCont)
|
||||||
{
|
{
|
||||||
_handsSystem.PickupOrDrop(user, sliceUid);
|
_handsSystem.PickupOrDrop(user, sliceUid);
|
||||||
@@ -115,8 +118,7 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
xform.LocalRotation = 0;
|
xform.LocalRotation = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeleteFood(uid, user);
|
return sliceUid;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DeleteFood(EntityUid uid, EntityUid user)
|
private void DeleteFood(EntityUid uid, EntityUid user)
|
||||||
|
|||||||
@@ -229,7 +229,7 @@
|
|||||||
Quantity: 9
|
Quantity: 9
|
||||||
- type: SliceableFood
|
- type: SliceableFood
|
||||||
count: 3
|
count: 3
|
||||||
slice: FoodMeatPenguinCutletSlice
|
slice: FoodMeatPenguinCutlet
|
||||||
- type: Construction
|
- type: Construction
|
||||||
graph: PenguinSteak
|
graph: PenguinSteak
|
||||||
node: start
|
node: start
|
||||||
|
|||||||
Reference in New Issue
Block a user