Guest User

SalemMapper

a guest
Apr 28th, 2012
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Drawing;
  7.  
  8. namespace SalemMapper
  9. {
  10.     class MainClass
  11.     {
  12.         static void Main(String[] args)
  13.         {        
  14.             // Create a reference to the current directory.
  15.             DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory);
  16.             // Create an array representing the files in the current directory.
  17.             FileInfo[] fi = di.GetFiles();
  18.             // Print out the names of the files in the current directory.
  19.             int minx = 100, maxx = -100, miny = 100, maxy = -100;
  20.             foreach (FileInfo fiTemp in fi)
  21.             {
  22.                 if(fiTemp.Name.StartsWith("tile")){
  23.                     String s1 = fiTemp.Name.Substring(fiTemp.Name.IndexOf('_') + 1, fiTemp.Name.LastIndexOf('_') - fiTemp.Name.IndexOf('_') - 1);
  24.                     int x = Convert.ToInt32(s1);
  25.                     int i1 = fiTemp.Name.LastIndexOf('_') + 1;
  26.                     int i2 = fiTemp.Name.IndexOf('.') - fiTemp.Name.LastIndexOf('_') - 1;
  27.                     String s2 = fiTemp.Name.Substring(i1, i2);
  28.                     int y = Convert.ToInt32(s2);
  29.                     if (minx > x) minx = x;
  30.                     if (maxx < x) maxx = x;
  31.                     if (miny > y) miny = y;
  32.                     if (maxy < y) maxy = y;
  33.                 }
  34.             }
  35.  
  36.             FileInfo[,] fis = new FileInfo[maxx - minx + 1, maxy - miny + 1];
  37.             foreach (FileInfo fiTemp in fi)
  38.             {
  39.                 if(fiTemp.Name.StartsWith("tile")){
  40.                     String s1 = fiTemp.Name.Substring(fiTemp.Name.IndexOf('_') + 1, fiTemp.Name.LastIndexOf('_') - fiTemp.Name.IndexOf('_') - 1);
  41.                     int x = Convert.ToInt32(s1);
  42.                     int i1 = fiTemp.Name.LastIndexOf('_') + 1;
  43.                     int i2 = fiTemp.Name.IndexOf('.') - fiTemp.Name.LastIndexOf('_') - 1;
  44.                     String s2 = fiTemp.Name.Substring(i1, i2);
  45.                     int y = Convert.ToInt32(s2);
  46.  
  47.                     fis[x - minx, y - miny] = fiTemp;
  48.                 }
  49.             }
  50.            
  51.             Bitmap b = new Bitmap((maxx - minx + 1)*100, (maxy - miny +1)*100);
  52.             for (int i = 0; i < fis.GetLength(0); i++)
  53.             {
  54.                 for (int j = 0; j < fis.GetLength(1); j++)
  55.                 {
  56.                     try
  57.                     {
  58.                         Bitmap bt = new Bitmap(fis[i, j].Name);
  59.                         Graphics g = Graphics.FromImage(b);
  60.                         g.DrawImage(bt, new Point(i * 100, j * 100));
  61.                     }catch(Exception){
  62.  
  63.                     }
  64.                 }
  65.             }
  66.  
  67.             b.Save("mapped.png");
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment