Commit e6c9495c authored by Jesse Freeman's avatar Jesse Freeman

Created a new service layer allowing classes to register themselves with the...

Created a new service layer allowing classes to register themselves with the ChipManager and expose functionality to the chips without being tightly coupled to their APIs. Fixed bugs and missing code in SoundChip and MusicChip. Corrected ColorData Hex color conversion to be more accurate and added RoundToInt to the MathUtil. General code cleanup and other updated to bring SDK codebase in line with above changes.
parent 524f6e4e
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Pp]roperties/
/[Bb]in/
# Autogenerated VS/MD solution and project files
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.meta
# Unity3D generated meta files
*.pidb.meta
# Unity3D Generated File On Crash Reports
sysinfo.txt
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Pp]roperties/
/[Bb]in/
# Autogenerated VS/MD solution and project files
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.meta
# Unity3D generated meta files
*.pidb.meta
# Unity3D Generated File On Crash Reports
sysinfo.txt
*.DS_Store
\ No newline at end of file
This diff is collapsed.
//
// Copyright (c) Jesse Freeman. All rights reserved.
//
// Licensed under the Microsoft Public License (MS-PL) License.
// See LICENSE file in the project root for full license information.
//
// Contributors
// --------------------------------------------------------
// This is the official list of Pixel Vision 8 contributors:
//
// Jesse Freeman - @JesseFreeman
// Christer Kaitila - @McFunkypants
// Pedro Medeiros - @saint11
// Shawn Rakowski - @shwany
//
using System;
using System.Collections.Generic;
using System.Text;
namespace PixelVisionSDK.Chips
{
/// <summary>
/// The AbstractChip represents plug-in that adds new functionality to the
/// PixelVisionEngine. Simply extend this abstract class and override the
/// Config() method. Each Chip is responsible for registering itself with
/// the engine and managing its own state. Chips can also communicate to
/// each other via the reference of the ChipManager which is part of the
/// PixelVisionEngine instance supplied to the Config() method.
/// </summary>
/// <example>
/// // Create a new class that extends the abstract chip
/// public class CustomChip : AbstractChip
/// {
/// // You need to override the Config method with your own custom setup code
/// public override Config()
/// {
/// // Add custom logic here
/// }
/// }
/// // Create a new instance of your chip
/// var chip = new CustomChip();
/// // When ready, activate the chip by passing in a reference to an engine instance
/// chip.Activate(engine);
/// </example>
public class AbstractChip : IChip
{
protected PixelVisionEngine engine;
/// <summary>
/// A flag for the ChipManager to determine if the chip
/// should be part of the serialization process.
/// </summary>
/// <value>bool</value>
public bool export = true;
/// <summary>
/// Determines if the chip is enabled or active by the
/// ChipManager. If marked as active it may be deleted
/// when the ChipManager performs its cleanup.
/// </summary>
/// <value name>bool</value>
public bool active { get; private set; }
/// <summary>
/// Activate is the beginning of the chip's life cycle.
/// This allows the chip to gain a reference to the engine
/// itself. This allows chips to talk back to the engine
/// as well as to each other through the engine's exposed APIs.
/// </summary>
/// <param name="parent">A reference to the engine.</param>
public virtual void Activate(PixelVisionEngine parent)
{
engine = parent;
active = true;
Configure();
}
/// <summary>
/// Configure is the second part of the chip's life-cycle.
/// It is called after Activate() and is designed to be overridden by
/// children classes so perform specific configuration tasks. This
/// method must be implemented in order for a chip to activate
/// correctly.
/// </summary>
public virtual void Configure()
{
throw new NotImplementedException();
}
/// <summary>
/// When called, this method sets the active field to
/// false. It's part of the chip's life-cycle and is called when
/// shutting down the ChipManager.
/// </summary>
public virtual void Deactivate()
{
active = false;
}
// /// <summary>
// /// This methods sets up the foundation for serializing a component as
// /// JSON. It automatically creates a json wrapper before calling
// /// CustomSerializedData().
// /// </summary>
// /// <returns>string</returns>
// public virtual string SerializeData()
// {
// var sb = new StringBuilder();
// sb.Append("{");
// CustomSerializedData(sb);
// sb.Append("}");
// return sb.ToString();
// }
//
// /// <summary>
// /// Override this to add custom json data to the serialized string
// /// passed in by the StringBuilder reference.
// /// </summary>
// /// <param name="sb">
// /// A StringBuilder reference to add additional json string properties
// /// to.
// /// </param>
// public virtual void CustomSerializedData(StringBuilder sb)
// {
// // Override to add custom data
// }
//
// /// <summary>
// /// Override this to method to handle your own custom de-serialized
// /// logic. It expects a Dictionary with a string as the key and a
// /// generic object as the value.
// /// </summary>
// /// <param name="data">
// /// A Dictionary with a string as the key and a generic object as the
// /// value.
// /// </param>
// public virtual void DeserializeData(Dictionary<string, object> data)
// {
// throw new NotImplementedException();
// }
public virtual void Init()
{
}
public virtual void Reset()
{
}
}
//
// Copyright (c) Jesse Freeman. All rights reserved.
//
// Licensed under the Microsoft Public License (MS-PL) License.
// See LICENSE file in the project root for full license information.
//
// Contributors
// --------------------------------------------------------
// This is the official list of Pixel Vision 8 contributors:
//
// Jesse Freeman - @JesseFreeman
// Christer Kaitila - @McFunkypants
// Pedro Medeiros - @saint11
// Shawn Rakowski - @shwany
//
using System;
namespace PixelVisionSDK.Chips
{
/// <summary>
/// The AbstractChip represents plug-in that adds new functionality to the
/// PixelVisionEngine. Simply extend this abstract class and override the
/// Config() method. Each Chip is responsible for registering itself with
/// the engine and managing its own state. Chips can also communicate to
/// each other via the reference of the ChipManager which is part of the
/// PixelVisionEngine instance supplied to the Config() method.
/// </summary>
/// <example>
/// // Create a new class that extends the abstract chip
/// public class CustomChip : AbstractChip
/// {
/// // You need to override the Config method with your own custom setup code
/// public override Config()
/// {
/// // Add custom logic here
/// }
/// }
/// // Create a new instance of your chip
/// var chip = new CustomChip();
/// // When ready, activate the chip by passing in a reference to an engine instance
/// chip.Activate(engine);
/// </example>
public class AbstractChip : IChip
{
protected PixelVisionEngine engine;
/// <summary>
/// A flag for the ChipManager to determine if the chip
/// should be part of the serialization process.
/// </summary>
/// <value>bool</value>
public bool export = true;
/// <summary>
/// Determines if the chip is enabled or active by the
/// ChipManager. If marked as active it may be deleted
/// when the ChipManager performs its cleanup.
/// </summary>
/// <value name>bool</value>
public bool active { get; private set; }
/// <summary>
/// Activate is the beginning of the chip's life cycle.
/// This allows the chip to gain a reference to the engine
/// itself. This allows chips to talk back to the engine
/// as well as to each other through the engine's exposed APIs.
/// </summary>
/// <param name="parent">A reference to the engine.</param>
public virtual void Activate(PixelVisionEngine parent)
{
engine = parent;
active = true;
Configure();
}
/// <summary>
/// Configure is the second part of the chip's life-cycle.
/// It is called after Activate() and is designed to be overridden by
/// children classes so perform specific configuration tasks. This
/// method must be implemented in order for a chip to activate
/// correctly.
/// </summary>
public virtual void Configure()
{
throw new NotImplementedException();
}
/// <summary>
/// When called, this method sets the active field to
/// false. It's part of the chip's life-cycle and is called when
/// shutting down the ChipManager.
/// </summary>
public virtual void Deactivate()
{
active = false;
}
public virtual void Init()
{
}
public virtual void Reset()
{
}
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
//
// Copyright (c) Jesse Freeman. All rights reserved.
//
// Licensed under the Microsoft Public License (MS-PL) License.
// See LICENSE file in the project root for full license information.
//
// Contributors
// --------------------------------------------------------
// This is the official list of Pixel Vision 8 contributors:
//
// Jesse Freeman - @JesseFreeman
// Christer Kaitila - @McFunkypants
// Pedro Medeiros - @saint11
// Shawn Rakowski - @shwany
//
namespace PixelVisionSDK.Chips
{
/// <summary>
/// </summary>
public interface IGameLoop : IUpdate, IDraw
{
/// <summary>
/// The Init() method for the game's live-cycle. This is the first
/// method called on a game when it is run.
/// </summary>
void Init();
/// <summary>
/// This is called to when the game loads up after Init() and when the
/// engine is reset. Use this to store configuration logic for the game
/// you want to execute when a game is started/restarted.
/// </summary>
void Reset();
}
//
// Copyright (c) Jesse Freeman. All rights reserved.
//
// Licensed under the Microsoft Public License (MS-PL) License.
// See LICENSE file in the project root for full license information.
//
// Contributors
// --------------------------------------------------------
// This is the official list of Pixel Vision 8 contributors:
//
// Jesse Freeman - @JesseFreeman
// Christer Kaitila - @McFunkypants
// Pedro Medeiros - @saint11
// Shawn Rakowski - @shwany
//
namespace PixelVisionSDK.Chips
{
/// <summary>
/// </summary>
public interface IGameLoop : IUpdate, IDraw
{
/// <summary>
/// The Init() method for the game's live-cycle. This is the first
/// method called on a game when it is run.
/// </summary>
void Init();
/// <summary>
/// This is called to when the game loads up after Init() and when the
/// engine is reset. Use this to store configuration logic for the game
/// you want to execute when a game is started/restarted.
/// </summary>
void Reset();
}
}
\ No newline at end of file
This diff is collapsed.
//
// Copyright (c) Jesse Freeman. All rights reserved.
//
// Licensed under the Microsoft Public License (MS-PL) License.
// See LICENSE file in the project root for full license information.
//
// Contributors
// --------------------------------------------------------
// This is the official list of Pixel Vision 8 contributors:
//
// Jesse Freeman - @JesseFreeman
// Christer Kaitila - @McFunkypants
// Pedro Medeiros - @saint11
// Shawn Rakowski - @shwany
//
using System;
namespace PixelVisionSDK.Chips
{
/// <summary>
/// The color map chip is used to help import sprites and tile maps into the
/// engine if their colors don't match the system colors. When loading
/// artwork, if a color map is present, it will use the order of the colors
/// in the map as the index to remap to the system colors in the ColorChip.
/// </summary>
public class ColorMapChip : AbstractChip, IColorChip
{
protected string[] _colors = new string[256];
protected string transparent = "#ff00ff";
public ColorData[] colors
{
get
{
var t = total;
var colorCache = new ColorData[t];
for (var i = 0; i < t; i++)
{
colorCache[i] = new ColorData(_colors[i]);
}
return colorCache;
}
}
public int total
{
get { return _colors.Length; }
set
{
Array.Resize(ref _colors, value);
Clear();
}
}
public void Clear()
{
var t = _colors.Length;
for (var i = 0; i < t; i++)
{
UpdateColorAt(i, transparent);
}
}
public string ReadColorAt(int index)
{
return index < 0 || index > _colors.Length - 1 ? transparent : _colors[index];
}
public int FindColorID(string color)
{
return Array.IndexOf(_colors, color);
}
public void UpdateColorAt(int index, string color)
{
if (index > _colors.Length)
return;
if (ColorData.ValidateColor(color))
{
_colors[index] = color;
}
}
/// <summary>
/// This method registers the color map with the engine. It also marks
/// export to false so it is not serialized with the
/// other chips in the ChipManager.
/// </summary>
public override void Configure()
{
// This is a temporary chip so don't export it
export = false;
engine.colorMapChip = this;
}
public override void Deactivate()
{
base.Deactivate();
engine.colorMapChip = null;
}
}
//
// Copyright (c) Jesse Freeman. All rights reserved.
//
// Licensed under the Microsoft Public License (MS-PL) License.
// See LICENSE file in the project root for full license information.
//
// Contributors
// --------------------------------------------------------
// This is the official list of Pixel Vision 8 contributors:
//
// Jesse Freeman - @JesseFreeman
// Christer Kaitila - @McFunkypants
// Pedro Medeiros - @saint11
// Shawn Rakowski - @shwany
//
using System;
namespace PixelVisionSDK.Chips
{
/// <summary>
/// The color map chip is used to help import sprites and tile maps into the
/// engine if their colors don't match the system colors. When loading
/// artwork, if a color map is present, it will use the order of the colors
/// in the map as the index to remap to the system colors in the ColorChip.
/// </summary>
public class ColorMapChip : AbstractChip, IColorChip
{
protected string[] _colors = new string[256];
protected string transparent = "#ff00ff";
public ColorData[] colors
{
get
{
var t = total;
var colorCache = new ColorData[t];
for (var i = 0; i < t; i++)
{
colorCache[i] = new ColorData(_colors[i]);
}
return colorCache;
}
}
public string[] hexColors {
get
{
var colors = new string[total];
Array.Copy(_colors, colors, total);
return colors;
}
}
public int total
{
get { return _colors.Length; }
set
{
Array.Resize(ref _colors, value);
Clear();
}
}
public void Clear()
{
var t = _colors.Length;
for (var i = 0; i < t; i++)
{
UpdateColorAt(i, transparent);
}
}
public string ReadColorAt(int index)
{
return index < 0 || index > _colors.Length - 1 ? transparent : _colors[index];
}
public int FindColorID(string color)
{
return Array.IndexOf(_colors, color);
}
public void UpdateColorAt(int index, string color)
{
if (index > _colors.Length)
return;
if (ColorData.ValidateColor(color))
{
_colors[index] = color;
}
}
/// <summary>
/// This method registers the color map with the engine. It also marks
/// export to false so it is not serialized with the
/// other chips in the ChipManager.
/// </summary>
public override void Configure()
{
// This is a temporary chip so don't export it
export = false;
engine.colorMapChip = this;
}
public override void Deactivate()
{
base.Deactivate();
engine.colorMapChip = null;
}
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
//
// Copyright (c) Jesse Freeman. All rights reserved.
//
// Licensed under the Microsoft Public License (MS-PL) License.
// See LICENSE file in the project root for full license information.
//
// Contributors
// --------------------------------------------------------
// This is the official list of Pixel Vision 8 contributors:
//
// Jesse Freeman - @JesseFreeman
// Christer Kaitila - @McFunkypants
// Pedro Medeiros - @saint11
// Shawn Rakowski - @shwany
//
namespace PixelVisionSDK.Chips
{
/// <summary>
/// The Interface for the chip class. It handles Activating, configuring and
/// deactivating the chip as part of its life-cycle. This Interface also
/// implements the <see cref="ILoad" /> and <see cref="ISave" /> interfaces
/// for serialization.
/// </summary>
public interface IChip
{
/// <summary>
/// <see cref="Activate" /> is the beginning of the chip's life cycle.
/// This allows the chip to gain a reference to the engine itself. This
/// allows chips to talk back to the engine as well as to each other
/// through the engine's exposed APIs.
/// </summary>
/// <param name="parent">A reference to the engine.</param>
void Activate(PixelVisionEngine parent);
/// <summary>
/// <see cref="Configure" /> is the second part of the chip's life-cycle.
/// It is called after Activate() and is designed to be overridden by
/// children classes so perform specific configuration tasks. This
/// method must be implemented in order for a chip to activate
/// correctly.
/// </summary>
void Deactivate();
/// <summary>
/// When called, this method sets the disabled field to false. It's part
/// of the chip's life-cycle and is called when shutting down the
/// ChipManager.
/// </summary>
void Configure();
}
//
// Copyright (c) Jesse Freeman. All rights reserved.
//
// Licensed under the Microsoft Public License (MS-PL) License.
// See LICENSE file in the project root for full license information.
//
// Contributors
// --------------------------------------------------------
// This is the official list of Pixel Vision 8 contributors:
//
// Jesse Freeman - @JesseFreeman
// Christer Kaitila - @McFunkypants
// Pedro Medeiros - @saint11
// Shawn Rakowski - @shwany
//
namespace PixelVisionSDK.Chips