Add microwave visualizer. Clean up microwave code.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using Content.Shared.GameObjects.Components.Power;
|
||||
using Content.Shared.Kitchen;
|
||||
using Robust.Client.Animations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Interfaces.GameObjects.Components;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Kitchen
|
||||
{
|
||||
public sealed class MicrowaveVisualizer : AppearanceVisualizer
|
||||
{
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
var sprite = component.Owner.GetComponent<ISpriteComponent>();
|
||||
if (!component.TryGetData(PowerDeviceVisuals.VisualState, out MicrowaveVisualState state))
|
||||
{
|
||||
state = MicrowaveVisualState.PoweredIdle;
|
||||
}
|
||||
switch (state)
|
||||
{
|
||||
case MicrowaveVisualState.PoweredIdle:
|
||||
sprite.LayerSetState(MicrowaveVisualizerLayers.Base, "mw");
|
||||
sprite.LayerSetState(MicrowaveVisualizerLayers.BaseUnlit, "mw_unlit");
|
||||
break;
|
||||
|
||||
case MicrowaveVisualState.Cooking:
|
||||
sprite.LayerSetState(MicrowaveVisualizerLayers.Base, "mw");
|
||||
sprite.LayerSetState(MicrowaveVisualizerLayers.BaseUnlit, "mw_running_unlit");
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
var glowingPartsVisible = !(component.TryGetData(PowerDeviceVisuals.Powered, out bool powered) && !powered);
|
||||
sprite.LayerSetVisible(MicrowaveVisualizerLayers.BaseUnlit, glowingPartsVisible);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public enum MicrowaveVisualizerLayers
|
||||
{
|
||||
Base,
|
||||
BaseUnlit
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -8,6 +8,11 @@ using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Content.Shared.Prototypes.Kitchen;
|
||||
using Content.Shared.Kitchen;
|
||||
using Robust.Shared.Timers;
|
||||
using Robust.Server.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Power;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.GameObjects.Components.Power;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Kitchen
|
||||
{
|
||||
@@ -17,19 +22,28 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
{
|
||||
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
|
||||
[Dependency] private readonly IEntityManager _entityManager;
|
||||
[Dependency] private readonly RecipeManager _recipeManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
public override string Name => "Microwave";
|
||||
|
||||
private int _cookTimeSeconds;
|
||||
private string _badRecipeName;
|
||||
[ViewVariables]
|
||||
private SolutionComponent _contents;
|
||||
|
||||
private AppearanceComponent _appearance;
|
||||
|
||||
private AudioSystem _audioSystem;
|
||||
|
||||
private PowerDeviceComponent _powerDevice;
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _badRecipeName, "failureResult", "FoodBadRecipe");
|
||||
serializer.DataField(ref _cookTimeSeconds, "cookTime", 5000);
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
@@ -46,23 +60,43 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
_contents = Owner.AddComponent<SolutionComponent>();
|
||||
}
|
||||
}
|
||||
|
||||
_appearance = Owner.GetComponent<AppearanceComponent>();
|
||||
_powerDevice = Owner.GetComponent<PowerDeviceComponent>();
|
||||
_audioSystem = _entitySystemManager.GetEntitySystem<AudioSystem>();
|
||||
}
|
||||
|
||||
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
if(_contents.ReagentList.Count > 0)
|
||||
if (_contents.ReagentList.Count == 0 || !_powerDevice.Powered)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach(var r in _recipeManager.Recipes)
|
||||
{
|
||||
if(CanSatisfyRecipe(r))
|
||||
{
|
||||
SetAppearance(MicrowaveVisualState.Cooking);
|
||||
Timer.Spawn(_cookTimeSeconds, () =>
|
||||
{
|
||||
RemoveContents(r);
|
||||
var resultPrototype = r.Result;
|
||||
_entityManager.SpawnEntity(resultPrototype, Owner.Transform.GridPosition);
|
||||
_entityManager.SpawnEntity(r.Result, Owner.Transform.GridPosition);
|
||||
|
||||
_audioSystem.Play("/Audio/machines/ding.ogg");
|
||||
SetAppearance(MicrowaveVisualState.PoweredIdle);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SetAppearance(MicrowaveVisualState.Cooking);
|
||||
Timer.Spawn(_cookTimeSeconds, () =>
|
||||
{
|
||||
_contents.RemoveAllSolution();
|
||||
_entityManager.SpawnEntity(_badRecipeName, Owner.Transform.GridPosition);
|
||||
_audioSystem.Play("/Audio/machines/ding.ogg");
|
||||
SetAppearance(MicrowaveVisualState.PoweredIdle);
|
||||
});
|
||||
}
|
||||
|
||||
private bool CanSatisfyRecipe(FoodRecipePrototype recipe)
|
||||
@@ -91,6 +125,10 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void SetAppearance(MicrowaveVisualState state)
|
||||
{
|
||||
if (_appearance != null || Owner.TryGetComponent(out _appearance))
|
||||
_appearance.SetData(PowerDeviceVisuals.VisualState, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Only unused on .NET Core due to KeyValuePair.Deconstruct
|
||||
// Only unused on .NET Core due to KeyValuePair.Deconstruct
|
||||
// ReSharper disable once RedundantUsingDirective
|
||||
using Robust.Shared.Utility;
|
||||
using System;
|
||||
|
||||
18
Content.Shared/Kitchen/SharedMicrowave.cs
Normal file
18
Content.Shared/Kitchen/SharedMicrowave.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Robust.Shared.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Content.Shared.Kitchen
|
||||
{
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum MicrowaveVisualState
|
||||
{
|
||||
Off,
|
||||
PoweredIdle,
|
||||
Cooking
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
BIN
Resources/Audio/machines/ding.ogg
Normal file
BIN
Resources/Audio/machines/ding.ogg
Normal file
Binary file not shown.
@@ -9,6 +9,9 @@
|
||||
- type: Solution
|
||||
maxVol: 100
|
||||
caps: 1
|
||||
- type: Appearance
|
||||
visuals:
|
||||
- type: MicrowaveVisualizer
|
||||
|
||||
- type: Collidable
|
||||
shapes:
|
||||
@@ -19,7 +22,12 @@
|
||||
- type: Sprite
|
||||
netsync: false
|
||||
sprite: Objects/Kitchen/microwave.rsi
|
||||
state: mw0
|
||||
layers:
|
||||
- state: mw0
|
||||
map: ["enum.MicrowaveVisualizerLayers.Base"]
|
||||
- state: mw_unlit
|
||||
shader: unshaded
|
||||
map: ["enum.MicrowaveVisualizerLayers.BaseUnlit"]
|
||||
- type: PowerDevice
|
||||
- type: Icon
|
||||
sprite: Objects/Kitchen/microwave.rsi
|
||||
|
||||
@@ -5,3 +5,11 @@
|
||||
ingredients:
|
||||
chem.H2O: 15
|
||||
chem.Nutriment: 5
|
||||
|
||||
- type: microwaveMealRecipe
|
||||
id: RecipeFlashlight
|
||||
name: Flashlight Recipe
|
||||
result: FoodCheeseWedge
|
||||
ingredients:
|
||||
chem.H2O: 15
|
||||
chem.Glucose: 5
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.1 KiB |
@@ -1 +1,105 @@
|
||||
{"version": 1, "size": {"x": 32, "y": 32}, "license": "AGPL v3", "copyright": "Taken from https://github.com/discordia-space/CEV-Eris", "states": [{"name": "mw", "directions": 1, "delays": [[1.0]]}, {"name": "mw0", "directions": 1, "delays": [[1.0]]}, {"name": "mw1", "directions": 1, "delays": [[0.1, 0.1]]}, {"name": "mwb", "directions": 1, "delays": [[1.0]]}, {"name": "mwbloody", "directions": 1, "delays": [[1.0]]}, {"name": "mwbloody0", "directions": 1, "delays": [[1.0]]}, {"name": "mwbloody1", "directions": 1, "delays": [[0.1, 0.1]]}, {"name": "mwbloodyo", "directions": 1, "delays": [[0.1, 0.1]]}, {"name": "mwo", "directions": 1, "delays": [[0.1, 0.1]]}]}
|
||||
{
|
||||
"version": 1,
|
||||
"size": {
|
||||
"x": 32,
|
||||
"y": 32
|
||||
},
|
||||
"license": "AGPL v3",
|
||||
"copyright": "Taken from https://github.com/discordia-space/CEV-Eris",
|
||||
"states": [
|
||||
{
|
||||
"name": "mw",
|
||||
"directions": 1,
|
||||
"delays": [
|
||||
[
|
||||
1.0
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "mw_unlit",
|
||||
"directions": 1,
|
||||
"delays": [
|
||||
[
|
||||
1.0
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "mw0",
|
||||
"directions": 1,
|
||||
"delays": [
|
||||
[
|
||||
1.0
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "mw_running_unlit",
|
||||
"directions": 1,
|
||||
"delays": [
|
||||
[
|
||||
1.0,
|
||||
1.0
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "mwb",
|
||||
"directions": 1,
|
||||
"delays": [
|
||||
[
|
||||
1.0
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "mwbloody",
|
||||
"directions": 1,
|
||||
"delays": [
|
||||
[
|
||||
1.0
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "mwbloody0",
|
||||
"directions": 1,
|
||||
"delays": [
|
||||
[
|
||||
1.0
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "mwbloody1",
|
||||
"directions": 1,
|
||||
"delays": [
|
||||
[
|
||||
0.1,
|
||||
0.1
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "mwbloodyo",
|
||||
"directions": 1,
|
||||
"delays": [
|
||||
[
|
||||
0.1,
|
||||
0.1
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "mwo",
|
||||
"directions": 1,
|
||||
"delays": [
|
||||
[
|
||||
0.1,
|
||||
0.1
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
BIN
Resources/Textures/Objects/Kitchen/microwave.rsi/mw_unlit.png
Normal file
BIN
Resources/Textures/Objects/Kitchen/microwave.rsi/mw_unlit.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
Reference in New Issue
Block a user