Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make smoking cool again. #6046

Merged
merged 1 commit into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 19 additions & 37 deletions Content.Client/Smoking/BurnStateVisualizer.cs
Original file line number Diff line number Diff line change
@@ -1,66 +1,48 @@
using Content.Client.Clothing;
using Content.Shared.Smoking;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;

namespace Content.Client.Smoking
{
[UsedImplicitly]
public class BurnStateVisualizer : AppearanceVisualizer
public sealed class BurnStateVisualizer : AppearanceVisualizer, ISerializationHooks
{
[Dependency] private readonly IEntityManager _entMan = default!;

[DataField("burntIcon")]
private string _burntIcon = "burnt-icon";
[DataField("litIcon")]
private string _litIcon = "lit-icon";
[DataField("unlitIcon")]
private string _unlitIcon = "icon";

[DataField("burntPrefix")]
private string _burntPrefix = "unlit";
[DataField("litPrefix")]
private string _litPrefix = "lit";
[DataField("unlitPrefix")]
private string _unlitPrefix = "unlit";
void ISerializationHooks.AfterDeserialization()
{
IoCManager.InjectDependencies(this);
}

public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);

if (component.TryGetData<SmokableState>(SmokingVisuals.Smoking, out var smoking))
{
SetState(component, smoking);
}
}
if (!_entMan.TryGetComponent(component.Owner, out SpriteComponent? sprite))
return;

private void SetState(AppearanceComponent component, SmokableState burnState)
{
var entities = IoCManager.Resolve<IEntityManager>();
var clothing = entities.GetComponentOrNull<ClothingComponent>(component.Owner);
if (!component.TryGetData<SmokableState>(SmokingVisuals.Smoking, out var burnState))
return;

if (entities.TryGetComponent(component.Owner, out ISpriteComponent sprite))
var state = burnState switch
{
switch (burnState)
{
case SmokableState.Lit:
if (clothing != null)
clothing.EquippedPrefix = _litPrefix;
sprite.LayerSetState(0, _litIcon);
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;
}
}
SmokableState.Lit => _litIcon,
SmokableState.Burnt => _burntIcon,
_ => _unlitIcon
};

sprite.LayerSetState(0, state);
}
}
}
8 changes: 8 additions & 0 deletions Content.Server/Nutrition/Components/SmokableComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,13 @@ public class SmokableComponent : Component

[DataField("state")]
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";
}
}
13 changes: 11 additions & 2 deletions Content.Server/Nutrition/EntitySystems/SmokingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Content.Server.Body.Components;
using Content.Server.Body.Systems;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.Clothing.Components;
using Content.Server.Nutrition.Components;
using Content.Shared.Chemistry;
using Content.Shared.Chemistry.Reagent;
Expand Down Expand Up @@ -38,14 +39,22 @@ public override void Initialize()
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;

smokable.State = state;
appearance.SetData(SmokingVisuals.Smoking, state);

clothing.EquippedPrefix = state switch
{
SmokableState.Lit => smokable.LitPrefix,
SmokableState.Burnt => smokable.BurntPrefix,
_ => smokable.UnlitPrefix
};

if (state == SmokableState.Lit)
_active.Add(uid);
else
Expand Down