diff --git a/JotunnLib/Configs/LocationConfig.cs b/JotunnLib/Configs/LocationConfig.cs index f03dfc860..1f2e3aa39 100644 --- a/JotunnLib/Configs/LocationConfig.cs +++ b/JotunnLib/Configs/LocationConfig.cs @@ -42,10 +42,23 @@ public class LocationConfig [Obsolete("This property is unused by Valheim.")] public float ChanceToSpawn { get; set; } = 10f; + private float? _exteriorRadius; + /// /// Radius of the location. Terrain delta is calculated within this circle. + /// If left unset, falls back to the prefab's component value when one exists. + /// Defaults to 10f when no value has been set and no component is present. /// - public float ExteriorRadius { get; set; } = 10f; + public float ExteriorRadius + { + get => _exteriorRadius ?? 10f; + set => _exteriorRadius = value; + } + + /// + /// True when the caller explicitly assigned a value to . + /// + internal bool HasExteriorRadius => _exteriorRadius.HasValue; /// /// Attempt to place in the central zone first @@ -128,10 +141,22 @@ public class LocationConfig /// public bool HasInterior { get; set; } + private float? _interiorRadius; + + /// + /// Radius of the interior attached to the location. + /// If left unset, falls back to the prefab's component value when one exists. + /// + public float InteriorRadius + { + get => _interiorRadius ?? 0f; + set => _interiorRadius = value; + } + /// - /// Radius of the interior attached to the location + /// True when the caller explicitly assigned a value to . /// - public float InteriorRadius { get; set; } + internal bool HasInteriorRadius => _interiorRadius.HasValue; /// /// Environment string used by the interior @@ -158,10 +183,22 @@ public class LocationConfig /// public bool IconAlways { get; set; } + private bool? _clearArea; + + /// + /// Enable to forbid Vegetation from spawning inside the circle defined by . + /// If left unset, falls back to the prefab's component value when one exists. + /// + public bool ClearArea + { + get => _clearArea ?? false; + set => _clearArea = value; + } + /// - /// Enable to forbid Vegetation from spawning inside the circle defined by + /// True when the caller explicitly assigned a value to . /// - public bool ClearArea { get; set; } + internal bool HasClearArea => _clearArea.HasValue; /// /// Create a new diff --git a/JotunnLib/Entities/CustomLocation.cs b/JotunnLib/Entities/CustomLocation.cs index 7f21a9fce..ede21adc9 100644 --- a/JotunnLib/Entities/CustomLocation.cs +++ b/JotunnLib/Entities/CustomLocation.cs @@ -15,6 +15,8 @@ namespace Jotunn.Entities /// public class CustomLocation : CustomEntity { + private readonly LocationConfig _locationConfig; + /// /// The exterior prefab for this custom location. /// @@ -87,6 +89,7 @@ public CustomLocation(GameObject exteriorPrefab, GameObject interiorPrefab, bool { Prefab = exteriorPrefab; Name = exteriorPrefab.name; + _locationConfig = locationConfig; if (exteriorPrefab.TryGetComponent(out var location)) { @@ -107,6 +110,8 @@ public CustomLocation(GameObject exteriorPrefab, GameObject interiorPrefab, bool ZoneLocation.m_prefab = new SoftReference(AssetManager.Instance.AddAsset(exteriorPrefab)); ZoneLocation.m_prefabName = exteriorPrefab.name; + SyncZoneLocationFromComponent(Location, locationConfig); + FixReference = fixReference; } @@ -124,6 +129,7 @@ public CustomLocation(SoftReference softReferencePrefab, bool fixRef return; } + _locationConfig = locationConfig; var parent = ZoneManager.Instance.LocationContainer.transform; AssetManager.Instance.ResolveMocksOnLoad(softReferencePrefab, parent, OnLocationResolve); Name = softReferencePrefab.Name; @@ -136,12 +142,29 @@ public CustomLocation(SoftReference softReferencePrefab, bool fixRef private void OnLocationResolve(GameObject gameObject) { + if (gameObject.TryGetComponent(out var location)) + { + SyncZoneLocationFromComponent(location, _locationConfig); + } + if (gameObject.TryGetComponent(out var zoneLocation)) { ZoneManager.Instance.PrepareLocation(zoneLocation, SourceMod); } } + private void SyncZoneLocationFromComponent(Location location, LocationConfig locationConfig) + { + if (location == null || ZoneLocation == null) + { + return; + } + + if (!locationConfig.HasExteriorRadius) ZoneLocation.m_exteriorRadius = location.m_exteriorRadius; + if (!locationConfig.HasInteriorRadius) ZoneLocation.m_interiorRadius = location.m_interiorRadius; + if (!locationConfig.HasClearArea) ZoneLocation.m_clearArea = location.m_clearArea; + } + /// /// Helper method to determine if a location prefab with a given name is a custom location created with Jötunn. ///