private Decoration ParseDecoration(string path, Vector3 loc) { Decoration dec = null; // Instantiate the list Assembly assembly = Assembly.GetExecutingAssembly(); XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreComments = true; string _d_path = "U5Designs.Resources.Data.Decorations." + path; Stream fstream = assembly.GetManifestResourceStream(_d_path); XmlDocument doc = new XmlDocument(); XmlReader reader = XmlReader.Create(fstream, settings); doc.Load(reader); Vector3 scale = LoadLevel.parseVector3(doc.GetElementsByTagName("scale")[0]); bool _draw2 = Convert.ToBoolean(doc.GetElementsByTagName("draw2")[0].InnerText); bool _draw3 = Convert.ToBoolean(doc.GetElementsByTagName("draw3")[0].InnerText); // Check to see if the current Obstacle is 2D or 3D and handle accordingly if (Convert.ToBoolean(doc.GetElementsByTagName("is2d")[0].InnerText)) { // Create the SpriteSheet SpriteSheet ss = LoadLevel.parseSpriteFile(doc.GetElementsByTagName("sprite")[0].InnerText); Billboarding bb = Billboarding.Yes; //Have to put something here for it to compile switch (doc.GetElementsByTagName("billboards")[0].InnerText) { case "yes": case "Yes": bb = Billboarding.Yes; break; case "lock2d": case "Lock2d": bb = Billboarding.Lock2d; break; case "lock3d": case "Lock3d": bb = Billboarding.Lock3d; break; default: Console.WriteLine("Bad obstacle file: " + path); Environment.Exit(1); break; } dec = new Decoration(loc, scale, _draw2, _draw3, bb, ss); } else { XmlNodeList _m = doc.GetElementsByTagName("mesh"); ObjMesh _mesh = new ObjMesh(assembly.GetManifestResourceStream("U5Designs.Resources.Geometry." + _m.Item(0).InnerText)); XmlNodeList _b = doc.GetElementsByTagName("bmp"); List<Bitmap> texFrames = new List<Bitmap>(); foreach (XmlNode n in _b) { texFrames.Add(new Bitmap(assembly.GetManifestResourceStream("U5Designs.Resources.Textures." + n.InnerText))); } MeshTexture _bmp = new MeshTexture(texFrames); _bmp.init(); dec = new Decoration(loc, scale, _draw2, _draw3, _mesh, _bmp); } fstream.Close(); return dec; }
private Obstacle ParseObstacle(string path, Vector3 loc) { Obstacle o = null; Assembly assembly = Assembly.GetExecutingAssembly(); XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreComments = true; XmlDocument doc = new XmlDocument(); string _o_path = "U5Designs.Resources.Data.Obstacles." + path; Stream fstream = assembly.GetManifestResourceStream(_o_path); XmlReader reader = XmlReader.Create(fstream, settings); doc.Load(reader); Vector3 scale = LoadLevel.parseVector3(doc.GetElementsByTagName("scale")[0]); Vector3 pbox = LoadLevel.parseVector3(doc.GetElementsByTagName("pbox")[0]); bool _draw2 = Convert.ToBoolean(doc.GetElementsByTagName("draw2")[0].InnerText); bool _draw3 = Convert.ToBoolean(doc.GetElementsByTagName("draw3")[0].InnerText); bool _collides2d = Convert.ToBoolean(doc.GetElementsByTagName("collidesIn2d")[0].InnerText); bool _collides3d = Convert.ToBoolean(doc.GetElementsByTagName("collidesIn3d")[0].InnerText); // Check to see if the current Obstacle is 2D or 3D and handle accordingly XmlNodeList _type = doc.GetElementsByTagName("is2d"); if (Convert.ToBoolean(_type.Item(0).InnerText)) { String ss_path = doc.GetElementsByTagName("sprite")[0].InnerText; fstream.Close(); SpriteSheet ss = LoadLevel.parseSpriteFile(ss_path); Billboarding bb = Billboarding.Yes; //Have to put something here for it to compile switch (doc.GetElementsByTagName("billboards")[0].InnerText) { case "yes": case "Yes": bb = Billboarding.Yes; break; case "lock2d": case "Lock2d": bb = Billboarding.Lock2d; break; case "lock3d": case "Lock3d": bb = Billboarding.Lock3d; break; default: Console.WriteLine("Bad obstacle file: " + path); Environment.Exit(1); break; } o = new Obstacle(loc, scale, pbox, _draw2, _draw3, _collides2d, _collides3d, bb, ss); } else { fstream.Close(); XmlNodeList _m = doc.GetElementsByTagName("mesh"); ObjMesh _mesh = new ObjMesh(assembly.GetManifestResourceStream("U5Designs.Resources.Geometry." + _m.Item(0).InnerText)); XmlNodeList _b = doc.GetElementsByTagName("bmp"); List<Bitmap> texFrames = new List<Bitmap>(); foreach (XmlNode n in _b) { texFrames.Add(new Bitmap(assembly.GetManifestResourceStream("U5Designs.Resources.Textures." + n.InnerText))); } MeshTexture _tex = new MeshTexture(texFrames); _tex.init(); o = new Obstacle(loc, scale, pbox, _draw2, _draw3, _collides2d, _collides3d, _mesh, _tex); fstream.Close(); } return o; }