Ejemplo n.º 1
0
        public static void DumpNewWalls()
        {
            Dictionary<int, WallInfo> walls = Global.Instance.Info.Walls;
            WallInfo wi;
            Map useMap = new Map();
            useMap.wall(true);
            String tileXML;
            FileStream stream = new FileStream("newWallXML.txt", FileMode.Create);
            StreamWriter writer = new StreamWriter(stream);

			string[] wallNames = null;// Enum.GetNames(typeof(MoreTerra.Enums.WallEnum));

			for (int i = 1; i <= 224; i++)
            {
                useMap.type = (byte)i;

				if (!walls.TryGetValue(i, out wi))
				{
					wi = new WallInfo();
					wi.name = wallNames[i];
					wi.wallImage = i;
					wi.colorName = "Unknown";
				}

                tileXML = "    <wall ";
                if (wi.name != null)
                    tileXML = tileXML + "name=\"" + wi.name + "\" ";

                tileXML = tileXML + "wallImage=\"" + i + "\" ";

                if (!String.IsNullOrEmpty(wi.colorName))
                    tileXML = tileXML + "color=\"" + wi.colorName + "\" ";
                else
                    tileXML = tileXML + String.Format("color=\"#{0:X2}{1:X2}{2:X2}\" ", wi.color.R, wi.color.G, wi.color.B);

                OfficialColor c = useMap.tileColor(0);
                tileXML = tileXML + String.Format("officialColor=\"#{0:X2}{1:X2}{2:X2}\" ", c.R, c.G, c.B);

                tileXML = tileXML + "/>";
                //            <wall name="Blue Dungeon Brick" wallImage="7" unsafe="true" color="Wall Dungeon Blue" />

                writer.WriteLine(tileXML);
            }
            writer.Close();
        }
Ejemplo n.º 2
0
		private void LoadWalls(XmlNodeList wallNodes)
		{
			Int32 count = -1;

			if ((wallNodes == null) || (wallNodes.Count == 0))
			{
				errorLog.AppendLine("There are no Wall items to load.");
				return;
			}

			foreach (XmlNode wallNode in wallNodes)
			{
				String name = String.Empty;
				String color = String.Empty;
                String officialColor = String.Empty;
				Color useColor;
                Color useOfficialColor;
				Boolean safe = false;
                Boolean transparent = false;

				Int32 wallImage = -1;
				count++;

				foreach (XmlAttribute att in wallNode.Attributes)
				{
					switch (att.Name)
					{
						case "name":
							name = att.Value;
							break;
						case "color":
							color = att.Value;
							break;
                        case "officialColor":
                            officialColor = att.Value;
                            break;
						case "wallImage":
							if (Int32.TryParse(att.Value, out wallImage) == false)
							{
								errorLog.AppendLine(String.Format("Wall #{0} has an invalid wallImage attribute. Value = \"{1}\"",
									count, att.Value));
								continue;
							}

							if (wallImage < 0)
							{
								errorLog.AppendLine(String.Format("Wall #{0} had an out of range wallImage attribute.  Value=\"{1}\"",
									count, wallImage));
								continue;
							}
							break;
						case "unsafe":
							if (Boolean.TryParse(att.Value, out safe) == false)
							{
								errorLog.AppendLine(String.Format("Wall #{0} had an invalid unsafe attribute.  Value=\"{1}\"",
									count, att.Value));
								continue;
							}
							safe = !safe;
							break;
                        case "transparent":
							if (Boolean.TryParse(att.Value, out transparent) == false)
							{
								errorLog.AppendLine(String.Format("Wall #{0} had an invalid transparent attribute.  Value=\"{1}\"",
									count, att.Value));
								continue;
							}
							break;
						default:
								errorLog.AppendLine(String.Format("Wall #{0} has unknown attribute \"{1}\" has value \"{2}\"",
								count, att.Name, att.Value));
							break;
					}
				}

				if (name == String.Empty)
				{
					errorLog.AppendLine(String.Format("Wall #{0} had no name attribute.", count));
					continue;
				}

                if (color == String.Empty)
                {
                    errorLog.AppendLine(String.Format("Wall #{0} had no color attribute.", count));
                    continue;
                }

                if (Global.TryParseColor(color, out useColor) == false)
                {
                    if (!colors.ContainsKey(color))
                    {
                        errorLog.AppendLine(String.Format("Wall #{0} had a color attribute that was not a color or a color lookup name. Value=\"{1}\"",
                            count, color));
                        continue;
                    }
                    else
                    {
                        useColor = colors[color].color;
                    }
                }
                else
                {
                    color = String.Empty;
                }

                if (officialColor == String.Empty)
                {
                    errorLog.AppendLine(String.Format("Wall #{0} had no officialColor attribute.", count));
                    continue;
                }

                if (Global.TryParseColor(officialColor, out useOfficialColor) == false)
                {
                    errorLog.AppendLine(String.Format("Wall #{0} had a officialColor attribute that was not a color. Value=\"{1}\"",
                            count, officialColor));
                    continue;
                }
                else
                {
                    officialColor = String.Empty;
                }

                if (wallImage == -1)
				{
					errorLog.AppendLine(String.Format("Wall #{0} had no wallImage attribute.", count));
					continue;
				}

				if (walls.ContainsKey(wallImage))
				{
					errorLog.AppendLine(String.Format("Wall #{0} had a duplicate wallImage to {1}.", count, wallImage));
					continue;
				}

				WallInfo wall = new WallInfo();
				wall.name = name;
				wall.wallImage = wallImage;
				wall.colorName = color;
				wall.color = useColor;
                wall.officialColor = useOfficialColor;
                wall.transparent = transparent;
                wall.color = wall.transparent ? Color.FromArgb(0,useColor) : useColor;
                
				walls.Add(wallImage, wall);
			}
		}