Converted BurnState Visualizer (#15661)
This commit is contained in:
@@ -1,49 +0,0 @@
|
|||||||
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 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";
|
|
||||||
|
|
||||||
void ISerializationHooks.AfterDeserialization()
|
|
||||||
{
|
|
||||||
IoCManager.InjectDependencies(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Obsolete("Subscribe to AppearanceChangeEvent instead.")]
|
|
||||||
public override void OnChangeData(AppearanceComponent component)
|
|
||||||
{
|
|
||||||
base.OnChangeData(component);
|
|
||||||
|
|
||||||
if (!_entMan.TryGetComponent(component.Owner, out SpriteComponent? sprite))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!component.TryGetData<SmokableState>(SmokingVisuals.Smoking, out var burnState))
|
|
||||||
return;
|
|
||||||
|
|
||||||
var state = burnState switch
|
|
||||||
{
|
|
||||||
SmokableState.Lit => _litIcon,
|
|
||||||
SmokableState.Burnt => _burntIcon,
|
|
||||||
_ => _unlitIcon
|
|
||||||
};
|
|
||||||
|
|
||||||
sprite.LayerSetState(0, state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
25
Content.Client/Smoking/BurnStateVisualizerSystem.cs
Normal file
25
Content.Client/Smoking/BurnStateVisualizerSystem.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using Robust.Client.GameObjects;
|
||||||
|
using Content.Shared.Smoking;
|
||||||
|
|
||||||
|
namespace Content.Client.Smoking;
|
||||||
|
|
||||||
|
public sealed class BurnStateVisualizerSystem : VisualizerSystem<BurnStateVisualsComponent>
|
||||||
|
{
|
||||||
|
protected override void OnAppearanceChange(EntityUid uid, BurnStateVisualsComponent component, ref AppearanceChangeEvent args)
|
||||||
|
{
|
||||||
|
if (args.Sprite == null)
|
||||||
|
return;
|
||||||
|
if (!args.AppearanceData.TryGetValue(SmokingVisuals.Smoking, out var burnState))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var state = burnState switch
|
||||||
|
{
|
||||||
|
SmokableState.Lit => component.LitIcon,
|
||||||
|
SmokableState.Burnt => component.BurntIcon,
|
||||||
|
_ => component.UnlitIcon
|
||||||
|
};
|
||||||
|
|
||||||
|
args.Sprite.LayerSetState(0, state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
13
Content.Client/Smoking/BurnStateVisualsComponent.cs
Normal file
13
Content.Client/Smoking/BurnStateVisualsComponent.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
namespace Content.Client.Smoking;
|
||||||
|
|
||||||
|
[RegisterComponent]
|
||||||
|
public sealed class BurnStateVisualsComponent : Component
|
||||||
|
{
|
||||||
|
[DataField("burntIcon")]
|
||||||
|
public string BurntIcon = "burnt-icon";
|
||||||
|
[DataField("litIcon")]
|
||||||
|
public string LitIcon = "lit-icon";
|
||||||
|
[DataField("unlitIcon")]
|
||||||
|
public string UnlitIcon = "icon";
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Shared.Smoking
|
namespace Content.Shared.Smoking
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,9 +16,8 @@
|
|||||||
size: 3
|
size: 3
|
||||||
sprite: Objects/Consumable/Smokeables/Pipes/pipe.rsi
|
sprite: Objects/Consumable/Smokeables/Pipes/pipe.rsi
|
||||||
- type: Appearance
|
- type: Appearance
|
||||||
visuals:
|
- type: BurnStateVisuals
|
||||||
- type: BurnStateVisualizer
|
unlitIcon: unlit-icon
|
||||||
unlitIcon: unlit-icon
|
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: SmokingPipeFilledTobacco
|
id: SmokingPipeFilledTobacco
|
||||||
@@ -31,15 +30,15 @@
|
|||||||
bowl_slot: !type:ContainerSlot
|
bowl_slot: !type:ContainerSlot
|
||||||
- type: ItemSlots
|
- type: ItemSlots
|
||||||
- type: SmokingPipe
|
- type: SmokingPipe
|
||||||
bowl_slot:
|
bowl_slot:
|
||||||
name: Bowl
|
name: Bowl
|
||||||
startingItem: GroundTobacco
|
startingItem: GroundTobacco
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- Smokable
|
- Smokable
|
||||||
insertSound:
|
insertSound:
|
||||||
path: /Audio/Weapons/Guns/Empty/empty.ogg
|
path: /Audio/Weapons/Guns/Empty/empty.ogg
|
||||||
ejectSound:
|
ejectSound:
|
||||||
path: /Audio/Weapons/Guns/Empty/empty.ogg
|
path: /Audio/Weapons/Guns/Empty/empty.ogg
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
@@ -53,13 +52,13 @@
|
|||||||
bowl_slot: !type:ContainerSlot
|
bowl_slot: !type:ContainerSlot
|
||||||
- type: ItemSlots
|
- type: ItemSlots
|
||||||
- type: SmokingPipe
|
- type: SmokingPipe
|
||||||
bowl_slot:
|
bowl_slot:
|
||||||
name: Bowl
|
name: Bowl
|
||||||
startingItem: GroundCannabis
|
startingItem: GroundCannabis
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- Smokable
|
- Smokable
|
||||||
insertSound:
|
insertSound:
|
||||||
|
path: /Audio/Weapons/Guns/Empty/empty.ogg
|
||||||
|
ejectSound:
|
||||||
path: /Audio/Weapons/Guns/Empty/empty.ogg
|
path: /Audio/Weapons/Guns/Empty/empty.ogg
|
||||||
ejectSound:
|
|
||||||
path: /Audio/Weapons/Guns/Empty/empty.ogg
|
|
||||||
@@ -8,8 +8,7 @@
|
|||||||
- type: Sprite
|
- type: Sprite
|
||||||
netsync: false
|
netsync: false
|
||||||
- type: Appearance
|
- type: Appearance
|
||||||
visuals:
|
- type: BurnStateVisuals
|
||||||
- type: BurnStateVisualizer
|
|
||||||
- type: Tag
|
- type: Tag
|
||||||
tags:
|
tags:
|
||||||
- Trash
|
- Trash
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
- type: entity
|
- type: entity
|
||||||
id: SmallboxItem
|
id: SmallboxItem
|
||||||
parent: BaseStorageItem
|
parent: BaseStorageItem
|
||||||
abstract: true
|
abstract: true
|
||||||
@@ -37,11 +37,10 @@
|
|||||||
radius: 1.1
|
radius: 1.1
|
||||||
color: darkorange
|
color: darkorange
|
||||||
- type: Appearance
|
- type: Appearance
|
||||||
visuals:
|
- type: BurnStateVisuals
|
||||||
- type: BurnStateVisualizer
|
unlitIcon: match_unlit
|
||||||
unlitIcon: match_unlit
|
litIcon: match_lit
|
||||||
litIcon: match_lit
|
burntIcon: match_burnt
|
||||||
burntIcon: match_burnt
|
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: Matchstick
|
parent: Matchstick
|
||||||
|
|||||||
Reference in New Issue
Block a user