Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
DigiWorm0 committed Aug 24, 2022
2 parents 9a80ad0 + f3f7521 commit aa165c7
Show file tree
Hide file tree
Showing 35 changed files with 1,170 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.x
dotnet-version: 6.x

- name: Run the Cake script
uses: cake-build/cake-action@v1
Expand Down
4 changes: 2 additions & 2 deletions LevelImposter/Core/Builders/AdminMapBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ namespace LevelImposter.Core
{
public class AdminMapBuilder : Builder
{
public const float ICON_OFFSET = -0.3f;
public const float ICON_OFFSET = -0.25f;
private static List<CounterArea> counterAreaDB = new List<CounterArea>();
private PoolableBehavior poolPrefab = null;

public void Build(LIElement elem, GameObject obj)
{
if (elem.type != "util-room")
if (elem.type != "util-room" || elem.properties.isRoomAdminVisible == false)
return;

MapBehaviour mapBehaviour = MinimapBuilder.GetMinimap();
Expand Down
55 changes: 55 additions & 0 deletions LevelImposter/Core/Builders/AmbientSoundBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using HarmonyLib;
using LevelImposter.DB;
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.Events;

namespace LevelImposter.Core
{
class AmbientSoundBuilder : Builder
{
public void Build(LIElement elem, GameObject obj)
{
if (elem.type != "util-sound1")
return;

// Colliders
Collider2D[] colliders = obj.GetComponents<Collider2D>();
foreach (Collider2D collider in colliders)
{
collider.isTrigger = true;
}

// AudioClip
if (elem.properties.sounds == null)
{
LILogger.Warn("Ambient sound missing audio listing");
return;
}

if (elem.properties.sounds.Length <= 0)
{
LILogger.Warn("Ambient sound missing audio elements");
return;
}

LISound soundData = elem.properties.sounds[0];
if (soundData.data == null)
{
LILogger.Warn("Ambient sound missing audio data [" + soundData.id + "]");
return;
}
AudioClip clip = MapUtils.ConvertToAudio(elem.name, soundData.data);

// Sound Player
AmbientSoundPlayer ambientPlayer = obj.AddComponent<AmbientSoundPlayer>();
ambientPlayer.HitAreas = colliders;
ambientPlayer.AmbientSound = clip;
ambientPlayer.MaxVolume = soundData.volume;
}

public void PostBuild() {}
}
}
7 changes: 6 additions & 1 deletion LevelImposter/Core/Builders/BuildRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ public class BuildRouter
new SabBuilder(),
new SabMapBuilder(),
new LadderBuilder(),
new PlatformBuilder()
new PlatformBuilder(),
new StarfieldBuilder(),
new AmbientSoundBuilder(),
new StepSoundBuilder(),

new NoShadowBuilder()
};

public GameObject Build(LIElement element)
Expand Down
16 changes: 5 additions & 11 deletions LevelImposter/Core/Builders/CamBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,11 @@ public void Build(LIElement elem, GameObject obj)
// Camera
SurvCamera survCam = obj.AddComponent<SurvCamera>();
survCam.CamName = elem.name;
if (elem.properties.camXOffset != null && elem.properties.camYOffset != null)
{
survCam.Offset = new Vector3(
(float)elem.properties.camXOffset,
(float)elem.properties.camYOffset
);
}
if (elem.properties.camZoom != null)
{
survCam.CamSize = (float)elem.properties.camZoom;
}
survCam.Offset = new Vector3(
elem.properties.camXOffset == null ? 0 : (float)elem.properties.camXOffset,
elem.properties.camYOffset == null ? 0 : (float)elem.properties.camYOffset
);
survCam.CamSize = elem.properties.camZoom == null ? 0 : (float)elem.properties.camZoom;
}

public void PostBuild() { }
Expand Down
4 changes: 1 addition & 3 deletions LevelImposter/Core/Builders/DecBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public void Build(LIElement elem, GameObject obj)
{
spriteRenderer = obj.AddComponent<SpriteRenderer>();
spriteRenderer.sprite = utilData.SpriteRenderer.sprite;
spriteRenderer.material = utilData.SpriteRenderer.material;
}
obj.layer = (int)Layer.ShortObjects;
}
Expand All @@ -32,12 +31,11 @@ public void Build(LIElement elem, GameObject obj)
{
spriteRenderer = obj.AddComponent<SpriteRenderer>();
spriteRenderer.sprite = utilData.SpriteRenderer.sprite;
spriteRenderer.material = utilData.SpriteRenderer.material;
}
obj.layer = (int)Layer.Ship;
}
}

public void PostBuild() { }
}
}
}
15 changes: 6 additions & 9 deletions LevelImposter/Core/Builders/DefaultBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using LevelImposter.DB;

namespace LevelImposter.Core
{
public class DefaultBuilder
{
public GameObject Build(LIElement elem)
{
GameObject gameObject = new GameObject(elem.name);
string objName = elem.name.Replace("\\n", " ");
GameObject gameObject = new GameObject(objName);
gameObject.layer = (int)Layer.Ship;
gameObject.transform.position = new Vector3(elem.x, elem.y, elem.z);
gameObject.transform.rotation = Quaternion.Euler(0, 0, elem.rotation);
Expand All @@ -22,7 +24,8 @@ public GameObject Build(LIElement elem)
if (elem.properties.spriteData.StartsWith("data:image/gif;base64,"))
{
GIFAnimator animator = gameObject.AddComponent<GIFAnimator>();
animator.Animate(elem.properties.spriteData);
animator.Init(elem.properties.spriteData);
animator.Play(true);
}
else
{
Expand Down Expand Up @@ -64,18 +67,12 @@ public GameObject Build(LIElement elem)
}
}

BoxCollider2D boxCollider = gameObject.AddComponent<BoxCollider2D>();
boxCollider.size = new Vector2(elem.xScale, elem.yScale);
boxCollider.offset = new Vector2(elem.xScale / 2, elem.yScale / 2);
boxCollider.isTrigger = true;

return gameObject;
}

private Sprite generateSprite(string base64)
{
string sub64 = base64.Substring(base64.IndexOf(",") + 1);
byte[] data = Convert.FromBase64String(sub64);
byte[] data = MapUtils.ParseBase64(base64);
Texture2D texture = new Texture2D(1, 1);
ImageConversion.LoadImage(texture, data);
return Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100.0f);
Expand Down
57 changes: 57 additions & 0 deletions LevelImposter/Core/Builders/NoShadowBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using LevelImposter.DB;

namespace LevelImposter.Core
{
public class NoShadowBuilder : Builder
{
private Material noShadowMat = null;
private Material defaultMat = null;

public void Build(LIElement elem, GameObject obj)
{
if (!(elem.type.StartsWith("dec-") || elem.type == "util-blank"))
return;

if (noShadowMat == null)
{
noShadowMat = AssetDB.dec["dec-rock5"].SpriteRenderer.material;
defaultMat = AssetDB.dec["dec-rock4"].SpriteRenderer.material;
}

SpriteRenderer spriteRenderer = obj.GetComponent<SpriteRenderer>();
if (spriteRenderer)
{
if (elem.properties.noShadows == true)
{
spriteRenderer.material = noShadowMat;

if (elem.properties.noShadowsBehaviour == true)
{
NoShadowBehaviour behaviour = obj.AddComponent<NoShadowBehaviour>();
behaviour.rend = spriteRenderer;

Collider2D[] shadows = obj.GetComponentsInChildren<Collider2D>();
for (int i = 0; i < shadows.Length; i++)
{
if (shadows[i].gameObject != obj)
{
behaviour.hitOverride = shadows[i];
return;
}
}
}
}
else
{
spriteRenderer.material = defaultMat;
}
}
}

public void PostBuild() { }
}
}
18 changes: 13 additions & 5 deletions LevelImposter/Core/Builders/RoomBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,31 @@ namespace LevelImposter.Core
{
public class RoomBuilder : Builder
{
private int roomId = 1;
private byte roomId = 1;
private static Dictionary<Guid, SystemTypes> systemDB = new Dictionary<Guid, SystemTypes>();

public void Build(LIElement elem, GameObject obj)
{
if (elem.type != "util-room")
return;

SystemTypes systemType = (SystemTypes)roomId;
roomId++;
SystemTypes systemType;
do
{
systemType = (SystemTypes)roomId;
roomId++;
}
while (systemType == SystemTypes.LowerEngine || systemType == SystemTypes.UpperEngine);

PlainShipRoom shipRoom = obj.AddComponent<PlainShipRoom>();
shipRoom.RoomId = systemType;
shipRoom.roomArea = obj.GetComponent<Collider2D>();
shipRoom.roomArea.isTrigger = true;
if (shipRoom.roomArea != null)
shipRoom.roomArea.isTrigger = true;
else
LILogger.Warn("Admin table will not function in " + shipRoom.name + " because it has no collider");

MapUtils.Rename(systemType, elem.name);
MapUtils.Rename(systemType, obj.name);
systemDB.Add(elem.id, systemType);
}

Expand Down
10 changes: 8 additions & 2 deletions LevelImposter/Core/Builders/RoomNameBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class RoomNameBuilder : Builder

public void Build(LIElement elem, GameObject obj)
{
if (elem.type != "util-room")
if (elem.type != "util-room" || elem.properties.isRoomNameVisible == false)
return;

MapBehaviour mapBehaviour = MinimapBuilder.GetMinimap();
Expand All @@ -36,9 +36,15 @@ public void Build(LIElement elem, GameObject obj)
// Text
UnityEngine.Object.Destroy(roomName.GetComponent<TextTranslatorTMP>());
TextMeshPro roomText = roomName.GetComponent<TextMeshPro>();
roomText.text = elem.name;
roomText.text = elem.name.Replace("\\n", "\n");
roomText.fontSizeMin = roomText.fontSizeMax;
roomText.alignment = TextAlignmentOptions.Bottom;
roomText.enabled = true;
nameCount++;

// Transform
RectTransform rectTransform = roomName.GetComponent<RectTransform>();
rectTransform.sizeDelta = new Vector2(10, 0);
}

public void PostBuild()
Expand Down
50 changes: 50 additions & 0 deletions LevelImposter/Core/Builders/StarfieldBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using HarmonyLib;
using LevelImposter.DB;
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;

namespace LevelImposter.Core
{
class StarfieldBuilder : Builder
{
public void Build(LIElement elem, GameObject obj)
{
if (elem.type != "util-starfield")
return;

// Sprite
GameObject prefab = GameObject.Instantiate(obj, LIShipStatus.Instance.transform);
LIStar prefabStar = prefab.AddComponent<LIStar>();
SpriteRenderer prefabRenderer = obj.GetComponent<SpriteRenderer>();
if (prefabRenderer != null)
{
prefabRenderer.material = AssetDB.dec["dec-rock4"].SpriteRenderer.material;
}
else
{
LILogger.Warn("Star Fields do not work without a cooresponding sprite");
return;
}

// Stars
int count = 20;
if (elem.properties.starfieldCount != null)
count = (int)elem.properties.starfieldCount;
for (int i = 0; i < count; i++)
{
GameObject starObj = GameObject.Instantiate(prefab, obj.transform);
starObj.name = "Star " + i;
LIStar starComp = starObj.GetComponent<LIStar>();
starComp.Init(elem);
}

// Disable Obj
obj.GetComponent<SpriteRenderer>().enabled = false;
GameObject.Destroy(prefab);
}

public void PostBuild() { }
}
}
Loading

0 comments on commit aa165c7

Please sign in to comment.