Esempio n. 1
0
      /// <summary>Loads the map data from the given file. Do not specify a base path, but rather change the FilePath property as required.</summary>
      public void Load(string filename) {
         if (filename == "")
            return;
         m_FileName = filename; //set even if it doesnt exist, so that a (potential) future save can use it

         string fullfilepath = m_FilePath + filename;
         Debug.WriteLine("Load Map: " + fullfilepath);

         //Exit if the file does not exist
         if (!File.Exists(fullfilepath)) {
            Debug.WriteLine("FILE NOT FOUND: " + fullfilepath);
            return;
         }

         //LAYOUT
         //M RRGGBB,x,y,z,x,y,z (so on) 3D Map line. must have at least a pair of vectors.
         //P RRGGBB,x,y,z,text          Label for on map display.
         //H pattern                    Regex pattern to match against spawn names. One pattern per line.

         try {
            m_suspendDirty = true;
            FileStream stream = File.OpenRead(fullfilepath);
            StreamReader reader = new StreamReader(stream);
            string line = "";
            string lineData = "";
            string[] parts;
            int linepos = 0; //for error tracking

            while ((line = reader.ReadLine()) != null) {
               lineData = line.Substring(2);
               switch (line[0]) {
                  case 'M': //map line
                     parts = lineData.Split(',');
                     if (parts.Length == 0) //malformed entry if there are no delimiters
                        continue;
                     if (parts[0].Length != 6) //the first item is the line color
                        continue;
                     if ((parts.Length - 1) % 3 != 0) //the line should always have 3 coords per vector
                        continue;

                     try {
                        //covert the RRGGBB line color to a Color object
                        int red = System.Convert.ToByte(parts[0].Substring(0, 2), 16);
                        int green = System.Convert.ToByte(parts[0].Substring(2, 2), 16);
                        int blue = System.Convert.ToByte(parts[0].Substring(4, 2), 16);
                        MapLine mapline = new MapLine(Color.FromArgb(red, green, blue));

                        int i = 1;
                        while (i < parts.Length) {
                           mapline.Add(
                              float.Parse(parts[i], CultureInfo.InvariantCulture),
                              float.Parse(parts[i + 1], CultureInfo.InvariantCulture),
                              float.Parse(parts[i + 2], CultureInfo.InvariantCulture)
                           );
                           i += 3;
                        }
                        mapline.Updated += new MapLineEvent(line_Updated);
                        mapline.Update();
                        m_lines.Add(mapline);
                     } catch (Exception ex) {
                        //swallow any parsing errors here. this will effectivly reject the line in whole
                        Debug.WriteLine("Error occurred parsing M type on line #" + linepos + ": " + ex.Message);
                     }

                     break;
                  case 'P': //point of interest (map label)
                     parts = lineData.Split(',');
                     if (parts.Length != 5) //there are exactly 5 parts to each label. too bad if someone added a comma in the label text!
                        continue;
                     if (parts[0].Length != 6) //the first item is the line color
                        continue;

                     try {
                        //covert the RRGGBB line color to a Color object
                        int red = System.Convert.ToByte(parts[0].Substring(0, 2), 16);
                        int green = System.Convert.ToByte(parts[0].Substring(2, 2), 16);
                        int blue = System.Convert.ToByte(parts[0].Substring(4, 2), 16);

                        //create the label object
                        MapLabel label = new MapLabel(
                           parts[4],
                           new MapPoint(
                              float.Parse(parts[1], CultureInfo.InvariantCulture),
                              float.Parse(parts[2], CultureInfo.InvariantCulture),
                              float.Parse(parts[3], CultureInfo.InvariantCulture)
                           ),
                           Color.FromArgb(red, green, blue)
                        );
                        m_labels.Add(label);
                     } catch (Exception ex) {
                        //swallow any parsing errors here. this will effectivly reject the line in whole
                        Debug.WriteLine("Error occurred parsing P type on line #" + linepos + ": " + ex.Message);
                     }

                     break;
                  case 'H': //auto-hunt
                     m_hunts.Add(lineData, true);
                     break;
                  case 'R': //auto-replacement
                     parts = lineData.Split(',');
                     m_replacements.Add(parts[0], parts[1], true);
                     break;
               }
               linepos++;
            }

            //close the writer
            reader.Close();
            m_Empty = false;

            //automatically snap the range into view (if enabled)
            if (m_engine.AutoRangeSnap)
               m_engine.SnapToRange();
         } catch (Exception ex) {
            Debug.WriteLine("READ ERROR: " + ex.Message);
         } finally {
            m_suspendDirty = false;
         }
      }
Esempio n. 2
0
 private void label_Updated(MapLabel label) {
    m_Empty = false;
    Dirty = true;
    if (DataChanged != null)
       DataChanged();
 }
Esempio n. 3
0
 /// <summary>Adds a label to the current map.</summary>
 public void AddLabel(MapLabel label) {
    m_labels.Add(label);
    label.Updated += new MapLabelEvent(label_Updated);
    if (DataChanged != null)
       DataChanged();
 }