Skip to content

Commit

Permalink
optimize Payday 2 layers
Browse files Browse the repository at this point in the history
  • Loading branch information
Aytackydln committed Oct 11, 2024
1 parent a63fbe3 commit 33f82f0
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ protected override UserControl CreateControl()

public override EffectLayer Render(IGameState state)
{
var bgLayer = new EffectLayer("Payday 2 - Background");

if (state is not GameState_PD2 pd2) return bgLayer;
if (state is not GameState_PD2 pd2) return EffectLayer.EmptyLayer;
var bgColor = Properties.AmbientColor;

var currenttime = Time.GetMillisecondsSinceEpoch();
Expand Down Expand Up @@ -176,10 +174,10 @@ public override EffectLayer Render(IGameState state)
*/
}

bgLayer.FillOver(bgColor);
EffectLayer.FillOver(bgColor);

if (Properties.PeripheralUse)
bgLayer.Set(DeviceKeys.Peripheral, bgColor);
EffectLayer.Set(DeviceKeys.Peripheral, bgColor);
}
else if (pd2.Level.Phase == LevelPhase.Stealth && pd2.Game.State == GameStates.Ingame)
{
Expand All @@ -192,10 +190,10 @@ public override EffectLayer Render(IGameState state)

var suspicionSequence = new KeySequence(new FreeFormObject(0, 0, 1.0f / (Effects.Canvas.EditorToCanvasWidth / Effects.Canvas.Width), 1.0f / (Effects.Canvas.EditorToCanvasHeight / Effects.Canvas.Height)));

bgLayer.PercentEffect(suspicionSpec, suspicionSequence, percentSuspicious, 1.0D, Properties.SuspicionEffectType);
EffectLayer.PercentEffect(suspicionSpec, suspicionSequence, percentSuspicious, 1.0D, Properties.SuspicionEffectType);

if (Properties.PeripheralUse)
bgLayer.Set(DeviceKeys.Peripheral, suspicionSpec.GetColorAt((float)percentSuspicious));
EffectLayer.Set(DeviceKeys.Peripheral, suspicionSpec.GetColorAt((float)percentSuspicious));
}
}
else if (pd2.Level.Phase == LevelPhase.Point_of_no_return && pd2.Game.State == GameStates.Ingame)
Expand All @@ -213,19 +211,19 @@ public override EffectLayer Render(IGameState state)
if (_noReturnFlashamount < 0.0f)
_noReturnFlashamount = 0.0f;

bgLayer.FillOver(noReturnColor);
EffectLayer.FillOver(noReturnColor);

if (Properties.PeripheralUse)
bgLayer.Set(DeviceKeys.Peripheral, noReturnColor);
EffectLayer.Set(DeviceKeys.Peripheral, noReturnColor);
}
else
{
bgLayer.FillOver(bgColor);
EffectLayer.FillOver(bgColor);

if (Properties.PeripheralUse)
bgLayer.Set(DeviceKeys.Peripheral, bgColor);
EffectLayer.Set(DeviceKeys.Peripheral, bgColor);
}

return bgLayer;
return EffectLayer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,44 @@
using AuroraRgb.Utils;
using Newtonsoft.Json;

namespace AuroraRgb.Profiles.Payday_2.Layers
namespace AuroraRgb.Profiles.Payday_2.Layers;

public partial class PD2FlashbangLayerHandlerProperties : LayerHandlerProperties2Color
{
public partial class PD2FlashbangLayerHandlerProperties : LayerHandlerProperties2Color
private Color? _flashbangColor;

[JsonProperty("_FlashbangColor")]
public Color FlashbangColor
{
private Color? _flashbangColor;
get => Logic?._FlashbangColor ?? _flashbangColor ?? Color.Empty;
set => _flashbangColor = value;
}

[JsonProperty("_FlashbangColor")]
public Color FlashbangColor
{
get => Logic?._FlashbangColor ?? _flashbangColor ?? Color.Empty;
set => _flashbangColor = value;
}
public override void Default()
{
base.Default();

public override void Default()
{
base.Default();
_flashbangColor = Color.FromArgb(255, 255, 255);
}

_flashbangColor = Color.FromArgb(255, 255, 255);
}
}

public class PD2FlashbangLayerHandler : LayerHandler<PD2FlashbangLayerHandlerProperties>
{
protected override UserControl CreateControl()
{
return new Control_PD2FlashbangLayer(this);
}

public class PD2FlashbangLayerHandler : LayerHandler<PD2FlashbangLayerHandlerProperties>
public override EffectLayer Render(IGameState gameState)
{
protected override UserControl CreateControl()
{
return new Control_PD2FlashbangLayer(this);
}

public override EffectLayer Render(IGameState state)
{
var flashedLayer = new EffectLayer("Payday 2 - Flashed");

if (state is not GameState_PD2 pd2State) return flashedLayer;
//Update Flashed
if (pd2State.Game.State != GameStates.Ingame || !(pd2State.Players.LocalPlayer.FlashAmount > 0)) return flashedLayer;
var flashColor = ColorUtils.MultiplyColorByScalar(Properties.FlashbangColor, pd2State.Players.LocalPlayer.FlashAmount);
if (gameState is not GameState_PD2 pd2State) return EffectLayer.EmptyLayer;
//Update Flashed
if (pd2State.Game.State != GameStates.Ingame || pd2State.Players.LocalPlayer.FlashAmount <= 0) return EffectLayer.EmptyLayer;
var flashColor = ColorUtils.MultiplyColorByScalar(Properties.FlashbangColor, pd2State.Players.LocalPlayer.FlashAmount);

flashedLayer.FillOver(flashColor);
EffectLayer.FillOver(flashColor);

return flashedLayer;
}
return EffectLayer.EmptyLayer;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Controls;
using AuroraRgb.EffectsEngine;
Expand Down Expand Up @@ -73,23 +74,23 @@ public override void Default()

public class PD2StatesLayerHandler : LayerHandler<PD2StatesLayerHandlerProperties>
{
private readonly EffectLayer _swansongLayer = new("Payday 2 - Swansong", true);

protected override UserControl CreateControl()
{
return new Control_PD2StatesLayer(this);
}

public override EffectLayer Render(IGameState state)
public override EffectLayer Render(IGameState gameState)
{
var statesLayer = new EffectLayer("Payday 2 - States");

if (state is not GameState_PD2 pd2State) return statesLayer;
if (gameState is not GameState_PD2 pd2State) return EffectLayer.EmptyLayer;

if (pd2State.Game.State != GameStates.Ingame) return statesLayer;
if (pd2State.Game.State != GameStates.Ingame) return EffectLayer.EmptyLayer;
switch (pd2State.LocalPlayer.State)
{
case PlayerState.Incapacitated or PlayerState.Bleed_out or PlayerState.Fatal:
{
var incapAlpha = (int)(pd2State.LocalPlayer.DownTime > 10 ? 0 : 255 * (1.0D - (double)pd2State.LocalPlayer.DownTime / 10.0D));
var incapAlpha = (int)(pd2State.LocalPlayer.DownTime > 10 ? 0 : 255 * (1.0D - pd2State.LocalPlayer.DownTime / 10.0D));

if (incapAlpha > 255)
incapAlpha = 255;
Expand All @@ -98,26 +99,30 @@ public override EffectLayer Render(IGameState state)

var incapColor = Color.FromArgb(incapAlpha, Properties.DownedColor);

statesLayer.FillOver(incapColor);
statesLayer.Set(DeviceKeys.Peripheral, incapColor);
EffectLayer.FillOver(incapColor);
EffectLayer.Set(DeviceKeys.Peripheral, incapColor);
break;
}
case PlayerState.Arrested:
statesLayer.FillOver(Properties.ArrestedColor);
statesLayer.Set(DeviceKeys.Peripheral, Properties.ArrestedColor);
EffectLayer.FillOver(Properties.ArrestedColor);
EffectLayer.Set(DeviceKeys.Peripheral, Properties.ArrestedColor);
break;
}

if (!pd2State.LocalPlayer.SwanSong || !Properties.ShowSwanSong) return statesLayer;
var blendPercent = Math.Pow(Math.Cos((Time.GetMillisecondsSinceEpoch() % 1300L) / 1300.0D * Properties.SwanSongSpeedMultiplier * 2.0D * Math.PI), 2.0D);
if (!pd2State.LocalPlayer.SwanSong || !Properties.ShowSwanSong) return EffectLayer;
var blendPercent = Math.Pow(Math.Cos(Time.GetMillisecondsSinceEpoch() % 1300L / 1300.0D * Properties.SwanSongSpeedMultiplier * 2.0D * Math.PI), 2.0D);

var swansongColor = ColorUtils.MultiplyColorByScalar(Properties.SwanSongColor, blendPercent);

var swansongLayer = new EffectLayer("Payday 2 - Swansong", swansongColor);
swansongLayer.Set(DeviceKeys.Peripheral, swansongColor);
_swansongLayer.Set(DeviceKeys.Peripheral, swansongColor);

statesLayer += swansongLayer;
return EffectLayer + _swansongLayer;
}

return statesLayer;
protected override void PropertiesChanged(object? sender, PropertyChangedEventArgs args)
{
base.PropertiesChanged(sender, args);

_swansongLayer.Set(DeviceKeys.Peripheral, Properties.SwanSongColor);
}
}

0 comments on commit 33f82f0

Please sign in to comment.