EndProject\r
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CharacterTestBed", "CharacterTestBed\CharacterTestBed.csproj", "{757B5B2E-27C5-43E3-BF29-5025E9DDDBF1}"\r
EndProject\r
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MapProcessorLib", "MapProcessorLib\MapProcessorLib.csproj", "{EA5996C5-17A9-4827-AAB8-884B476B62EE}"\r
+EndProject\r
Global\r
GlobalSection(SubversionScc) = preSolution\r
Svn-Managed = True\r
EndGlobalSection\r
GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
Debug|x86 = Debug|x86\r
+ Debug|Xbox 360 = Debug|Xbox 360\r
+ Debug|Zune = Debug|Zune\r
Release|x86 = Release|x86\r
+ Release|Xbox 360 = Release|Xbox 360\r
+ Release|Zune = Release|Zune\r
EndGlobalSection\r
GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
{FDDA5BCD-3616-400D-A40B-CFD57C54D0F2}.Debug|x86.ActiveCfg = Debug|x86\r
{FDDA5BCD-3616-400D-A40B-CFD57C54D0F2}.Debug|x86.Build.0 = Debug|x86\r
+ {FDDA5BCD-3616-400D-A40B-CFD57C54D0F2}.Debug|Xbox 360.ActiveCfg = Debug|x86\r
+ {FDDA5BCD-3616-400D-A40B-CFD57C54D0F2}.Debug|Zune.ActiveCfg = Debug|x86\r
{FDDA5BCD-3616-400D-A40B-CFD57C54D0F2}.Release|x86.ActiveCfg = Release|x86\r
{FDDA5BCD-3616-400D-A40B-CFD57C54D0F2}.Release|x86.Build.0 = Release|x86\r
- {C115BBCA-D6FD-42AF-B2A1-3E895808BC14}.Debug|x86.ActiveCfg = Debug|x86\r
- {C115BBCA-D6FD-42AF-B2A1-3E895808BC14}.Release|x86.ActiveCfg = Release|x86\r
+ {FDDA5BCD-3616-400D-A40B-CFD57C54D0F2}.Release|Xbox 360.ActiveCfg = Release|x86\r
+ {FDDA5BCD-3616-400D-A40B-CFD57C54D0F2}.Release|Zune.ActiveCfg = Release|x86\r
{757B5B2E-27C5-43E3-BF29-5025E9DDDBF1}.Debug|x86.ActiveCfg = Debug|x86\r
{757B5B2E-27C5-43E3-BF29-5025E9DDDBF1}.Debug|x86.Build.0 = Debug|x86\r
+ {757B5B2E-27C5-43E3-BF29-5025E9DDDBF1}.Debug|Xbox 360.ActiveCfg = Debug|x86\r
+ {757B5B2E-27C5-43E3-BF29-5025E9DDDBF1}.Debug|Zune.ActiveCfg = Debug|x86\r
{757B5B2E-27C5-43E3-BF29-5025E9DDDBF1}.Release|x86.ActiveCfg = Release|x86\r
{757B5B2E-27C5-43E3-BF29-5025E9DDDBF1}.Release|x86.Build.0 = Release|x86\r
+ {757B5B2E-27C5-43E3-BF29-5025E9DDDBF1}.Release|Xbox 360.ActiveCfg = Release|x86\r
+ {757B5B2E-27C5-43E3-BF29-5025E9DDDBF1}.Release|Zune.ActiveCfg = Release|x86\r
+ {C115BBCA-D6FD-42AF-B2A1-3E895808BC14}.Debug|x86.ActiveCfg = Debug|x86\r
+ {C115BBCA-D6FD-42AF-B2A1-3E895808BC14}.Debug|Xbox 360.ActiveCfg = Debug|x86\r
+ {C115BBCA-D6FD-42AF-B2A1-3E895808BC14}.Debug|Zune.ActiveCfg = Debug|x86\r
+ {C115BBCA-D6FD-42AF-B2A1-3E895808BC14}.Release|x86.ActiveCfg = Release|x86\r
+ {C115BBCA-D6FD-42AF-B2A1-3E895808BC14}.Release|Xbox 360.ActiveCfg = Release|x86\r
+ {C115BBCA-D6FD-42AF-B2A1-3E895808BC14}.Release|Zune.ActiveCfg = Release|x86\r
{4F0BE90F-1E46-4959-80A5-E92B578F6A48}.Debug|x86.ActiveCfg = Debug|x86\r
+ {4F0BE90F-1E46-4959-80A5-E92B578F6A48}.Debug|Xbox 360.ActiveCfg = Debug|x86\r
+ {4F0BE90F-1E46-4959-80A5-E92B578F6A48}.Debug|Zune.ActiveCfg = Debug|x86\r
{4F0BE90F-1E46-4959-80A5-E92B578F6A48}.Release|x86.ActiveCfg = Release|x86\r
+ {4F0BE90F-1E46-4959-80A5-E92B578F6A48}.Release|Xbox 360.ActiveCfg = Release|x86\r
+ {4F0BE90F-1E46-4959-80A5-E92B578F6A48}.Release|Zune.ActiveCfg = Release|x86\r
+ {EA5996C5-17A9-4827-AAB8-884B476B62EE}.Debug|x86.ActiveCfg = Debug|x86\r
+ {EA5996C5-17A9-4827-AAB8-884B476B62EE}.Debug|x86.Build.0 = Debug|x86\r
+ {EA5996C5-17A9-4827-AAB8-884B476B62EE}.Debug|Xbox 360.ActiveCfg = Debug|Xbox 360\r
+ {EA5996C5-17A9-4827-AAB8-884B476B62EE}.Debug|Xbox 360.Build.0 = Debug|Xbox 360\r
+ {EA5996C5-17A9-4827-AAB8-884B476B62EE}.Debug|Zune.ActiveCfg = Debug|Zune\r
+ {EA5996C5-17A9-4827-AAB8-884B476B62EE}.Debug|Zune.Build.0 = Debug|Zune\r
+ {EA5996C5-17A9-4827-AAB8-884B476B62EE}.Release|x86.ActiveCfg = Release|x86\r
+ {EA5996C5-17A9-4827-AAB8-884B476B62EE}.Release|x86.Build.0 = Release|x86\r
+ {EA5996C5-17A9-4827-AAB8-884B476B62EE}.Release|Xbox 360.ActiveCfg = Release|Xbox 360\r
+ {EA5996C5-17A9-4827-AAB8-884B476B62EE}.Release|Xbox 360.Build.0 = Release|Xbox 360\r
+ {EA5996C5-17A9-4827-AAB8-884B476B62EE}.Release|Zune.ActiveCfg = Release|Zune\r
+ {EA5996C5-17A9-4827-AAB8-884B476B62EE}.Release|Zune.Build.0 = Release|Zune\r
EndGlobalSection\r
GlobalSection(SolutionProperties) = preSolution\r
HideSolutionNode = FALSE\r
<Compile Include="Game.cs" />\r
<Compile Include="IDeterministicGame.cs" />\r
<Compile Include="IScreenManager.cs" />\r
+ <Compile Include="Map.cs" />\r
+ <Compile Include="MapReader.cs" />\r
<Compile Include="NetworkManager.cs" />\r
+ <Compile Include="Parse.cs" />\r
<Compile Include="Properties\AssemblyInfo.cs" />\r
<Compile Include="Program.cs" />\r
<Compile Include="XnaGame.cs" />\r
<Processor>TextureProcessor</Processor>\r
</Compile>\r
</ItemGroup>\r
+ <ItemGroup>\r
+ <ProjectReference Include="..\..\MapProcessorLib\MapProcessorLib.csproj">\r
+ <Project>{EA5996C5-17A9-4827-AAB8-884B476B62EE}</Project>\r
+ <Name>MapProcessorLib</Name>\r
+ </ProjectReference>\r
+ </ItemGroup>\r
+ <ItemGroup>\r
+ <Compile Include="Maps\sandbox.cfmap">\r
+ <Name>sandbox</Name>\r
+ </Compile>\r
+ </ItemGroup>\r
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\v3.0\Microsoft.Xna.GameStudio.ContentPipeline.targets" />\r
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. \r
Other similar extension points exist, see Microsoft.Common.targets.\r
\r
namespace CarFire\r
{\r
- class Game : IDeterministicGame\r
+ public class Game : IDeterministicGame\r
{\r
#region IDeterministicGame Members\r
\r
--- /dev/null
+using System;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Text;\r
+using Microsoft.Xna.Framework;\r
+using System.IO;\r
+using System.Text.RegularExpressions;\r
+using System.Runtime.Serialization;\r
+using System.Diagnostics;\r
+\r
+namespace CarFire\r
+{\r
+ /// <summary>\r
+ /// A map object represents the map or virtual world where players and other\r
+ /// game entities exist. The map consists of a grid where each grid space can\r
+ /// contain static scenery and/or game entities which can move and interact\r
+ /// with other game entities.\r
+ /// </summary>\r
+ public class Map\r
+ {\r
+ #region Types\r
+\r
+ public class Data\r
+ {\r
+ public string Author;\r
+ public string Name;\r
+ public int MinNumPlayers;\r
+ public int MaxNumPlayers;\r
+ public Point Dimensions;\r
+ public string Tileset; // TODO: this should be a tilemap object\r
+ public Type Type;\r
+ public char[,] Grid;\r
+ }\r
+ \r
+ public enum Type\r
+ {\r
+ None,\r
+ Campaign,\r
+ Battle\r
+ }\r
+\r
+ #endregion\r
+\r
+\r
+ public Map(Data data)\r
+ {\r
+ Console.WriteLine("Read map " + data.Name + " of type " + data.Type + " written by " + data.Author);\r
+ }\r
+ }\r
+}\r
--- /dev/null
+using System;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Runtime.Serialization;\r
+using System.Text.RegularExpressions;\r
+using Microsoft.Xna.Framework;\r
+using Microsoft.Xna.Framework.Content;\r
+using Microsoft.Xna.Framework.Graphics;\r
+\r
+namespace CarFire\r
+{\r
+ /// <summary>\r
+ /// This class will be instantiated by the XNA Framework Content\r
+ /// Pipeline to read cfmap files from binary .xnb format.\r
+ /// </summary>\r
+ public class MapReader : ContentTypeReader<Map>\r
+ {\r
+ public class ParserException : System.ApplicationException\r
+ {\r
+ public ParserException()\r
+ {\r
+ }\r
+\r
+ public ParserException(string message) :\r
+ base(message)\r
+ {\r
+ }\r
+\r
+ public ParserException(string message, System.Exception inner) :\r
+ base(message, inner)\r
+ {\r
+ }\r
+\r
+ protected ParserException(SerializationInfo info, StreamingContext context) :\r
+ base(info, context)\r
+ {\r
+ }\r
+ }\r
+\r
+ ContentReader mInput;\r
+ int mLineNumber = 0;\r
+ int mExpectedNumberOfLines;\r
+\r
+ Map.Data mData;\r
+\r
+\r
+ protected override Map Read(ContentReader input, Map existingInstance)\r
+ {\r
+ mInput = input;\r
+ mExpectedNumberOfLines = mInput.ReadInt32();\r
+\r
+ ReadData();\r
+\r
+ return new Map(mData);\r
+ }\r
+\r
+\r
+ #region Private Reading Methods\r
+ \r
+ string ReadLine()\r
+ {\r
+ return mInput.ReadString();\r
+ }\r
+\r
+ void ReadData()\r
+ {\r
+ mData = new Map.Data();\r
+\r
+ while (mLineNumber < mExpectedNumberOfLines)\r
+ {\r
+ string line = ReadLine();\r
+ mLineNumber++;\r
+\r
+ while (line != null)\r
+ {\r
+ if (!IsLineSignificant(line)) break;\r
+\r
+ string section = Parse.IniSectionHeader(line);\r
+ if (section != null)\r
+ {\r
+ if (section == "metadata")\r
+ {\r
+ line = ReadMetadataSection();\r
+ }\r
+ else if (section == "maptable")\r
+ {\r
+ line = ReadMapTableSection();\r
+ }\r
+ else if (section.Length == 1)\r
+ {\r
+ line = ReadEntitySection(section[0]);\r
+ }\r
+ else\r
+ {\r
+ ThrowException("Unknown section", section);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ ThrowException("Unexpected text", line);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ string ReadMetadataSection()\r
+ {\r
+ while (mLineNumber < mExpectedNumberOfLines)\r
+ {\r
+ string line = ReadLine();\r
+ mLineNumber++;\r
+\r
+ if (!IsLineSignificant(line)) continue;\r
+\r
+ string[] pair = Parse.KeyValuePair(line);\r
+ if (pair != null)\r
+ {\r
+ if (pair[0] == "type")\r
+ {\r
+ object type = Parse.Constant<Map.Type>(pair[1]);\r
+ if (type != null)\r
+ {\r
+ mData.Type = (Map.Type)type;\r
+ }\r
+ else\r
+ {\r
+ ThrowException("Invalid type", pair[1]);\r
+ }\r
+ }\r
+ else if (pair[0] == "dimensions")\r
+ {\r
+ Point? dimensions = Parse.Coordinates(pair[1]);\r
+ if (dimensions != null)\r
+ {\r
+ mData.Dimensions = dimensions.Value;\r
+ if (mData.Dimensions.X <= 0 || mData.Dimensions.Y <= 0)\r
+ {\r
+ ThrowException("Invalid dimensions", pair[1]);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ ThrowException("Invalid value", pair[1]);\r
+ }\r
+ }\r
+ else if (pair[0] == "tileset")\r
+ {\r
+ string tileset = Parse.String(pair[1]);\r
+ if (tileset != null)\r
+ {\r
+ mData.Tileset = tileset;\r
+ }\r
+ else\r
+ {\r
+ ThrowException("Invalid tileset", pair[1]);\r
+ }\r
+ }\r
+ else if (pair[0] == "numplayers")\r
+ {\r
+ int[] numPlayers = Parse.Range(pair[1]);\r
+ if (numPlayers != null)\r
+ {\r
+ mData.MinNumPlayers = numPlayers[0];\r
+ mData.MaxNumPlayers = numPlayers[1];\r
+ if (mData.MinNumPlayers <= 0 || mData.MaxNumPlayers <= 0 ||\r
+ mData.MinNumPlayers > mData.MaxNumPlayers)\r
+ {\r
+ ThrowException("Invalid range", pair[1]);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ ThrowException("Invalid value", pair[1]);\r
+ }\r
+ }\r
+ else if (pair[0] == "author")\r
+ {\r
+ string author = Parse.String(pair[1]);\r
+ if (author != null)\r
+ {\r
+ mData.Author = author;\r
+ }\r
+ else\r
+ {\r
+ ThrowException("Invalid value", pair[1]);\r
+ }\r
+ }\r
+ else if (pair[0] == "levelname")\r
+ {\r
+ string level = Parse.String(pair[1]);\r
+ if (level != null)\r
+ {\r
+ mData.Name = level;\r
+ }\r
+ else\r
+ {\r
+ ThrowException("Invalid value", pair[1]);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ Console.WriteLine("Unimplemented key: " + pair[0]);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ return line;\r
+ }\r
+ }\r
+\r
+ return null;\r
+ }\r
+\r
+ string ReadMapTableSection()\r
+ {\r
+ if (mData.Dimensions.X == 0 || mData.Dimensions.Y == 0)\r
+ {\r
+ ThrowException("Unexpected section", "You must define the map dimensions before this section.");\r
+ }\r
+\r
+ mData.Grid = new char[mData.Dimensions.X, mData.Dimensions.Y];\r
+\r
+ int y;\r
+ for (y = 0; y < mData.Dimensions.Y && mLineNumber < mExpectedNumberOfLines; y++)\r
+ {\r
+ string line = ReadLine();\r
+ mLineNumber++;\r
+\r
+ if (line.Length < mData.Dimensions.X)\r
+ {\r
+ ThrowException("Not enough characters", "Expecting " + mData.Dimensions.X + " characters.");\r
+ }\r
+\r
+ for (int x = 0; x < mData.Dimensions.X; x++)\r
+ {\r
+ mData.Grid[x, y] = line[x];\r
+ }\r
+ }\r
+\r
+ if (y < mData.Dimensions.Y)\r
+ {\r
+ ThrowException("Unexpected ", "");\r
+ }\r
+\r
+ return null;\r
+ }\r
+\r
+ string ReadEntitySection(char entity)\r
+ {\r
+ while (mLineNumber < mExpectedNumberOfLines)\r
+ {\r
+ string line = ReadLine();\r
+ mLineNumber++;\r
+\r
+ string[] pair = Parse.KeyValuePair(line);\r
+ if (pair != null)\r
+ {\r
+ // TODO\r
+ }\r
+ else\r
+ {\r
+ return line;\r
+ }\r
+ }\r
+\r
+ return null;\r
+ }\r
+\r
+ #endregion\r
+\r
+\r
+ #region Private Methods\r
+\r
+ bool IsLineSignificant(string line)\r
+ {\r
+ if (line.Length == 0 || Regex.IsMatch(line, @"^;|^\s*$")) return false;\r
+ return true;\r
+ }\r
+\r
+ void ThrowException(string problem, string text)\r
+ {\r
+ throw new ParserException(problem + " on line " + mLineNumber + ": " + text);\r
+ }\r
+\r
+ #endregion\r
+ }\r
+}\r
--- /dev/null
+using System;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Text;\r
+using System.Text.RegularExpressions;\r
+using Microsoft.Xna.Framework;\r
+\r
+namespace CarFire\r
+{\r
+ /// <summary>\r
+ /// Class with handy static methods taking strings and returning objects\r
+ /// parsed from those strings.\r
+ /// </summary>\r
+ public class Parse\r
+ {\r
+ /// <summary>\r
+ /// Parses a section header of an INI file.\r
+ /// </summary>\r
+ /// <param name="line">Text.</param>\r
+ /// <returns>The section header, or null if parsing failed.</returns>\r
+ public static string IniSectionHeader(string line)\r
+ {\r
+ Match match = Regex.Match(line, @"^\s*\[(\w+)\]\s*$");\r
+ if (match.Success) return match.Groups[1].Value;\r
+ return null;\r
+ }\r
+\r
+ /// <summary>\r
+ /// Parses a key-value pair.\r
+ /// </summary>\r
+ /// <param name="line">Text.</param>\r
+ /// <returns>An array of two strings containg the key and value,\r
+ /// in that order, or null if parsing failed.</returns>\r
+ public static string[] KeyValuePair(string line)\r
+ {\r
+ Match match = Regex.Match(line, @"^\s*(\w+)\s*=\s*(.+)\s*$");\r
+ if (match.Success)\r
+ {\r
+ string[] pair = { match.Groups[1].Value, match.Groups[2].Value };\r
+ return pair;\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /// <summary>\r
+ /// Parses a pair of coordinates.\r
+ /// </summary>\r
+ /// <param name="atom">Text.</param>\r
+ /// <returns>The coordinates, or null if parsing failed.</returns>\r
+ public static Point? Coordinates(string atom)\r
+ {\r
+ Match match = Regex.Match(atom, @"^\s*\[(\S+?)\s*,\s*(\S+?)\]\s*$");\r
+ if (match.Success)\r
+ {\r
+ int? x = Integer(match.Groups[1].Value);\r
+ int? y = Integer(match.Groups[2].Value);\r
+ if (x != null && y != null)\r
+ {\r
+ return new Point(x.Value, y.Value);\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /// <summary>\r
+ /// Parses a range of integers.\r
+ /// </summary>\r
+ /// <param name="atom">Text.</param>\r
+ /// <returns>An array of two integers containing the min and max,\r
+ /// in that order, or null if parsing failed.</returns>\r
+ public static int[] Range(string atom)\r
+ {\r
+ Match match = Regex.Match(atom, @"^\s*<(\S+?)\s*,\s*(\S+?)>\s*$");\r
+ if (match.Success)\r
+ {\r
+ int? min = Integer(match.Groups[1].Value);\r
+ int? max = Integer(match.Groups[2].Value);\r
+ if (min != null && max != null)\r
+ {\r
+ int[] range = { min.Value, max.Value };\r
+ return range;\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /// <summary>\r
+ /// Parses a string.\r
+ /// </summary>\r
+ /// <param name="atom">Text.</param>\r
+ /// <returns>The string, or null if parsing failed.</returns>\r
+ public static string String(string atom)\r
+ {\r
+ Match match = Regex.Match(atom, @"^\s*(""?)(.*)\1\s*$");\r
+ if (match.Success) return match.Groups[2].Value;\r
+ return null;\r
+ }\r
+\r
+ /// <summary>\r
+ /// Parses a constant from an enum.\r
+ /// </summary>\r
+ /// <typeparam name="T">An enumeration.</typeparam>\r
+ /// <param name="atom">Text.</param>\r
+ /// <returns>The constant, or null if parsing failed.</returns>\r
+ public static T Constant<T>(string atom)\r
+ {\r
+ string constant = String(atom);\r
+ if (constant != null)\r
+ {\r
+ foreach (string enumConstant in System.Enum.GetNames(typeof(T)))\r
+ {\r
+ if (constant == enumConstant)\r
+ {\r
+ return (T)System.Enum.Parse(typeof(T), constant);\r
+ }\r
+ }\r
+ }\r
+ return default(T);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Parses an integer.\r
+ /// </summary>\r
+ /// <param name="atom">Text.</param>\r
+ /// <returns>The integer, or null if parsing failed.</returns>\r
+ public static int? Integer(string atom)\r
+ {\r
+ try\r
+ {\r
+ int integer = Convert.ToInt32(atom.Trim());\r
+ return integer;\r
+ }\r
+#pragma warning disable 0168\r
+ catch (System.Exception ex)\r
+#pragma warning restore 0168\r
+ {\r
+ return null;\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Parses a boolean value.\r
+ /// </summary>\r
+ /// <param name="atom">Text.</param>\r
+ /// <returns>True or false, or null if parsing failed.</returns>\r
+ public static bool? Boolean(string atom)\r
+ {\r
+ Match match = Regex.Match(atom, @"^\s*(true|false)\s*$", RegexOptions.IgnoreCase);\r
+ if (match.Success)\r
+ {\r
+ if (match.Groups[1].Value[0] == 't' || match.Groups[1].Value[0] == 'T') return true;\r
+ else return false;\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /// <summary>\r
+ /// Parses a function.\r
+ /// </summary>\r
+ /// <param name="atom">Text.</param>\r
+ /// <returns>An array two strings containing the function name and\r
+ /// parameter-list, in that order, or null if parsing failed.</returns>\r
+ public static string[] Function(string atom)\r
+ {\r
+ Match match = Regex.Match(atom, @"^\s*(\w+)\((.*)\)\s*$");\r
+ if (match.Success)\r
+ {\r
+ string[] pair = { match.Groups[1].Value, match.Groups[2].Value };\r
+ return pair;\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /// <summary>\r
+ /// Parses a comma-separated list of atoms.\r
+ /// </summary>\r
+ /// <param name="text">Text.</param>\r
+ /// <returns>An array of strings containing the atoms, or null\r
+ /// if parsing failed.</returns>\r
+ public static string[] ParameterList(string text)\r
+ {\r
+ return null;\r
+ }\r
+\r
+ /// <summary>\r
+ /// Parses a whitespace-separated list of atoms.\r
+ /// </summary>\r
+ /// <param name="text">Text.</param>\r
+ /// <returns>An array of atoms, or null if parsing failed.</returns>\r
+ public static string[] List(string text)\r
+ {\r
+ List<string> list = new List<string>();\r
+\r
+ MatchCollection matches = Regex.Matches(text, @"\s*("".*?"")|(\w+\(.*?\))|(\[.*?\])|(<.*?>)|(\S+)(?:\s+|$)");\r
+ // FIXME: This may barf all over itself if there are nested parentheses, doublequotes, brackets, etc.\r
+ foreach (Match match in matches)\r
+ {\r
+ Console.WriteLine("matched: " + match.Value);\r
+ list.Add(match.Value);\r
+ }\r
+\r
+ return list.ToArray();\r
+ }\r
+ }\r
+}\r
\r
namespace CarFire\r
{\r
- class ScreenManager : IScreenManager\r
+ public class ScreenManager : IScreenManager\r
{\r
#region local variables\r
float scale;\r
--- /dev/null
+using System;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using Microsoft.Xna.Framework;\r
+using Microsoft.Xna.Framework.Graphics;\r
+using Microsoft.Xna.Framework.Content.Pipeline;\r
+using Microsoft.Xna.Framework.Content.Pipeline.Graphics;\r
+\r
+using TImport = MapProcessorLib.MapSourceCode;\r
+\r
+namespace MapProcessorLib\r
+{\r
+ /// <summary>\r
+ /// This class will be instantiated by the XNA Framework Content Pipeline\r
+ /// to import a file from disk into the specified type, TImport.\r
+ /// \r
+ /// This should be part of a Content Pipeline Extension Library project.\r
+ /// </summary>\r
+ [ContentImporter(".cfmap", DisplayName = "CarFire Map Importer", DefaultProcessor = "PassThroughProcessor")]\r
+ public class MapImporter : ContentImporter<TImport>\r
+ {\r
+ public override TImport Import(string filename, ContentImporterContext context)\r
+ {\r
+ string[] lines = System.IO.File.ReadAllLines(filename);\r
+ return new MapSourceCode(lines);\r
+ }\r
+ }\r
+}\r
--- /dev/null
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">\r
+ <PropertyGroup>\r
+ <ProjectGuid>{EA5996C5-17A9-4827-AAB8-884B476B62EE}</ProjectGuid>\r
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>\r
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>\r
+ <OutputType>Library</OutputType>\r
+ <AppDesignerFolder>Properties</AppDesignerFolder>\r
+ <RootNamespace>MapProcessorLib</RootNamespace>\r
+ <AssemblyName>MapProcessorLib</AssemblyName>\r
+ <XnaFrameworkVersion>v3.0</XnaFrameworkVersion>\r
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>\r
+ </PropertyGroup>\r
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">\r
+ <DebugSymbols>true</DebugSymbols>\r
+ <DebugType>full</DebugType>\r
+ <Optimize>false</Optimize>\r
+ <OutputPath>bin\x86\Debug</OutputPath>\r
+ <DefineConstants>DEBUG;TRACE</DefineConstants>\r
+ <ErrorReport>prompt</ErrorReport>\r
+ <WarningLevel>4</WarningLevel>\r
+ <PlatformTarget>x86</PlatformTarget>\r
+ <XnaPlatform>Windows</XnaPlatform>\r
+ </PropertyGroup>\r
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">\r
+ <DebugType>pdbonly</DebugType>\r
+ <Optimize>true</Optimize>\r
+ <OutputPath>bin\x86\Release</OutputPath>\r
+ <DefineConstants>TRACE</DefineConstants>\r
+ <ErrorReport>prompt</ErrorReport>\r
+ <WarningLevel>4</WarningLevel>\r
+ <PlatformTarget>x86</PlatformTarget>\r
+ <XnaPlatform>Windows</XnaPlatform>\r
+ </PropertyGroup>\r
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|Xbox 360' ">\r
+ <DebugSymbols>true</DebugSymbols>\r
+ <DebugType>full</DebugType>\r
+ <Optimize>false</Optimize>\r
+ <OutputPath>bin\Xbox 360\Debug</OutputPath>\r
+ <DefineConstants>DEBUG;TRACE</DefineConstants>\r
+ <ErrorReport>prompt</ErrorReport>\r
+ <WarningLevel>4</WarningLevel>\r
+ <UseVSHostingProcess>false</UseVSHostingProcess>\r
+ <PlatformTarget>x86</PlatformTarget>\r
+ <XnaPlatform>Xbox 360</XnaPlatform>\r
+ </PropertyGroup>\r
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|Xbox 360' ">\r
+ <DebugType>pdbonly</DebugType>\r
+ <Optimize>true</Optimize>\r
+ <OutputPath>bin\Xbox 360\Release</OutputPath>\r
+ <DefineConstants>TRACE</DefineConstants>\r
+ <ErrorReport>prompt</ErrorReport>\r
+ <WarningLevel>4</WarningLevel>\r
+ <UseVSHostingProcess>false</UseVSHostingProcess>\r
+ <PlatformTarget>x86</PlatformTarget>\r
+ <XnaPlatform>Xbox 360</XnaPlatform>\r
+ </PropertyGroup>\r
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|Zune' ">\r
+ <DebugSymbols>true</DebugSymbols>\r
+ <DebugType>full</DebugType>\r
+ <Optimize>false</Optimize>\r
+ <OutputPath>bin\Zune\Debug</OutputPath>\r
+ <DefineConstants>DEBUG;TRACE</DefineConstants>\r
+ <ErrorReport>prompt</ErrorReport>\r
+ <WarningLevel>4</WarningLevel>\r
+ <UseVSHostingProcess>false</UseVSHostingProcess>\r
+ <PlatformTarget>x86</PlatformTarget>\r
+ <XnaPlatform>Zune</XnaPlatform>\r
+ </PropertyGroup>\r
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|Zune' ">\r
+ <DebugType>pdbonly</DebugType>\r
+ <Optimize>true</Optimize>\r
+ <OutputPath>bin\Zune\Release</OutputPath>\r
+ <DefineConstants>TRACE</DefineConstants>\r
+ <ErrorReport>prompt</ErrorReport>\r
+ <WarningLevel>4</WarningLevel>\r
+ <UseVSHostingProcess>false</UseVSHostingProcess>\r
+ <PlatformTarget>x86</PlatformTarget>\r
+ <XnaPlatform>Zune</XnaPlatform>\r
+ </PropertyGroup>\r
+ <ItemGroup>\r
+ <Reference Include="Microsoft.Xna.Framework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d, processorArchitecture=x86">\r
+ <Private>False</Private>\r
+ <SpecificVersion>True</SpecificVersion>\r
+ </Reference>\r
+ <Reference Include="Microsoft.Xna.Framework.Game, Version=3.0.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d, processorArchitecture=MSIL">\r
+ <Private>False</Private>\r
+ <SpecificVersion>True</SpecificVersion>\r
+ </Reference>\r
+ <Reference Include="Microsoft.Xna.Framework.Content.Pipeline, Version=3.0.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d, processorArchitecture=x86">\r
+ <Private>False</Private>\r
+ <SpecificVersion>true</SpecificVersion>\r
+ </Reference>\r
+ <Reference Include="System">\r
+ <Private>False</Private>\r
+ </Reference>\r
+ <Reference Include="System.Data" />\r
+ <Reference Include="System.Xml">\r
+ <Private>False</Private>\r
+ </Reference>\r
+ <Reference Include="System.Core">\r
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>\r
+ </Reference>\r
+ <Reference Include="System.Xml.Linq">\r
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>\r
+ </Reference>\r
+ </ItemGroup>\r
+ <ItemGroup>\r
+ <Compile Include="MapWriter.cs" />\r
+ <Compile Include="MapImporter.cs" />\r
+ <Compile Include="MapSourceCode.cs" />\r
+ <Compile Include="Properties\AssemblyInfo.cs" />\r
+ </ItemGroup>\r
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />\r
+ <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\Microsoft.Xna.GameStudio.ContentPipelineExtensions.targets" />\r
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it. \r
+ Other similar extension points exist, see Microsoft.Common.targets.\r
+ <Target Name="BeforeBuild">\r
+ </Target>\r
+ <Target Name="AfterBuild">\r
+ </Target>\r
+ -->\r
+</Project>
\ No newline at end of file
--- /dev/null
+using System;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Text;\r
+using Microsoft.Xna.Framework.Content.Pipeline;\r
+\r
+namespace MapProcessorLib\r
+{\r
+ /// <summary>\r
+ /// Container for the map file before it is rewritten as an XNB file.\r
+ /// </summary>\r
+ public class MapSourceCode\r
+ {\r
+ string[] mLines;\r
+ public string[] Lines { get { return mLines; } }\r
+\r
+ public MapSourceCode(string[] lines)\r
+ {\r
+ mLines = lines;\r
+ }\r
+ }\r
+}\r
--- /dev/null
+using System;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using Microsoft.Xna.Framework;\r
+using Microsoft.Xna.Framework.Graphics;\r
+using Microsoft.Xna.Framework.Content.Pipeline;\r
+using Microsoft.Xna.Framework.Content.Pipeline.Graphics;\r
+using Microsoft.Xna.Framework.Content.Pipeline.Processors;\r
+using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;\r
+\r
+using TWrite = MapProcessorLib.MapSourceCode;\r
+\r
+namespace MapProcessorLib\r
+{\r
+ /// <summary>\r
+ /// This class will be instantiated by the XNA Framework Content Pipeline\r
+ /// to write the specified data type into binary .xnb format.\r
+ ///\r
+ /// This should be part of a Content Pipeline Extension Library project.\r
+ /// </summary>\r
+ [ContentTypeWriter]\r
+ public class MapWriter : ContentTypeWriter<TWrite>\r
+ {\r
+ protected override void Write(ContentWriter output, TWrite value)\r
+ {\r
+ output.Write(value.Lines.Length);\r
+ foreach (string line in value.Lines)\r
+ {\r
+ output.Write(line);\r
+ }\r
+ }\r
+\r
+ public override string GetRuntimeReader(TargetPlatform targetPlatform)\r
+ {\r
+ return "CarFire.MapReader, CarFire";\r
+ }\r
+ }\r
+}\r
--- /dev/null
+using System.Reflection;\r
+using System.Runtime.CompilerServices;\r
+using System.Runtime.InteropServices;\r
+\r
+// General Information about an assembly is controlled through the following \r
+// set of attributes. Change these attribute values to modify the information\r
+// associated with an assembly.\r
+[assembly: AssemblyTitle("MapProcessorLib")]\r
+[assembly: AssemblyDescription("")]\r
+[assembly: AssemblyConfiguration("")]\r
+[assembly: AssemblyCompany("Microsoft")]\r
+[assembly: AssemblyProduct("MapProcessorLib")]\r
+[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]\r
+[assembly: AssemblyTrademark("")]\r
+[assembly: AssemblyCulture("")]\r
+\r
+// Setting ComVisible to false makes the types in this assembly not visible \r
+// to COM components. If you need to access a type in this assembly from \r
+// COM, set the ComVisible attribute to true on that type.\r
+[assembly: ComVisible(false)]\r
+\r
+// The following GUID is for the ID of the typelib if this project is exposed to COM\r
+[assembly: Guid("f2f52768-d8d6-47ee-8ee8-ef34e3f2d195")]\r
+\r
+// Version information for an assembly consists of the following four values:\r
+//\r
+// Major Version\r
+// Minor Version \r
+// Build Number\r
+// Revision\r
+//\r
+[assembly: AssemblyVersion("1.0.0.0")]\r
+[assembly: AssemblyFileVersion("1.0.0.0")]\r