Skip to content
This repository has been archived by the owner on Jan 27, 2025. It is now read-only.

Commit

Permalink
Fading ACTUALLY works now
Browse files Browse the repository at this point in the history
I forgot how lerps worked, because I'm dumb
  • Loading branch information
AutumnRivers committed May 25, 2024
1 parent 8befea6 commit d280912
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 6 additions & 4 deletions Cutscenes/Patches/CutsceneExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,15 @@ private static void FadeImage(StuxnetCutscene cs, float gameTime, int index)

string id = target.Item1;
float targetOpacity = target.Item3 ? 1.0f : 0.0f;
float startingOpacity = target.Item3 ? 0.0f : 1.0f;
StuxnetCutsceneImage refImage = cs.images[id];
float currentOpacity = refImage.opacity;

float duration = gameTime / target.Item4;
float currentProgress = duration + target.Item5;
float lerpAmount = gameTime / target.Item4;
float currentProgress = lerpAmount + target.Item5;

float newOpacity = MathHelper.Lerp(currentOpacity, targetOpacity, currentProgress);
Console.WriteLine($"D: {lerpAmount} / P: {currentProgress} / O: {refImage.opacity}");

float newOpacity = MathHelper.Lerp(startingOpacity, targetOpacity, currentProgress);
refImage.opacity = newOpacity;
cs.images[id] = refImage;

Expand Down
10 changes: 9 additions & 1 deletion Cutscenes/StuxnetCutscenes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public class StuxnetCutsceneImage
public Vector2 position;
public Vector2 size;
public float currentRotation = 0f;
public float opacity = 1.0f;
public float opacity = 0.0f;

public Vector2 GetCalculatedPosition()
{
Expand Down Expand Up @@ -390,6 +390,8 @@ public StuxnetCutsceneInstruction(StuxnetCutscene associatedCutscene)

public void Execute()
{
Console.WriteLine($"Executing {instructionType}...");

switch(instructionType)
{
case InstructionTypes.InstantIn:
Expand Down Expand Up @@ -427,6 +429,10 @@ public void Execute()

public void ExecuteFade(bool fadeIn)
{
if(!cutscene.activeImages.Exists(id => id == typeID) && fadeIn)
{
cutscene.activeImages.Add(typeID);
}
CutsceneExecutor.AddFadeImage(typeID, fadeIn, FadeDuration);
}

Expand Down Expand Up @@ -496,6 +502,7 @@ public void ExecuteInstantTrans(bool activate = true)
} else if(objectType == "Image")
{
if (cutscene.activeImages.Contains(id)) { return; }
cutscene.images[id].opacity = 1.0f;
cutscene.activeImages.Add(id);
}
} else
Expand All @@ -508,6 +515,7 @@ public void ExecuteInstantTrans(bool activate = true)
else if (objectType == "Image")
{
if (!cutscene.activeImages.Contains(id)) { return; }
cutscene.images[id].opacity = 0.0f;
cutscene.activeImages.Remove(id);
}
}
Expand Down

0 comments on commit d280912

Please sign in to comment.