Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
DigiWorm0 committed Oct 4, 2022
2 parents c514f99 + bef81ad commit e09a1bb
Show file tree
Hide file tree
Showing 69 changed files with 885 additions and 839 deletions.
23 changes: 12 additions & 11 deletions LevelImposter/Core/Builders/AdminMapBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ namespace LevelImposter.Core
public class AdminMapBuilder : IElemBuilder
{
public const float ICON_OFFSET = -0.25f;
private static List<CounterArea> counterAreaDB = new List<CounterArea>();
private PoolableBehavior poolPrefab = null;

private static List<CounterArea> _counterAreaDB = new List<CounterArea>();
private PoolableBehavior _poolPrefab = null;

public void Build(LIElement elem, GameObject obj)
{
Expand All @@ -22,8 +23,8 @@ public void Build(LIElement elem, GameObject obj)
MapCountOverlay mapCountOverlay = mapBehaviour.countOverlay;

// Prefab
if (poolPrefab == null)
poolPrefab = mapCountOverlay.CountAreas[0].pool.Prefab;
if (_poolPrefab == null)
_poolPrefab = mapCountOverlay.CountAreas[0].pool.Prefab;

// System
SystemTypes systemType = RoomBuilder.GetSystem(elem.id);
Expand All @@ -33,30 +34,30 @@ public void Build(LIElement elem, GameObject obj)
GameObject roomObj = new GameObject(elem.name);
roomObj.transform.SetParent(mapCountOverlay.transform);
roomObj.transform.localPosition = new Vector3(
elem.x * MinimapBuilder.mapScale * (1 / overlayScale),
elem.y * MinimapBuilder.mapScale * (1 / overlayScale) + ICON_OFFSET,
elem.x * MinimapBuilder.MinimapScale * (1 / overlayScale),
elem.y * MinimapBuilder.MinimapScale * (1 / overlayScale) + ICON_OFFSET,
-25.0f
);

CounterArea counterArea = roomObj.AddComponent<CounterArea>();
counterArea.RoomType = systemType;
counterArea.pool = roomObj.AddComponent<ObjectPoolBehavior>();
counterArea.pool.Prefab = poolPrefab;
counterArea.pool.Prefab = _poolPrefab;

counterAreaDB.Add(counterArea);
_counterAreaDB.Add(counterArea);

mapCountOverlay.CountAreas = counterAreaDB.ToArray();
mapCountOverlay.CountAreas = _counterAreaDB.ToArray();
}

public void PostBuild()
{
MapBehaviour mapBehaviour = MinimapBuilder.GetMinimap();
MapCountOverlay mapCountOverlay = mapBehaviour.countOverlay;

while (mapCountOverlay.transform.childCount > counterAreaDB.Count)
while (mapCountOverlay.transform.childCount > _counterAreaDB.Count)
UnityEngine.Object.DestroyImmediate(mapCountOverlay.transform.GetChild(0).gameObject);

counterAreaDB.Clear();
_counterAreaDB.Clear();
}
}
}
2 changes: 1 addition & 1 deletion LevelImposter/Core/Builders/AmbientSoundBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void Build(LIElement elem, GameObject obj)
return;

// Colliders
Collider2D[] colliders = obj.GetComponents<Collider2D>();
Collider2D[] colliders = obj.GetComponentsInChildren<Collider2D>();
foreach (Collider2D collider in colliders)
{
collider.isTrigger = true;
Expand Down
18 changes: 14 additions & 4 deletions LevelImposter/Core/Builders/BuildRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public BuildRouter()
InitStack();
}

/*
* Patch this Method to add/remove builders
*/
/// <summary>
/// Patchable method to append or remove builders from the build stack
/// </summary>
public void InitStack()
{
_buildStack = new List<IElemBuilder> {
_buildStack = new() {
new DefaultBuilder(),

new RoomBuilder(),
Expand Down Expand Up @@ -51,6 +51,13 @@ public void InitStack()
};
}

/// <summary>
/// Passes <c>LIElement</c> data through the build
/// stack to construct a GameObject.
/// Should be run from <c>LIShipStatus.AddElement</c>.
/// </summary>
/// <param name="element">Element data to build</param>
/// <returns></returns>
public GameObject Build(LIElement element)
{
string objName = element.name.Replace("\\n", " ");
Expand All @@ -62,6 +69,9 @@ public GameObject Build(LIElement element)
return gameObject;
}

/// <summary>
/// Runs the post-build process on every <c>IElemBuilder</c>.
/// </summary>
public void PostBuild()
{
foreach (IElemBuilder builder in _buildStack)
Expand Down
2 changes: 1 addition & 1 deletion LevelImposter/Core/Builders/CamBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Build(LIElement elem, GameObject obj)
if (elem.type != "util-cam")
return;

UtilData utilData = AssetDB.utils[elem.type];
UtilData utilData = AssetDB.Utils[elem.type];

// Default Sprite
SpriteRenderer spriteRenderer = obj.GetComponent<SpriteRenderer>();
Expand Down
4 changes: 2 additions & 2 deletions LevelImposter/Core/Builders/DecBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void Build(LIElement elem, GameObject obj)
{
if (elem.type.StartsWith("dec-"))
{
DecData utilData = AssetDB.dec[elem.type];
DecData utilData = AssetDB.Decor[elem.type];

SpriteRenderer spriteRenderer = obj.GetComponent<SpriteRenderer>();
if (!spriteRenderer)
Expand All @@ -27,7 +27,7 @@ public void Build(LIElement elem, GameObject obj)
}
else if (elem.type.StartsWith("room-"))
{
RoomData utilData = AssetDB.room[elem.type];
RoomData utilData = AssetDB.Room[elem.type];

SpriteRenderer spriteRenderer = obj.GetComponent<SpriteRenderer>();
if (!spriteRenderer)
Expand Down
32 changes: 16 additions & 16 deletions LevelImposter/Core/Builders/DefaultBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,42 +34,42 @@ public void Build(LIElement elem, GameObject obj)

if (elem.properties.colliders != null)
{
GameObject shadowObj = null;
foreach (LICollider colliderData in elem.properties.colliders)
{
GameObject colliderObj = new GameObject("Collider " + colliderData.id);
colliderObj.transform.SetParent(obj.transform);
colliderObj.transform.localPosition = new Vector3(0, 0, 0);
colliderObj.transform.localRotation = Quaternion.Euler(0, 0, 0);
colliderObj.transform.localScale = Vector3.one;

if (colliderData.isSolid)
{
PolygonCollider2D collider = obj.AddComponent<PolygonCollider2D>();
PolygonCollider2D collider = colliderObj.AddComponent<PolygonCollider2D>();
collider.pathCount = 1;
collider.SetPath(0, colliderData.GetPoints());
}
else
{
EdgeCollider2D collider = obj.AddComponent<EdgeCollider2D>();
EdgeCollider2D collider = colliderObj.AddComponent<EdgeCollider2D>();
collider.SetPoints(colliderData.GetPoints());
}

if (colliderData.blocksLight)
{
if (shadowObj == null)
{
shadowObj = new GameObject("Shadows");
shadowObj.transform.SetParent(obj.transform);
shadowObj.transform.localPosition = new Vector3(0, 0, 0);
shadowObj.transform.localRotation = Quaternion.Euler(0, 0, 0);
shadowObj.transform.localScale = Vector3.one;
shadowObj.layer = (int)Layer.Shadow;
}
GameObject shadowObj = new GameObject("Shadow " + colliderData.id);
shadowObj.transform.SetParent(obj.transform);
shadowObj.transform.localPosition = new Vector3(0, 0, 0);
shadowObj.transform.localRotation = Quaternion.Euler(0, 0, 0);
shadowObj.transform.localScale = Vector3.one;
shadowObj.layer = (int)Layer.Shadow;

EdgeCollider2D collider = shadowObj.AddComponent<EdgeCollider2D>();
collider.SetPoints(colliderData.GetPoints(colliderData.isSolid));
EdgeCollider2D shadowCollider = shadowObj.AddComponent<EdgeCollider2D>();
shadowCollider.SetPoints(colliderData.GetPoints(colliderData.isSolid));
}
}
}
}

public void PostBuild() { }


}
}
2 changes: 1 addition & 1 deletion LevelImposter/Core/Builders/DummyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void Build(LIElement elem, GameObject obj)
if (elem.type != "util-dummy")
return;

ShipStatus shipStatus = LIShipStatus.Instance.shipStatus;
ShipStatus shipStatus = LIShipStatus.Instance.ShipStatus;
shipStatus.DummyLocations = MapUtils.AddToArr(shipStatus.DummyLocations, obj.transform);
}

Expand Down
13 changes: 13 additions & 0 deletions LevelImposter/Core/Builders/IElemBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@

namespace LevelImposter.Core
{
/// <summary>
/// Constructs a specific subset of map elements or element features.
/// Stored in the build stack located in <c>BuildRouter._buildStack</c>.
/// </summary>
public interface IElemBuilder
{
/// <summary>
/// Parses and builds a GameObject based on <c>LIElement</c> data.
/// </summary>
/// <param name="elem">Element to be parsed and built</param>
/// <param name="obj">GameObject to append data and components to</param>
public void Build(LIElement elem, GameObject obj);

/// <summary>
/// Final clean-up after all elements in a map have been built.
/// </summary>
public void PostBuild();
}
}
15 changes: 8 additions & 7 deletions LevelImposter/Core/Builders/LadderBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ namespace LevelImposter.Core
{
class LadderBuilder : IElemBuilder
{
public const float LADDER_Y_OFFSET = -0.4f;

public static List<Ladder> AllLadders = new List<Ladder>();

private byte ladderID = 0;
private const float LADDER_Y_OFFSET = -0.4f;
private static Dictionary<string, float> defaultLadderHeights = new Dictionary<string, float>
private byte _ladderID = 0;
private static Dictionary<string, float> _defaultLadderHeights = new Dictionary<string, float>
{
{ "util-ladder1", 3.0f },
{ "util-ladder2", 1.5f }
Expand All @@ -25,7 +26,7 @@ public void Build(LIElement elem, GameObject obj)
if (!elem.type.StartsWith("util-ladder"))
return;

UtilData utilData = AssetDB.utils[elem.type];
UtilData utilData = AssetDB.Utils[elem.type];
Ladder topClone = utilData.GameObj.transform.GetChild(0).GetComponent<Ladder>();
Ladder bottomClone = utilData.GameObj.transform.GetChild(1).GetComponent<Ladder>();

Expand All @@ -44,7 +45,7 @@ public void Build(LIElement elem, GameObject obj)

// Console
float ladderHeight = elem.properties.ladderHeight == null ?
defaultLadderHeights[elem.type] : (float)elem.properties.ladderHeight;
_defaultLadderHeights[elem.type] : (float)elem.properties.ladderHeight;

GameObject topObj = new GameObject("LadderTop");
topObj.transform.SetParent(obj.transform);
Expand All @@ -57,14 +58,14 @@ public void Build(LIElement elem, GameObject obj)

Ladder topConsole = topObj.AddComponent<Ladder>();
Ladder bottomConsole = bottomObj.AddComponent<Ladder>();
topConsole.Id = ladderID++;
topConsole.Id = _ladderID++;
topConsole.IsTop = true;
topConsole.Destination = bottomConsole;
topConsole.UseSound = topClone.UseSound;
topConsole.Image = spriteRenderer;
AllLadders.Add(topConsole);

bottomConsole.Id = ladderID++;
bottomConsole.Id = _ladderID++;
bottomConsole.IsTop = false;
bottomConsole.Destination = topConsole;
bottomConsole.UseSound = bottomClone.UseSound;
Expand Down
24 changes: 12 additions & 12 deletions LevelImposter/Core/Builders/MinimapBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ public class MinimapBuilder : IElemBuilder
{
public const float DEFAULT_SCALE = 4.975f;

public static float mapScale = DEFAULT_SCALE;
public static float MinimapScale = DEFAULT_SCALE;

private bool isBuilt = false;
private bool _isBuilt = false;

public void Build(LIElement elem, GameObject obj)
{
if (elem.type != "util-minimap")
return;
if (isBuilt)
if (_isBuilt)
{
LILogger.Warn("Only 1 minimap object should be used per map");
return;
}

float scale = elem.properties.minimapScale == null ? 1 : (float)elem.properties.minimapScale;
mapScale = 1 / (scale * DEFAULT_SCALE);
LIShipStatus.Instance.shipStatus.MapScale = scale * DEFAULT_SCALE;
MinimapScale = 1 / (scale * DEFAULT_SCALE);
LIShipStatus.Instance.ShipStatus.MapScale = scale * DEFAULT_SCALE;

MapBehaviour mapBehaviour = GetMinimap();

Expand All @@ -38,44 +38,44 @@ public void Build(LIElement elem, GameObject obj)
SpriteRenderer bgRenderer = background.GetComponent<SpriteRenderer>();
bgRenderer.sprite = sprite;
background.transform.localPosition = background.transform.localPosition;
background.transform.localScale = obj.transform.localScale * mapScale;
background.transform.localScale = obj.transform.localScale * MinimapScale;
background.transform.localRotation = obj.transform.localRotation;
if (elem.properties.color != null)
bgRenderer.color = MapUtils.LIColorToColor(elem.properties.color);
}

Vector3 mapOffset = -(obj.transform.localPosition * mapScale);
Vector3 mapOffset = -(obj.transform.localPosition * MinimapScale);

// Offsets
Transform roomNames = mapBehaviour.transform.GetChild(mapBehaviour.transform.childCount - 1);
roomNames.localPosition = mapOffset;
Transform hereIndicatorParent = mapBehaviour.transform.FindChild("HereIndicatorParent");
hereIndicatorParent.localPosition = mapOffset + new Vector3(0, LIShipStatus.Y_OFFSET * mapScale, -0.1f);
hereIndicatorParent.localPosition = mapOffset + new Vector3(0, LIShipStatus.Y_OFFSET * MinimapScale, -0.1f);
mapBehaviour.countOverlay.transform.localPosition = mapOffset;
mapBehaviour.infectedOverlay.transform.localPosition = mapOffset;

obj.SetActive(false);
isBuilt = true;
_isBuilt = true;
}

public void PostBuild()
{
if (!isBuilt)
if (!_isBuilt)
{
MapBehaviour mapBehaviour = GetMinimap();
mapBehaviour.ColorControl.gameObject.SetActive(false);
mapBehaviour.transform.FindChild("HereIndicatorParent").gameObject.SetActive(false);
mapBehaviour.transform.FindChild("RoomNames").gameObject.SetActive(false);
}
isBuilt = false;
_isBuilt = false;
}

public static MapBehaviour GetMinimap()
{
MapBehaviour mapBehaviour = MapBehaviour.Instance;
if (mapBehaviour == null)
{
mapBehaviour = UnityEngine.Object.Instantiate(LIShipStatus.Instance.shipStatus.MapPrefab, HudManager.Instance.transform);
mapBehaviour = UnityEngine.Object.Instantiate(LIShipStatus.Instance.ShipStatus.MapPrefab, HudManager.Instance.transform);
mapBehaviour.gameObject.SetActive(false);
}
return mapBehaviour;
Expand Down
Loading

0 comments on commit e09a1bb

Please sign in to comment.