Updated comments

This commit is contained in:
2025-06-30 16:34:55 +02:00
parent ba83e64b8d
commit bcce66a3f5

View File

@@ -87,9 +87,9 @@ public class MapGenManager : MonoBehaviour
} }
} }
/* ============================================================ */ /// <summary>
/* CORRIDORS */ /// Builds corridors and doors between rooms.
/* ============================================================ */ /// </summary>
private void BuildCorridors() private void BuildCorridors()
{ {
// Jediné dva směry, které musíme zkontrolovat z každé místnosti (right/up) // Jediné dva směry, které musíme zkontrolovat z každé místnosti (right/up)
@@ -109,9 +109,9 @@ public class MapGenManager : MonoBehaviour
foreach (Vector2Int dir in directions) foreach (Vector2Int dir in directions)
{ {
Vector2Int nKey = cell + dir; Vector2Int nKey = cell + dir;
if (!gridToRoom.TryGetValue(nKey, out GameObject roomB)) continue; // žádná sousední místnost if (!gridToRoom.TryGetValue(nKey, out GameObject roomB)) continue;
// Geometrie pro daný směr // Handle geometry
Vector3 axis; float lenStraight, lenDoor; Quaternion rot; Vector3 axis; float lenStraight, lenDoor; Quaternion rot;
if (dir == Vector2Int.right) if (dir == Vector2Int.right)
{ {
@@ -128,18 +128,18 @@ public class MapGenManager : MonoBehaviour
rot = Quaternion.identity; rot = Quaternion.identity;
} }
// Pozice stěn (počítáme od středu místnosti k jejímu okraji) // Wall calculation
float halfA = Vector3.Scale(GetPrefabXZ(roomA), axis).magnitude * 0.5f; float halfA = Vector3.Scale(GetPrefabXZ(roomA), axis).magnitude * 0.5f;
float halfB = Vector3.Scale(GetPrefabXZ(roomB), axis).magnitude * 0.5f; float halfB = Vector3.Scale(GetPrefabXZ(roomB), axis).magnitude * 0.5f;
Vector3 wallA = roomA.transform.position + axis * halfA; Vector3 wallA = roomA.transform.position + axis * halfA;
Vector3 wallB = roomB.transform.position - axis * halfB; Vector3 wallB = roomB.transform.position - axis * halfB;
// DVEŘE pivot dveří do středu úsečky mezi okraji stěn // Doors
Vector3 doorPos = (wallA + wallB) * 0.5f; Vector3 doorPos = (wallA + wallB) * 0.5f;
GameObject doorGO = Instantiate(DoorCorridor, doorPos, rot, transform); GameObject doorGO = Instantiate(DoorCorridor, doorPos, rot, transform);
DoorAnimation anim = doorGO.GetComponent<DoorAnimation>(); DoorAnimation anim = doorGO.GetComponent<DoorAnimation>();
// REGISTRACE do obou místností // Register the corridor to both rooms
RoomHandler rhA = roomA.GetComponent<RoomHandler>(); RoomHandler rhA = roomA.GetComponent<RoomHandler>();
RoomHandler rhB = roomB.GetComponent<RoomHandler>(); RoomHandler rhB = roomB.GetComponent<RoomHandler>();
if (dir == Vector2Int.right) if (dir == Vector2Int.right)
@@ -171,19 +171,19 @@ public class MapGenManager : MonoBehaviour
private void PlaceStraightSegments( private void PlaceStraightSegments(
Vector3 startEdge, Vector3 startEdge,
Vector3 wallEdge, Vector3 wallEdge,
Vector3 direction, // normalizovaný (+/- axis) Vector3 direction,
Quaternion rot, Quaternion rot,
float len) // délka STANDARDNÍHO rovného segmentu float len)
{ {
const float EPS = 0.01f; // ≈1 cm tolerance const float EPS = 0.01f;
float dist = Vector3.Distance(startEdge, wallEdge); float dist = Vector3.Distance(startEdge, wallEdge);
if (dist < EPS) return; // nic netřeba if (dist < EPS) return;
int fullCount = Mathf.FloorToInt(dist / len); int fullCount = Mathf.FloorToInt(dist / len);
float remainder = dist - fullCount * len; // 0 .. len float remainder = dist - fullCount * len;
// -------- 1) CELÉ segmenty -------- // Full segments
Vector3 firstPivot = startEdge + direction * (len * 0.5f); // hrana sedí na startEdge Vector3 firstPivot = startEdge + direction * (len * 0.5f);
for (int i = 0; i < fullCount; i++) for (int i = 0; i < fullCount; i++)
{ {
Vector3 pos = firstPivot + direction * (i * len); Vector3 pos = firstPivot + direction * (i * len);
@@ -191,16 +191,14 @@ public class MapGenManager : MonoBehaviour
Instantiate(prefab, pos, rot, transform); Instantiate(prefab, pos, rot, transform);
} }
// -------- 2) POSLEDNÍ ZKRÁCENÝ segment (pokud je třeba) -------- // Short segment to fill the gap
if (remainder > EPS) // zbylo něco > 1 cm if (remainder > EPS)
{ {
// pivot tak, aby přední hrana nepřesáhla wallEdge
Vector3 remPivot = wallEdge - direction * (remainder * 0.5f); Vector3 remPivot = wallEdge - direction * (remainder * 0.5f);
GameObject last = Instantiate(CorridorStraightUnlit, remPivot, rot, transform); GameObject last = Instantiate(CorridorStraightUnlit, remPivot, rot, transform);
// zmenšíme délku po místní ose Z (prefab je "dlouhý" po Z)
Vector3 sc = last.transform.localScale; Vector3 sc = last.transform.localScale;
sc.z *= remainder / len; // poměr 0 .. 1 sc.z *= remainder / len;
last.transform.localScale = sc; last.transform.localScale = sc;
} }
} }