diff --git a/LevelImposter/Builders/Minimap/AdminMapBuilder.cs b/LevelImposter/Builders/Minimap/AdminMapBuilder.cs index 010c1e4..87f77a1 100644 --- a/LevelImposter/Builders/Minimap/AdminMapBuilder.cs +++ b/LevelImposter/Builders/Minimap/AdminMapBuilder.cs @@ -22,7 +22,7 @@ public void OnBuild(LIElement elem, GameObject obj) return; // ShipStatus - var shipStatus = LIShipStatus.GetInstance().ShipStatus; + var shipStatus = LIShipStatus.GetShip(); var mapBehaviour = MinimapBuilder.GetMinimap(); var mapCountOverlay = mapBehaviour.countOverlay; diff --git a/LevelImposter/Builders/Minimap/MinimapBuilder.cs b/LevelImposter/Builders/Minimap/MinimapBuilder.cs index 6eb05ff..29859bc 100644 --- a/LevelImposter/Builders/Minimap/MinimapBuilder.cs +++ b/LevelImposter/Builders/Minimap/MinimapBuilder.cs @@ -9,13 +9,13 @@ public class MinimapBuilder : IElemBuilder private bool _isBuilt; - public void OnBuild(LIElement elem, GameObject obj) + public void OnPreBuild(LIElement elem, GameObject obj) { if (elem.type != "util-minimap") return; // ShipStatus - var shipStatus = LIShipStatus.GetInstance().ShipStatus; + var shipStatus = LIShipStatus.GetShip(); // Check Singleton if (_isBuilt) @@ -28,33 +28,23 @@ public void OnBuild(LIElement elem, GameObject obj) var mapBehaviour = GetMinimap(); // Map Scale - var mapScaleVal = elem.properties.minimapScale == null ? 1 : (float)elem.properties.minimapScale; - var mapScale = mapScaleVal * DEFAULT_SCALE; - shipStatus.MapScale = mapScale; - var mapOffset = -(obj.transform.localPosition / mapScale); - - // Sprite Renderer - var spriteRenderer = obj.GetComponent(); - if (spriteRenderer == null) - { - LILogger.Warn("Minimap object has no sprite attached"); - return; - } + var mapScaleVal = elem.properties.minimapScale ?? 1; + shipStatus.MapScale = mapScaleVal * DEFAULT_SCALE; + var mapOffset = -(obj.transform.localPosition / shipStatus.MapScale); // Background var background = mapBehaviour.ColorControl.gameObject; var bgRenderer = background.GetComponent(); background.transform.localPosition = background.transform.localPosition; - background.transform.localScale = obj.transform.localScale / mapScale; + background.transform.localScale = obj.transform.localScale / shipStatus.MapScale; background.transform.localRotation = obj.transform.localRotation; // Load Sprite - SpriteBuilder.OnSpriteLoad += (loadedElem, _) => + SpriteBuilder.OnSpriteLoad += (loadedElem, loadedSprite) => { if (loadedElem.id != elem.id || bgRenderer == null) return; - bgRenderer.sprite = spriteRenderer.sprite; - bgRenderer.color = spriteRenderer.color; + bgRenderer.sprite = loadedSprite.Sprite; Object.Destroy(obj); }; diff --git a/LevelImposter/Builders/Minimap/MinimapSpriteBuilder.cs b/LevelImposter/Builders/Minimap/MinimapSpriteBuilder.cs index 7872dee..88918d4 100644 --- a/LevelImposter/Builders/Minimap/MinimapSpriteBuilder.cs +++ b/LevelImposter/Builders/Minimap/MinimapSpriteBuilder.cs @@ -18,7 +18,7 @@ public void OnBuild(LIElement elem, GameObject obj) return; // ShipStatus - var shipStatus = LIShipStatus.GetInstance().ShipStatus; + var shipStatus = LIShipStatus.GetShip(); // Minimap var mapBehaviour = MinimapBuilder.GetMinimap(); @@ -31,34 +31,12 @@ public void OnBuild(LIElement elem, GameObject obj) // GameObject var mapScale = shipStatus.MapScale; - GameObject spriteObj = new(elem.name); - spriteObj.layer = (int)Layer.UI; - spriteObj.transform.SetParent(parentTransform); - spriteObj.transform.localPosition = new Vector3( + obj.layer = (int)Layer.UI; + obj.transform.SetParent(parentTransform, false); + obj.transform.localPosition = new Vector3( elem.x / mapScale, elem.y / mapScale, elem.z ); - spriteObj.transform.localScale = new Vector3(elem.xScale, elem.yScale, 1); - spriteObj.transform.localRotation = Quaternion.Euler(0, 0, elem.rotation); - - // Sprite Renderer - var spriteRenderer = obj.GetComponent(); - if (spriteRenderer == null) - { - LILogger.Warn("util-minimapsprite does not have a sprite attatched"); - return; - } - - // Load Sprite - var bgRenderer = spriteObj.AddComponent(); - SpriteBuilder.OnSpriteLoad += (loadedElem, _) => - { - if (loadedElem.id != elem.id || bgRenderer == null) - return; - bgRenderer.sprite = spriteRenderer.sprite; - bgRenderer.color = spriteRenderer.color; - Object.Destroy(obj); - }; } } \ No newline at end of file diff --git a/LevelImposter/Builders/Minimap/RoomNameBuilder.cs b/LevelImposter/Builders/Minimap/RoomNameBuilder.cs index 0549dd2..ec9632b 100644 --- a/LevelImposter/Builders/Minimap/RoomNameBuilder.cs +++ b/LevelImposter/Builders/Minimap/RoomNameBuilder.cs @@ -19,10 +19,9 @@ public void OnBuild(LIElement elem, GameObject obj) return; // ShipStatus - var shipStatus = LIShipStatus.GetInstanceOrNull()?.ShipStatus; - if (shipStatus == null) - throw new MissingShipException(); + var shipStatus = LIShipStatus.GetShip(); + // Minimap var mapBehaviour = MinimapBuilder.GetMinimap(); // Clone