Skip to content

Commit

Permalink
Fixed possible top-down compile errors caused by removal of old anima…
Browse files Browse the repository at this point in the history
…tion classes.
  • Loading branch information
vchelaru committed Feb 25, 2024
1 parent f88a005 commit 640fbc7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 101 deletions.
4 changes: 2 additions & 2 deletions FRBDK/Glue/CompilerPlugin/CompilerPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override void StartUp()
ReactToPluginEvent("Compiler_Output_Error", output);
};

CreateBuildControl();
CreateBuildTab();
}

private void HandleGluxLoaded()
Expand Down Expand Up @@ -115,7 +115,7 @@ private void LoadOrCreateBuildSettings()
}
}

private void CreateBuildControl()
private void CreateBuildTab()
{
MainControl = new BuildTabView();
MainControl.DataContext = _compilerViewModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using FlatRedBall.Glue.FormHelpers;
using System.Threading.Tasks;
using PlatformerPluginCore.Views;
using FlatRedBall.IO;

namespace EntityInputMovementPlugin
{
Expand Down Expand Up @@ -165,11 +166,15 @@ await topDownController.GenerateAndAddCsv(
else
{
// Platformer removes here. Should we also remove top-down?

GlueCommands.Self.ProjectCommands.RemoveFromProjects(TopDownPlugin.CodeGenerators.TopDownAnimationControllerGenerator.Self.FileLocation);

}

// Remove old files no longer needed:
var projectLocation = GlueState.Self.CurrentGlueProjectDirectory;
GlueCommands.Self.ProjectCommands.RemoveFromProjects(new FilePath( projectLocation + "TopDown\\AnimationSet.Generated.cs"));
GlueCommands.Self.ProjectCommands.RemoveFromProjects(new FilePath( projectLocation + "TopDown\\DirectionBasedAnimationLayer.Generated.cs"));


// remove requirement for the old top-down plugin otherwise projects will get a message forever about it:
var didChangeGlux = GlueCommands.Self.GluxCommands.SetPluginRequirement(
"Top Down Plugin",
Expand Down
96 changes: 0 additions & 96 deletions FRBDK/Glue/TopDownPlugin/CodeGenerators/EntityCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ private void GenerateTopDownElementSave(IElement element, ICodeBlock codeBlock)
// Made a Vector3 to make assignment and usage easier.
codeBlock.Line("public Microsoft.Xna.Framework.Vector3 GroundVelocity;");

WriteAnimationFields(element, codeBlock);

codeBlock.Line("DataTypes.TopDownValues mCurrentMovement;");
codeBlock.Line("public float TopDownSpeedMultiplier { get; set; } = 1;");

Expand Down Expand Up @@ -131,100 +129,6 @@ private void GenerateTopDownElementSave(IElement element, ICodeBlock codeBlock)
codeBlock.Line("#endregion");
}

private static void WriteAnimationFields(IElement element, ICodeBlock codeBlock)
{
string ToQuotedSetName(string setValue)
{
if(setValue == null)
{
return "null";
}
else
{
return $"\"{setValue}\"";
}
}

TopDownAnimationData animationData = null;
var animationFilePath = MainController.GetAnimationFilePathFor(element as EntitySave);
if (animationFilePath.Exists())
{
try
{
var contents = System.IO.File.ReadAllText(animationFilePath.FullPath);
animationData = JsonConvert.DeserializeObject<TopDownAnimationData>(contents);
}
catch
{
// do nothing, codegen will skip this
}
}

var hasAnimationSets =
animationData?.Animations.Count > 0;

if(!hasAnimationSets)
{
codeBlock.Line("public List<TopDown.AnimationSet> AnimationSets { get; set; } = new List<TopDown.AnimationSet>();");

}
else
{
codeBlock.Line("public List<TopDown.AnimationSet> AnimationSets { get; set; } = new List<TopDown.AnimationSet>");

var listBlock = codeBlock.Block();
(listBlock.PostCodeLines[0] as CodeLine).Value += ";";

foreach(var movementValueAnimation in animationData.Animations)
{

string prefix = movementValueAnimation.MovementValuesName + "_";

foreach(var set in movementValueAnimation.AnimationSets)
{

var hasAnimations =
set.UpLeftAnimation != null ||
set.UpAnimation != null ||
set.UpRightAnimation != null ||
set.LeftAnimation != null ||
set.RightAnimation != null ||
set.DownLeftAnimation != null ||
set.DownAnimation != null ||
set.DownRightAnimation != null;

if(hasAnimations)
{
listBlock.Line($"new TopDown.AnimationSet()");
var assignmentBlock = listBlock.Block();
(assignmentBlock.PostCodeLines[0] as CodeLine).Value += ",";

string minSpeed =
set.AnimationSetName == "Idle" ? "0f" : ".1f";

assignmentBlock.Line($"MinSpeed = {minSpeed},");

assignmentBlock.Line($"MovementValueName = \"{movementValueAnimation.MovementValuesName}\",");



assignmentBlock.Line($"UpLeftAnimationName = {ToQuotedSetName(set.UpLeftAnimation)},");
assignmentBlock.Line($"UpAnimationName = {ToQuotedSetName(set.UpAnimation)},");
assignmentBlock.Line($"UpRightAnimationName = {ToQuotedSetName(set.UpRightAnimation)},");

assignmentBlock.Line($"LeftAnimationName = {ToQuotedSetName(set.LeftAnimation)},");
assignmentBlock.Line($"RightAnimationName = {ToQuotedSetName(set.RightAnimation)},");

assignmentBlock.Line($"DownLeftAnimationName = {ToQuotedSetName(set.DownLeftAnimation)},");
assignmentBlock.Line($"DownAnimationName = {ToQuotedSetName(set.DownAnimation)},");
assignmentBlock.Line($"DownRightAnimationName = {ToQuotedSetName(set.DownRightAnimation)}");

}
}
}
}

}

public override ICodeBlock GenerateInitialize(ICodeBlock codeBlock, IElement element)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public interface ITopDownEntity
{{
DataTypes.TopDownValues CurrentMovement {{ get; }}
Entities.TopDownDirection DirectionFacing {{ get; }}
System.Collections.Generic.List<TopDown.AnimationSet> AnimationSets {{ get; }}
FlatRedBall.Input.I2DInput MovementInput {{ get; set; }}
float MaxSpeed {{ get; }}
Expand Down

0 comments on commit 640fbc7

Please sign in to comment.