* Recipe stuff.

* Lathe GUI and stuff

* god dammit

* Lathe menu works, yay.

* EventArgs henk

* Some work

* SS14 -> Robust

* More SS14 -> Robust

* Lathe materials

* Lathe works, Lathe GUI, Queue GUI, etc

too many changes to name them here

* Remove materials button, add ViewVariables and update lathe on connect

* Add Autolathe RSI

* Adds new recipes, fixes a few bugs.

* Remove unused ScrollContainers

* Use same delegate for spawn.

* Removes client-side LatheComponent in favor of BoundUserInterface

* Remove GetMaterial and TryGetMaterial

* Use auto-properties in a few places.

* Adds LatheDatabase, and a bunch of other changes

* Remove useless log.

* Remove lathetype from prototypes.

* Turns Storage, Lathe and Database into autoproperties

* Remove Hacked property from LatheRecipePrototype

* Remove unneeded dependency injection from components

* Refactors LatheDatabaseComponent to use ComponentState

* Refactors MaterialStorageComponent to use ComponentState

* Oopsie

* Another oopsie

* Last oopsie, I hope

* Fix missing Close call.
This commit is contained in:
Víctor Aguilera Puerto
2019-04-26 15:51:05 +02:00
committed by Pieter-Jan Briers
parent 092539ae59
commit fe0414eda7
37 changed files with 1580 additions and 13 deletions

View File

@@ -0,0 +1,87 @@
using System.Collections.Generic;
using Content.Shared.Materials;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.Reflection;
using Robust.Shared.Interfaces.Serialization;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
namespace Content.Shared.GameObjects.Components.Materials
{
/// <summary>
/// Component to store data such as "this object is made out of steel".
/// This is not a storage system for say smelteries.
/// </summary>
public class MaterialComponent : Component
{
public const string SerializationCache = "mat";
public override string Name => "Material";
public Dictionary<object, Material> MaterialTypes => _materialTypes;
private Dictionary<object, Material> _materialTypes;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
// TODO: Writing.
if (!serializer.Reading)
{
return;
}
if (serializer.TryGetCacheData(SerializationCache, out Dictionary<object, Material> cached))
{
_materialTypes = cached.ShallowClone();
return;
}
_materialTypes = new Dictionary<object, Material>();
if (serializer.TryReadDataField("materials", out List<MaterialDataEntry> list))
{
var protoMan = IoCManager.Resolve<IPrototypeManager>();
int index = 0;
foreach (var entry in list)
{
var proto = protoMan.Index<MaterialPrototype>(entry.Value);
_materialTypes[entry.Key] = proto.Material;
index++;
}
}
serializer.SetCacheData(SerializationCache, _materialTypes.ShallowClone());
}
class MaterialDataEntry : IExposeData
{
public object Key;
public string Value;
public void ExposeData(ObjectSerializer serializer)
{
if (!serializer.Reading)
{
return;
}
var refl = IoCManager.Resolve<IReflectionManager>();
Value = serializer.ReadDataField<string>("mat");
var key = serializer.ReadDataField<string>("key");
if (refl.TryParseEnumReference(key, out var @enum))
{
Key = @enum;
return;
}
Key = key;
}
}
}
public enum MaterialKeys
{
Stack,
}
}

View File

@@ -0,0 +1,116 @@
using System;
using System.Collections.Generic;
using Content.Shared.Materials;
using Content.Shared.Research;
using Mono.Cecil;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.UserInterface;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
namespace Content.Shared.GameObjects.Components.Research
{
public class SharedLatheComponent : Component
{
public override string Name => "Lathe";
public override uint? NetID => ContentNetIDs.LATHE;
#pragma warning disable CS0649
[Dependency]
protected IPrototypeManager _prototypeManager;
#pragma warning restore
public bool CanProduce(LatheRecipePrototype recipe, int quantity = 1)
{
if (!Owner.TryGetComponent(out SharedMaterialStorageComponent storage)
|| !Owner.TryGetComponent(out SharedLatheDatabaseComponent database)) return false;
if (!database.Contains(recipe)) return false;
foreach (var (material, amount) in recipe.RequiredMaterials)
{
if (storage[material] <= (amount * quantity)) return false;
}
return true;
}
public bool CanProduce(string ID, int quantity = 1)
{
return _prototypeManager.TryIndex(ID, out LatheRecipePrototype recipe) && CanProduce(recipe, quantity);
}
/// <summary>
/// Sent to the server to sync material storage and the recipe queue.
/// </summary>
[Serializable, NetSerializable]
public class LatheSyncRequestMessage : BoundUserInterfaceMessage
{
public LatheSyncRequestMessage()
{
}
}
/// <summary>
/// Sent to the client when the lathe is producing a recipe.
/// </summary>
[Serializable, NetSerializable]
public class LatheProducingRecipeMessage : BoundUserInterfaceMessage
{
public readonly string ID;
public LatheProducingRecipeMessage(string id)
{
ID = id;
}
}
/// <summary>
/// Sent to the client when the lathe stopped/finished producing a recipe.
/// </summary>
[Serializable, NetSerializable]
public class LatheStoppedProducingRecipeMessage : BoundUserInterfaceMessage
{
public LatheStoppedProducingRecipeMessage()
{
}
}
/// <summary>
/// Sent to the client to let it know about the recipe queue.
/// </summary>
[Serializable, NetSerializable]
public class LatheFullQueueMessage : BoundUserInterfaceMessage
{
public readonly Queue<string> Recipes;
public LatheFullQueueMessage(Queue<string> recipes)
{
Recipes = recipes;
}
}
/// <summary>
/// Sent to the server when a client queues a new recipe.
/// </summary>
[Serializable, NetSerializable]
public class LatheQueueRecipeMessage : BoundUserInterfaceMessage
{
public readonly string ID;
public readonly int Quantity;
public LatheQueueRecipeMessage(string id, int quantity)
{
ID = id;
Quantity = quantity;
}
}
[NetSerializable, Serializable]
public enum LatheUiKey
{
Key,
}
}
}

View File

@@ -0,0 +1,107 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Content.Shared.Research;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
namespace Content.Shared.GameObjects.Components.Research
{
public class SharedLatheDatabaseComponent : Component, IEnumerable<LatheRecipePrototype>
{
public override string Name => "LatheDatabase";
public sealed override uint? NetID => ContentNetIDs.LATHE_DATABASE;
public sealed override Type StateType => typeof(LatheDatabaseState);
private List<LatheRecipePrototype> _recipes = new List<LatheRecipePrototype>();
/// <summary>
/// Removes all recipes from the database if it's not static.
/// </summary>
/// <returns>Whether it could clear the database or not.</returns>
public virtual void Clear()
{
_recipes.Clear();
}
/// <summary>
/// Adds a recipe to the database if it's not static.
/// </summary>
/// <param name="recipe">The recipe to be added.</param>
/// <returns>Whether it could be added or not</returns>
public virtual void AddRecipe(LatheRecipePrototype recipe)
{
_recipes.Add(recipe);
}
/// <summary>
/// Removes a recipe from the database if it's not static.
/// </summary>
/// <param name="recipe">The recipe to be removed.</param>
/// <returns>Whether it could be removed or not</returns>
public virtual bool RemoveRecipe(LatheRecipePrototype recipe)
{
return _recipes.Remove(recipe);
}
/// <summary>
/// Returns whether the database contains the recipe or not.
/// </summary>
/// <param name="recipe">The recipe to check</param>
/// <returns>Whether the database contained the recipe or not.</returns>
public virtual bool Contains(LatheRecipePrototype recipe)
{
return _recipes.Contains(recipe);
}
/// <summary>
/// Returns whether the database contains the recipe or not.
/// </summary>
/// <param name="id">The recipe id to check</param>
/// <returns>Whether the database contained the recipe or not.</returns>
public virtual bool Contains(string id)
{
foreach (var recipe in _recipes)
{
if (recipe.ID == id) return true;
}
return false;
}
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
var recipes = serializer.ReadDataField("recipes", new List<string>());
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
foreach (var id in recipes)
{
if (!prototypeManager.TryIndex(id, out LatheRecipePrototype recipe)) continue;
_recipes.Add(recipe);
}
}
public IEnumerator<LatheRecipePrototype> GetEnumerator()
{
return _recipes.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
[NetSerializable, Serializable]
public class LatheDatabaseState : ComponentState
{
public readonly List<string> Recipes;
public LatheDatabaseState(List<string> recipes) : base(ContentNetIDs.LATHE_DATABASE)
{
Recipes = recipes;
}
}
}

View File

@@ -0,0 +1,78 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Content.Shared.Materials;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Shared.GameObjects.Components.Research
{
public class SharedMaterialStorageComponent : Component, IEnumerable<KeyValuePair<string, int>>
{
[ViewVariables]
protected virtual Dictionary<string, int> Storage { get; set; }
public override string Name => "MaterialStorage";
public sealed override uint? NetID => ContentNetIDs.MATERIAL_STORAGE;
public sealed override Type StateType => typeof(MaterialStorageState);
public int this[string ID]
{
get
{
if (!Storage.ContainsKey(ID))
return 0;
return Storage[ID];
}
}
public int this[Material material]
{
get
{
var ID = material.ID;
if (!Storage.ContainsKey(ID))
return 0;
return Storage[ID];
}
}
/// <summary>
/// The total volume of material stored currently.
/// </summary>
[ViewVariables] public int CurrentAmount
{
get
{
var value = 0;
foreach (var amount in Storage.Values)
{
value += amount;
}
return value;
}
}
public IEnumerator<KeyValuePair<string, int>> GetEnumerator()
{
return Storage.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
[NetSerializable, Serializable]
public class MaterialStorageState : ComponentState
{
public readonly Dictionary<string, int> Storage;
public MaterialStorageState(Dictionary<string, int> storage) : base(ContentNetIDs.MATERIAL_STORAGE)
{
Storage = storage;
}
}
}