Make smoking cool again. (#6046)
This commit is contained in:
@@ -1,16 +1,18 @@
|
|||||||
using Content.Client.Clothing;
|
|
||||||
using Content.Shared.Smoking;
|
using Content.Shared.Smoking;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.Serialization.Manager.Attributes;
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
|
|
||||||
namespace Content.Client.Smoking
|
namespace Content.Client.Smoking
|
||||||
{
|
{
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public class BurnStateVisualizer : AppearanceVisualizer
|
public sealed class BurnStateVisualizer : AppearanceVisualizer, ISerializationHooks
|
||||||
{
|
{
|
||||||
|
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||||
|
|
||||||
[DataField("burntIcon")]
|
[DataField("burntIcon")]
|
||||||
private string _burntIcon = "burnt-icon";
|
private string _burntIcon = "burnt-icon";
|
||||||
[DataField("litIcon")]
|
[DataField("litIcon")]
|
||||||
@@ -18,49 +20,29 @@ namespace Content.Client.Smoking
|
|||||||
[DataField("unlitIcon")]
|
[DataField("unlitIcon")]
|
||||||
private string _unlitIcon = "icon";
|
private string _unlitIcon = "icon";
|
||||||
|
|
||||||
[DataField("burntPrefix")]
|
void ISerializationHooks.AfterDeserialization()
|
||||||
private string _burntPrefix = "unlit";
|
{
|
||||||
[DataField("litPrefix")]
|
IoCManager.InjectDependencies(this);
|
||||||
private string _litPrefix = "lit";
|
}
|
||||||
[DataField("unlitPrefix")]
|
|
||||||
private string _unlitPrefix = "unlit";
|
|
||||||
|
|
||||||
public override void OnChangeData(AppearanceComponent component)
|
public override void OnChangeData(AppearanceComponent component)
|
||||||
{
|
{
|
||||||
base.OnChangeData(component);
|
base.OnChangeData(component);
|
||||||
|
|
||||||
if (component.TryGetData<SmokableState>(SmokingVisuals.Smoking, out var smoking))
|
if (!_entMan.TryGetComponent(component.Owner, out SpriteComponent? sprite))
|
||||||
{
|
return;
|
||||||
SetState(component, smoking);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetState(AppearanceComponent component, SmokableState burnState)
|
if (!component.TryGetData<SmokableState>(SmokingVisuals.Smoking, out var burnState))
|
||||||
{
|
return;
|
||||||
var entities = IoCManager.Resolve<IEntityManager>();
|
|
||||||
var clothing = entities.GetComponentOrNull<ClothingComponent>(component.Owner);
|
|
||||||
|
|
||||||
if (entities.TryGetComponent(component.Owner, out ISpriteComponent sprite))
|
var state = burnState switch
|
||||||
{
|
{
|
||||||
switch (burnState)
|
SmokableState.Lit => _litIcon,
|
||||||
{
|
SmokableState.Burnt => _burntIcon,
|
||||||
case SmokableState.Lit:
|
_ => _unlitIcon
|
||||||
if (clothing != null)
|
};
|
||||||
clothing.EquippedPrefix = _litPrefix;
|
|
||||||
sprite.LayerSetState(0, _litIcon);
|
sprite.LayerSetState(0, state);
|
||||||
break;
|
|
||||||
case SmokableState.Burnt:
|
|
||||||
if (clothing != null)
|
|
||||||
clothing.EquippedPrefix = _burntPrefix;
|
|
||||||
sprite.LayerSetState(0, _burntIcon);
|
|
||||||
break;
|
|
||||||
case SmokableState.Unlit:
|
|
||||||
if (clothing != null)
|
|
||||||
clothing.EquippedPrefix = _unlitPrefix;
|
|
||||||
sprite.LayerSetState(0, _unlitIcon);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,5 +24,13 @@ namespace Content.Server.Nutrition.Components
|
|||||||
|
|
||||||
[DataField("state")]
|
[DataField("state")]
|
||||||
public SmokableState State { get; set; } = SmokableState.Unlit;
|
public SmokableState State { get; set; } = SmokableState.Unlit;
|
||||||
|
|
||||||
|
// clothing prefixes
|
||||||
|
[DataField("burntPrefix")]
|
||||||
|
public string BurntPrefix = "unlit";
|
||||||
|
[DataField("litPrefix")]
|
||||||
|
public string LitPrefix = "lit";
|
||||||
|
[DataField("unlitPrefix")]
|
||||||
|
public string UnlitPrefix = "unlit";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Linq;
|
|||||||
using Content.Server.Body.Components;
|
using Content.Server.Body.Components;
|
||||||
using Content.Server.Body.Systems;
|
using Content.Server.Body.Systems;
|
||||||
using Content.Server.Chemistry.EntitySystems;
|
using Content.Server.Chemistry.EntitySystems;
|
||||||
|
using Content.Server.Clothing.Components;
|
||||||
using Content.Server.Nutrition.Components;
|
using Content.Server.Nutrition.Components;
|
||||||
using Content.Shared.Chemistry;
|
using Content.Shared.Chemistry;
|
||||||
using Content.Shared.Chemistry.Reagent;
|
using Content.Shared.Chemistry.Reagent;
|
||||||
@@ -38,14 +39,22 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
InitializeCigars();
|
InitializeCigars();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetSmokableState(EntityUid uid, SmokableState state, SmokableComponent? smokable = null, AppearanceComponent? appearance = null)
|
public void SetSmokableState(EntityUid uid, SmokableState state, SmokableComponent? smokable = null,
|
||||||
|
AppearanceComponent? appearance = null, ClothingComponent? clothing = null)
|
||||||
{
|
{
|
||||||
if (!Resolve(uid, ref smokable, ref appearance))
|
if (!Resolve(uid, ref smokable, ref appearance, ref clothing))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
smokable.State = state;
|
smokable.State = state;
|
||||||
appearance.SetData(SmokingVisuals.Smoking, state);
|
appearance.SetData(SmokingVisuals.Smoking, state);
|
||||||
|
|
||||||
|
clothing.EquippedPrefix = state switch
|
||||||
|
{
|
||||||
|
SmokableState.Lit => smokable.LitPrefix,
|
||||||
|
SmokableState.Burnt => smokable.BurntPrefix,
|
||||||
|
_ => smokable.UnlitPrefix
|
||||||
|
};
|
||||||
|
|
||||||
if (state == SmokableState.Lit)
|
if (state == SmokableState.Lit)
|
||||||
_active.Add(uid);
|
_active.Add(uid);
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user