using System.Numerics; using Content.Server.Worldgen.Components; using Content.Server.Worldgen.Prototypes; using Robust.Shared.Prototypes; using Robust.Shared.Random; namespace Content.Server.Worldgen.Systems; /// /// This handles the noise index. /// public sealed class NoiseIndexSystem : EntitySystem { [Dependency] private readonly IPrototypeManager _prototype = default!; [Dependency] private readonly IRobustRandom _random = default!; /// /// Gets a particular noise channel from the index on the given entity. /// /// The holder of the index /// The channel prototype ID /// An initialized noise generator public NoiseGenerator Get(EntityUid holder, string protoId) { var idx = EnsureComp(holder); if (idx.Generators.TryGetValue(protoId, out var generator)) return generator; var proto = _prototype.Index(protoId); var gen = new NoiseGenerator(proto, _random.Next()); idx.Generators[protoId] = gen; return gen; } /// /// Attempts to evaluate the given noise channel using the generator on the given entity. /// /// The holder of the index /// The channel prototype ID /// The coordinates to evaluate at /// The result of evaluation public float Evaluate(EntityUid holder, string protoId, Vector2 coords) { var gen = Get(holder, protoId); return gen.Evaluate(coords); } }