Add microwave visualizer. Clean up microwave code.

This commit is contained in:
FL-OZ
2020-05-01 03:37:21 -05:00
parent 5d4c0609ec
commit b2aca9a686
11 changed files with 238 additions and 12 deletions

View File

@@ -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
}
}
}

View File

@@ -8,6 +8,11 @@ using Robust.Shared.Serialization;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;
using Content.Shared.Prototypes.Kitchen; using Content.Shared.Prototypes.Kitchen;
using Content.Shared.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 namespace Content.Server.GameObjects.Components.Kitchen
{ {
@@ -17,19 +22,28 @@ namespace Content.Server.GameObjects.Components.Kitchen
{ {
#pragma warning disable 649 #pragma warning disable 649
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
[Dependency] private readonly IEntityManager _entityManager; [Dependency] private readonly IEntityManager _entityManager;
[Dependency] private readonly RecipeManager _recipeManager; [Dependency] private readonly RecipeManager _recipeManager;
#pragma warning restore 649 #pragma warning restore 649
public override string Name => "Microwave"; public override string Name => "Microwave";
private int _cookTimeSeconds;
private string _badRecipeName;
[ViewVariables] [ViewVariables]
private SolutionComponent _contents; private SolutionComponent _contents;
private AppearanceComponent _appearance;
private AudioSystem _audioSystem;
private PowerDeviceComponent _powerDevice;
public override void ExposeData(ObjectSerializer serializer) public override void ExposeData(ObjectSerializer serializer)
{ {
base.ExposeData(serializer); base.ExposeData(serializer);
serializer.DataField(ref _badRecipeName, "failureResult", "FoodBadRecipe");
serializer.DataField(ref _cookTimeSeconds, "cookTime", 5000);
} }
public override void Initialize() public override void Initialize()
@@ -46,23 +60,43 @@ namespace Content.Server.GameObjects.Components.Kitchen
_contents = Owner.AddComponent<SolutionComponent>(); _contents = Owner.AddComponent<SolutionComponent>();
} }
} }
_appearance = Owner.GetComponent<AppearanceComponent>();
_powerDevice = Owner.GetComponent<PowerDeviceComponent>();
_audioSystem = _entitySystemManager.GetEntitySystem<AudioSystem>();
} }
void IActivate.Activate(ActivateEventArgs eventArgs) void IActivate.Activate(ActivateEventArgs eventArgs)
{ {
if(_contents.ReagentList.Count > 0) if (_contents.ReagentList.Count == 0 || !_powerDevice.Powered)
{ {
return;
}
foreach(var r in _recipeManager.Recipes) foreach(var r in _recipeManager.Recipes)
{ {
if(CanSatisfyRecipe(r)) if(CanSatisfyRecipe(r))
{
SetAppearance(MicrowaveVisualState.Cooking);
Timer.Spawn(_cookTimeSeconds, () =>
{ {
RemoveContents(r); RemoveContents(r);
var resultPrototype = r.Result; _entityManager.SpawnEntity(r.Result, Owner.Transform.GridPosition);
_entityManager.SpawnEntity(resultPrototype, Owner.Transform.GridPosition);
_audioSystem.Play("/Audio/machines/ding.ogg");
SetAppearance(MicrowaveVisualState.PoweredIdle);
});
return; 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) 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);
}
} }
} }

View File

@@ -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 // ReSharper disable once RedundantUsingDirective
using Robust.Shared.Utility; using Robust.Shared.Utility;
using System; using System;

View 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
}
}

Binary file not shown.

View File

@@ -9,6 +9,9 @@
- type: Solution - type: Solution
maxVol: 100 maxVol: 100
caps: 1 caps: 1
- type: Appearance
visuals:
- type: MicrowaveVisualizer
- type: Collidable - type: Collidable
shapes: shapes:
@@ -19,7 +22,12 @@
- type: Sprite - type: Sprite
netsync: false netsync: false
sprite: Objects/Kitchen/microwave.rsi 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: PowerDevice
- type: Icon - type: Icon
sprite: Objects/Kitchen/microwave.rsi sprite: Objects/Kitchen/microwave.rsi

View File

@@ -5,3 +5,11 @@
ingredients: ingredients:
chem.H2O: 15 chem.H2O: 15
chem.Nutriment: 5 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

View File

@@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB