Files
tbd-station-14/Content.Client/GameObjects/Components/Nutrition/DrinkFoodContainerVisualizer2D.cs
metalgearsloth de148fc98f Add hunger and thirst (#363)
* Add hunger and thirst

Based on the SS13 systems.
Food (Nutriment) / Drink -> Stomach -> Hunger / Thirst

* Cleanup rebase

* Cleanup stuff that was prototyped

* Address feedback

Still need to add a statuseffects system in a separate branch

* More cleanup on nutrition

Fix Remie's feedback and also damage tick.

* Re-implement nutrition with master

* Updated to use the StatusEffectsUI update
* Removed all clientside components as they only receive the UI updates now
* Implemented PR feedback
* Had to make a slight adjustment to the chemistry SolutionComponent given it doesn't have an Owner, same with Solution

Still TODO:
* Metabolisation effects
* Change drink contents to alcohol / wine etc.
* Add items to the dispensers
* For transparent containers use RecalculateColor

Could probably genericise DrinkFoodContainer as well to be a temporary item dispenser

* Fix broken bottle parent
2019-11-11 22:20:03 +01:00

68 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
using Content.Shared.GameObjects.Components.Nutrition;
using Content.Shared.Utility;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.Interfaces.GameObjects.Components;
using Robust.Shared.Utility;
using YamlDotNet.RepresentationModel;
namespace Content.Client.GameObjects.Components.Nutrition
{
[UsedImplicitly]
public sealed class DrinkFoodContainerVisualizer2D : AppearanceVisualizer
{
private string _baseState;
private int _steps;
private DrinkFoodContainerVisualMode _mode;
public override void LoadData(YamlMappingNode node)
{
base.LoadData(node);
_baseState = node.GetNode("base_state").AsString();
_steps = node.GetNode("steps").AsInt();
try
{
_mode = node.GetNode("mode").AsEnum<DrinkFoodContainerVisualMode>();
}
catch (KeyNotFoundException)
{
_mode = DrinkFoodContainerVisualMode.Rounded;
}
}
public override void OnChangeData(AppearanceComponent component)
{
var sprite = component.Owner.GetComponent<ISpriteComponent>();
if (!component.TryGetData<int>(DrinkFoodContainerVisuals.Current, out var current))
{
return;
}
if (!component.TryGetData<int>(DrinkFoodContainerVisuals.Capacity, out var capacity))
{
return;
}
int step;
switch (_mode)
{
case DrinkFoodContainerVisualMode.Discrete:
step = Math.Min(_steps - 1, current);
break;
case DrinkFoodContainerVisualMode.Rounded:
step = ContentHelpers.RoundToLevels(current, capacity, _steps);
break;
default:
throw new NullReferenceException();
}
sprite.LayerSetState(0, $"{_baseState}-{step}");
}
}
}