Save seed data in components and remove the seed-database (#7499)

This commit is contained in:
Leon Friedrich
2022-04-16 17:32:35 +12:00
committed by GitHub
parent 98e7c84dad
commit 6997bd83b2
16 changed files with 225 additions and 232 deletions

View File

@@ -87,7 +87,7 @@ namespace Content.Server.Botany.Components
public float WeedCoefficient { get; set; } = 1f;
[ViewVariables(VVAccess.ReadWrite)]
public SeedPrototype? Seed { get; set; }
public SeedData? Seed { get; set; }
[ViewVariables(VVAccess.ReadWrite)]
public bool ImproperHeat { get; set; }
@@ -613,15 +613,14 @@ namespace Content.Server.Botany.Components
appearanceComponent.SetData(PlantHolderVisuals.HarvestLight, Harvest);
}
public void CheckForDivergence(bool modified)
/// <summary>
/// Check if the currently contained seed is unique. If it is not, clone it so that we have a unique seed.
/// Necessary to avoid modifying global seeds.
/// </summary>
public void EnsureUniqueSeed()
{
// Make sure we're not modifying a "global" seed.
// If this seed is not in the global seed list, then no products of this line have been harvested yet.
// It is then safe to assume it's restricted to this tray.
if (Seed == null) return;
var plantSystem = EntitySystem.Get<BotanySystem>();
if (plantSystem.Seeds.ContainsKey(Seed.Uid))
Seed = Seed.Diverge(modified);
if (Seed != null && !Seed.Unique)
Seed = Seed.Clone();
}
public void ForceUpdateByExternalCause()

View File

@@ -1,7 +1,5 @@
using Content.Server.Botany.Systems;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Botany.Components;
@@ -11,5 +9,15 @@ public sealed class ProduceComponent : Component
{
[DataField("targetSolution")] public string SolutionName { get; set; } = "food";
[DataField("seed", required: true)] public string SeedName = default!;
/// <summary>
/// Seed data used to create a <see cref="SeedComponent"/> when this produce has its seeds extracted.
/// </summary>
[DataField("seed")]
public SeedData? Seed;
/// <summary>
/// Seed data used to create a <see cref="SeedComponent"/> when this produce has its seeds extracted.
/// </summary>
[DataField("seedId", customTypeSerializer: typeof(PrototypeIdSerializer<SeedPrototype>))]
public readonly string? SeedId;
}

View File

@@ -1,7 +1,4 @@
using Content.Server.Botany.Systems;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Botany.Components
@@ -9,7 +6,18 @@ namespace Content.Server.Botany.Components
[RegisterComponent, Friend(typeof(BotanySystem))]
public sealed class SeedComponent : Component
{
[DataField("seed", required: true, customTypeSerializer:typeof(PrototypeIdSerializer<SeedPrototype>))]
public string SeedName = default!;
/// <summary>
/// Seed data containing information about the plant type & properties that this seed can grow seed. If
/// null, will instead attempt to get data from a seed prototype, if one is defined. See <see
/// cref="SeedId"/>.
/// </summary>
[DataField("seed")]
public SeedData? Seed;
/// <summary>
/// Name of a base seed prototype that is used if <see cref="Seed"/> is null.
/// </summary>
[DataField("seedId", customTypeSerializer:typeof(PrototypeIdSerializer<SeedPrototype>))]
public readonly string? SeedId;
}
}