Esempio n. 1
0
        /// <summary>
        /// Gibt die spawnenden Monster für eine Map zurück
        /// </summary>
        /// <param name="map"></param>
        /// <returns></returns>
        public static List<MonsterSpawn> GetMonsterSpawnFromMap(TMX map)
        {
            List<MonsterSpawn> ret=new List<MonsterSpawn>();

            foreach(Objectgroup objgroup in map.ObjectLayers)
            {
                if(objgroup.Name.ToLower()=="object")
                {
                    foreach(CSCL.FileFormats.TMX.Object obj in objgroup.Objects)
                    {
                        if(obj.Type!=null)
                        {
                            if(obj.Type.ToLower()=="spawn")
                            {
                                int MAX_BEINGS=-1;
                                int MONSTER_ID=-1;
                                double SPAWN_RATE=-1;

                                foreach(Property prop in obj.Properties)
                                {
                                    switch(prop.Name.ToLower())
                                    {
                                        case "monster_id":
                                            {
                                                MONSTER_ID=Convert.ToInt32(prop.Value);
                                                break;
                                            }
                                        case "max_beings":
                                            {
                                                MAX_BEINGS=Convert.ToInt32(prop.Value);
                                                break;
                                            }
                                        case "spawn_rate":
                                            {
                                                SPAWN_RATE=Convert.ToDouble(prop.Value);
                                                break;
                                            }
                                    }
                                }

                                ret.Add(new MonsterSpawn(MAX_BEINGS, MONSTER_ID, SPAWN_RATE));
                            }
                        }
                    }
                }
            }

            return ret;
        }
Esempio n. 2
0
        static void UpdateMinimaps(bool all, bool clearCache)
        {
            List<string> files=FileSystem.GetFiles(Globals.folder_data_maps, true, "*.tmx");

            if(files==null)
            {
                Console.WriteLine("Es wurden keine Maps gefunden.");
                Console.WriteLine("Eventuell ist der Pfad des Repositories in der Konfigurationdatei falsch.");
                return;
            }

            #region Bilder berechnen
            foreach(string i in files)
            {
                //Nur sichtbare Weltkarte rendern.
                if(!all)
                {
                    Map map=new Map(0, FileSystem.GetFilenameWithoutExt(i));

                    //if(map.MapType=="iw") continue;
                    //if(map.MapType=="uw") continue;

                    if(map.MapType=="ow")
                    {
                        if(map.X>=-7&&map.X<=7&&map.Y>=-7&&map.Y<=7)
                        {
                            //nichts tun (sprich rendern)
                        }
                        else
                        {
                            continue;
                        }
                    }
                }

                Console.WriteLine("Überprüfe für Map {0} auf Aktualisierung...", FileSystem.GetFilename(i));

                GC.Collect(2);

                //Hashvergleich
                string text=File.ReadAllText(i);
                string textHash=Hash.SHA1.HashString(text);
                string xmlPath="xml.CalcMinimaps."+FileSystem.GetFilenameWithoutExt(i);

                string xmlHash;
                try
                {
                    xmlHash=Globals.Options.GetElementAsString(xmlPath);
                }
                catch
                {
                    xmlHash="";
                }

                //xmlHash=""; //DEBUG

                if(xmlHash=="")
                {
                    Globals.Options.WriteElement("xml.CalcMinimaps."+FileSystem.GetFilenameWithoutExt(i), textHash);
                }
                else
                {
                    Globals.Options.WriteElement(xmlPath, textHash);
                }

                //Hashvergleich
                if(clearCache==false)
                {
                    if(textHash==xmlHash)
                        continue;
                }

                //Karte berechnen
                Console.WriteLine("Berechne Minimap für Map {0}", FileSystem.GetFilename(i));

                TMX file=new TMX(i);

                Graphic pic=file.Render();

                int imageSizeOriginalWidth=(int)pic.Width;
                int imageSizeOriginalHeight=(int)pic.Height;
                double imageVerhaeltnis=imageSizeOriginalWidth/(double)imageSizeOriginalHeight;

                int imageSize=100;
                pic=pic.Resize(imageSize, (int)(imageSize/imageVerhaeltnis));

                string fn=FileSystem.GetFilenameWithoutExt(i);
                string fnMinimap=Globals.folder_data_graphics_minimaps+fn+".png";
                pic.SaveToFile(fnMinimap);
            }
            #endregion

            Globals.Options.Save();
        }
Esempio n. 3
0
        //public partial class FormTileReplacer : Form
        //{
        //    public string Filename { get; set; }
        //    public int TileID { get; private set; }
        //    private void pbImage_MouseDoubleClick(object sender, MouseEventArgs e)
        //    {
        //        int xInTiles=e.X/32;
        //        int yInTiles=e.Y/32;
        //        int tileID=yInTiles*32+xInTiles;
        //        TileID=tileID;
        //        DialogResult=DialogResult.OK;
        //    }
        //}
        static void TransformTileInMaps(string srcTileset, string dstTileset, int src, int dst)
        {
            //Maps laden
            List<string> mapfiles=FileSystem.GetFiles(Globals.folder_data, true, "*.tmx");

            foreach(string i in mapfiles)
            {
                bool changed=false;

                TMX maptmx=new TMX(i);

                //schauen ob zieltileset vorhanden
                bool TargetTilesetExists=false;

                TMX.TilesetData destTileset=null;

                foreach(TMX.TilesetData td in maptmx.Tilesets)
                {
                    if(td.imgsource.IndexOf(FileSystem.GetFilename(dstTileset))!=-1)
                    {
                        TargetTilesetExists=true;
                        destTileset=td;
                        break;
                    }
                }

                //Tiles transformieren
                maptmx.RemoveGidsFromLayerData(); //RemoveGidFrom Tiles

                if(TargetTilesetExists==false)
                {
                    //Tileset eintragen
                    TMX.TilesetData tsData=new TMX.TilesetData();
                    tsData.name=FileSystem.GetFilenameWithoutExt(dstTileset);
                    tsData.imgsource="../graphics/tiles/"+FileSystem.GetFilename(dstTileset);
                    tsData.tileheight=32;
                    tsData.tilewidth=32;
                    maptmx.Tilesets.Add(tsData);

                    destTileset=tsData;
                }

                foreach(TMX.LayerData ld in maptmx.Layers)
                {
                    for(int y=0;y<ld.height;y++)
                    {
                        for(int x=0;x<ld.width;x++)
                        {
                            TMX.TilesetData ts=ld.tilesetmap[x, y];
                            int TileNumber=ld.data[x, y];

                            if(ts.imgsource!=null)
                            {
                                if(ts.imgsource.IndexOf(FileSystem.GetFilename(srcTileset))!=-1)
                                {
                                    if(TileNumber==src)
                                    {
                                        changed=true;
                                        ld.data[x, y]=dst;
                                        ld.tilesetmap[x, y]=destTileset;
                                    }
                                }
                            }
                        }
                    }
                }

                if(changed)
                {
                    //FirstGids neu vergeben
                    maptmx.Tilesets.Sort();

                    int firstgit=1;

                    foreach(TMX.TilesetData gidChange in maptmx.Tilesets)
                    {
                        gidChange.firstgid=firstgit;
                        firstgit+=2000; //Sicherheitsabstand
                    }

                    //AddGidToTiles
                    maptmx.AddsGidsToLayerData();

                    //Map speichern
                    maptmx.Save(i);
                }
            }

            Console.WriteLine("Tile wurde transformiert.");
        }
Esempio n. 4
0
        static void SaveFeatureMapMusic(string filename, Graphic img, TMX map)
        {
            //Farben
            Color green=Color.FromArgb(128, 0, 255, 0);
            //Color yellow=Color.FromArgb(128, 255, 255, 0);
            Color red=Color.FromArgb(128, 255, 0, 0);
            //Color blue=Color.FromArgb(128, 0, 0, 255);

            //Images
            Graphic tmpImage=img.GetImage();
            Graphic tmpDraw=new Graphic(tmpImage.Width, tmpImage.Height, tmpImage.ChannelFormat);

            //Properties durchsuchen
            bool found=false;

            foreach(Property prop in map.Properties)
            {
                if(prop.Name=="music")
                {
                    found=true;
                    break;
                }
            }

            if(found)
                tmpDraw.Fill(green);
            else
                tmpDraw.Fill(red);

            //Drawen
            tmpImage.Draw(0, 0, tmpDraw, true);
            tmpImage.SaveToFile(filename);
        }
Esempio n. 5
0
        static void RenderTMX(string tmx, string output, double zoom)
        {
            #if! DEBUG
            try
            {
            #endif
            if(!FileSystem.ExistsFile(tmx))
            {
                Console.WriteLine("Die Datei {0} existiert nicht!.", tmx);
                return;
            }

            TMX map=new TMX(tmx);
            Graphic img=map.Render();

            if(zoom!=100)
            {
                int newWidth=(int)(img.Width/100.0*zoom+0.5);
                int newHeight=(int)(img.Height/100.0*zoom+0.5);
                img=img.Resize(newWidth, newHeight);
            }

            string fn=output+FileSystem.GetFilenameWithoutExt(tmx)+".png";
            img.SaveToPNG(fn);

            Console.WriteLine("Datei {0} wurde nach {1} gerendert", tmx, fn);
            #if! DEBUG
            }
            catch(Exception exception)
            {
                Console.WriteLine("Es gab Probleme beim Parsen der Datei {0}.\n{1}", FileSystem.GetFilename(tmx), exception.ToString());
            }
            #endif
        }
Esempio n. 6
0
        static void RenameTilesetNameInMapsToTilesetFilename()
        {
            //Maps laden
            List<string> mapfiles=FileSystem.GetFiles(Globals.folder_data, true, "*.tmx");

            foreach(string i in mapfiles)
            {
                bool changed=false;

                TMX maptmx=new TMX(i);

                //Tiles transformieren
                foreach(TMX.TilesetData ld in maptmx.Tilesets)
                {
                    string fnForTilesetName=FileSystem.GetFilenameWithoutExt(ld.imgsource);

                    if(ld.name!=fnForTilesetName)
                    {
                        changed=true;
                        ld.name=fnForTilesetName;
                    }
                }

                if(changed)
                {
                    //Map speichern
                    maptmx.Save(i);
                }
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Gibt die spawnenden Monster für eine Map zurück
 /// </summary>
 /// <param name="filename"></param>
 /// <returns></returns>
 public static List<MonsterSpawn> GetMonsterSpawnFromMap(string filename)
 {
     TMX map=new TMX(filename, false);
     return GetMonsterSpawnFromMap(map);
 }
Esempio n. 8
0
        static void WriteExternalMapEvents(string fnMap)
        {
            TMX tmx=new TMX(fnMap, false);

            bool ExistDef=false;

            string fnLuaScript=String.Format("scripts/maps/{0}.lua", FileSystem.GetFilenameWithoutExt(fnMap));

            foreach(Objectgroup og in tmx.ObjectLayers)
            {
                foreach(CSCL.FileFormats.TMX.Object objk in og.Objects)
                {
                    if(objk.Name.ToLower()=="external map events")
                    {
                        //name der Skriptdatei korrekt setzen
                        foreach(Property prop in objk.Properties)
                        {
                            if(prop.Name.ToLower()=="filename")
                            {
                                prop.Value=fnLuaScript;
                            }
                        }

                        ExistDef=true;
                        break;
                    }
                }
            }

            if(ExistDef==false)
            {
                Objectgroup objectGroup=null;

                if(tmx.ObjectLayers.Count==0)
                {
                    tmx.ObjectLayers.Add(new Objectgroup("Object", 0, 0, 0, 0));
                }

                objectGroup=tmx.ObjectLayers[0];
                CSCL.FileFormats.TMX.Object mapObject=new CSCL.FileFormats.TMX.Object("External Map Events", "SCRIPT", 0, 0, 0, 0);
                mapObject.Properties.Add(new Property("FILENAME", fnLuaScript));
                objectGroup.Objects.Add(mapObject);
            }

            tmx.Save(fnMap);
        }
Esempio n. 9
0
        static void RemoveBlankTilesFromMaps()
        {
            //Maps laden
            List<string> mapfiles=FileSystem.GetFiles(Globals.folder_data, true, "*.tmx");

            foreach(string i in mapfiles)
            {
                bool changed=false;

                TMX maptmx=new TMX(i);

                //für jeden Layer
                foreach(TMX.LayerData ld in maptmx.Layers)
                {
                    for(int y=0;y<ld.height;y++)
                    {
                        for(int x=0;x<ld.width;x++)
                        {
                            int TileNumber=ld.data[x, y];

                            if(TileNumber==0)
                                continue; //leeres Tile

                            Graphic tile=maptmx.GetTile(TileNumber);
                            Color median=tile.GetMedianColor();

                            int summe=median.A+median.R+median.G+median.R;

                            if(summe==0)
                            {
                                ld.data[x, y]=0;
                                changed=true;
                            }
                        }
                    }
                }

                if(changed)
                {
                    //Map speichern
                    maptmx.Save(i);
                }
            }

            Console.WriteLine("Leere Tiles wurden entfernt.");
        }
Esempio n. 10
0
        static void GetTilesetsFromMapsUsed()
        {
            if(Globals.folder_root=="")
            {
                Console.WriteLine("Bitte geben sie in den Optionen den Pfad zum Invertika Repository an.");
                return;
            }

            List<string> maps=FileSystem.GetFiles(Globals.folder_data, true, "*.tmx");
            Dictionary<string, int> usedTilesets=new Dictionary<string, int>();

            foreach(string fn in maps)
            {
                Console.WriteLine("Überprüfe Map {0} auf Tilesets...", FileSystem.GetFilename(fn));

                TMX map=new TMX(fn, false);

                foreach(CSCL.FileFormats.TMX.TMX.TilesetData fnTileset in map.Tilesets)
                {
                    string cleanTileset=FileSystem.GetFilename(fnTileset.imgsource);

                    if(usedTilesets.ContainsKey(cleanTileset)==false)
                    {
                        usedTilesets.Add(cleanTileset, 1);
                    }
                    else
                    {
                        int val=usedTilesets[cleanTileset];
                        val++;
                        usedTilesets[cleanTileset]=val;
                    }
                }
            }

            List<string> tilesets=new List<string>();

            foreach(string i in usedTilesets.Keys)
            {
                tilesets.Add(String.Format("{0} ({1} mal)", i, usedTilesets[i]));
            }

            tilesets.Sort();

            foreach(string i in tilesets)
            {
                Console.WriteLine(i);
            }
        }
Esempio n. 11
0
        static string CheckMaps()
        {
            Console.WriteLine("Überprüfe Maps...");

            string msg="";
            bool found=false;

            List<string> maps=FileSystem.GetFiles(Globals.folder_data_maps, true, "*.tmx");
            List<string> usedTilesets=new List<string>();

            if(maps==null)
            {
                Console.WriteLine("Es wurden keine Maps gefunden.");
                Console.WriteLine("Eventuell ist der Pfad des Repositories in der Konfigurationdatei falsch.");
                return "";
            }

            foreach(string fnCurrent in maps)
            {
                Console.WriteLine("Map {0} wird überprüft...", FileSystem.GetFilename(fnCurrent));

                bool ground=false, fringe=false, over=false, collision=false, @object=false;
                int countGround=0, countFringe=0, countOver=0, countCollision=0;

                TMX map=null;

                try
                {
                    map=new TMX(fnCurrent, false);
                }
                catch(NotSupportedCompressionException)
                {
                    msg+=String.Format("Unbekannte Kompressionsart (warscheinlich zlib) in Map {0} vorhanden.\n", fnCurrent);
                    continue;
                }
                catch
                {
                    msg+=String.Format("Map {0} konnte nicht geöffnet werden.\n", fnCurrent);
                    continue;
                }

                string fn=FileSystem.GetRelativePath(fnCurrent, Globals.folder_data);

                foreach(CSCL.FileFormats.TMX.TMX.TilesetData fnTileset in map.Tilesets)
                {
                    string cleanTileset=Globals.folder_data+fnTileset.imgsource.Replace("../graphics", "graphics");
                    if(usedTilesets.IndexOf(cleanTileset)==-1)
                        usedTilesets.Add(cleanTileset);
                }

                if(!CheckName(FileSystem.GetFilenameWithoutExt(fn)))
                {
                    found=true;
                    msg+=String.Format("Mapname {0} enthält kein iw, uw oder ow.\n", fn);
                }

                //Checkt ob die Layer die selbe Größe wie die Map haben
                foreach(TMX.LayerData ld in map.Layers)
                {
                    if(ld.width!=map.Width)
                        msg+=String.Format("Layerbreite des Layers {0} ungleich Mapbreite in Map {1}.\n", ld.name, fn);
                    if(ld.height!=map.Height)
                        msg+=String.Format("Layerhöhe des Layers {0} ungleich Maphöhe in Map {1}.\n", ld.name, fn);
                }

                foreach(TMX.LayerData ld in map.Layers)
                {
                    switch(ld.name)
                    {
                        case "Ground":
                            {
                                countGround++;
                                ground=true;
                                break;
                            }
                        case "Fringe":
                            {
                                countFringe++;
                                fringe=true;
                                break;
                            }
                        case "Over":
                            {
                                countOver++;
                                over=true;
                                break;
                            }
                        case "Collision":
                            {
                                countCollision++;
                                collision=true;
                                break;
                            }
                        default:
                            {
                                found=true;
                                msg+=String.Format("Unbekannter Layer ({0}) in Map {1} vorhanden.\n", ld.name, fn);
                                break;
                            }
                    }
                }

                bool newEntry=false;

                if(!ground)
                {
                    found=true;
                    newEntry=true;
                    msg+=String.Format("Ground Layer in Map {0} nicht vorhanden.\n", fn);
                }
                if(!fringe)
                {
                    found=true;
                    newEntry=true;
                    msg+=String.Format("Fringe Layer in Map {0} nicht vorhanden.\n", fn);
                }
                if(!over)
                {
                    found=true;
                    newEntry=true;
                    msg+=String.Format("Over Layer in Map {0} nicht vorhanden.\n", fn);
                }
                if(!collision)
                {
                    found=true;
                    newEntry=true;
                    msg+=String.Format("Collision Layer in Map {0} nicht vorhanden.\n", fn);
                }

                if(countFringe>1)
                {
                    found=true;
                    newEntry=true;
                    msg+=String.Format("Fringe Layer in Map {0} öfter als ein Mal vorhanden.\n", fn);
                }
                if(countCollision>1)
                {
                    found=true;
                    newEntry=true;
                    msg+=String.Format("Collision Layer in Map {0} öfter als ein Mal vorhanden.\n", fn);
                }

                int externalMapEventsCount=0;

                if(map.ObjectLayers.Count==0)
                {
                    msg+=String.Format("Kein Objektlayer in der Map {0} vorhanden.\n", fn);
                }

                if(map.ObjectLayers.Count>1)
                {
                    msg+=String.Format("Mehr als ein Objektlayer in der Map {0} vorhanden.\n", fn);
                }

                foreach(Objectgroup og in map.ObjectLayers)
                {
                    if(og.Name=="Object")
                    {
                            @object=true;

                        foreach(CSCL.FileFormats.TMX.Object obj in og.Objects)
                        {
                            //Namen überprüfen
                            if(obj.Name==null||obj.Name=="")
                            {
                                found=true;
                                newEntry=true;
                                msg+=String.Format("Objektname für ein Objekt in der Map {0} nicht gesetzt.\n", fn);
                            }

                            //Warp Überprüfung
                            if(obj.Type=="WARP")
                            {
                                //Prüfen ob Warp auf der Karte liegt
                                if(!(obj.X/32>=0&&obj.X/32<=map.Width&&obj.Y/32>=0&&obj.Y/32<=map.Height))
                                {
                                    found=true;
                                    newEntry=true;
                                    msg+=String.Format("WARP ({0}) in Map {1} liegt nicht in der Karte.\n", obj.Name, fn);
                                }

                                string dest_map="";
                                int dest_x=0;
                                int dest_y=0;

                                foreach(Property prop in obj.Properties)
                                {
                                    try
                                    {
                                        switch(prop.Name)
                                        {
                                            case "DEST_MAP":
                                                {
                                                    dest_map=prop.Value;
                                                    break;
                                                }
                                            case "DEST_X":
                                                {
                                                    dest_x=Convert.ToInt32(prop.Value);
                                                    break;
                                                }
                                            case "DEST_Y":
                                                {
                                                    dest_y=Convert.ToInt32(prop.Value);
                                                    break;
                                                }
                                        }
                                    }
                                    catch
                                    {
                                        found=true;
                                        newEntry=true;
                                        msg+=String.Format("Eigenschaft ({0}) in Objekt {1} auf der Map {2} ist nicht gesetzt.\n", prop.Name, obj.Name, fn);
                                    }
                                }

                                int dest_x_pixel=dest_x;
                                int dest_y_pixel=dest_y;

                                dest_x=dest_x/32;
                                dest_y=dest_y/32;

                                string warpmapname=Globals.folder_data_maps+dest_map+".tmx";
                                if(FileSystem.ExistsFile(warpmapname))
                                {
                                    TMX warpMap=null;

                                    try
                                    {
                                        warpMap=new TMX(warpmapname);
                                    }
                                    catch(TilesetNotExistsException ex)
                                    {
                                        Console.WriteLine("Tileset {0} existiert nicht (in Map {1})", FileSystem.GetFilename(ex.Filename), fn);
                                        continue;
                                    }

                                    if(!(dest_x>=0&&dest_x<=warpMap.Width&&dest_y>=0&&dest_y<=warpMap.Height)) //Warp in der Map enthalten
                                    {
                                        found=true;
                                        newEntry=true;
                                        msg+=String.Format("WARP ({0}) auf Map ({1}) in Map {2} zeigt auf nicht vorhandenen Bereich.\n", obj.Name, dest_map+".tmx", fn);
                                    }
                                    else
                                    {
                                        //Plausbilitätsprüfung
                                        foreach(Objectgroup ogWarp in warpMap.ObjectLayers)
                                        {
                                            foreach(CSCL.FileFormats.TMX.Object objWarp in ogWarp.Objects)
                                            {
                                                if(ogWarp.Name=="Object")
                                                {
                                                    //Warp Überprüfung
                                                    if(objWarp.Type=="WARP")
                                                    {
                                                        bool DestIsInWarp=false;

                                                        if((dest_x_pixel>=objWarp.X)&&(dest_x_pixel<=objWarp.X+objWarp.Width))
                                                        {
                                                            //X liegt drin
                                                            if((dest_y_pixel>=objWarp.Y)&&(dest_y_pixel<=objWarp.Y+objWarp.Height))
                                                            {
                                                                //Y liegt drin
                                                                DestIsInWarp=true;
                                                            }
                                                        }

                                                        if(DestIsInWarp)
                                                        {
                                                            found=true;
                                                            newEntry=true;
                                                            msg+=String.Format("WARP ({0}) auf Map ({1}) in Map {2} zeigt auf weiteren Warp.\n", obj.Name, dest_map+".tmx", fn);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    found=true;
                                    newEntry=true;
                                    msg+=String.Format("Per WARP ({0}) Referenzierte Map ({1}) in Map {2} existiert nicht.\n", obj.Name, dest_map+".tmx", fn);
                                }
                            }
                            else if(obj.Type=="SCRIPT") //Skripte überprüfen
                            {
                                if(obj.Name=="External Map Events")
                                {
                                    externalMapEventsCount++;

                                    if(externalMapEventsCount>1)
                                    {
                                        found=true;
                                        newEntry=true;
                                        msg+=String.Format("Mehrere External Map Events Objekte in der Map ({0}) gefunden.\n", fn);
                                    }

                                    string scriptfilename="";

                                    foreach(Property prop in obj.Properties)
                                    {
                                        switch(prop.Name)
                                        {
                                            case "FILENAME":
                                                {
                                                    scriptfilename=prop.Value;
                                                    break;
                                                }
                                        }
                                    }

                                    if(!CheckName(FileSystem.GetFilenameWithoutExt(fn)))
                                    {
                                        found=true;
                                        newEntry=true;
                                        msg+=String.Format("Dateiname der Skriptdatei {0} enthält kein uw, iw oder ow.", scriptfilename);
                                    }

                                    if(scriptfilename==""||FileSystem.GetFilenameWithoutExt(fn)!=FileSystem.GetFilenameWithoutExt(scriptfilename))
                                    {
                                        found=true;
                                        newEntry=true;
                                        msg+=String.Format("Dateiname der Skriptdatei in der Map ({0}) entspricht nicht dem Mapnamen.\n", fn);
                                    }
                                }
                                else
                                {
                                    found=true;
                                    newEntry=true;
                                    msg+=String.Format("Unbekanntes SCRIPT Objekt in der Map ({0}) gefunden.\n", fn);
                                }
                            }
                        }
                    }
                    else
                    {
                        found=true;
                        newEntry=true;
                        msg+=String.Format("Unbekannter Objektlayer ({0}) in Map {1} vorhanden.\n", og.Name, fn);
                    }
                }

                if(externalMapEventsCount==0)
                {
                    found=true;
                    newEntry=true;
                    msg+=String.Format("Es wurde kein \"External Map Events\" in der Map ({0}) gefunden.\n", fn);
                }

                if(!@object)
                {
                    found=true;
                    msg+=String.Format("Object Layer in Map {0} nicht vorhanden.\n", fn);
                }

                if(newEntry)
                    msg+="\n";
            }

            usedTilesets.Sort();

            foreach(string i in usedTilesets)
            {
                if(!FileSystem.ExistsFile(i))
                {
                    found=true;
                    msg+="Tileset existiert nicht: "+i+"\n";
                }
            }

            //Maps XML checken
            string fnMapsXml=Globals.folder_data+"maps.xml";
            List<Map> mapsXml=Map.GetMapsFromMapsXml(fnMapsXml);

            foreach(Map i in mapsXml)
            {
                string fnMap=Globals.folder_data_maps+i.Name+".tmx";

                if(!FileSystem.Exists(fnMap))
                {
                    found=true;

                    msg+="Map (in maps.xml) existiert nicht: "+i.Name+"\n";
                }
            }

            msg=msg.TrimEnd('\n');

            //nichts gefunden
            if(found==false)
            {
                msg="Keine Fehler gefunden.\n";
            }

            return msg;
        }
Esempio n. 12
0
        static void DecompressMaps()
        {
            List<string> files=FileSystem.GetFiles(Globals.folder_data_maps, true, "*.tmx");

            if(files==null)
            {
                Console.WriteLine("Es wurden keine Maps gefunden.");
                Console.WriteLine("Eventuell ist der Pfad des Repositories in der Konfigurationdatei falsch.");
                return;
            }

            #region Bilder berechnen
            foreach(string i in files)
            {
                //Karte berechnen
                Console.WriteLine("Dekpmprimiere Map {0}", FileSystem.GetFilename(i));

                TMX file=new TMX(i);
                file.Save(i, false);
            }
            #endregion

            Globals.Options.Save();
        }
Esempio n. 13
0
        static void CreateCollisionsOnMaps()
        {
            //Maps laden
            List<string> mapfiles=FileSystem.GetFiles(Globals.folder_data, true, "*.tmx");

            foreach(string filename in mapfiles)
            {
                TMX TestTMX=new TMX(filename);

                TMX.LayerData fringe=null;
                TMX.LayerData coll=null;

                foreach(TMX.LayerData layer in TestTMX.Layers)
                {
                    switch(layer.name)
                    {
                        case "Fringe":
                            {
                                fringe=layer;
                                break;
                            }
                        case "Collision":
                            {
                                coll=layer;
                                break;
                            }
                    }
                }

                if(fringe==null||coll==null)
                {
                    Console.WriteLine("Überspringe Map {0}", FileSystem.GetFilename(filename));
                    continue;
                }

                //CollID =
                int CollID=coll.data[0, 0];
                bool FileChanged=false;

                for(int y=0;y<fringe.height;y++)
                {
                    for(int x=0;x<fringe.width;x++)
                    {
                        int fieldData=fringe.data[x, y];
                        if(fieldData==0)
                            continue;

                        TMX.TilesetData tInfo=TestTMX.GetTileset(fieldData);

                        if(CollID==coll.data[x, y])
                            continue;

                        switch(FileSystem.GetFilename(tInfo.imgsource))
                        {
                            case "wood1_32_64.png":
                                {
                                    int realID=fieldData-tInfo.firstgid;

                                    switch(realID)
                                    {
                                        case 0: //Stein
                                        case 1: //Stein
                                        case 2: //Pfeil Links
                                        case 3: //Pfeil Rechts
                                        case 4: //Baum
                                        case 5: //Holzteil
                                        case 6: //Pflanze
                                        case 7: //Pflanze
                                        case 10: //Pflanze
                                        case 11: //Pflanze
                                        case 14: //Pflanze
                                        case 15: //Pflanze
                                        case 22: //Heu
                                        case 23: //Heu
                                        case 25: //Schild
                                        case 26: //Schild
                                        case 27: //Schild
                                        case 28: //Schild
                                        case 29: //Schild
                                        case 30: //Schild
                                        case 31: //Schild
                                        case 32: //Pflanze
                                        case 33: //Pflanze
                                        case 34: //Pflanze
                                        case 35: //Pflanze
                                        case 36: //Pflanze
                                        case 37: //Pflanze
                                        case 38: //Pflanze
                                            {
                                                FileChanged=true;
                                                coll.data[x, y]=CollID;
                                                break;
                                            }
                                    }

                                    break;
                                }
                            case "wood1_32_96.png":
                                {
                                    int realID=fieldData-tInfo.firstgid;

                                    switch(realID)
                                    {
                                        case 0: //Baum
                                        case 1: //Baum
                                        case 2: //Baum
                                        case 3: //Baum
                                        case 4: //Baum
                                        case 5: //Baum
                                        case 14: //Baum
                                        case 15: //Baum
                                        case 32: //Pflanze
                                        case 33: //Pflanze
                                        case 34: //Pflanze
                                        case 35: //Pflanze
                                        case 36: //Pflanze
                                        case 37: //Pflanze
                                        case 46: //Baum
                                        case 47: //Baum
                                            {
                                                FileChanged=true;
                                                coll.data[x, y]=CollID;
                                                break;
                                            }
                                    }

                                    break;
                                }
                            case "wood1_32_128.png":
                                {
                                    int realID=fieldData-tInfo.firstgid;

                                    switch(realID)
                                    {
                                        case 0: //Baum
                                        case 1: //Baum
                                        case 2: //Baum
                                        case 3: //Baum
                                            {
                                                FileChanged=true;
                                                coll.data[x, y]=CollID;
                                                break;
                                            }
                                        case 4:
                                        case 7:
                                            {
                                                FileChanged=true;
                                                coll.data[x, y--]=CollID;
                                                break;
                                            }
                                        case 5:
                                        case 6:
                                            {
                                                FileChanged=true;
                                                coll.data[x, y]=CollID;
                                                coll.data[x, y--]=CollID;
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case "wood1_32_160.png":
                                {
                                    int realID=fieldData-tInfo.firstgid;

                                    switch(realID)
                                    {
                                        case 1: //Baum
                                        case 4: //Baum
                                        case 7: //Baum
                                            {
                                                FileChanged=true;
                                                coll.data[x, y]=CollID;
                                                break;
                                            }
                                    }

                                    break;
                                }
                        }
                    }
                }

                if(FileChanged)
                    TestTMX.Save(filename);
            }

            Console.WriteLine("Vorgang beendet.");
        }
Esempio n. 14
0
        /// <summary>
        /// Speichert eine Karte welche je nach Monsterstärke eingefärbt wird
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="img"></param>
        /// <param name="map"></param>
        public static void SaveFeatureMapMonsterSpreading(string clientdata, string filename, Graphic img, TMX map)
        {
            //Farben
            Color green=Color.FromArgb(128, 0, 255, 0);
            Color yellow=Color.FromArgb(128, 255, 255, 0);
            Color red=Color.FromArgb(128, 255, 0, 0);
            Color blue=Color.FromArgb(128, 0, 0, 255);

            //Images
            Graphic tmpImage=img.GetImage();
            Graphic tmpDraw=new Graphic(tmpImage.Width, tmpImage.Height, tmpImage.ChannelFormat);

            //Ermittlung der Durchschnittswerte
            string fnMonsterXml=clientdata+"monsters.xml";
            List<Monster> monsters=Monster.GetMonstersFromMonsterXml(fnMonsterXml);
            monsters.Sort();

            Int64 minFightingStrength=999999999999;
            Int64 maxFightingStrength=-999999999999;

            Int64 medianFightingStrength=0;

            Dictionary<int, Int64> MonsterIDsAndFightingStrength=new Dictionary<int, Int64>();

            foreach(Monster monster in monsters)
            {
                if(monster.ID==1) continue; //Killermade ignorieren
                if(monster.ID==31) continue; //Seraphim Nex ignorieren
                if(monster.ID>9999) continue; //Experimentelle Monster ignorieren
                Int64 fightingStrength=monster.FightingStrength;

                if(fightingStrength<minFightingStrength) minFightingStrength=fightingStrength;
                if(fightingStrength>maxFightingStrength) maxFightingStrength=fightingStrength;

                MonsterIDsAndFightingStrength.Add(monster.ID, fightingStrength);
            }

            medianFightingStrength=(maxFightingStrength+minFightingStrength)/2;

            //Monster der Karte ermitteln
            List<MonsterSpawn> mSpawns=Monsters.GetMonsterSpawnFromMap(map);

            if(mSpawns.Count>0)
            {
                Int64 fss=0;

                foreach(MonsterSpawn spawn in mSpawns)
                {
                    if(spawn.MonsterID==1) continue; //Killermade ignorieren
                    if(spawn.MonsterID==31) continue; //Seraphim Nex ignorieren
                    if(spawn.MonsterID>=10000) continue; //Pflanzen etc ignorieren
                    fss+=MonsterIDsAndFightingStrength[spawn.MonsterID];
                }

                fss=fss/mSpawns.Count;

                //Einfärben je nach Stärke
                Int64 vSmarterGreen=(medianFightingStrength+minFightingStrength)/2;
                Int64 vSmarterYellow=(maxFightingStrength+medianFightingStrength)/2;

                if(fss<vSmarterGreen)
                {
                    tmpDraw.Fill(green);
                }
                else if(fss<vSmarterYellow)
                {
                    tmpDraw.Fill(yellow);
                }
                else
                {
                    tmpDraw.Fill(red);
                }
            }
            else //Keine Monster auf der Karte vorhanden
            {
                tmpDraw.Fill(blue);
            }

            //Drawen
            tmpImage.Draw(0, 0, tmpDraw, true);
            tmpImage.SaveToFile(filename);
        }
Esempio n. 15
0
        static void UpdateWorldmap(bool all, bool clearCache)
        {
            List<string> files=FileSystem.GetFiles(Globals.folder_data_maps, true, "*.tmx");

            if(files==null)
            {
                Console.WriteLine("Es wurden keine Maps gefunden.");
                Console.WriteLine("Eventuell ist der Pfad des Repositories in der Konfigurationdatei falsch.");
                return;
            }

            string temp=FileSystem.TempPath+"Invertika Editor"+FileSystem.PathDelimiter;
            string tempFmMonsterSpreading=FileSystem.TempPath+"Invertika Editor"+FileSystem.PathDelimiter+"fm-monster-spreading"+FileSystem.PathDelimiter;
            string tempFmMusic=FileSystem.TempPath+"Invertika Editor"+FileSystem.PathDelimiter+"fm-music"+FileSystem.PathDelimiter;

            #region Bilderordner löschen und neu anlegen
            Console.WriteLine("Bereinige Bilderordner...");

            FileSystem.RemoveDirectory(temp, true);
            FileSystem.CreateDirectory(temp, true);
            FileSystem.CreateDirectory(tempFmMonsterSpreading, true);
            FileSystem.CreateDirectory(tempFmMusic, true);
            #endregion

            #region Bilder berechnen
            //int debug=0;

            foreach(string i in files)
            {
                Console.WriteLine("Überprüfe für Map {0} auf Aktualisierung...", FileSystem.GetFilename(i));

                GC.Collect(2);

                //Nur sichtbare Weltkarte rendern.
                if(!all)
                {
                    Map map=new Map(0, FileSystem.GetFilenameWithoutExt(i));

                    //if(map.MapType=="iw") continue;
                    //if(map.MapType=="uw") continue;

                    if(map.MapType=="ow")
                    {
                        if(map.X>=-7&&map.X<=7&&map.Y>=-7&&map.Y<=7)
                        {
                            //nichts tun (sprich rendern)
                        }
                        else
                        {
                            continue;
                        }
                    }
                }

                //Hashvergleich
                string text=File.ReadAllText(i);
                string textHash=Hash.SHA1.HashString(text);
                string xmlPath="xml.CalcMapImages."+FileSystem.GetFilenameWithoutExt(i);

                string xmlHash;
                try
                {
                    xmlHash=Globals.Options.GetElementAsString(xmlPath);
                }
                catch
                {
                    xmlHash="";
                }

                //xmlHash=""; //DEBUG

                if(xmlHash=="")
                {
                    Globals.Options.WriteElement("xml.CalcMapImages."+FileSystem.GetFilenameWithoutExt(i), textHash);
                }
                else
                {
                    Globals.Options.WriteElement(xmlPath, textHash);
                }

                if(clearCache==false)
                {
                    if(textHash==xmlHash)
                        continue;
                }

                //Karte berechnen
                Console.WriteLine("Berechne Bilder für Map {0}", FileSystem.GetFilename(i));

                TMX file=new TMX(i);

                Graphic pic=file.Render();

                int imageSizeOriginalWidth=(int)pic.Width;
                int imageSizeOriginalHeight=(int)pic.Height;
                double imageVerhaeltnis=imageSizeOriginalWidth/(double)imageSizeOriginalHeight;

                //int imageSize=6400;
                int imageSize=800;
                pic=pic.Resize(imageSize, (int)(imageSize/imageVerhaeltnis));

                bool next=true;

                while(next)
                {
                    string fn=FileSystem.GetFilenameWithoutExt(i);
                    string fnNumeric=temp+fn+"-"+imageSize+".png";
                    pic.SaveToFile(fnNumeric);

                    //Featuremap Monster Spreading
                    string fnMonsterSpreading=tempFmMonsterSpreading+fn+"-"+imageSize+".png";
                    Imaging.SaveFeatureMapMonsterSpreading(Globals.folder_data, fnMonsterSpreading, pic, file);

                    //Featuremap Music
                    string fnMusic=tempFmMusic+fn+"-"+imageSize+".png";
                    SaveFeatureMapMusic(fnMusic, pic, file);

                    switch(imageSize)
                    {
                    //case 6400:
                    //    {
                    //        imageSize=1600;
                    //        break;
                    //    }
                    //case 100:
                    //    {
                    //        //Minimap zusätzlich speichern
                    //        string fnMinimap=Globals.folder_clientdata_graphics_minimaps+fn+".png";
                    //        pic.SaveToFile(fnMinimap);
                    //        break;
                    //    }
                        case 10:
                            {
                                next=false;
                                break;
                            }
                    }

                    imageSize=GetNextImageSize(imageSize);

                    pic=pic.Resize(imageSize, (int)(imageSize/imageVerhaeltnis));
                    GC.Collect(3);
                }

                //Debug
                //debug++;
                //if(debug>5) break;
            }
            #endregion

            #region Bilder per FTP hochladen
            List<string> filesToUpload=new List<string>();
            filesToUpload.AddRange(FileSystem.GetFiles(temp, true, "*.png"));

            Console.WriteLine("Lade {0} Dateien hoch...", filesToUpload.Count);

            FTPSClient Client=new FTPSClient();

            NetworkCredential networkCredential=new NetworkCredential();
            networkCredential.Domain=Globals.Options.GetElementAsString("xml.Options.FTP.Worldmap.Server");
            networkCredential.UserName=Globals.Options.GetElementAsString("xml.Options.FTP.Worldmap.User");
            networkCredential.Password=Globals.Options.GetElementAsString("xml.Options.FTP.Worldmap.Password");

            try
            {
                Client.Connect(networkCredential.Domain, networkCredential, ESSLSupportMode.ClearText);
            }
            catch(Exception exception)
            {
                Console.WriteLine("Fehler: {0}", exception.Message);
                return;
            }

            //Ordner für die Feature Maps
            if(!Client.Exists("fm-monster-spreading/ow-o0000-o0000-o0000-800.png")) //Monster Spreading
            {
                Client.CreateDirectory("fm-monster-spreading");
            }

            if(!Client.Exists("fm-music/ow-o0000-o0000-o0000-800.png")) //Music
            {
                Client.CreateDirectory("fm-music");
            }

            for(int i=0;i<filesToUpload.Count;i++)
            {
                string filename=filesToUpload[i];

                try
                {
                    Console.WriteLine("Lade Bild {0} hoch...", FileSystem.GetFilename(filename));
                    string uploadf=FileSystem.GetRelativePath(filename, temp);
                    uploadf=uploadf.Replace('\\', '/');
                    //Client.UploadFile(i, uploadf);
                    Client.PutFile(filename, uploadf);
                }
                catch
                {
                    Console.WriteLine("Fehler beim Upload von Bild {0}.", FileSystem.GetFilename(filename));
                    Thread.Sleep(2000);
                    Console.WriteLine("Stelle Verbindung wieder her...", FileSystem.GetFilename(filename));
                    Client.Connect(networkCredential.Domain, networkCredential, ESSLSupportMode.ClearText);

                    i--;
                }
            }

            Client.Close();
            #endregion

            Globals.Options.Save();
            Console.WriteLine("Weltkarte geupdatet");
        }
Esempio n. 16
0
        static void RemoveNonExistingTilesetsFromMaps()
        {
            if(Globals.folder_root=="")
            {
                Console.WriteLine("Bitte geben sie in den Optionen den Pfad zum Invertika Repository an.");
                return;
            }

            List<string> maps=FileSystem.GetFiles(Globals.folder_data, true, "*.tmx");
            int removedTilesets=0;

            foreach(string fnCurrent in maps)
            {
                TMX map=new TMX(fnCurrent, false);

                for(int i=0;i<map.Tilesets.Count;i++)
                {
                    CSCL.FileFormats.TMX.TMX.TilesetData fnTileset=map.Tilesets[i];

                    string cleanTileset=Globals.folder_data+fnTileset.imgsource.Replace("../graphics", "graphics");

                    if(!FileSystem.ExistsFile(cleanTileset))
                    {
                        map.Tilesets.Remove(fnTileset);
                        removedTilesets++;
                    }
                }

                map.Save(fnCurrent);
            }

            Console.WriteLine("Es wurden "+removedTilesets+" fehlerhafte Tilesets korrigiert.");
        }
Esempio n. 17
0
        static void UpdateWorldmapDatabaseSQLFile(string target)
        {
            if(Globals.folder_root=="")
            {
                Console.WriteLine("Bitte geben sie in den Optionen den Pfad zum Invertika Repository an.");
                return;
            }

            //Maps laden
            string fnMapsXml=Globals.folder_data+"maps.xml";
            List<Map> maps=Map.GetMapsFromMapsXml(fnMapsXml);

            //Ini
            List<string> sqlFile=new List<string>();

            //maps
            foreach(Map i in maps)
            {
                string fnMap=Globals.folder_data_maps+i.Name+".tmx";
                TMX tmx=new TMX(fnMap, false);

                Property p=tmx.GetProperty("music");
                if(p==null)
                {
                    sqlFile.Add(String.Format("UPDATE wmInformation SET Music = '{0}' WHERE FileName LIKE \"%{1}%\";", "keine Musikdatei angegeben", i.Name));
                }
                else
                {
                    sqlFile.Add(String.Format("UPDATE wmInformation SET Music = '{0}' WHERE FileName LIKE \"%{1}%\";", p.Value, i.Name));
                }
            }

            File.WriteAllLines(target, sqlFile.ToArray());

            Console.WriteLine("Weltkarten DB SQL Datei geschrieben.");
        }
Esempio n. 18
0
        static void RenameTileset(string oldName, string newName)
        {
            //Maps laden
            List<string> mapfiles=FileSystem.GetFiles(Globals.folder_data, true, "*.tmx");

            foreach(string i in mapfiles)
            {
                bool changed=false;

                TMX maptmx=new TMX(i);

                //Tiles transformieren
                foreach(TMX.TilesetData ld in maptmx.Tilesets)
                {
                    string newSource=ld.imgsource.Replace(oldName, newName);

                    if(ld.imgsource!=newSource)
                    {
                        ld.imgsource=newSource;
                        changed=true;
                    }
                }

                if(changed)
                {
                    Console.WriteLine("Bennene Tileset in Map {0} um.", FileSystem.GetFilename(i));
                    //Map speichern
                    maptmx.Save(i);
                }
            }

            //Tileset umbennen
            string oldFn=Globals.folder_data_graphics_tiles+oldName;
            string newFn=Globals.folder_data_graphics_tiles+newName;

            FileSystem.RenameFile(oldFn, newFn);
        }
Esempio n. 19
0
        //        static std::vector< int > tilesetFirstGids;
        //        
        public static Map readMap(string filename)
        {
            TMX tmx=null;

            try
            {
                tmx=new TMX(filename);
            }
            catch
            {
                Logger.Write(LogLevel.Error, "Not a map file ({0}), filename)");
                return null;
            }

            int w=tmx.Width;
            int h=tmx.Height;
            int tileW=tmx.TileWidth;
            int tileH=tmx.TileHeight;

            Map map=new Map(w, h, tileW, tileH);

            foreach(Property prop in  tmx.Properties)
            {
                Logger.Write(LogLevel.Debug, " {0}: {1}", prop.Name, prop.Value);
                map.setProperty(prop.Name, prop.Value);
            }

            foreach(TMX.LayerData layer in tmx.Layers)
            {
                if(layer.name.ToLower() == "collision")
                {
                    for(int y=0; y<layer.height; y++)
                    {
                        for(int x=0; x<layer.width; x++)
                        {
                            if(layer.data[x, y] != 0)
                            {
                                map.blockTile(x, y, invertika_game.Enums.BlockType.BLOCKTYPE_WALL);
                            }
                        }
                    }
                }

                //TODO Layer lesen implementieren
                //            node = node->xmlChildrenNode;
                //            int h = map->getHeight();
                //            int w = map->getWidth();
                //            int x = 0;
                //            int y = 0;
                //
                //            // Layers are assumed to be map size, with (0,0) as origin.
                //            // Find its single "data" element.
                //            while (node)
                //            {
                //                if (xmlStrEqual(node->name, BAD_CAST "data")) break;
                //                node = node->next;
                //            }
                //
                //            if (!node)
                //            {
                //                LOG_WARN("Layer without any 'data' element.");
                //                return;
                //            }
                //
                //            std::string encoding = XML::getProperty(node, "encoding", std::string());
                //            if (encoding == "base64")
                //            {
                //                // Read base64 encoded map file
                //                xmlNodePtr dataChild = node->xmlChildrenNode;
                //                if (!dataChild)
                //                {
                //                    LOG_WARN("Corrupted layer.");
                //                    return;
                //                }
                //
                //                int len = strlen((const char *) dataChild->content) + 1;
                //                char *charData = new char[len + 1];
                //                const char *charStart = (const char *) dataChild->content;
                //                char *charIndex = charData;
                //
                //                while (*charStart)
                //                {
                //                    if (*charStart != ' ' && *charStart != '\t' && *charStart != '\n')
                //                    {
                //                        *charIndex = *charStart;
                //                        ++charIndex;
                //                    }
                //                    ++charStart;
                //                }
                //                *charIndex = '\0';
                //
                //                int binLen;
                //                unsigned char *binData =
                //                    php_base64_decode((unsigned char *)charData, strlen(charData), &binLen);
                //
                //                delete[] charData;
                //
                //                if (!binData)
                //                {
                //                    LOG_WARN("Failed to decode base64-encoded layer.");
                //                    return;
                //                }
                //
                //                std::string compression =
                //                    XML::getProperty(node, "compression", std::string());
                //                if (compression == "gzip" || compression == "zlib")
                //                {
                //                    // Inflate the gzipped layer data
                //                    char *inflated;
                //                    unsigned inflatedSize;
                //                    bool res = inflateMemory((char *)binData, binLen, inflated, inflatedSize);
                //                    free(binData);
                //
                //                    if (!res)
                //                    {
                //                        LOG_WARN("Failed to decompress compressed layer");
                //                        return;
                //                    }
                //
                //                    binData = (unsigned char *)inflated;
                //                    binLen = inflatedSize;
                //                }
                //
                //                for (int i = 0; i < binLen - 3; i += 4)
                //                {
                //                    int gid = binData[i] |
                //                        (binData[i + 1] << 8)  |
                //                            (binData[i + 2] << 16) |
                //                            (binData[i + 3] << 24);
                //
                //                    setTileWithGid(map, x, y, gid);
                //
                //                    if (++x == w)
                //                    {
                //                        x = 0;
                //                        ++y;
                //                    }
                //                }
                //                free(binData);
                //                return;
                //            }
                //            else if (encoding == "csv")
                //            {
                //                xmlNodePtr dataChild = node->xmlChildrenNode;
                //                if (!dataChild)
                //                    return;
                //
                //                const char *data = (const char*) xmlNodeGetContent(dataChild);
                //                std::string csv(data);
                //
                //                size_t pos = 0;
                //                size_t oldPos = 0;
                //
                //                while (oldPos != csv.npos)
                //                {
                //                    pos = csv.find_first_of(",", oldPos);
                //
                //                    const int gid = atoi(csv.substr(oldPos, pos - oldPos).c_str());
                //
                //                    setTileWithGid(map, x, y, gid);
                //
                //                    x++;
                //                    if (x == w)
                //                    {
                //                        x = 0;
                //                        ++y;
                //
                //                        // When we're done, don't crash on too much data
                //                        if (y == h)
                //                            break;
                //                    }
                //
                //                    oldPos = pos + 1;
                //                }
                //            }
                //            else
                //            {
                //
                //                // Read plain XML map file
                //                node = node->xmlChildrenNode;
                //
                //                while (node)
                //                {
                //                    if (xmlStrEqual(node->name, BAD_CAST "tile") && y < h)
                //                    {
                //                        int gid = XML::getProperty(node, "gid", -1);
                //                        setTileWithGid(map, x, y, gid);
                //
                //                        if (++x == w)
                //                        {
                //                            x = 0;
                //                            ++y;
                //                        }
                //                    }
                //
                //                    node = node->next;
                //                }
                //            }
            }

            foreach(Objectgroup oGroup in tmx.ObjectLayers)
            {
                if(oGroup.Name.ToLower() != "object")
                    continue;

                foreach(CSCL.FileFormats.TMX.Object obj in oGroup.Objects)
                {
                    string objName = obj.Name;
                    string objType = obj.Type.ToUpper();

                    Rectangle rect = new Rectangle(obj.X, obj.Y, obj.Width, obj.Height);
                    MapObject newObject = new MapObject(rect, objName, objType);

                    foreach(Property prop in obj.Properties)
                    {
                        newObject.addProperty(prop.Name, prop.Value);
                    }

                    map.addObject(newObject);
                }
            }

            return map;
        }
Esempio n. 20
0
        public void ReplaceTilesetInTilesetMap(TMX.TilesetData oldTileset, TMX.TilesetData newTileset)
        {
            foreach(TMX.LayerData ld in Layers)
            {
                for(int y=0;y<ld.height;y++)
                {
                    for(int x=0;x<ld.width;x++)
                    {
                        TMX.TilesetData ts=ld.tilesetmap[x, y];

                        if(ts==oldTileset)
                        {
                            ld.tilesetmap[x, y]=newTileset;
                        }
                    }
                }
            }
        }