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

@@ -1,12 +1,8 @@
using System.Collections.Generic;
using Content.Server.Botany.Components;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.Popups;
using Content.Shared.GameTicking;
using Content.Shared.Tag;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
@@ -20,49 +16,13 @@ namespace Content.Server.Botany.Systems
[Dependency] private readonly IRobustRandom _robustRandom = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
private int _nextUid = 0;
private float _timer = 0f;
public readonly Dictionary<int, SeedPrototype> Seeds = new();
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
InitializeSeeds();
PopulateDatabase();
}
private void PopulateDatabase()
{
_nextUid = 0;
Seeds.Clear();
foreach (var seed in _prototypeManager.EnumeratePrototypes<SeedPrototype>())
{
seed.Uid = GetNextSeedUid();
Seeds[seed.Uid] = seed;
}
}
public bool AddSeedToDatabase(SeedPrototype seed)
{
// If it's not -1, it's already in the database. Probably.
if (seed.Uid != -1)
return false;
seed.Uid = GetNextSeedUid();
Seeds[seed.Uid] = seed;
return true;
}
private int GetNextSeedUid()
{
return _nextUid++;
}
public override void Update(float frameTime)
@@ -80,10 +40,5 @@ namespace Content.Server.Botany.Systems
plantHolder.Update();
}
}
public void Reset(RoundRestartCleanupEvent ev)
{
PopulateDatabase();
}
}
}