Beispiel #1
0
        public static void DumpNewTiles()
        {
            Dictionary<int, TileInfo> tiles = Global.Instance.Info.Tiles;
            TileInfo ti;
            Map useMap = new Map();
            useMap.active(true);
            String tileXML;
            FileStream stream = new FileStream("newTileXML.txt", FileMode.Create);
            StreamWriter writer = new StreamWriter(stream);

			string[] tileNames = null;// Enum.GetNames(typeof(MoreTerra.Enums.TileEnum));


			for (int i = 0; i < 420; i++)
			{

				if (!tiles.TryGetValue(i, out ti))
				{
					ti = new TileInfo();
					ti.name = tileNames[i];
					ti.tileImage = i;
					ti.colorName = "Unknown";
				}

				useMap.type = (ushort)i;

                tileXML = "    <tile ";
                if (ti.name != null)
                    tileXML = tileXML + "name=\"" + ti.name + "\" ";

                tileXML = tileXML + "tileImage=\"" + i + "\" ";

                if (ti.important)
                    tileXML = tileXML + "important=\"true\" ";

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

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

                if (!String.IsNullOrEmpty(ti.markerName))
                    tileXML = tileXML + "marker=\"" + ti.markerName + "\" ";

                tileXML = tileXML + "/>";

                writer.WriteLine(tileXML);
            }
            writer.Close();
        }
Beispiel #2
0
		private void LoadTiles(XmlNodeList tileNodes)
		{
			Int32 count = -1;

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

			foreach (XmlNode tileNode in tileNodes)
			{
				String name = String.Empty;
				String color = String.Empty;
                String officialColor = String.Empty;
				String marker = String.Empty;
				Color useColor;
                Color useOfficialColor;
                Boolean important = false;

				Int32 tileImage = -1;

				count++;

				foreach (XmlAttribute att in tileNode.Attributes)
				{

					switch (att.Name)
					{
						case "name":
							name = att.Value;
							break;
						case "tileImage":
							if (Int32.TryParse(att.Value, out tileImage) == false)
							{
								errorLog.AppendLine(String.Format("Tile #{0} has an invalid tileImage attribute. Value = \"{1}\"",
									count, att.Value));
								continue;
							}

							if ((tileImage < 0) || (tileImage >= TileProperties.TYPES))
							{
								errorLog.AppendLine(String.Format("Tile #{0} had a out of range numMade attribute.  Value=\"{1}\"",
									count, tileImage));
								continue;
							}
							break;
						case "important":
							if (!Boolean.TryParse(att.Value, out important))
                            {
                                errorLog.AppendLine(String.Format("Tile #{0} had an invalid important attribute. Value=\"{1}\"",
                                    count, att.Value));
                                continue;
                            }
							break;
						case "color":
							color = att.Value;
							break;
                        case "officialColor":
                            officialColor = att.Value;
                            break;
						case "marker":
							marker = att.Value;
							break;
						default:
							errorLog.AppendLine(String.Format("Tile #{0} has unknown attribute \"{1}\" has value \"{2}\"",
								count, att.Name, att.Value));
							break;
					}
				}

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

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

				if (tiles.ContainsKey(tileImage))
				{
					errorLog.AppendLine(String.Format("Tile #{0} had a duplicate tileImage value to \"{1}\"",
						count, tileImage));
					continue;
				}

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

                if (Global.TryParseColor(color, out useColor) == false)
				{
					if (!colors.ContainsKey(color))
					{
						errorLog.AppendLine(String.Format("Tile #{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("Tile #{0} had no officialColor attribute.", count));
                    officialColor = "#FF00FF";
//                    continue;
                }

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

				TileInfo tile = new TileInfo();
				tile.name = name;
				tile.colorName = color;
				tile.color = useColor;
                tile.important = important;
                tile.officialColor = useOfficialColor;
				tile.markerName = marker;
				tile.tileImage = tileImage;

				tiles.Add(tileImage, tile);
			}

		}