Skip to content

Commit

Permalink
Fixed Minimap Sprites
Browse files Browse the repository at this point in the history
  • Loading branch information
Digi committed Oct 12, 2024
1 parent 46cd8b4 commit fe124be
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 48 deletions.
2 changes: 1 addition & 1 deletion LevelImposter/Builders/Minimap/AdminMapBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 8 additions & 18 deletions LevelImposter/Builders/Minimap/MinimapBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<SpriteRenderer>();
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<SpriteRenderer>();
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);
};

Expand Down
30 changes: 4 additions & 26 deletions LevelImposter/Builders/Minimap/MinimapSpriteBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<SpriteRenderer>();
if (spriteRenderer == null)
{
LILogger.Warn("util-minimapsprite does not have a sprite attatched");
return;
}

// Load Sprite
var bgRenderer = spriteObj.AddComponent<SpriteRenderer>();
SpriteBuilder.OnSpriteLoad += (loadedElem, _) =>
{
if (loadedElem.id != elem.id || bgRenderer == null)
return;
bgRenderer.sprite = spriteRenderer.sprite;
bgRenderer.color = spriteRenderer.color;
Object.Destroy(obj);
};
}
}
5 changes: 2 additions & 3 deletions LevelImposter/Builders/Minimap/RoomNameBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fe124be

Please sign in to comment.