using System;
using Luneraria.Core;
using Luneraria.View;
namespace Luneraria.EditorTools
{
///
/// Weg 2 (Stufen) of the U5 map decision (docs/port/U5-VISUAL.md): target quality along the
/// lanes, simpler materials in the edge zones. A point counts as lane tier while it is within
/// LaneCorridor metres of a lane centreline, a building or the grotto — the corridor the
/// players actually look at. Everything beyond (mountains, rim cliffs, far vegetation) gets
/// the edge tier: colour and stone relief, no PBR maps (Surface _Quality 0).
///
public static class LuneZones
{
/// Metres from a lane centreline (or a building) that still count as lane tier.
public const float LaneCorridor = 22f;
/// Distance from at to the nearest lane centreline sample.
public static double DistanceToLanes(LuneMap map, Vec2 at)
{
double best = double.MaxValue;
foreach (string lane in LuneMap.Lanes)
{
LanePath path = map.LanePaths[lane];
for (int i = 0; i < path.Points.Length; i++)
{
float distance = path.Points[i].DistanceTo(at);
if (distance < best)
best = distance;
}
}
return best;
}
/// True while at is in the target-quality corridor of the slice.
public static bool NearLane(LuneMap map, Vec2 at)
{
if (DistanceToLanes(map, at) <= LaneCorridor)
return true;
foreach (BuildingDef building in map.Buildings)
{
if (building.Position.DistanceTo(at) <= LaneCorridor)
return true;
}
return map.GrottoCenter().DistanceTo(at) <= LaneCorridor * 1.5;
}
/// Quality for the Surface shader: 1 lane tier (full PBR), 0 edge tier.
public static float QualityOf(LuneMap map, Vec2 at)
{
return NearLane(map, at) ? 1f : 0f;
}
/// Quality of a world-space point (Unity coordinates; x is mirrored).
public static float QualityOfWorld(LuneMap map, UnityEngine.Vector3 world)
{
return QualityOf(map, LuneSpace.Map(world));
}
}
}