Skip to content

Commit

Permalink
Selectable light controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal78900 committed Nov 19, 2021
1 parent 54f1a51 commit 210ebc0
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,23 @@ public LightControllerComponent Init(LightControllerObject lightControllerObject
/// </summary>
public LightControllerObject Base;

/// <summary>
/// List of attached <see cref="FlickerableLightController"/> objects.
/// </summary>
public List<FlickerableLightController> LightControllers = new List<FlickerableLightController>();

/// <inheritdoc cref="MapEditorObject.UpdateObject()"/>
public override void UpdateObject()
{
OnDestroy();

Color color = new Color(Base.Red, Base.Green, Base.Blue, Base.Alpha);
Color color = new Color(Base.Red / 255f, Base.Green / 255f, Base.Blue / 255f, Base.Alpha);

foreach (Room room in Map.Rooms.Where(x => x.Type == Base.RoomType))
foreach (Room room in Map.Rooms.Where(x => x.Type == ForcedRoomType))
{
FlickerableLightController lightController = null;

if (Base.RoomType != RoomType.Surface)
if (ForcedRoomType != RoomType.Surface)
{
lightController = room.GetComponentInChildren<FlickerableLightController>();
}
Expand All @@ -56,7 +61,7 @@ public override void UpdateObject()

if (lightController != null)
{
lightControllers.Add(lightController);
LightControllers.Add(lightController);

lightController.Network_warheadLightColor = color;
lightController.Network_lightIntensityMultiplier = color.a;
Expand All @@ -75,7 +80,7 @@ private void Update()
currentColor = ShiftHueBy(currentColor, Base.ShiftSpeed * Time.deltaTime);
currentColor.a = Base.Alpha;

foreach (FlickerableLightController lightController in lightControllers)
foreach (FlickerableLightController lightController in LightControllers)
{
lightController.Network_warheadLightColor = currentColor;
lightController.Network_lightIntensityMultiplier = currentColor.a;
Expand All @@ -84,14 +89,14 @@ private void Update()

private void OnDestroy()
{
foreach (FlickerableLightController lightController in lightControllers)
foreach (FlickerableLightController lightController in LightControllers)
{
lightController.Network_warheadLightColor = FlickerableLightController.DefaultWarheadColor;
lightController.Network_lightIntensityMultiplier = 1f;
lightController.Network_warheadLightOverride = false;
}

lightControllers.Clear();
LightControllers.Clear();
}

// Credits to Killers0992
Expand All @@ -108,7 +113,5 @@ private Color ShiftHueBy(Color color, float amount)
}

private Color currentColor;

private List<FlickerableLightController> lightControllers = new List<FlickerableLightController>();
}
}
39 changes: 30 additions & 9 deletions MapEditorReborn/API/Extenstions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,20 @@ public static class Extenstions
/// <param name="mapObject">The <see cref="MapEditorObject"/> which details are gonna be shown.</param>
public static void ShowGameObjectHint(this Player player, MapEditorObject mapObject)
{
Vector3 relativePosition = mapObject.RelativePosition;
Vector3 relativeRotation = mapObject.RelativeRotation;

string message = "<size=30>Selected object type: <color=yellow><b>{objectType}</b></color></size>\n";
message += $"<size=20>" +
$"Position {string.Format("X: <color=yellow><b>{0:F3}</b></color> Y: <color=yellow><b>{1:F3}</b></color> Z: <color=yellow><b>{2:F3}</b></color>", relativePosition.x, relativePosition.y, relativePosition.z)} | " +
$"Rotation {string.Format("X: <color=yellow><b>{0:F3}</b></color> Y: <color=yellow><b>{1:F3}</b></color> Z: <color=yellow><b>{2:F3}</b></color>", relativeRotation.x, relativeRotation.y, relativeRotation.z)} | " +
$"Scale {string.Format("X: <color=yellow><b>{0:F3}</b></color> Y: <color=yellow><b>{1:F3}</b></color> Z: <color=yellow><b>{2:F3}</b></color>", mapObject.Scale.x, mapObject.Scale.y, mapObject.Scale.z)}\n" +
$"RoomType: <color=yellow><b>{mapObject.RoomType}</b></color></size>" +
$"</size>\n";

if (!(mapObject is LightControllerComponent))
{
Vector3 relativePosition = mapObject.RelativePosition;
Vector3 relativeRotation = mapObject.RelativeRotation;

message += $"<size=20>" +
$"Position {string.Format("X: <color=yellow><b>{0:F3}</b></color> Y: <color=yellow><b>{1:F3}</b></color> Z: <color=yellow><b>{2:F3}</b></color>", relativePosition.x, relativePosition.y, relativePosition.z)} | " +
$"Rotation {string.Format("X: <color=yellow><b>{0:F3}</b></color> Y: <color=yellow><b>{1:F3}</b></color> Z: <color=yellow><b>{2:F3}</b></color>", relativeRotation.x, relativeRotation.y, relativeRotation.z)} | " +
$"Scale {string.Format("X: <color=yellow><b>{0:F3}</b></color> Y: <color=yellow><b>{1:F3}</b></color> Z: <color=yellow><b>{2:F3}</b></color>", mapObject.Scale.x, mapObject.Scale.y, mapObject.Scale.z)}\n" +
$"RoomType: <color=yellow><b>{mapObject.RoomType}</b></color></size>" +
$"</size>\n";
}

switch (mapObject)
{
Expand Down Expand Up @@ -128,6 +132,23 @@ public static void ShowGameObjectHint(this Player player, MapEditorObject mapObj
break;
}

case LightControllerComponent lightController:
{
message = message.Replace("{objectType}", "LightController");

message += $"<size=20>" +
$"RoomType: <color=yellow><b>{mapObject.ForcedRoomType}</b></color>\n" +
$"<color=red>Red:</color> <color=yellow><b>{lightController.Base.Red}</b></color></color>\n" +
$"<color=green>Green:</color> <color=yellow><b>{lightController.Base.Green}</b></color></color>\n" +
$"<color=blue>Blue:</color> <color=yellow><b>{lightController.Base.Blue}</b></color></color>\n" +
$"<color=#00FFFF>Alpha:</color> <color=yellow><b>{lightController.Base.Alpha}</b></color></color>\n" +
$"ShiftSpeed: <color=yellow><b>{lightController.Base.ShiftSpeed}</b></color>\n" +
$"OnlyWarheadLight: {(lightController.Base.OnlyWarheadLight ? "<color=green><b>TRUE</b></color>" : "<color=red><b>FALSE</b></color>")}" +
$"</size>";

break;
}

case TeleportComponent teleport:
{
message = message.Replace("{objectType}", $"Teleporter{(teleport.IsEntrance ? "Entrance" : "Exit")}");
Expand Down
2 changes: 1 addition & 1 deletion MapEditorReborn/API/Objects/LightControllerObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public LightControllerObject()
/// <summary>
/// Gets or sets the LightController's red color.
/// </summary>
public float Red { get; set; } = 1f;
public float Red { get; set; } = 255f;

/// <summary>
/// Gets or sets the LightController's green color.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
}
}

if (mapObject is LightControllerComponent)
{
response = "You can't modify this object's position!";
return false;
}

if (float.TryParse(arguments.At(0), out float x) && float.TryParse(arguments.At(1), out float y) && float.TryParse(arguments.At(2), out float z))
{
Vector3 newPosition = new Vector3(x, y, z);
Expand All @@ -54,7 +60,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
mapObject.UpdateIndicator();
player.ShowGameObjectHint(mapObject);

response = newPosition.ToString();
response = newPosition.ToString("F3");
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
}
}

if (mapObject is LightControllerComponent)
{
response = "You can't modify this object's position!";
return false;
}

Vector3 newPosition = player.Position;

if (mapObject.name.Contains("Door"))
Expand All @@ -55,7 +61,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
mapObject.UpdateIndicator();
player.ShowGameObjectHint(mapObject);

response = newPosition.ToString();
response = newPosition.ToString("F3");
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
}
}

if (mapObject is LightControllerComponent)
{
response = "You can't modify this object's position!";
return false;
}

if (float.TryParse(arguments.At(0), out float x) && float.TryParse(arguments.At(1), out float y) && float.TryParse(arguments.At(2), out float z))
{
Vector3 newPosition = new Vector3(x, y, z);
Expand All @@ -55,7 +61,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
mapObject.UpdateIndicator();
player.ShowGameObjectHint(mapObject);

response = newPosition.ToString();
response = newPosition.ToString("F3");
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
}
}

if (mapObject is PlayerSpawnPointComponent)
if (mapObject is LightControllerComponent || mapObject is PlayerSpawnPointComponent)
{
response = "You can't modify this object's rotation!";
return false;
Expand All @@ -59,7 +59,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s

mapObject.UpdateObject();

response = newRotation.ToString();
response = newRotation.ToString("F3");
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
}
}

if (mapObject is PlayerSpawnPointComponent)
if (mapObject is LightControllerComponent || mapObject is PlayerSpawnPointComponent)
{
response = "You can't modify this object's rotation!";
return false;
Expand All @@ -59,7 +59,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s

mapObject.UpdateObject();

response = newRotation.ToString();
response = newRotation.ToString("F3");
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
}
}

if (mapObject is PlayerSpawnPointComponent || mapObject is RagdollSpawnPointComponent)
if (mapObject is LightControllerComponent || mapObject is PlayerSpawnPointComponent || mapObject is RagdollSpawnPointComponent)
{
response = "You can't modify this object's scale!";
return false;
Expand All @@ -60,7 +60,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
mapObject.UpdateObject();
mapObject.UpdateIndicator();

response = newScale.ToString();
response = newScale.ToString("F3");
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
}
}

if (mapObject is PlayerSpawnPointComponent || mapObject is RagdollSpawnPointComponent)
if (mapObject is LightControllerComponent || mapObject is PlayerSpawnPointComponent || mapObject is RagdollSpawnPointComponent)
{
response = "You can't modify this object's scale!";
return false;
Expand All @@ -60,7 +60,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
mapObject.UpdateObject();
mapObject.UpdateIndicator();

response = newScale.ToString();
response = newScale.ToString("F3");
return true;
}

Expand Down
33 changes: 31 additions & 2 deletions MapEditorReborn/Commands/ModifyingCommands/SetRoomType.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace MapEditorReborn.Commands
{
using System;
using System.Linq;
using API;
using CommandSystem;
using Exiled.API.Enums;
Expand Down Expand Up @@ -46,10 +47,29 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s

if (arguments.Count == 0)
{
mapObject.ForcedRoomType = RoomType.Unknown;
mapObject.ForcedRoomType = mapObject.FindRoom().Type;
if (mapObject is LightControllerComponent _)
{
RoomType playerRoomType = player.CurrentRoom.Type;
if (Handler.SpawnedObjects.FirstOrDefault(x => x is LightControllerComponent light && light.ForcedRoomType == playerRoomType) != null)
{
response = "There can be only one Light Controller per one room type!";
return false;
}

mapObject.ForcedRoomType = RoomType.Unknown;
mapObject.ForcedRoomType = playerRoomType;
}
else
{
mapObject.ForcedRoomType = RoomType.Unknown;
mapObject.ForcedRoomType = mapObject.FindRoom().Type;
}

player.ShowGameObjectHint(mapObject);

if (mapObject is LightControllerComponent)
mapObject.UpdateObject();

response = $"Object's RoomType has been reseted! It is now \"{mapObject.ForcedRoomType}\"";
return true;
}
Expand All @@ -59,9 +79,18 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
if (roomType == RoomType.Unknown)
roomType = RoomType.Surface;

if (Handler.SpawnedObjects.FirstOrDefault(x => x is LightControllerComponent light && light.ForcedRoomType == player.CurrentRoom.Type) != null)
{
response = "There can be only one Light Controller per one room type!";
return false;
}

mapObject.ForcedRoomType = roomType;
player.ShowGameObjectHint(mapObject);

if (mapObject is LightControllerComponent)
mapObject.UpdateObject();

response = $"Object's RoomType has been set to \"{roomType}\"!";
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion MapEditorReborn/Commands/ToolgunCommands/CreateObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
if (parsedEnum == ToolGunMode.LightController)
{
Room colliderRoom = Map.FindParentRoom(hit.collider.gameObject);
if (Handler.SpawnedObjects.FirstOrDefault(x => x is LightControllerComponent light && (Map.FindParentRoom(x.gameObject) == colliderRoom || light.Base.RoomType == colliderRoom.Type)) != null)
if (Handler.SpawnedObjects.FirstOrDefault(x => x is LightControllerComponent light && light.ForcedRoomType == colliderRoom.Type) != null)
{
response = "There can be only one Light Controller per one room type!";
return false;
Expand Down
13 changes: 12 additions & 1 deletion MapEditorReborn/Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ internal static void OnGenerated()
}
}

internal static void OnWaitingForPlayers()
{
FlickerableLightsPositions.Clear();

foreach (var light in Object.FindObjectsOfType<FlickerableLight>())
{
FlickerableLightsPositions.Add(light.transform.position);
}
}

/// <inheritdoc cref="Exiled.Events.Handlers.Server.OnRoundStarted()"/>
internal static void OnRoundStarted()
{
Expand Down Expand Up @@ -121,7 +131,7 @@ internal static void OnShooting(ShootingEventArgs ev)
if (mode == ToolGunMode.LightController)
{
Room colliderRoom = Map.FindParentRoom(hit.collider.gameObject);
if (SpawnedObjects.FirstOrDefault(x => x is LightControllerComponent light && (Map.FindParentRoom(x.gameObject) == colliderRoom || light.Base.RoomType == colliderRoom.Type)) != null)
if (SpawnedObjects.FirstOrDefault(x => x is LightControllerComponent light && light.ForcedRoomType == colliderRoom.Type) != null)
{
ev.Shooter.ShowHint("There can be only one Light Controller per one room type!");
return;
Expand Down Expand Up @@ -305,6 +315,7 @@ public static MapSchematic CurrentLoadedMap
public static string CopiedObjectSessionVarName { get; } = "MapEditorReborn_CopiedObject";

private static MapSchematic _mapSchematic;
private static readonly List<Vector3> FlickerableLightsPositions = new List<Vector3>();
private static readonly Config Config = MapEditorReborn.Singleton.Config;
private static readonly Translation Translation = MapEditorReborn.Singleton.Translation;

Expand Down
Loading

0 comments on commit 210ebc0

Please sign in to comment.