Skip to content

Commit

Permalink
[Glue + Tiled] - Foldered entities can be instantiated in Tiled maps …
Browse files Browse the repository at this point in the history
…using either forward or back slashes.

[Autopmated Test] - Added test for instantiating entities.
  • Loading branch information
vchelaru committed Feb 24, 2019
1 parent f75d0ac commit 8048cf7
Show file tree
Hide file tree
Showing 12 changed files with 201 additions and 58 deletions.
Expand Up @@ -525,7 +525,9 @@ private static IEntityFactory GetFactory(string entityType)
var methodInfo = type.GetMethod("CreateNew", new[] { typeof(Layer), typeof(float), typeof(float) });
var returntypeString = methodInfo.ReturnType.Name;
return entityType == returntypeString || entityType.EndsWith("\\" + returntypeString);
return entityType == returntypeString ||
entityType.EndsWith("\\" + returntypeString) ||
entityType.EndsWith("/" + returntypeString);
});
return factory;
}
Expand Down
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Text;
using FlatRedBall;
using FlatRedBall.Input;
using FlatRedBall.Instructions;
using FlatRedBall.AI.Pathfinding;
using FlatRedBall.Graphics.Animation;
using FlatRedBall.Graphics.Particle;
using FlatRedBall.Math.Geometry;

namespace GlueTestProject.Entities.EntityFolder
{
public partial class TiledEntityInFolder
{
/// <summary>
/// Initialization logic which is execute only one time for this Entity (unless the Entity is pooled).
/// This method is called when the Entity is added to managers. Entities which are instantiated but not
/// added to managers will not have this method called.
/// </summary>
private void CustomInitialize()
{


}

private void CustomActivity()
{


}

private void CustomDestroy()
{


}

private static void CustomLoadStaticContent(string contentManagerName)
{


}
}
}
Expand Up @@ -396,6 +396,10 @@
<Compile Include="Entities\EntityFolder\StateEntityInFolder.Generated.cs">
<DependentUpon>StateEntityInFolder.cs</DependentUpon>
</Compile>
<Compile Include="Entities\EntityFolder\TiledEntityInFolder.cs" />
<Compile Include="Entities\EntityFolder\TiledEntityInFolder.Generated.cs">
<DependentUpon>TiledEntityInFolder.cs</DependentUpon>
</Compile>
<Compile Include="Entities\EntityForTestPlugin.cs" />
<Compile Include="Entities\EntityForTestPlugin.Generated.cs">
<DependentUpon>EntityForTestPlugin.cs</DependentUpon>
Expand Down Expand Up @@ -842,6 +846,7 @@
<Compile Include="Factories\RecyclableEntityFactory.Generated.cs" />
<Compile Include="Factories\ShapeEntityCreatedByOtherEntitiesFactory.Generated.cs" />
<Compile Include="Factories\TextInheritingEntityFactory.Generated.cs" />
<Compile Include="Factories\TiledEntityInFolderFactory.Generated.cs" />
<Compile Include="FileAliases.Generated.cs" />
<Compile Include="Forms\Controls\CustomUserControl.cs" />
<Compile Include="Game1.Custom.cs">
Expand Down
Expand Up @@ -3724,6 +3724,15 @@
<GenerateTimedEmit>true</GenerateTimedEmit>
<IndependentOfCamera>true</IndependentOfCamera>
</NamedObjectSave>
<NamedObjectSave>
<SourceType>FlatRedBallType</SourceType>
<SourceClassType>PositionedObjectList&lt;T&gt;</SourceClassType>
<SourceClassGenericType>Entities\EntityFolder\TiledEntityInFolder</SourceClassGenericType>
<InstanceName>TiledEntityInFolderList</InstanceName>
<AttachToContainer>true</AttachToContainer>
<GenerateTimedEmit>true</GenerateTimedEmit>
<IndependentOfCamera>true</IndependentOfCamera>
</NamedObjectSave>
</NamedObjects>
</ScreenSave>
<ScreenSave>
Expand Down Expand Up @@ -3812,6 +3821,12 @@
<RuntimeType>FlatRedBall.TileGraphics.LayeredTileMap</RuntimeType>
<ProjectsToExcludeFrom />
</ReferencedFileSave>
<ReferencedFileSave>
<Name>Screens/TmxScreen/TmxWithEntities.tmx</Name>
<IsSharedStatic>true</IsSharedStatic>
<RuntimeType>FlatRedBall.TileGraphics.LayeredTileMap</RuntimeType>
<ProjectsToExcludeFrom />
</ReferencedFileSave>
</ReferencedFiles>
<NamedObjects>
<NamedObjectSave>
Expand Down Expand Up @@ -3843,6 +3858,15 @@
<GenerateTimedEmit>true</GenerateTimedEmit>
<IndependentOfCamera>true</IndependentOfCamera>
</NamedObjectSave>
<NamedObjectSave>
<SourceType>FlatRedBallType</SourceType>
<SourceClassType>PositionedObjectList&lt;T&gt;</SourceClassType>
<SourceClassGenericType>Entities\EntityFolder\TiledEntityInFolder</SourceClassGenericType>
<InstanceName>TiledEntityInFolderList</InstanceName>
<AttachToContainer>true</AttachToContainer>
<GenerateTimedEmit>true</GenerateTimedEmit>
<IndependentOfCamera>true</IndependentOfCamera>
</NamedObjectSave>
</NamedObjects>
</ScreenSave>
<ScreenSave>
Expand Down Expand Up @@ -8124,6 +8148,48 @@
<Name>Entities\EntityFolder\StateEntityInFolder</Name>
<Is2D>true</Is2D>
</EntitySave>
<EntitySave>
<Tags>
<string>GLUE</string>
</Tags>
<Source>GLUE</Source>
<CustomVariables>
<CustomVariable>
<Properties>
<PropertySave>
<Name>Type</Name>
<ValueAsString>float</ValueAsString>
</PropertySave>
</Properties>
<Name>X</Name>
<Type>float</Type>
</CustomVariable>
<CustomVariable>
<Properties>
<PropertySave>
<Name>Type</Name>
<ValueAsString>float</ValueAsString>
</PropertySave>
</Properties>
<Name>Y</Name>
<Type>float</Type>
</CustomVariable>
<CustomVariable>
<Properties>
<PropertySave>
<Name>Type</Name>
<ValueAsString>float</ValueAsString>
</PropertySave>
</Properties>
<Name>Z</Name>
<Type>float</Type>
</CustomVariable>
</CustomVariables>
<ImplementsIDrawableBatch>false</ImplementsIDrawableBatch>
<Name>Entities\EntityFolder\TiledEntityInFolder</Name>
<CreatedByOtherEntities>true</CreatedByOtherEntities>
<Is2D>true</Is2D>
</EntitySave>
<EntitySave>
<Properties>
<PropertySave>
Expand Down
Expand Up @@ -13,6 +13,8 @@
using Cursor = FlatRedBall.Gui.Cursor;
using GuiManager = FlatRedBall.Gui.GuiManager;
using FlatRedBall.Localization;
using GlueTestProject.TestFramework;
using FlatRedBall.TileEntities;

#if FRB_XNA || SILVERLIGHT
using Keys = Microsoft.Xna.Framework.Input.Keys;
Expand Down Expand Up @@ -62,6 +64,8 @@ void CustomInitialize()

TestTileSizeOnMapWithObjects();

TestEntitiesInFolders();

// Make the shapes visible, to make sure that they get removed when the screen is destroyed:
foreach(var shapeCollection in TmxWithShapes.ShapeCollections)
{
Expand All @@ -70,6 +74,16 @@ void CustomInitialize()
}
}

private void TestEntitiesInFolders()
{
this.TiledEntityInFolderList.Count
.ShouldBe(0, "because entities haven't yet been created");
TileEntityInstantiator.CreateEntitiesFrom(TmxWithEntities);

this.TiledEntityInFolderList.Count
.ShouldBe(2, "because there are 2 tile instances creating this entity, one with a forward slash, one with a back slash");
}

private void TestTileSizeOnMapWithObjects()
{
var expectedWidth = 32 * 16;
Expand Down
Expand Up @@ -84,7 +84,14 @@ internal static void ResetWindow ()
}
else
{
FlatRedBall.FlatRedBallServices.GraphicsOptions.SetResolution((int)(Data.ResolutionWidth * Data.Scale/ 100.0f), (int)(Data.ResolutionHeight * Data.Scale/ 100.0f));
var width = (int)(Data.ResolutionWidth * Data.Scale / 100.0f);
var height = (int)(Data.ResolutionHeight * Data.Scale / 100.0f);
// subtract to leave room for windows borders
var maxWidth = Microsoft.Xna.Framework.Graphics.GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width - 6;
var maxHeight = Microsoft.Xna.Framework.Graphics.GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height - 28;
width = System.Math.Min(width, maxWidth);
height = System.Math.Min(height, maxHeight);
FlatRedBall.FlatRedBallServices.GraphicsOptions.SetResolution(width, height);
}
#elif IOS || ANDROID
FlatRedBall.FlatRedBallServices.GraphicsOptions.SetFullScreen(FlatRedBall.FlatRedBallServices.GraphicsOptions.ResolutionWidth, FlatRedBall.FlatRedBallServices.GraphicsOptions.ResolutionHeight);
Expand All @@ -95,8 +102,8 @@ internal static void ResetWindow ()
}
else
{
FlatRedBall.FlatRedBallServices.GraphicsOptions.SetResolution((int)(Data.ResolutionWidth * Data.Scale/ 100.0f), (int)(Data.ResolutionHeight * Data.Scale/ 100.0f));
var newWindowSize = new Windows.Foundation.Size((int)(Data.ResolutionWidth * Data.Scale/ 100.0f), (int)(Data.ResolutionHeight * Data.Scale/ 100.0f));
FlatRedBall.FlatRedBallServices.GraphicsOptions.SetResolution(Data.ResolutionWidth, Data.ResolutionHeight);
var newWindowSize = new Windows.Foundation.Size(Data.ResolutionWidth, Data.ResolutionHeight);
Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().TryResizeView(newWindowSize);
}
#endif
Expand Down
Expand Up @@ -525,7 +525,9 @@ private static IEntityFactory GetFactory(string entityType)
var methodInfo = type.GetMethod("CreateNew", new[] { typeof(Layer), typeof(float), typeof(float) });
var returntypeString = methodInfo.ReturnType.Name;
return entityType == returntypeString || entityType.EndsWith("\\" + returntypeString);
return entityType == returntypeString ||
entityType.EndsWith("\\" + returntypeString) ||
entityType.EndsWith("/" + returntypeString);
});
return factory;
}
Expand Down

0 comments on commit 8048cf7

Please sign in to comment.