* Fix TransformComponent.MapPosition warnings in Content.Client * Fix TransformComponent.MapPosition warnings in Content.IntegrationTests * Fix TransformComponent.MapPosition warnings in Content.Shared * Fix TransformComponent.MapPosition warnings in Content.Server * Fix TransformComponent.WorldPosition warnings in Content.Shared * Fix TransformComponent.WorldPosition warnings in Content.Client Excepts ClickableComponent b/c that needs to be ECS'd entirely later * Fix TransformComponent.WorldPosition warnings in Content.Server * Fix TransformComponent.WorldRotation warnings in Content.* * Fix TransformComponent.MapPosition warnings I missed * Fix TransformComponent.WorldMatrix warnings in Content.* * Fix TransformComponent.InvWorldMatrix warnings in Content.* * Fix TransformComponent.GetWorldPositionRotationMatrixWithInv warnings in Content.* * Fix TransformComponent.GetWorldPositionRotationMatrix warnings in Content.* * Fix TransformComponent.GetWorldPositionRotation warnings in Content.* * Fix TransformComponent.Anchored.set warnings in Content.* * Fix TransformComponent.Coordinates.set warnings in Content.* * Fix TransformComponent.LocalPosition.set warnings in Content.* * Fix TransformComponent.AttachToGridOrMap warnings in Content.* * Fix TransformComponent.AttachParent warnings in Content.* * Preempt TransformComponent.LocalRotation.set warnings in Content.Shared * Preempt TransformComponent.LocalRotation.set warnings in Content.Client * Preempt TransformComponent.LocalRotation.set warnings in Content.IntegrationTests * Preempt TransformComponent.LocalRotation.set warnings in Content.Server * Fix/Preempt the remaining obsolete TransformComponent properties/methods in Content.* * ECS ClickableComponent * Fix obsolete SharedTransformSystem methods in Content.* * Fix ExplosionOverlay `SharedTransformSystem` dependency * Maybe fix null eye position breaking tests * MGS requested changes
61 lines
2.2 KiB
C#
61 lines
2.2 KiB
C#
using System.Numerics;
|
|
using Content.Server.Worldgen.Components;
|
|
using JetBrains.Annotations;
|
|
|
|
namespace Content.Server.Worldgen.Systems;
|
|
|
|
/// <summary>
|
|
/// This provides some additional functions for world generation systems.
|
|
/// Exists primarily for convenience and to avoid code duplication.
|
|
/// </summary>
|
|
[PublicAPI]
|
|
public abstract class BaseWorldSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly WorldControllerSystem _worldController = default!;
|
|
[Dependency] private readonly SharedTransformSystem _xformSystem = default!;
|
|
|
|
/// <summary>
|
|
/// Gets a chunk's coordinates in chunk space as an integer value.
|
|
/// </summary>
|
|
/// <param name="ent"></param>
|
|
/// <param name="xform"></param>
|
|
/// <returns>Chunk space coordinates</returns>
|
|
[Pure]
|
|
public Vector2i GetChunkCoords(EntityUid ent, TransformComponent? xform = null)
|
|
{
|
|
if (!Resolve(ent, ref xform))
|
|
throw new Exception("Failed to resolve transform, somehow.");
|
|
|
|
return WorldGen.WorldToChunkCoords(_xformSystem.GetWorldPosition(xform)).Floored();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets a chunk's coordinates in chunk space as a floating point value.
|
|
/// </summary>
|
|
/// <param name="ent"></param>
|
|
/// <param name="xform"></param>
|
|
/// <returns>Chunk space coordinates</returns>
|
|
[Pure]
|
|
public Vector2 GetFloatingChunkCoords(EntityUid ent, TransformComponent? xform = null)
|
|
{
|
|
if (!Resolve(ent, ref xform))
|
|
throw new Exception("Failed to resolve transform, somehow.");
|
|
|
|
return WorldGen.WorldToChunkCoords(_xformSystem.GetWorldPosition(xform));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attempts to get a chunk, creating it if it doesn't exist.
|
|
/// </summary>
|
|
/// <param name="chunk">Chunk coordinates to get the chunk entity for.</param>
|
|
/// <param name="map">Map the chunk is in.</param>
|
|
/// <param name="controller">The controller this chunk belongs to.</param>
|
|
/// <returns>A chunk, if available.</returns>
|
|
[Pure]
|
|
public EntityUid? GetOrCreateChunk(Vector2i chunk, EntityUid map, WorldControllerComponent? controller = null)
|
|
{
|
|
return _worldController.GetOrCreateChunk(chunk, map, controller);
|
|
}
|
|
}
|
|
|