protected override void ExportCore(GisEditorWpfMap map)
        {
            Bitmap bitmap = map.GetBitmap((int)map.ActualWidth, (int)map.ActualHeight, MapResizeMode.PreserveScaleAndCenter);

            SaveFileDialog saveFileDialog = new SaveFileDialog {
                Filter = "PNG files|*.png|PNG with PGW files|*.png"
            };

            if (saveFileDialog.ShowDialog(Application.Current.MainWindow).GetValueOrDefault())
            {
                bitmap.Save(saveFileDialog.FileName, System.Drawing.Imaging.ImageFormat.Png);
                if (saveFileDialog.FilterIndex == 2)
                {
                    string fileName = Path.ChangeExtension(saveFileDialog.FileName, ".pgw");
                    Collection <string> contents  = new Collection <string>();
                    WorldFile           worldFile = new WorldFile(map.CurrentExtent, (float)map.ActualWidth, (float)map.ActualHeight);
                    contents.Add(worldFile.HorizontalResolution.ToString(CultureInfo.InvariantCulture));
                    contents.Add(worldFile.RotationRow.ToString(CultureInfo.InvariantCulture));
                    contents.Add(worldFile.RotationColumn.ToString(CultureInfo.InvariantCulture));
                    contents.Add(worldFile.VerticalResolution.ToString(CultureInfo.InvariantCulture));
                    contents.Add(worldFile.UpperLeftX.ToString(CultureInfo.InvariantCulture));
                    contents.Add(worldFile.UpperLeftY.ToString(CultureInfo.InvariantCulture));
                    File.WriteAllLines(fileName, contents);
                }
            }
        }
 internal void Reset(WorldFile worldFile)
 {
     Position  = worldFile.KarelStartPosition;
     Direction = worldFile.KarelStartDirection;
     PositionChanged.Invoke(this);
     DirectionChanged.Invoke(this);
 }
Example #3
0
        /// <summary>
        /// Set the envelope by the definition in the world file
        /// </summary>
        /// <param name="fileName">Filename to the image</param>
        private void SetEnvelope(string fileName)
        {
            var wld = Path.ChangeExtension(fileName, ".wld");

            if (File.Exists(wld))
            {
                _worldFile = ReadWorldFile(wld);
            }
            else
            {
                var ext = CreateWorldFileExtension(Path.GetExtension(fileName));
                if (string.IsNullOrEmpty(ext))
                {
                    return;
                }
                {
                    wld = Path.ChangeExtension(fileName, ext);
                    if (File.Exists(wld))
                    {
                        _worldFile = ReadWorldFile(wld);
                    }
                }
            }

            SetEnvelope();
        }
Example #4
0
        private void UpdateMe(On.Terraria.Main.orig_UpdateMenu orig)
        {
            if (Main.mouseMiddle && !genning)
            {
                genning = true;
                PutMeInAWorld();
            }

            if (genning && !WorldGen.gen && Main.menuMode != 888)
            {
                using (FileStream f = File.Create(ModLoader.ModPath + "/TempWorld"))
                {
                    BinaryWriter w = new BinaryWriter(f);
                    WorldFile.SaveWorld_Version2(w);
                }

                var temp = new PlayerFileData(ModLoader.ModPath + "/TempPlayer", false);
                temp.Name        = "Temporary Player";
                temp.Player      = new Player();
                temp.Player.name = "Temporary Player";
                temp.Metadata    = FileMetadata.FromCurrentSettings(FileType.Player);

                Main.player[0] = temp.Player;

                Main.ActivePlayerFileData = temp;

                WorldGen.playWorld();
                genning = false;
            }

            orig();
        }
Example #5
0
    IEnumerator world(string url)
    {
        WWW www = new WWW(url);

        yield return(www);

        string[] S_gfw = www.text.Split('\n'); // stringed gfw file
        if (S_gfw.Length == 7)
        {
            bool  worked  = true;
            float x_scale = 0f;
            float y_scale = 0f;
            float x       = 0f;
            float y       = 0f;
            worked = worked && float.TryParse(S_gfw[0], out x_scale);
            //worked = worked && float.TryParse(S_gfw[1], out a);
            //worked = worked && float.TryParse(S_gfw[2], out b);
            worked = worked && float.TryParse(S_gfw[3], out y_scale);
            worked = worked && float.TryParse(S_gfw[4], out x);
            worked = worked && float.TryParse(S_gfw[5], out y);
            if (!worked)
            {
                Debug.Log("couldnt parse world file");
            }
            gfw = new WorldFile(x, y, x_scale, y_scale);
            UpdateOffset();
        }
        else
        {
            Debug.Log("wrong length in gfw? " + S_gfw.Length);
        }
    }
Example #6
0
 private static void CleanupServer()
 {
     StopListening();
     try
     {
         ClosePort(ListenPort);
     }
     catch
     {
     }
     for (int i = 0; i < 256; i++)
     {
         Clients[i].Reset();
     }
     if (Main.menuMode != 15)
     {
         Main.netMode  = 0;
         Main.menuMode = 10;
         WorldFile.SaveWorld();
         Main.menuMode = 0;
     }
     else
     {
         Main.netMode = 0;
     }
     Main.myPlayer = 0;
 }
Example #7
0
        // Open a world file with the given filename.
        public void OpenFile(string fileName)
        {
            // Load the world.
            WorldFile worldFile   = new WorldFile();
            World     loadedWorld = worldFile.Load(fileName);

            // Verify the world was loaded successfully.
            if (loadedWorld != null)
            {
                CloseFile();

                hasMadeChanges   = false;
                worldFilePath    = fileName;
                worldFileName    = Path.GetFileName(fileName);
                needsRecompiling = true;

                world = loadedWorld;
                if (world.Levels.Count > 0)
                {
                    OpenLevel(0);
                }

                RefreshWorldTreeView();
                editorForm.worldTreeView.ExpandAll();
            }
            else
            {
                // Display the error.
                MessageBox.Show(editorForm, "Failed to open world file:\n" +
                                worldFile.ErrorMessage, "Error Opening World",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        protected bool doCanRead(Object source, AVList parameters)
        {
            String path = WWIO.getSourcePath(source);

            if (path == null)
            {
                return(false);
            }

            GeotiffReader reader = null;

            try
            {
                reader = new GeotiffReader(path);
                bool isGeoTiff = reader.isGeotiff(0);
                if (!isGeoTiff)
                {
                    isGeoTiff = WorldFile.hasWorldFiles(source);
                }
                return(isGeoTiff);
            }
            catch (Exception e)
            {
                // Intentionally ignoring exceptions.
                return(false);
            }
            finally
            {
                if (reader != null)
                {
                    reader.close();
                }
            }
        }
Example #9
0
 private void ReadHeader()
 {
     try
     {
         _dataset = Gdal.Open(Filename, Access.GA_Update);
     }
     catch
     {
         try
         {
             _dataset = Gdal.Open(Filename, Access.GA_ReadOnly);
         }
         catch (Exception ex)
         {
             throw new GdalException(ex.ToString());
         }
     }
     Init(_dataset.RasterXSize, _dataset.RasterYSize);
     NumBands = _dataset.RasterCount;
     WorldFile = new WorldFile { Affine = new double[6] };
     double[] test = new double[6];
     _dataset.GetGeoTransform(test);
     Bounds = new RasterBounds(Height, Width, test);
     WorldFile.Affine = test;
     DoClose();
 }
Example #10
0
        protected bool doCanRead(Object source, AVList parameters)
        {
            if (!(source is java.io.File) && !(source is java.net.URL))
            {
                return(false);
            }

            // If the data source doesn't already have all the necessary metadata, then we determine whether or not
            // the missing metadata can be read.
            String error = this.validateMetadata(source, parameters);

            if (!WWUtil.isEmpty(error))
            {
                if (!WorldFile.hasWorldFiles(source))
                {
                    Logging.logger().fine(error);
                    return(false);
                }
            }

            if (null != parameters)
            {
                if (!params.hasKey(AVKey.PIXEL_FORMAT))
                {
                    parameters.setValue(AVKey.PIXEL_FORMAT, AVKey.ELEVATION);
                }
            }

            return(true);
        }
Example #11
0
 private void ReadHeader()
 {
     try
     {
         _dataset = Gdal.Open(Filename, Access.GA_Update);
     }
     catch
     {
         try
         {
             _dataset = Gdal.Open(Filename, Access.GA_ReadOnly);
         }
         catch (Exception ex)
         {
             throw new GdalException(ex.ToString());
         }
     }
     Init(_dataset.RasterXSize, _dataset.RasterYSize);
     NumBands  = _dataset.RasterCount;
     WorldFile = new WorldFile {
         Affine = new double[6]
     };
     double[] test = new double[6];
     _dataset.GetGeoTransform(test);
     Bounds           = new RasterBounds(Height, Width, test);
     WorldFile.Affine = test;
     DoClose();
 }
Example #12
0
 /// <summary>
 /// Creates a new instance of gdalImage
 /// </summary>
 public GdalTiledImage(string fileName)
     : base(fileName)
 {
     WorldFile = new WorldFile { Affine = new double[6] };
     GdalHelper.Configure();
     ReadHeader();
 }
Example #13
0
 private static void CleanupServer()
 {
     Netplay.StopListening();
     try
     {
         Netplay.ClosePort(Netplay.ListenPort);
     }
     catch
     {
     }
     for (int index = 0; index < 256; ++index)
     {
         Netplay.Clients[index].Reset();
     }
     if (Main.menuMode != 15)
     {
         Main.netMode  = 0;
         Main.menuMode = 10;
         WorldFile.SaveWorld();
         Main.menuMode = 0;
     }
     else
     {
         Main.netMode = 0;
     }
     Main.myPlayer = 0;
 }
Example #14
0
        //-----------------------------------------------------------------------------
        // Methods
        //-----------------------------------------------------------------------------

        public void LoadWorld(string fileName)
        {
            WorldFile worldFile = new WorldFile();
            World     world     = worldFile.Load(fileName);

            LoadWorld(world);
        }
Example #15
0
        private void WriteWorldFile(double minx, double maxy, double resolutionx, double resolutiony, string filename, ISpatialReference spatial)
        {
            WorldFile worldFile = new WorldFile();

            worldFile.CreatWorldFile(resolutionx, -resolutiony, minx, maxy, filename);
            worldFile.CreatXmlFile(spatial == null ? SpatialReference.GetDefault() : spatial, filename);
        }
        void ReverseConvertSigns(CommandArgs e)
        {
            Task.Factory.StartNew(() =>
            {
                using (var reader = Database.QueryReader("SELECT COUNT(*) AS Count FROM Signs"))
                {
                    reader.Read();
                    if (reader.Get <int>("Count") > 1000)
                    {
                        e.Player.SendErrorMessage("The signs cannot be reverse-converted without losing data.");
                        return;
                    }
                }

                int i = 0;
                using (var reader = Database.QueryReader("SELECT Text, X, Y FROM Signs WHERE WorldID = @0", Main.worldID))
                {
                    while (reader.Read())
                    {
                        var sign  = (Main.sign[i++] = new Terraria.Sign());
                        sign.text = reader.Get <string>("Text");
                        sign.x    = reader.Get <int>("X");
                        sign.y    = reader.Get <int>("Y");
                    }
                }
                Database.Query("DELETE FROM Signs WHERE WorldID = @0", Main.worldID);
                e.Player.SendSuccessMessage("Reverse converted {0} signs.", i);
                if (i > 0)
                {
                    WorldFile.saveWorld();
                }
            });
        }
        private static ISpatialReference TryGetSpatialRefForAuxFile(string fname, out double[] GTs)
        {
            ISpatialReference spatial = null;

            GTs = null;
            string wdFile = WorldFile.GetWorldFilenameByRasterFilename(fname);

            if (File.Exists(wdFile))
            {
                WorldFile wf = new WorldFile(wdFile);
                GTs = new double[] { wf.MinX, wf.XResolution, 0, wf.MaxY, 0, wf.YResolution };
            }
            string auxFile = fname + ".aux.xml";

            if (File.Exists(auxFile))
            {
                XElement ele = XElement.Load(auxFile);
                XElement srs = ele.Element("SRS");
                if (srs != null)
                {
                    string wkt = srs.Value;
                    spatial = SpatialReference.FromWkt(wkt, enumWKTSource.EsriPrjFile);
                }
            }
            return(spatial);
        }
Example #18
0
        ////////////////

        public static void ExitToDesktop(bool save = true)
        {
            LogHelpers.Log("Exiting to desktop " + (save?"with save...":"..."));

            if (Main.netMode == 0)
            {
                if (save)
                {
                    Main.SaveSettings();
                }
                SocialAPI.Shutdown();
                Main.instance.Exit();
            }
            else
            {
                if (save)
                {
                    WorldFile.saveWorld();
                }
                Netplay.disconnect = true;
                if (Main.netMode == 1)
                {
                    SocialAPI.Shutdown();
                }
                Environment.Exit(0);
            }
        }
Example #19
0
        private void reset(CommandArgs args)
        {
            if (args.Parameters.Count != 0)
            {
                int second = int.Parse(args.Parameters[0]);
                for (int i = 0; i < second; i++)
                {
                    TShock.Utils.Broadcast("服务器即将重置,倒计时:" + (second - i), Color.Red);
                    Thread.Sleep(1000);
                }
            }
            //Kick all players
            status = Status.Cleaning;
            Main.WorldFileMetadata = null;
            foreach (var player in TShock.Players)
            {
                if (player != null)
                //player.Kick("服务器正在重置,请稍后进入", true);
                {
                    //TShock.Utils.Kick(player, "服务器正在重置,请稍后进入", true);
                    player.Disconnect("服务器正在重置,请稍后进入");
                }
            }

            //Reset World Map
            Main.gameMenu = true;
            //Main.serverGenLock = true;
            generationProgress = new GenerationProgress();
            Task task = WorldGen.CreateNewWorld(generationProgress);

            status = Status.Generating;

            while (!task.IsCompleted)//Main.serverGenLock)
            {
                TShock.Log.ConsoleInfo(GetProgress());
                Thread.Sleep(100);
            }
            //Reload world map
            status    = Status.Cleaning;
            Main.rand = new UnifiedRandom((int)DateTime.Now.Ticks);
            WorldFile.LoadWorld(false);
            Main.dayTime    = WorldFile._tempDayTime;
            Main.time       = WorldFile._tempTime;
            Main.raining    = WorldFile._tempRaining;
            Main.rainTime   = WorldFile._tempRainTime;
            Main.maxRaining = WorldFile._tempMaxRain;
            Main.cloudAlpha = WorldFile._tempMaxRain;
            Main.moonPhase  = WorldFile._tempMoonPhase;
            Main.bloodMoon  = WorldFile._tempBloodMoon;
            Main.eclipse    = WorldFile._tempEclipse;

            //Reset player data
            TShock.DB.Query("DELETE FROM tsCharacter", Array.Empty <object>());

            //Reset status to playing
            Main.gameMenu      = false;
            generationProgress = null;
            status             = Status.Available;
        }
Example #20
0
 /// <summary>
 /// Creates a new instance of gdalImage
 /// </summary>
 public GdalTiledImage(string fileName)
     : base(fileName)
 {
     WorldFile = new WorldFile {
         Affine = new double[6]
     };
     ReadHeader();
 }
Example #21
0
 /// <summary>
 /// Creates a new instance of gdalImage, and gets much of the header
 /// information without actually reading any values from the file.
 /// </summary>
 public GdalImage(string fileName)
 {
     Filename  = fileName;
     WorldFile = new WorldFile {
         Affine = new double[6]
     };
     ReadHeader();
 }
Example #22
0
 /// <summary>
 /// Creates a new instance of gdalImage
 /// </summary>
 public GdalTiledImage(string fileName)
     : base(fileName)
 {
     WorldFile = new WorldFile {
         Affine = new double[6]
     };
     GdalHelper.Configure();
     ReadHeader();
 }
Example #23
0
    public void LoadRadarData(string station_)
    {
        station = station_;
        var url = RadarURL();

        gps.x = 0f;
        wh.x  = 0;
        gfw   = null;
        StartCoroutine(LoadRadarDataEnum(url));
    }
Example #24
0
        internal void generateDimension()
        {
            WorldFile.saveWorld(false, true);
            WorldGen.clearWorld();

            generator.GenerateDimension(Main.rand.Next());
            itemUseCooldown = 500;

            WorldGen.EveryTileFrame();
        }
Example #25
0
        private void generateDimension()
        {
            WorldFile.saveWorld(false, true);
            WorldGen.clearWorld();

            SolarWorldGen.GenerateSolarWorld(-1);
            itemUseCooldown = 500;

            //TUAWorld.solarWorldGen(mod);
            WorldGen.EveryTileFrame();
        }
Example #26
0
        //-----------------------------------------------------------------------------
        // World
        //-----------------------------------------------------------------------------

        // Save the world file to the given filename.
        public void SaveFileAs(string fileName)
        {
            if (IsWorldOpen)
            {
                WorldFile saveFile = new WorldFile();
                saveFile.Save(fileName, world);
                hasMadeChanges = false;
                worldFilePath  = fileName;
                worldFileName  = Path.GetFileName(fileName);
            }
        }
Example #27
0
 // Test/play the world.
 public void TestWorld()
 {
     if (IsWorldOpen)
     {
         string    worldPath = Path.Combine(Directory.GetParent(Application.ExecutablePath).FullName, "testing.zwd");
         WorldFile worldFile = new WorldFile();
         worldFile.Save(worldPath, world);
         string exePath = Path.Combine(Directory.GetParent(Application.ExecutablePath).FullName, "ZeldaOracle.exe");
         Process.Start(exePath, "\"" + worldPath + "\"");
     }
 }
Example #28
0
 private void ReadHeader()
 {
     _dataset = Helpers.Open(Filename);
     Init(_dataset.RasterXSize, _dataset.RasterYSize);
     NumBands = _dataset.RasterCount;
     WorldFile = new WorldFile { Affine = new double[6] };
     double[] test = new double[6];
     _dataset.GetGeoTransform(test);
     Bounds = new RasterBounds(Height, Width, test);
     WorldFile.Affine = test;
     Close();
 }
Example #29
0
        public static List <GenPass> NormalGenPassList()
        {
            List <GenPass> list = new List <GenPass>
            {
                new SubworldGenPass(progress =>
                {
                    WorldGen.generateWorld(WorldGen._genRandSeed, progress);
                    WorldFile.saveWorld();
                })
            };

            return(list);
        }
 internal static void FinishPlayWorld()
 {
     Main.OnTick -= FinishPlayWorld;
     Main.player[Main.myPlayer].Spawn();
     Main.player[Main.myPlayer].Update(Main.myPlayer);
     Main.ActivePlayerFileData.StartPlayTimer();
     WorldGen._lastSeed = Main.ActiveWorldFileData.Seed;
     Player.Hooks.EnterWorld(Main.myPlayer);
     WorldFile.SetOngoingToTemps();
     Main.PlaySound(11);
     Main.resetClouds     = true;
     WorldGen.noMapUpdate = false;
 }
Example #31
0
        public void ToScreenCoordinates_CoordinateNull_ThrowArgumentNullException()
        {
            // Setup
            var worldFile = new WorldFile(1.0, 0.0, 0.0, 1.0, 0.0, 0.0);

            // Call
            TestDelegate call = () => worldFile.ToScreenCoordinates(null);

            // Assert
            string paramName = Assert.Throws <ArgumentNullException>(call).ParamName;

            Assert.AreEqual("point", paramName);
        }
Example #32
0
        private void WriteWorldFile()
        {
            double minx = doubleTextBox1.Value; //double.Parse(textBox3.Text);
            double maxy = doubleTextBox2.Value; //double.Parse(textBox4.Text);

            double xResolution = double.Parse(doubleTextBox5.Text);
            double yResolution = double.Parse(doubleTextBox6.Text);

            WorldFile worldFile = new WorldFile();

            worldFile.CreatWorldFile(xResolution, -yResolution, minx, maxy, Filename);
            worldFile.CreatXmlFile(_spatial == null ? SpatialReference.GetDefault() : _spatial, Filename);
        }
Example #33
0
 // This constructor is intended only for loading extant worlds from File
 private World(WorldFile worldFile, Tile[,] tileArray, List <Herd> herds, List <Tribe> tribes)
 {
     this.x = worldFile.dimensions[0];
     this.z = worldFile.dimensions[1];
     Coordinates.setWorldSize(x, z);
     currentDate          = new WorldDate(1, 1);
     this.herds           = herds;
     this.tribes          = tribes;
     doubleLayerGenerator = new LayerGenerator(x, z, ROUND_TO);
     intLayerGenerator    = new LayerGenerator(x, z, 0);
     randy          = new Random();
     this.tileArray = tileArray;
 }
Example #34
0
        //-----------------------------------------------------------------------------
        // Methods
        //-----------------------------------------------------------------------------
        // Start a new game.
        public void StartGame()
        {
            roomTicks = 0;

            roomTicks = 0;

            // Setup the player beforehand so certain classes such as the HUD can reference it
            player = new Player();

            inventory						= new Inventory(this);
            menuWeapons						= new MenuWeapons(gameManager);
            menuSecondaryItems				= new MenuSecondaryItems(gameManager);
            menuEssences					= new MenuEssences(gameManager);
            menuWeapons.PreviousMenu		= menuEssences;
            menuWeapons.NextMenu			= menuSecondaryItems;
            menuSecondaryItems.PreviousMenu	= menuWeapons;
            menuSecondaryItems.NextMenu		= menuEssences;
            menuEssences.PreviousMenu		= menuSecondaryItems;
            menuEssences.NextMenu			= menuWeapons;

            GameData.LoadInventory(inventory, true);

            inventory.ObtainAmmo("ammo_scent_seeds");
            //inventory.ObtainAmmo("ammo_pegasus_seeds");
            //inventory.ObtainAmmo("ammo_gale_seeds");
            inventory.ObtainAmmo("ammo_mystery_seeds");

            hud = new HUD(this);
            hud.DynamicHealth = player.Health;

            rewardManager = new RewardManager(this);

            GameData.LoadRewards(rewardManager);

            // Create the room control.
            roomControl = new RoomControl();
            gameManager.PushGameState(roomControl);

            // Create the test world.

            // Load the world.
            //WorldFile worldFile = new WorldFile();
            //world = worldFile.Load("Content/Worlds/temp_world.zwd");

            // Begin the room state.
            if (gameManager.LaunchParameters.Length > 0) {
                WorldFile worldFile = new WorldFile();
                world = worldFile.Load(gameManager.LaunchParameters[0]);
                if (gameManager.LaunchParameters.Length > 1 && gameManager.LaunchParameters[1] == "-test") {
                    int startLevel = Int32.Parse(gameManager.LaunchParameters[2]);
                    int startRoomX = Int32.Parse(gameManager.LaunchParameters[3]);
                    int startRoomY = Int32.Parse(gameManager.LaunchParameters[4]);
                    int startPlayerX = Int32.Parse(gameManager.LaunchParameters[5]);
                    int startPlayerY = Int32.Parse(gameManager.LaunchParameters[6]);

                    player.Position = new Point2I(startPlayerX, startPlayerY) * GameSettings.TILE_SIZE + new Point2I(8, 16);
                    roomControl.BeginRoom(world.Levels[startLevel].Rooms[startRoomX, startRoomY]);
                }
                else {
                    player.Position = world.StartTileLocation * GameSettings.TILE_SIZE + new Point2I(8, 16);
                    roomControl.BeginRoom(world.StartRoom);
                }
            }
            else {
                world = GameDebug.CreateTestWorld();
                player.Position = world.StartTileLocation * GameSettings.TILE_SIZE + new Point2I(8, 16);
                roomControl.BeginRoom(world.StartRoom);
            }
            roomStateStack = new RoomStateStack(new RoomStateNormal());
            roomStateStack.Begin(this);

            AudioSystem.MasterVolume = 0.06f;
        }
        public static PlayerProfile MainMenu(int MenuChoice)
        {
            //0 New Game
            //1 Tutorial
            //2 Load Game
            //3 Custom Game
            //4 Quit

            Player = new PlayerProfile();

            if (MenuChoice == 0)   //New Game
            {
                LoDConsole.Clear();

                //Load Campaign World
                using (Stream stream = File.Open(".\\Worlds\\LoDCampaign.LoD", FileMode.Open))
                {
                    BinaryFormatter bin = new BinaryFormatter();
                    WorldState = (WorldFile)bin.Deserialize(stream);
                }
                world = WorldState.WorldState;
                Player = WorldState.DefaultPlayer;

                LoDConsole.WriteLine("Loading Legend Of Drongo Campaign");
                Player.name = LoDConsole.ReadLine("What is your name?", "Name", Player.name);
                LoDConsole.Clear();

            }
            else if (MenuChoice == 1)   //Tutorial
            {
                Player = new PlayerProfile();

                //Load Tutorial World
                using (Stream stream = File.Open(".\\Worlds\\LoDTutorial.LoD", FileMode.Open))
                {
                    BinaryFormatter bin = new BinaryFormatter();
                    WorldState = (WorldFile)bin.Deserialize(stream);
                }
                world = WorldState.WorldState;
                LoDConsole.Clear();
                Player = WorldState.DefaultPlayer;
                Player.name = LoDConsole.ReadLine("What is your name?", "Name", Player.name);
                LoDConsole.Clear();
            }
            else if (MenuChoice == 2)   //Load Game
            {
                string SavePath = LoDConsole.FindFile("\\Saves\\");
                if (SavePath == "!FAIL!" || !File.Exists(SavePath))
                {
                    return new PlayerProfile();
                }
                else
                {

                    GameState gamestate = new GameState();
                    using (Stream stream = File.Open(SavePath, FileMode.Open))
                    {
                        BinaryFormatter bin = new BinaryFormatter();
                        gamestate = (GameState)bin.Deserialize(stream);
                    }
                    Player = gamestate.PlayerState;
                    WorldState = gamestate.WorldState;
                    world = WorldState.WorldState;

                    LoDConsole.WriteLine(WordWrap("\n            Loading"));
                    //Thread.Sleep(1500);
                    LoDConsole.Clear();

                    PlayerStatus();
                    LoDConsole.WriteLine(WordWrap("Press any key to continue your adventure..."));
                    LoDConsole.Clear();
                }
            }
            else if (MenuChoice == 3)   //Custom Game
            {
                string SavePath = LoDConsole.FindFile("\\Worlds\\");
                if (SavePath == "!FAIL!" || !File.Exists(SavePath))
                {
                    return new PlayerProfile();
                }
                else
                {
                    using (Stream stream = File.Open(SavePath, FileMode.Open))
                    {
                        BinaryFormatter bin = new BinaryFormatter();
                        WorldState = (WorldFile)bin.Deserialize(stream);
                    }
                    world = WorldState.WorldState;
                    Player = WorldState.DefaultPlayer;
                    Player.name = LoDConsole.ReadLine("What is your name?", "Name", Player.name);
                    LoDConsole.Clear();
                    LoDConsole.WriteLine(WordWrap("\n            Loading"));
                    //Thread.Sleep(1500);
                    LoDConsole.Clear();
                }
            }
            else if (MenuChoice == 4)   //Quit
            {
                lock(myLock) { stopTime = -1; }
                Environment.Exit(0);
            }
            return Player;
        }
Example #36
0
 //-----------------------------------------------------------------------------
 // Methods
 //-----------------------------------------------------------------------------
 public void LoadWorld(string fileName)
 {
     WorldFile worldFile = new WorldFile();
     World world = worldFile.Load(fileName);
     LoadWorld(world);
 }
Example #37
0
 // Test/play the world with the player placed at the given room and point.
 public void TestWorld(Point2I roomCoord, Point2I playerCoord)
 {
     if (IsWorldOpen) {
         playerPlaceMode = false;
         int levelIndex = 0;
         for (levelIndex = 0; levelIndex < world.Levels.Count; levelIndex++) {
             if (world.Levels[levelIndex] == level)
                 break;
         }
         string worldPath = Path.Combine(Directory.GetParent(Application.ExecutablePath).FullName, "testing.zwd");
         WorldFile worldFile = new WorldFile();
         worldFile.Save(worldPath, world);
         string exePath = Path.Combine(Directory.GetParent(Application.ExecutablePath).FullName, "ZeldaOracle.exe");
         Process.Start(exePath, "\"" + worldPath + "\" -test " + levelIndex + " " + roomCoord.X + " " + roomCoord.Y + " " + playerCoord.X + " " + playerCoord.Y);
         // TODO: editorForm.ButtonTestPlayerPlace.Checked = false;
     }
 }
Example #38
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="ds"></param>
        /// <param name="band"></param>
        internal GdalImage(string filename, Dataset ds, ImageBandType band)
        {
            _dataset = ds;
            if (band == ImageBandType.ARGB)
            {
                using (Band bnd = ds.GetRasterBand(1))
                {
                    bnd.SetRasterColorInterpretation(ColorInterp.GCI_AlphaBand);
                }
                using (Band bnd = ds.GetRasterBand(2))
                {
                    bnd.SetRasterColorInterpretation(ColorInterp.GCI_RedBand);
                }
                using (Band bnd = ds.GetRasterBand(3))
                {
                    bnd.SetRasterColorInterpretation(ColorInterp.GCI_GreenBand);
                }
                using (Band bnd = ds.GetRasterBand(4))
                {
                    bnd.SetRasterColorInterpretation(ColorInterp.GCI_BlueBand);
                }
            }
            else if (band == ImageBandType.RGB)
            {
                using (Band bnd = ds.GetRasterBand(1))
                {
                    bnd.SetRasterColorInterpretation(ColorInterp.GCI_RedBand);
                }
                using (Band bnd = ds.GetRasterBand(2))
                {
                    bnd.SetRasterColorInterpretation(ColorInterp.GCI_GreenBand);
                }
                using (Band bnd = ds.GetRasterBand(3))
                {
                    bnd.SetRasterColorInterpretation(ColorInterp.GCI_BlueBand);
                }
            }
            else if (band == ImageBandType.PalletCoded)
            {
                using (Band bnd = ds.GetRasterBand(3))
                {
                    bnd.SetRasterColorInterpretation(ColorInterp.GCI_PaletteIndex);
                }
            }
            else
            {
                using (Band bnd = ds.GetRasterBand(3))
                {
                    bnd.SetRasterColorInterpretation(ColorInterp.GCI_GrayIndex);
                }
            }

            Filename = filename;
            WorldFile = new WorldFile { Affine = new double[6] };
            Gdal.AllRegister();
        }
Example #39
0
        // Open a world file with the given filename.
        public void OpenFile(string fileName)
        {
            CloseFile();

            hasMadeChanges = false;
            worldFilePath = fileName;
            worldFileName = Path.GetFileName(fileName);

            // Load the world.
            WorldFile worldFile = new WorldFile();
            world = worldFile.Load(fileName);
            if (world.Levels.Count > 0)
                OpenLevel(0);

            RefreshWorldTreeView();
            editorForm.LevelTreeView.ExpandAll();
        }
Example #40
0
        public static World CreateTestWorld()
        {
            // Create the world.
            World world = new World();
            world.StartLevelIndex	= 0;
            world.StartRoomLocation	= new Point2I(2, 1);
            world.StartTileLocation	= new Point2I(3, 2);

            // Load the levels from java level files.
            world.Levels.Add(LoadJavaLevel("Content/Worlds/test_level.zwd"));
            world.Levels.Add(LoadJavaLevel("Content/Worlds/interiors.zwd"));
            world.Levels.Add(LoadJavaLevel("Content/Worlds/big_interiors.zwd"));
            world.Levels[0].Properties.Set("id", "overworld");
            world.Levels[1].Properties.Set("id", "interiors");
            world.Levels[2].Properties.Set("id", "big_interiors");

            TileData tdBlock		= Resources.GetResource<TileData>("movable_block");
            TileData tdDiamond		= Resources.GetResource<TileData>("diamond_rock");
            TileData tdBush			= Resources.GetResource<TileData>("bush");
            TileData tdPot			= Resources.GetResource<TileData>("pot");
            TileData tdRock			= Resources.GetResource<TileData>("rock");
            TileData tdGrass		= Resources.GetResource<TileData>("grass");
            TileData tdOwl			= Resources.GetResource<TileData>("owl");
            TileData tdLantern		= Resources.GetResource<TileData>("lantern");
            TileData tdSign			= Resources.GetResource<TileData>("sign");
            TileData tdChest		= Resources.GetResource<TileData>("chest");
            TileData tdReward		= Resources.GetResource<TileData>("reward");
            EventTileData etdWarp	= Resources.GetResource<EventTileData>("warp");

            Level level;
            Room r;
            TileDataInstance t;
            EventTileDataInstance e;

            // Setup the overworld rooms.
            level = world.Levels[0];
            r = level.GetRoomAt(2, 1);
            t = r.CreateTile(tdOwl, 8, 1, 1);
                t.Properties.Set("text", "Hello, World!");
            t = r.CreateTile(tdChest, 7, 1, 1);
                t.Properties.Set("reward", "heart_piece");
            t = r.CreateTile(tdReward, 6, 3, 1);
                t.Properties.Set("reward", "item_flippers_1");
            t = r.CreateTile(tdSign, 1, 1, 1);
                t.Properties.Set("text", "This will<n> prime your load catchers and boost your desktop wallpaper.");
            t = r.CreateTile(tdReward, 2, 6, 1);
                t.Properties.Set("reward", "heart_piece");
            r.CreateTile(tdBlock, 2, 5, 1);
            r.CreateTile(tdGrass, 2, 2, 1);
            r.CreateTile(tdGrass, 2, 3, 1);
            r.CreateTile(tdGrass, 2, 4, 1);
            r.CreateTile(tdGrass, 3, 4, 1);
            r.CreateTile(tdGrass, 4, 5, 1);
            r.CreateTile(tdGrass, 3, 6, 1);
            r.CreateTile(tdGrass, 4, 6, 1);
            r.CreateTile(tdGrass, 5, 6, 1);
            r.CreateTile(tdGrass, 4, 7, 1);
            r.CreateTile(tdGrass, 5, 7, 1);
            r.CreateTile(tdGrass, 6, 7, 1);
            r.CreateTile(tdGrass, 7, 7, 1);
            r.CreateTile(tdGrass, 7, 2, 1);
            r.CreateTile(tdGrass, 8, 2, 1);
            r.CreateTile(tdGrass, 8, 3, 1);

            r = level.GetRoomAt(2, 2);
            e = r.CreateEventTile(etdWarp, 16, 64);
                e.Properties.Add(Property.CreateString("id", "warp_a"));
                e.Properties.Add(Property.CreateString("warp_type", "tunnel"));
                e.Properties.Add(Property.CreateString("destination_level", "overworld"));
                e.Properties.Add(Property.CreateString("destination_warp_point", "warp_b"));

            r = level.GetRoomAt(1, 1);
            e = r.CreateEventTile(etdWarp, 64, 96);
                e.Properties.Add(Property.CreateString("id", "warp_b"));
                e.Properties.Add(Property.CreateString("warp_type", "stairs"));
                e.Properties.Add(Property.CreateString("destination_level", "overworld"));
                e.Properties.Add(Property.CreateString("destination_warp_point", "warp_a"));

            r = level.GetRoomAt(new Point2I(1, 1));
            r.CreateTile(tdDiamond, 1, 1, 1);
            r.CreateTile(tdDiamond, 2, 2, 1);
            r.CreateTile(tdDiamond, 2, 4, 1);
            r.CreateTile(tdPot, 8, 2, 1);

            r = level.GetRoomAt(new Point2I(3, 0));
            r.CreateTile(tdLantern, 3, 2, 1);

            r = level.GetRoomAt(new Point2I(1, 0));
            r.CreateTile(tdRock, 8, 2, 1);

            r = level.GetRoomAt(new Point2I(2, 0));
            for (int x = 1; x < 8; x++) {
                for (int y = 2; y < 6; y++) {
                    r.CreateTile(tdBush, x, y, 1);
                }
            }

            // Set the rooms to random zones.
            /*Random random = new Random();
            for (int x = 0; x < level.Width; x++) {
                for (int y = 0; y < level.Height; y++) {
                    int index = random.Next(0, 3);
                    Zone zone = GameData.ZONE_SUMMER;
                    if (index == 1)
                        zone = GameData.ZONE_GRAVEYARD;
                    else if (index == 2)
                        zone = GameData.ZONE_FOREST;
                    level.GetRoom(new Point2I(x, y)).Zone = zone;
                }
            }*/

            // Setup the interior rooms.
            level = world.Levels[1];
            r = level.GetRoomAt(2, 1);
            r.Zone = GameData.ZONE_INTERIOR;
            r.CreateTile(tdPot, 1, 2, 1);
            r.CreateTile(tdPot, 1, 3, 1);
            r.CreateTile(tdPot, 5, 1, 1);
            r = level.GetRoomAt(3, 1);
            r.Zone = GameData.ZONE_INTERIOR;
            r.CreateTile(tdChest, 8, 1, 1);
            r.CreateTile(tdPot, 8, 2, 1);
            r.CreateTile(tdPot, 4, 6, 1);
            r.CreateTile(tdPot, 5, 6, 1);
            r.CreateTile(tdPot, 6, 6, 1);
            r.CreateTile(tdPot, 7, 6, 1);
            r.CreateTile(tdPot, 8, 6, 1);

            // Save and load the world.
            {
                WorldFile worldFile = new WorldFile();
                worldFile.Save("Content/Worlds/custom_world.zwd", world);
            }
            {
                WorldFile worldFile = new WorldFile();
                world = worldFile.Load("Content/Worlds/custom_world.zwd");
            }

            return world;
        }
Example #41
0
 /// <summary>
 /// Method to set the <see cref="Envelope"/>
 /// </summary>
 private void SetEnvelope()
 {
     _worldFile = _worldFile ?? new WorldFile(1, 0, 0, -1, 0, _image.Height);
     _envelope = _worldFile.ToGroundBounds(_image.Width, _image.Height).EnvelopeInternal;
 }
Example #42
0
        /// <summary>
        /// Set the envelope by the definition in the world file
        /// </summary>
        /// <param name="fileName">Filename to the image</param>
        private void SetEnvelope(string fileName)
        {
            var wld = Path.ChangeExtension(fileName, ".wld");

            if (File.Exists(wld))
            {
                _worldFile = ReadWorldFile(wld);
            }
            else
            {
                var ext = CreateWorldFileExtension(Path.GetExtension(fileName));
                if (string.IsNullOrEmpty(ext)) return;
                {
                    wld = Path.ChangeExtension(fileName, ext);
                    if (File.Exists(wld))
                    {
                        _worldFile = ReadWorldFile(wld);
                    }
                }
            }

            SetEnvelope();
        }
        private IEnumerable<Tuple<Point, Point>> GetValidPoints(int y, int y1, int x1, int x2, WorldFile inReference, Size checkSize)
        {
            var len = (x2 - x1);
            var len2 = len*2;
            var xy = new double[len2];
            var i = 0;
            for (var x = x1; x < x2; x++)
            {
                var c = _mapArgs.PixelToProj(new Point(x, y));
                xy[i++] = c.X;
                xy[i++] = c.Y;
            }

            Projections.Reproject.ReprojectPoints(xy, null, _target, _source, 0, len);
            //Projections.Reproject.ReprojectPoints(xy, null, _target, KnownCoordinateSystems.Geographic.World.WGS1984, 0, len);
            //ClipWGS84(xy);
            //Projections.Reproject.ReprojectPoints(xy, null, KnownCoordinateSystems.Geographic.World.WGS1984, _source, 0, len);

            i = 0;
            y -= y1;
            x2 -= x1;
            for (var x = 0; x < x2; x++)
            {
                var coord = new Coordinate(xy[i++], xy[i++]);
                var inPoint = inReference.ToRaster(coord);
                if (Verbose)
                {
                    var tmp1 = _mapArgs.PixelToProj(new Point(x + x1, y + y1));
                    var tmp2 = new [] {tmp1.X, tmp1.Y};
                    //Projections.Reproject.ReprojectPoints(tmp2, null, _target, _source, 0, 1);
                    Console.WriteLine("{0} -> [{1},{2}] -> [{3},{4}] -> {5}", new Point(x + x1, y + y1),
                        tmp2[0].ToString(NumberFormatInfo.InvariantInfo), tmp2[1].ToString(NumberFormatInfo.InvariantInfo),
                        coord.X.ToString(NumberFormatInfo.InvariantInfo), coord.Y.ToString(NumberFormatInfo.InvariantInfo), 
                        inPoint);
                }
                //if (!IsValid(checkSize, inPoint))
                //{
                //    coord.X *= -1;
                //    inPoint = inReference.ToRaster(coord);
                //}

                if (IsValid(checkSize, inPoint))
                    yield return Tuple.Create(inPoint, new Point(x, y));
            }
        }
        // Open a world file with the given filename.
        public void OpenFile(string fileName)
        {
            // Load the world.
            WorldFile worldFile = new WorldFile();
            World loadedWorld = worldFile.Load(fileName);

            // Verify the world was loaded successfully.
            if (loadedWorld != null) {
                CloseFile();

                hasMadeChanges		= false;
                worldFilePath		= fileName;
                worldFileName		= Path.GetFileName(fileName);
                needsRecompiling	= true;

                world = loadedWorld;
                if (world.Levels.Count > 0)
                    OpenLevel(0);

                RefreshWorldTreeView();
                editorForm.worldTreeView.ExpandAll();
            }
            else {
                // Display the error.
                MessageBox.Show(editorForm, "Failed to open world file:\n" +
                    worldFile.ErrorMessage, "Error Opening World",
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Example #45
0
 //-----------------------------------------------------------------------------
 // World
 //-----------------------------------------------------------------------------
 // Save the world file to the given filename.
 public void SaveFileAs(string fileName)
 {
     if (IsWorldOpen) {
         WorldFile saveFile = new WorldFile();
         saveFile.Save(fileName, world);
         hasMadeChanges = false;
     }
 }
Example #46
0
 /// <summary>
 /// Creates a new instance of gdalImage, and gets much of the header
 /// information without actually reading any values from the file.
 /// </summary>
 public GdalImage(string fileName)
 {
     Filename = fileName;
     WorldFile = new WorldFile { Affine = new double[6] };
     GdalHelper.Configure();
     ReadHeader();
 }
Example #47
0
 // Test/play the world.
 public void TestWorld()
 {
     if (IsWorldOpen) {
         string worldPath = Path.Combine(Directory.GetParent(Application.ExecutablePath).FullName, "testing.zwd");
         WorldFile worldFile = new WorldFile();
         worldFile.Save(worldPath, world);
         string exePath = Path.Combine(Directory.GetParent(Application.ExecutablePath).FullName, "ZeldaOracle.exe");
         Process.Start(exePath, "\"" + worldPath + "\"");
     }
 }
Example #48
0
 /// <summary>
 /// Creates a new instance of gdalImage
 /// </summary>
 public GdalTiledImage(string fileName)
     : base(fileName)
 {
     WorldFile = new WorldFile {Affine = new double[6]};
     ReadHeader();
 }
        public void Reproject(WorldFile inReference, Bitmap inTile, out WorldFile outReference, out Bitmap outTile)
        {
            // Shortcut when no projections have been assigned or they are of the same reference
            if (_source == null || _target == null || _source == _target)
            {
                outReference = inReference;
                outTile = inTile;
                return;
            }

            // Bounding polygon on the ground
            var ps = inReference.ToGroundBounds(inTile.Width, inTile.Height);

            // Bounding polygon on the ground in target projection
            var pt = ps.Shell.Reproject(_source, _target);

            // The target extent
            var ptExtent = pt.EnvelopeInternal.ToExtent();

            // The target extent projected to the current viewport
            var ptRect = _mapArgs.ProjToPixel(ptExtent);

            // Get the intersection with the current viewport
            ptRect.Intersect(_mapArgs.ImageRectangle);
            
            // Is it empty, don't return anything
            if (ptRect.Width == 0 || ptRect.Height == 0)
            {
                outTile = null;
                outReference = null;
                return;
            }

            var offX = ptRect.X;
            var offY = ptRect.Y;

            // Prepare the result tile
            outTile = new Bitmap(ptRect.Size.Width, ptRect.Size.Height, 
                                 PixelFormat.Format32bppArgb);
            using (var g = Graphics.FromImage(outTile))
            {
                g.Clear(Color.Transparent);
            }

            var caIn  = ColorAccess.Create(inTile);
            // not needed anymore
            var inSize = inTile.Size;
            inTile.Dispose();
            var caOut = ColorAccess.Create(outTile);

            // Copy values to output buffer
            for (var i = 0; i < outTile.Height; i++)
            {
                foreach (Tuple<Point, Point> ppair in
                         GetValidPoints(offY + i, offY, offX, offX + outTile.Width, inReference, inSize))
                {
                    var c = caIn[ppair.Item1.X, ppair.Item1.Y];
                    caOut[ppair.Item2.X, ppair.Item2.Y] = c;
                }

            }
            // Copy to output tile
            SetBitmapBuffer(outTile, caOut.Buffer);

            // Compute the reference
            var outExtent = _mapArgs.PixelToProj(ptRect);
            outReference = new WorldFile(
                outExtent.Width / ptRect.Width, 0,
                0, -outExtent.Height / ptRect.Height,
                outExtent.X, outExtent.Y);
        }