Skip to content

Instantly share code, notes, and snippets.

@hakelimopu
Created January 12, 2017 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakelimopu/3decb7f3fcb34af8af94654c01dcc003 to your computer and use it in GitHub Desktop.
Save hakelimopu/3decb7f3fcb34af8af94654c01dcc003 to your computer and use it in GitHub Desktop.
Some of the classes for extending GameChips for PixelVision8 (and making their use more attribute-y and generic-y/reflect-y)
using PixelVisionSDK.Engine;
using PixelVisionSDK.Engine.Chips.Game;
using System;
using System.Linq;
namespace PixelVisionSDK.Extensions
{
public static class EngineExtensionMethods
{
public static void LoadExtendedGameChip<T>(this IEngine engine, T gameChip) where T:GameChip
{
LoadExtendedGameChip(engine, gameChip, typeof(T));
}
public static void LoadExtendedGameChip(this IEngine engine, GameChip gameChip, Type type)
{
type
.GetCustomAttributes(typeof(ChipDependencyAttribute), true)
.Select(x => (ChipDependencyAttribute)x).ToList()
.ForEach(x => engine.chipManager.GetChip(x.Dependency.FullName, x.ActivateOnCreate));
engine.LoadGame(gameChip);
}
}
}
using PixelVisionSDK.Engine.Chips.Graphics.Sprites;
using PixelVisionSDK.Engine.Chips.Graphics.Colors;
using PixelVisionSDK.Engine.Chips.Graphics.Display;
using PixelVisionSDK.Engine.Chips.IO.Controller;
using PixelVisionSDK.Extensions;
namespace ExtendedDemos
{
[ChipDependency(typeof(ColorChip), true)]
[ChipDependency(typeof(SpriteChip), true)]
[ChipDependency(typeof(ScreenBufferChip), true)]
[ChipDependency(typeof(TileMapChip), true)]
[ChipDependency(typeof(FontChip), true)]
[ChipDependency(typeof(ControllerChip), true)]
[ChipDependency(typeof(DisplayChip), true)]
[ColorResource("colors.png")]
[SpriteResource("sprites.png",true)]
[LogicalSize(256,240)]
public class ExtendedDrawSpriteDemo: DrawSpriteDemo
{
}
}
using PixelVisionSDK.Engine.Chips.Game;
using System;
using System.Linq;
namespace PixelVisionSDK.Extensions
{
public static class GameChipExtensionMethods
{
public static void WithColorResource<T>(this T gameChip, Action<string> action) where T:GameChip
{
var attribute = typeof(T).GetCustomAttributes(typeof(ColorResourceAttribute), false).Select(x => (ColorResourceAttribute)x).SingleOrDefault();
if(attribute!=null)
{
action(attribute.FileName);
}
}
public static void WithSpriteResources<T>(this T gameChip, Action<string,bool> action) where T:GameChip
{
typeof(T)
.GetCustomAttributes(typeof(SpriteResourceAttribute), false)
.Select(x => (SpriteResourceAttribute)x)
.ToList()
.ForEach(attribute =>
{
action(attribute.FileName, attribute.Unique);
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment