Last active
February 11, 2016 22:05
-
-
Save npruehs/c3270996b178868dbaa1 to your computer and use it in GitHub Desktop.
Generated Entitas Blueprint Source Code Files - Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//------------------------------------------------------------------------------ | |
// <auto-generated> | |
// This code was generated by Entitas. | |
// | |
// Changes to this file may cause incorrect behavior and will be lost if | |
// the code is regenerated. | |
// </auto-generated> | |
//------------------------------------------------------------------------------ | |
namespace Entitas | |
{ | |
public static class BlueprintPoolExtension | |
{ | |
public static Entity CreateEntity(this Pool pool, Blueprints.IBlueprint blueprint) | |
{ | |
var entity = pool.CreateEntity(); | |
foreach (var componentTypeName in blueprint.ComponentTypes) | |
{ | |
var componentId = ComponentNameToId[componentTypeName]; | |
switch (componentId) | |
{ | |
case ComponentIds.Movable: | |
entity.IsMovable(true); | |
break; | |
case ComponentIds.Position: | |
entity.AddPosition(blueprint.PropertyValues); | |
break; | |
case ComponentIds.Destroy: | |
entity.IsDestroy(true); | |
break; | |
case ComponentIds.GameBoardCache: | |
entity.AddGameBoardCache(blueprint.PropertyValues); | |
break; | |
case ComponentIds.GameBoard: | |
entity.AddGameBoard(blueprint.PropertyValues); | |
break; | |
case ComponentIds.GameBoardElement: | |
entity.IsGameBoardElement(true); | |
break; | |
case ComponentIds.Input: | |
entity.AddInput(blueprint.PropertyValues); | |
break; | |
case ComponentIds.Interactive: | |
entity.IsInteractive(true); | |
break; | |
case ComponentIds.Resource: | |
entity.AddResource(blueprint.PropertyValues); | |
break; | |
case ComponentIds.View: | |
entity.AddView(blueprint.PropertyValues); | |
break; | |
case ComponentIds.Score: | |
entity.AddScore(blueprint.PropertyValues); | |
break; | |
} | |
} | |
return entity; | |
} | |
private static readonly System.Collections.Generic.Dictionary<string, int> ComponentNameToId = new System.Collections.Generic.Dictionary<string, int> | |
{ | |
{ "Movable", ComponentIds.Movable }, | |
{ "Position", ComponentIds.Position }, | |
{ "Destroy", ComponentIds.Destroy }, | |
{ "GameBoardCache", ComponentIds.GameBoardCache }, | |
{ "GameBoard", ComponentIds.GameBoard }, | |
{ "GameBoardElement", ComponentIds.GameBoardElement }, | |
{ "Input", ComponentIds.Input }, | |
{ "Interactive", ComponentIds.Interactive }, | |
{ "Resource", ComponentIds.Resource }, | |
{ "View", ComponentIds.View }, | |
{ "Score", ComponentIds.Score }, | |
}; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-16"?> | |
<Blueprints> | |
<Blueprint Id="Piece0"> | |
<Properties> | |
<Property Key="Resource.name" Type="System.String"> | |
<Value>Piece0</Value> | |
</Property> | |
</Properties> | |
<Components> | |
<Component>GameBoardElement</Component> | |
<Component>Movable</Component> | |
<Component>Interactive</Component> | |
<Component>Resource</Component> | |
</Components> | |
</Blueprint> | |
<Blueprint Id="Blocker"> | |
<Properties> | |
<Property Key="Resource.name" Type="System.String"> | |
<Value>Blocker</Value> | |
</Property> | |
</Properties> | |
<Components> | |
<Component>GameBoardElement</Component> | |
<Component>Resource</Component> | |
</Components> | |
</Blueprint> | |
</Blueprints> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//------------------------------------------------------------------------------ | |
// <auto-generated> | |
// This code was generated by Entitas. | |
// | |
// Changes to this file may cause incorrect behavior and will be lost if | |
// the code is regenerated. | |
// </auto-generated> | |
//------------------------------------------------------------------------------ | |
namespace Entitas | |
{ | |
public partial class Entity | |
{ | |
public Entity AddPosition(System.Collections.Generic.IDictionary<string, object> properties) | |
{ | |
var componentPool = this.GetComponentPool(ComponentIds.Position); | |
var component = (PositionComponent)(componentPool.Count > 0 ? componentPool.Pop() : new PositionComponent()); | |
component.x = (int)properties["Position.x"]; | |
component.y = (int)properties["Position.y"]; | |
return this.AddComponent(ComponentIds.Position, component); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment