Ejemplo n.º 1
0
        private void menuAddTileset_Click(object sender, EventArgs e)
        {
            using (var dialog = new OpenFileDialog())
            {
                dialog.Title           = @"Selected texture to import";
                dialog.Multiselect     = true;
                dialog.CheckFileExists = true;
                dialog.CheckPathExists = true;
                dialog.Filter          = @"Image Files|*.png;";

                var result = dialog.ShowDialog();

                if (result == DialogResult.OK)
                {
                    for (int i = 0; i < dialog.FileNames.Length; i++)
                    {
                        Tilesets.Add(new Texture(dialog.FileNames[i]));
                        TilesetString.Add(dialog.SafeFileNames[i]);
                    }

                    CurrentTileset = Tilesets.Count - 1;
                    _tilesetController.UpdateTilesetDisplay();
                }
            }
        }
Ejemplo n.º 2
0
        public override void Init()
        {
            base.Init();

            Engine.Instance.StateRenderer.GameEffect = null;
            Engine.Instance.StateRenderer.UiEffect   = null;

            WindowManager.LevelEditor = true;

            Engine.EditingLevel = true;

            Physics.Init();
            Lights.Init();
            Tilesets.Load();

            Ui.Add(Camera = new Camera(new FollowingDriver()));
            Console       = new Console(Area);

            Editor = new EditorWindow(new Editor {
                Area   = Area,
                Level  = Level,
                Camera = Camera
            });


            Level = Editor.Editor.Level;
            for (var i = 0; i < Level.Explored.Length; i++)
            {
                Level.Explored[i] = true;
            }
        }
 static void ProcessRMCollectionInstall(RMCollection collection, string installPath, string sourcePath, string _namespace)
 {
     if (collection is RMAudioCollection)
     {
         Audio.InstallAudioCollection(installPath, sourcePath, collection as RMAudioCollection, _namespace);
     }
     else if (collection is RMDataCollection)
     {
         SingleFile.InstallSingleFileCollection(installPath, sourcePath, RMSingleFileCollection.CollectionType.Data, collection as RMSingleFileCollection, _namespace);
     }
     else if (collection is RMAnimationCollection)
     {
         SingleFile.InstallSingleFileCollection(installPath, sourcePath, RMSingleFileCollection.CollectionType.Animation, collection as RMSingleFileCollection, _namespace);
     }
     else if (collection is RMBattleBacks1_Collection)
     {
         SingleFile.InstallSingleFileCollection(installPath, sourcePath, RMSingleFileCollection.CollectionType.BattleBacks_1, collection as RMSingleFileCollection, _namespace);
     }
     else if (collection is RMBattleBacks2_Collection)
     {
         SingleFile.InstallSingleFileCollection(installPath, sourcePath, RMSingleFileCollection.CollectionType.BattleBacks_2, collection as RMSingleFileCollection, _namespace);
     }
     else if (collection is RMParallaxCollection)
     {
         SingleFile.InstallSingleFileCollection(installPath, sourcePath, RMSingleFileCollection.CollectionType.Parallax, collection as RMSingleFileCollection, _namespace);
     }
     else if (collection is RMPictureCollection)
     {
         SingleFile.InstallSingleFileCollection(installPath, sourcePath, RMSingleFileCollection.CollectionType.Pictures, collection as RMSingleFileCollection, _namespace);
     }
     else if (collection is RMSysImageCollection)
     {
         SingleFile.InstallSingleFileCollection(installPath, sourcePath, RMSingleFileCollection.CollectionType.System, collection as RMSingleFileCollection, _namespace);
     }
     else if (collection is RMTitles1_Collection)
     {
         SingleFile.InstallSingleFileCollection(installPath, sourcePath, RMSingleFileCollection.CollectionType.Titles_1, collection as RMSingleFileCollection, _namespace);
     }
     else if (collection is RMTitles2_Collection)
     {
         SingleFile.InstallSingleFileCollection(installPath, sourcePath, RMSingleFileCollection.CollectionType.Titles_2, collection as RMSingleFileCollection, _namespace);
     }
     else if (collection is RMPluginsCollection)
     {
         SingleFile.InstallSingleFileCollection(installPath, sourcePath, RMSingleFileCollection.CollectionType.Plugins, collection as RMSingleFileCollection, _namespace);
     }
     else if (collection is RMCharImageCollection)
     {
         Characters.InstallCharacters(installPath, sourcePath, collection as RMCharImageCollection, _namespace);
     }
     else if (collection is RMTilesetCollection)
     {
         Tilesets.InstallTileset(installPath, sourcePath, collection as RMTilesetCollection, _namespace);
     }
     else if (collection is RMMovieCollection)
     {
         Movies.InstallMovie(installPath, sourcePath, collection as RMMovieCollection, _namespace);
     }
 }
Ejemplo n.º 4
0
        public ChrProcess()
        {
            InitializeComponent();

            var tilesets = Tilesets.Read(FileConstants.Tilesets);

            this.inputTextBox.Lines = (new[] { FileConstants.SprChr, FileConstants.TitleChr }).Union(tilesets.LoadedSets.Select(ts => ts.ChrPath())).ToArray();
        }
Ejemplo n.º 5
0
 private void LoadTilesets()
 {
     Tilesets.Clear();
     foreach (var loaded in _moduleDataService.LoadAll <TilesetData>())
     {
         var tileset = _observableDataFactory.CreateAndMap <TilesetDataObservable, TilesetData>(loaded);
         Tilesets.Add(tileset);
     }
 }
Ejemplo n.º 6
0
Archivo: Model.cs Proyecto: rje/gbforge
        public void AddTileset(string name)
        {
            var toAdd = new Tileset();

            toAdd.Name = name;
            Tilesets.Add(toAdd);
            FireOnTilesetAdded(toAdd);
            SelectTileset(name);
        }
Ejemplo n.º 7
0
 private void LoadTilesetList()
 {
     this.config = Tilesets.Read(this.inputsTextbox.Text);
     this.tilesetComboBox.Items.Clear();
     foreach (var id in this.config.LoadedSets.Select(ls => ls.Id).ToArray())
     {
         this.tilesetComboBox.Items.Add(id);
     }
     this.tilesetComboBox.SelectedIndex = 0;
 }
Ejemplo n.º 8
0
        private void New()
        {
            TilesetDataObservable tileset = _observableDataFactory.Create <TilesetDataObservable>();

            tileset.Name = "Tileset" + (Tilesets.Count + 1);
            Tilesets.Add(tileset);

            _eventAggregator.GetEvent <TilesetCreatedEvent>().Publish(tileset);
            RaiseValidityChangedEvent();
        }
Ejemplo n.º 9
0
    private void LoadTilesets()
    {
        int        numTilesets = IsYellow ? 25 : 24;
        ReadStream dataStream  = ROM.From("Tilesets");

        for (byte i = 0; i < numTilesets; i++)
        {
            Tilesets.Add(new RbyTileset(this, i, dataStream));
        }
    }
Ejemplo n.º 10
0
    private void LoadTilesets()
    {
        int        numTilesets = this is Crystal ? 37 : 29;
        ByteStream dataStream  = ROM.From("Tilesets");

        for (int index = 0; index < numTilesets; index++)
        {
            Tilesets.Add(new GscTileset(this, (byte)index, dataStream));
        }
    }
Ejemplo n.º 11
0
        void ParseTilesetElement()
        {
            string externalTilesetFilename = null;

            // Tileset source
            if (currentAttributeDict.TryGetValue(TilesetElementFileSource, out externalTilesetFilename))
            {
                externalTilesetFilename = CCFileUtils.FullPathFromRelativeFile(externalTilesetFilename,
                                                                               TileMapFileName);

                currentFirstGID = short.Parse(currentAttributeDict[TilesetElementFirstGid]);

                ParseXmlFile(externalTilesetFilename);
            }
            else
            {
                var tileset = new CCTileSetInfo();

                tileset.Name = currentAttributeDict[TilesetElementName];

                // First GID
                if (currentFirstGID == 0)
                {
                    tileset.FirstGid = short.Parse(currentAttributeDict[TilesetElementFirstGid]);
                }
                else
                {
                    tileset.FirstGid = currentFirstGID;
                    currentFirstGID  = 0;
                }

                string tileSpacingStr = null;
                string borderSizeStr  = null;

                // Tilesheet tile spacing
                if (currentAttributeDict.TryGetValue(TilesetElementTileSpacing, out tileSpacingStr))
                {
                    tileset.TileSpacing = int.Parse(tileSpacingStr);
                }

                // Tilesheet border width
                if (currentAttributeDict.TryGetValue(TilesetElementBorderSize, out borderSizeStr))
                {
                    tileset.BorderWidth = int.Parse(borderSizeStr);
                }

                // Tile texel size
                CCSize tileTexelSize;
                tileTexelSize.Width   = CCUtils.CCParseFloat(currentAttributeDict[TilesetElementTexelWidth]);
                tileTexelSize.Height  = CCUtils.CCParseFloat(currentAttributeDict[TilesetElementTexelHeight]);
                tileset.TileTexelSize = tileTexelSize;

                Tilesets.Add(tileset);
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Returns the tileset with the given name.
 /// </summary>
 /// <param name="name">The name of the tileset to search for.</param>
 /// <returns>The tileset with the given name.</returns>
 /// <see cref="MapImporter.Tileset"/>
 public Tileset GetTileset(string name)
 {
     try
     {
         return(Tilesets.Find(item => item.Name == name));
     }
     catch
     {
         throw new Exception("\nCould not find Tileset.");
     }
 }
Ejemplo n.º 13
0
 public void Save(string filename)
 {
     foreach (var ts in Tilesets)
     {
         if (ts.ImageFilename.Length > FILENAME_LENGTH_LIMIT)
         {
             throw new InvalidDataException(
                       $"Image filename more than {FILENAME_LENGTH_LIMIT} characters: {ts.ImageFilename}");
         }
     }
     CheckCellValueLimit();
     using (var w = new PortableBinaryWriter(MapFilenameNewExt))
     {
         w.Write(Width);
         w.Write(Height);
         w.Write(TileWidth);
         w.Write(TileHeight);
         w.Write(Tilesets.Count());
         w.Write(Layers.Count());
         foreach (var ts in Tilesets)
         {
             w.Write(ts.FirstGid);
             w.Write(FILENAME_LENGTH_LIMIT, ts.TilesetFilenameNewExt);
         }
         for (int r = 0; r < Height; ++r)
         {
             for (int c = 0; c < Width; ++c)
             {
                 foreach (var layer in Layers)
                 {
                     w.Write((short)layer.Cells[r][c]);
                 }
             }
         }
     }
     foreach (var ts in Tilesets)
     {
         using (var w = new PortableBinaryWriter(ts.TilesetFilenameNewExt))
         {
             w.Write(ts.ImageWidth);
             w.Write(ts.ImageHeight);
             w.Write(ts.TileCount);
             w.Write(ts.Columns);
             w.Write(TiledTileset.TileProps.PropertyCount);
             w.Write(FILENAME_LENGTH_LIMIT, ts.ImageFilename);
             w.Write(Encoding.ASCII.GetBytes("PROP"));
             for (int t = 0; t < ts.TileCount; ++t)
             {
                 var props = ts.GetTileProperties(t);
                 w.Write(props.Pack());
             }
         }
     }
 }
Ejemplo n.º 14
0
        public TmxTileset GetTilesetByGid(int gid)
        {
            if (Tilesets.Count == 0)
            {
                return(null);
            }

            return(Tilesets
                   .Where((t, i) =>
                          gid >= t.FirstGid && ((i + 1) >= Tilesets.Count || Tilesets[i + 1].FirstGid > gid)
                          )
                   .FirstOrDefault());
        }
Ejemplo n.º 15
0
        public TmxMap(string filename)
            : this()
        {
            XDocument xDoc = ReadXml(filename);
            var       xMap = xDoc.Element("map");

            if (xMap == null)
            {
                throw new ArgumentOutOfRangeException("filename", "The given file is ether invalid xml or dos not contain a map element");
            }

            Version     = (string)xMap.Attribute("version");
            Orientation = (EOrientationType)Enum.Parse(typeof(EOrientationType), xMap.Attribute("orientation").Value, true);
            Width       = (int)xMap.Attribute("width");
            Height      = (int)xMap.Attribute("height");
            TileWidth   = (int)xMap.Attribute("tilewidth");
            TileHeight  = (int)xMap.Attribute("tileheight");

            var xBackgroundColor = (string)xMap.Attribute("backgroundcolor");

            if (xBackgroundColor != null)
            {
                xBackgroundColor = xBackgroundColor.TrimStart("#".ToCharArray());
                BackgroundColor  = UInt32.Parse(xBackgroundColor, NumberStyles.HexNumber);
            }

            foreach (var e in xMap.Elements("tileset"))
            {
                Tilesets.Add(new TmxTileset(e, TmxDirectory));
            }

            foreach (var e in xMap.Elements("layer"))
            {
                Layers.Add(new TmxLayer(this, e, Width, Height));
            }

            foreach (var e in xMap.Elements("objectgroup"))
            {
                ObjectGroups.Add(new TmxObjectGroup(e));
            }

            foreach (var e in xMap.Elements("imagelayer"))
            {
                ImageLayers.Add(new TmxImageLayer(this, e, TmxDirectory));
            }

            Properties.AddRange(xMap.Element("properties"));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Loads the tilesets into the tree
        /// </summary>
        /// <param name="ts">The tilesets to load into the tree</param>
        public void LoadTilesets(Tilesets ts)
        {
            TreeNode top = new TreeNode("Tilesets");
            top.Tag = ts;
            TreeNode node = null;

            this.Nodes.Add(top);
            this.Tag = ts;

            foreach (Tileset t in ts)
            {
                node = new TreeNode(t.Name);
                node.Tag = t;
                top.Nodes.Add(node);
            }
        }
Ejemplo n.º 17
0
        public void SortTilesets()
        {
            Tilesets.Sort((a, b) => a.FirstGid.CompareTo(b.FirstGid));
            tilesetsSorted = true;

            //Set largest tile size, used for culling
            var x = 0;
            var y = 0;

            foreach (var tileset in Tilesets)
            {
                x = tileset.TileWidth > x ? tileset.TileWidth : x;
                y = tileset.TileHeight > y ? tileset.TileHeight : y;
            }

            LargestTileSize = new Vector2(x, y);
        }
Ejemplo n.º 18
0
 private void Delete()
 {
     ConfirmDeleteRequest.Raise(
         new Confirmation
     {
         Title   = "Delete Tileset?",
         Content = "Are you sure you want to delete this tileset?"
     }, c =>
     {
         if (!c.Confirmed)
         {
             return;
         }
         _eventAggregator.GetEvent <TilesetDeletedEvent>().Publish(SelectedTileset);
         Tilesets.Remove(SelectedTileset);
         RaiseValidityChangedEvent();
     });
 }
Ejemplo n.º 19
0
        public override void Init()
        {
            base.Init();

            floors    = new string[FloorRegistry.Instance.Size + 2];
            floors[0] = "Random";
            floors[1] = "None";

            for (var i = 0; i < FloorRegistry.Instance.Size; i++)
            {
                floors[i + 2] = FloorRegistry.Instance.Get(i).GetType().Name.Replace("Floor", "");
            }

            walls    = new string[WallRegistry.Instance.Size + 2];
            walls[0] = "Random";
            walls[1] = "None";

            for (var i = 0; i < WallRegistry.Instance.Size; i++)
            {
                walls[i + 2] = WallRegistry.Instance.Get(i).GetType().Name.Replace("Walls", "").Replace("Wall", "");
            }

            Tilesets.Load();

            Ui.Add(new Camera(new FollowingDriver())
            {
                Position = new Vector2(Display.Width / 2f, Display.Height / 2f)
            });

            level = new RegularLevel {
                Width           = Display.Width / 16,
                Height          = Display.Height / 16 + 1,
                NoLightNoRender = false,
                DrawLight       = false
            };

            Area.Add(level);

            level.SetBiome(BiomeRegistry.Get(Biome.Castle));
            level.Setup();

            Paint();
        }
Ejemplo n.º 20
0
        private void AddTileset(XmlElement element, string filePath, GraphicsDevice device)
        {
            if (element.HasAttribute("source"))
            {
                string      source = element.GetAttribute("source");
                XmlDocument doc    = new XmlDocument();
                doc.Load(filePath + "\\" + source);
                foreach (XmlElement tilesetElement in doc.GetElementsByTagName("tileset"))
                {
                    element = tilesetElement;
                }
            }

            Tileset tileset = new Tileset();

            tileset.FromXml(element, filePath, device);

            Tilesets.Add(tileset);
        }
Ejemplo n.º 21
0
 private void LoadTilesetList(int?selectTileset = null, int?selectPalette = null)
 {
     this.disableRedrawing = true;
     this.config           = Tilesets.Read(FileConstants.Tilesets);
     this.palettes         = Palettes.Read(FileConstants.PalettesSpec);
     this.tilesetComboBox.Items.Clear();
     foreach (var id in this.config.LoadedSets.Select(ls => ls.Id).ToArray())
     {
         this.tilesetComboBox.Items.Add(id);
     }
     this.tilesetComboBox.SelectedIndex = selectTileset ?? 0;
     this.paletteComboBox.Items.Clear();
     foreach (var id in this.palettes.BackgroundPalettes.Select(ls => ls.Id).ToArray())
     {
         this.paletteComboBox.Items.Add(id);
     }
     this.paletteComboBox.SelectedIndex = selectPalette ?? 0;
     this.disableRedrawing = false;
     this.Redraw();
 }
Ejemplo n.º 22
0
        private void AreaPropertiesOpened(AreaDataObservable area)
        {
            _editingArea = area;
            Name         = area.Name;
            Tag          = area.Tag;
            Resref       = area.Resref;
            Width        = area.Width;
            Height       = area.Height;

            SelectedTileset = Tilesets.SingleOrDefault(x => x.GlobalID == area.TilesetGlobalID);
            LocalVariables.Clear();

            foreach (var @string in area.LocalVariables.LocalStrings)
            {
                LocalVariables.LocalStrings.Add(@string);
            }

            foreach (var @double in area.LocalVariables.LocalDoubles)
            {
                LocalVariables.LocalDoubles.Add(@double);
            }
        }
Ejemplo n.º 23
0
 private void ParseAllTilesets(XDocument doc)
 {
     Logger.WriteVerbose("Parsing tileset elements ...");
     foreach (XElement item in from item in doc.Descendants("tileset")
              select(item))
     {
         TsxTileset tsxTileset = TsxTileset.FromXml(item, this);
         if (tsxTileset != null)
         {
             Tilesets.Add(tsxTileset);
         }
     }
     foreach (XElement item2 in from item in doc.Descendants("imagelayer")
              select(item))
     {
         TsxTileset tsxTileset2 = TsxTileset.FromImageLayerXml(item2, this);
         if (tsxTileset2 != null)
         {
             Tilesets.Add(tsxTileset2);
         }
     }
 }
Ejemplo n.º 24
0
        private void LoadTilesets()
        {
            var tPath = TilesetPath();

            if (Directory.Exists(Application.StartupPath + tPath))
            {
                string[] tempArray = Directory.GetFiles(Application.StartupPath + tPath, "*.png");
                foreach (string s in tempArray)
                {
                    string temp = Path.GetFileName(s);
                    TilesetString.Add(temp);
                    Tilesets.Add(new Texture(s));
                }
                if (Tilesets.Count > 0)
                {
                    CurrentTileset = 0;
                    _tilesetController.UpdateTilesetDisplay();
                }
            }
            else
            {
                Directory.CreateDirectory("Tileset");
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// cTor. Reads MapTilesets.yml and imports all its data to a Tileset-
        /// object.
        /// </summary>
        /// <param name="fullpath">path+file+extension of MapTilesets.yml</param>
        public TilesetLoader(string fullpath)
        {
            //LogFile.WriteLine("");
            //LogFile.WriteLine("TilesetLoader cTor");

            // TODO: if exists(fullpath)
            // else error out.

            var progress = ProgressBarForm.Instance;

            progress.SetInfo("Parsing MapTilesets ...");

            var typeCount = 0;             // TODO: optimize the reading (here & below) into a buffer.

            using (var sr = File.OpenText(fullpath))
            {
                string line = String.Empty;
                while ((line = sr.ReadLine()) != null)
                {
                    if (line.Contains("- type"))
                    {
                        ++typeCount;
                    }
                }
            }
            progress.SetTotal(typeCount);


//mappings  will be deserialized as Dictionary<object,object>
//sequences will be deserialized as List<object>
//scalars   will be deserialized as string

//			bool warned = false;

//			bool isUfoConfigured  = !String.IsNullOrEmpty(SharedSpace.Instance.GetShare(SharedSpace.ResourceDirectoryUfo));
//			bool isTftdConfigured = !String.IsNullOrEmpty(SharedSpace.Instance.GetShare(SharedSpace.ResourceDirectoryTftd));

            string nodeGroup, nodeCategory, nodeLabel, terr, path, nodeBasepath;

            YamlSequenceNode nodeTerrains;
            YamlScalarNode   nodetry1;
            YamlMappingNode  nodetry2;

            Tuple <string, string> terrain;
            Dictionary <int, Tuple <string, string> > terrains;


            using (var sr = new StreamReader(File.OpenRead(fullpath)))
            {
                var str = new YamlStream();
                str.Load(sr);

                var nodeRoot = str.Documents[0].RootNode as YamlMappingNode;
//				foreach (var node in nodeRoot.Children) // parses YAML document divisions, ie "---"
//				{
                //LogFile.WriteLine(". node.Key(ScalarNode)= " + (YamlScalarNode)node.Key); // "tilesets"


                var nodeTilesets = nodeRoot.Children[new YamlScalarNode(GlobalsXC.TILESETS)] as YamlSequenceNode;
                foreach (YamlMappingNode nodeTileset in nodeTilesets)                 // iterate over all the tilesets
                {
                    //LogFile.WriteLine(". . nodeTilesets= " + nodeTilesets); // lists all data in the tileset

                    // IMPORTANT: ensure that tileset-labels (ie, type) and terrain-labels
                    // (ie, terrains) are stored and used only as UpperCASE strings.


                    // get the Group of the tileset
                    nodeGroup = nodeTileset.Children[new YamlScalarNode(GlobalsXC.GROUP)].ToString();
                    //LogFile.WriteLine(". . group= " + nodeGroup); // eg. "ufoShips"

//					if (   (isUfoConfigured  && nodeGroup.StartsWith("ufo",  StringComparison.OrdinalIgnoreCase))
//						|| (isTftdConfigured && nodeGroup.StartsWith("tftd", StringComparison.OrdinalIgnoreCase)))
//					{
                    if (!Groups.Contains(nodeGroup))
                    {
                        Groups.Add(nodeGroup);
                    }


                    // get the Category of the tileset ->
                    nodeCategory = nodeTileset.Children[new YamlScalarNode(GlobalsXC.CATEGORY)].ToString();
                    //LogFile.WriteLine(". . category= " + nodeCategory); // eg. "Ufo"


                    // get the Label of the tileset ->
                    nodeLabel = nodeTileset.Children[new YamlScalarNode(GlobalsXC.TYPE)].ToString();
                    nodeLabel = nodeLabel.ToUpperInvariant();
                    //LogFile.WriteLine("\n. . type= " + nodeLabel); // eg. "UFO_110"


                    // get the Terrains of the tileset ->
                    terrains = new Dictionary <int, Tuple <string, string> >();

                    nodeTerrains = nodeTileset.Children[new YamlScalarNode(GlobalsXC.TERRAINS)] as YamlSequenceNode;
                    if (nodeTerrains != null)
                    {
                        for (int i = 0; i != nodeTerrains.Children.Count; ++i)
                        {
                            terr = null;
                            path = null;                             // NOTE: 'path' will *not* be appended w/ "TERRAIN" here.

                            nodetry1 = nodeTerrains[i] as YamlScalarNode;
                            //LogFile.WriteLine(". . . nodetry1= " + nodetry1); // eg. "U_EXT02"

                            if (nodetry1 != null)                             // ie. ':' not found. Use Configurator basepath ...
                            {
                                terr = nodetry1.ToString();
                                path = String.Empty;
                            }
                            else                             // has ':' + path
                            {
                                nodetry2 = nodeTerrains[i] as YamlMappingNode;
                                //LogFile.WriteLine(". . . nodetry2= " + nodetry2); // eg. "{ { U_EXT02, basepath } }"

                                foreach (var keyval in nodetry2.Children)                                 // note: there's only one keyval in each terrain-node.
                                {
                                    terr = keyval.Key.ToString();
                                    path = keyval.Value.ToString();
                                }
                            }

                            //LogFile.WriteLine(". terr= " + terr);
                            //LogFile.WriteLine(". path= " + path);

                            terrain     = new Tuple <string, string>(terr, path);
                            terrains[i] = terrain;
                        }
                    }


                    // get the BasePath of the tileset ->
                    nodeBasepath = String.Empty;
                    var basepath = new YamlScalarNode(GlobalsXC.BASEPATH);
                    if (nodeTileset.Children.ContainsKey(basepath))
                    {
                        nodeBasepath = nodeTileset.Children[basepath].ToString();
                        //LogFile.WriteLine(". . basepath= " + nodeBasepath);
                    }
                    //else LogFile.WriteLine(". . basepath not found.");


                    var tileset = new Tileset(
                        nodeLabel,
                        nodeGroup,
                        nodeCategory,
                        terrains,
                        nodeBasepath);
                    Tilesets.Add(tileset);

                    progress.UpdateProgress();
//					}

/*					else if (!warned)
 *                                      {
 *                                              warned = true;
 *                                              MessageBox.Show(
 *                                                                      "This warning can be ignored safely on your firstrun of MapView2"
 + " or if you are purposely regenerating the tileset configuration"
 + " file MapTilesets.yml."
 + Environment.NewLine + Environment.NewLine
 + "A group was found for which the Resource paths (UFO or TFTD) have not been"
 + " configured. SAVING THE MAPTREE WILL REMOVE SUCH GROUPS FROM MapTilesets.yml"
 + " - Proceed with caution. Perhaps backup your current MapTilesets.yml in the"
 + " /settings subfolder."
 + Environment.NewLine + Environment.NewLine
 + "The default MapTilesets.yml (tileset configs) defines both UFO and"
 + " TFTD tilesets and can be regenerated with the Configurator."
 + " But if you have any custom tilesets defined it's strongly advised"
 + " to close MapView and backup that file.",
 +                                                                      "Warning",
 +                                                                      MessageBoxButtons.OK,
 +                                                                      MessageBoxIcon.Warning,
 +                                                                      MessageBoxDefaultButton.Button1,
 +                                                                      0);
 +                                      } */
                }
            }
            progress.Hide();
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Adds a new tileset to the map
 /// </summary>
 /// <param name="tileset"></param>
 public void AddTileset(TMXTileset tileset)
 {
     Tilesets.Add(tileset);
 }
Ejemplo n.º 27
0
        /// <summary>
        /// Deletes from the database any Tileset that is no longer in this list, then calls insertupdate on each object
        /// </summary>
        /// <param name="os">The list of tilesets to have in the database</param>
        public static void InsertUpdateTilesets(Tilesets os)
        {
            Tilesets curr = GetTilesets();

            if (curr != null && curr.Count > 0 && os != null)
            {
                foreach (Tileset o in curr)
                {
                    if (os.FindByID(o.ID) == null)
                    {
                        DeleteObjectDirectory(o.ID);
                    }
                }
            }

            foreach (Tileset o in os)
            {
                InsertUpdateTileset(o);
            }
        }
Ejemplo n.º 28
0
        private void Load()
        {
            Log.Info("Starting asset loading thread");

            SaveManager.Load(gameArea, SaveType.Global);
            checkFullscreen = true;
            progress++;

            var t = DateTime.Now.Millisecond;
            var c = DateTime.Now.Millisecond;

            Assets.Load(ref progress);
            Log.Info($"Assets took {(DateTime.Now.Millisecond - c) / 1000f} seconds");
            c = DateTime.Now.Millisecond;

            Dialogs.Load();
            progress++;
            CommonAse.Load();
            progress++;
            ImGuiHelper.BindTextures();
            progress++;
            Shaders.Load();
            progress++;
            Prefabs.Load();
            progress++;
            Items.Load();
            progress++;
            LootTables.Load();
            progress++;
            Mods.Load();
            progress++;             // Should be 13 here
            Log.Info($"Custom assets took {(DateTime.Now.Millisecond - c) / 1000f} seconds");

            Log.Info("Done loading assets! Loading level now.");

            Lights.Init();
            Physics.Init();
            gameArea = new Area();

            Run.Level = null;
            Tilesets.Load();
            progress++;

            Achievements.Load();
            c = DateTime.Now.Millisecond;

            if (!LoadEditor)
            {
                SaveManager.Load(gameArea, SaveType.Game);
                progress++;
                Log.Info($"Game took {(DateTime.Now.Millisecond - c) / 1000f} seconds");
                c = DateTime.Now.Millisecond;

                Rnd.Seed = $"{Run.Seed}_{Run.Depth}";

                SaveManager.Load(gameArea, SaveType.Level);
                progress++;
                Log.Info($"Level took {(DateTime.Now.Millisecond - c) / 1000f} seconds");
                c = DateTime.Now.Millisecond;

                if (Run.Depth > 0)
                {
                    SaveManager.Load(gameArea, SaveType.Player);
                }
                else
                {
                    SaveManager.Generate(gameArea, SaveType.Player);
                }

                Log.Info($"Player took {(DateTime.Now.Millisecond - c) / 1000f}");
            }

            progress++;             // Should be 18 here
            Log.Info($"Done loading level! ({(DateTime.Now.Millisecond - t) / 1000f} seconds) Going to menu.");

            Engine.AssetsLoaded?.Invoke();
            ready = true;
        }
Ejemplo n.º 29
0
        protected override void ReadXml(XElement xMap)
        {
            Version      = (string)xMap.Attribute("version");
            TiledVersion = (string)xMap.Attribute("tiledversion");

            var orientation = (string)xMap.Attribute("orientation");

            if (orientation != null)
            {
                Orientation = OrientationParser[orientation];
            }

            var renderOrder = (string)xMap.Attribute("renderorder");

            if (renderOrder != null)
            {
                RenderOrder = RenderOrderParser[renderOrder];
            }

            Width         = (int)xMap.Attribute("width");
            Height        = (int)xMap.Attribute("height");
            TileWidth     = (int)xMap.Attribute("tilewidth");
            TileHeight    = (int)xMap.Attribute("tileheight");
            HexSideLength = (int?)xMap.Attribute("hexsidelength");

            var axis = (string)xMap.Attribute("staggeraxis");

            if (axis != null)
            {
                StaggerAxis = AxisParser[axis];
            }

            var staggerIndex = (string)xMap.Attribute("staggerindex");

            if (staggerIndex != null)
            {
                StaggerIndex = StaggerIndexParser[staggerIndex];
            }

            BackgroundColor = new TiledColor((string)xMap.Attribute("backgroundcolor"));
            Infinite        = ((int)xMap.Attribute("infinite")) == 0 ? false : true;
            NextObjectId    = (int?)xMap.Attribute("nextobjectid");

            Properties = ReadProperties(xMap.Element("properties"));

            foreach (var tileset in xMap.Elements("tileset"))
            {
                Tilesets.Add(new TiledTileset(tileset));
            }

            foreach (var xLayer in xMap.Elements("layer"))
            {
                Layers.Add(new TiledLayer(xLayer));
            }

            foreach (var xObjectGroup in xMap.Elements("objectgroup"))
            {
                Objects.Add(new TiledObjectGroup(xObjectGroup));
            }

            foreach (var xImageLayer in xMap.Elements("imagelayer"))
            {
                Images.Add(new TiledImageLayer(xImageLayer));
            }

            foreach (var xGroup in xMap.Elements("group"))
            {
                Groups.Add(new TiledGroup(xGroup));
            }
        }
Ejemplo n.º 30
0
        /// <summary>
        /// cTor.
        /// </summary>
        /// <param name="fullpath">path+file+extension of MapTilesets.yml</param>
        public TilesetManager(string fullpath)
        {
            //LogFile.WriteLine("");
            //LogFile.WriteLine("TilesetManager cTor");

            // TODO: if exists(fullpath)
            // else error out.

            var progress = ProgressBarForm.Instance;

            progress.SetInfo("Parsing MapTilesets ...");

            var typeCount = 0;             // TODO: optimize the reading (here & below) into a buffer.

            using (var reader = File.OpenText(fullpath))
            {
                string line = String.Empty;
                while ((line = reader.ReadLine()) != null)
                {
                    if (line.Contains("- type"))
                    {
                        ++typeCount;
                    }
                }
            }
            progress.SetTotal(typeCount);


            bool isUfoConfigured  = !String.IsNullOrEmpty(SharedSpace.Instance.GetShare(SharedSpace.ResourceDirectoryUfo));
            bool isTftdConfigured = !String.IsNullOrEmpty(SharedSpace.Instance.GetShare(SharedSpace.ResourceDirectoryTftd));

            using (var sr = new StreamReader(File.OpenRead(fullpath)))
            {
                var str = new YamlStream();
                str.Load(sr);

                var nodeRoot = str.Documents[0].RootNode as YamlMappingNode;
//				foreach (var node in nodeRoot.Children) // parses YAML document divisions, ie "---"
//				{
                //LogFile.WriteLine(". node.Key(ScalarNode)= " + (YamlScalarNode)node.Key); // "tilesets"

                var nodeTilesets = nodeRoot.Children[new YamlScalarNode("tilesets")] as YamlSequenceNode;
                foreach (YamlMappingNode nodeTileset in nodeTilesets)                 // iterate over all the tilesets
                {
                    //LogFile.WriteLine(". . tileset= " + tileset); // lists all data in the tileset

                    // IMPORTANT: ensure that tileset-labels (ie, type) and terrain-labels
                    // (ie, terrains) are stored and used only as UpperCASE strings.


                    string nodeGroup = nodeTileset.Children[new YamlScalarNode("group")].ToString();
                    //LogFile.WriteLine(". . group= " + nodeGroup); // eg. "ufoShips"

                    if ((!isUfoConfigured && nodeGroup.StartsWith("ufo", StringComparison.OrdinalIgnoreCase)) ||
                        (!isTftdConfigured && nodeGroup.StartsWith("tftd", StringComparison.OrdinalIgnoreCase)))
                    {
                        continue;
                    }

                    if (!Groups.Contains(nodeGroup))
                    {
                        Groups.Add(nodeGroup);
                    }


                    string nodeCategory = nodeTileset.Children[new YamlScalarNode("category")].ToString();
                    //LogFile.WriteLine(". . category= " + nodeCategory); // eg. "Ufo"

                    string nodeLabel = nodeTileset.Children[new YamlScalarNode("type")].ToString();
                    nodeLabel = nodeLabel.ToUpperInvariant();
                    //LogFile.WriteLine(". . type= " + nodeLabel); // eg. "UFO_110"

                    var terrainList = new List <string>();

                    var nodeTerrains = nodeTileset.Children[new YamlScalarNode("terrains")] as YamlSequenceNode;
                    foreach (YamlScalarNode nodeTerrain in nodeTerrains)
                    {
                        //LogFile.WriteLine(". . . terrain= " + nodeTerrain); // eg. "U_EXT02" etc.

                        string terrain = nodeTerrain.ToString();
                        terrain = terrain.ToUpperInvariant();

                        terrainList.Add(terrain);
                    }


                    string nodeBasepath = String.Empty;
                    var    basepath     = new YamlScalarNode("basepath");
                    if (nodeTileset.Children.ContainsKey(basepath))
                    {
                        nodeBasepath = nodeTileset.Children[basepath].ToString();
                        //LogFile.WriteLine(". . basepath= " + nodeBasepath);
                    }
                    //else LogFile.WriteLine(". . basepath not found.");


                    var tileset = new Tileset(
                        nodeLabel,
                        nodeGroup,
                        nodeCategory,
                        terrainList,
                        nodeBasepath);
                    Tilesets.Add(tileset);

                    progress.UpdateProgress();
                }
            }
            progress.Hide();
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Gets all tilesets.
        /// </summary>
        /// <returns>All tilesets</returns>
        public static Tilesets GetTilesets()
        {
            Tilesets toReturn = new Tilesets();
            Tileset temp = null;
            DataTable dt = null;
            string query = "SELECT * FROM [Tileset] " +
                           "JOIN ObjectDirectory ON Tileset.ID = ObjectDirectory.ID";

            dt = DatabaseHelper.ExecuteTextCommandQuery(GetConnectionString(), query);

            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    temp = new Tileset();
                    temp.ID = DatabaseHelper.GetValidValueFromObject(dr["ID"], (long)0);
                    temp.Name = DatabaseHelper.GetValidValueFromObject(dr["Name"], string.Empty);
                    temp.TileHeight = DatabaseHelper.GetValidValueFromObject(dr["TileHeight"], (int)0);
                    temp.TileWidth = DatabaseHelper.GetValidValueFromObject(dr["TileWidth"], (int)0);

                    toReturn.Add(temp);
                }
            }

            return toReturn;
        }
Ejemplo n.º 32
0
        public TmxMap(XMLReader reader, string?filePath = null)
        {
            XMLReader?xMap = reader.Element("map");

            if (xMap == null)
            {
                return;
            }

            Version      = xMap.Attribute("version");
            TiledVersion = xMap.Attribute("tiledversion");

            Width           = xMap.AttributeInt("width");
            Height          = xMap.AttributeInt("height");
            TileWidth       = xMap.AttributeInt("tilewidth");
            TileHeight      = xMap.AttributeInt("tileheight");
            HexSideLength   = xMap.AttributeIntN("hexsidelength");
            Orientation     = xMap.AttributeEnum <Orientation>("orientation");
            StaggerAxis     = xMap.AttributeEnum <StaggerAxis>("staggeraxis");
            StaggerIndex    = xMap.AttributeEnum <StaggerIndex>("staggerindex");
            RenderOrder     = xMap.AttributeEnum <RenderOrder>("renderorder");
            NextObjectId    = xMap.AttributeIntN("nextobjectid");
            BackgroundColor = TmxHelpers.ParseTmxColor(xMap.Attribute("backgroundcolor"));

            Properties = TmxHelpers.GetPropertyDict(xMap.Element("properties"));

            foreach (XMLReader e in xMap.Elements("tileset"))
            {
                string?fileSource = e.Attribute("source");
                int    firstGid   = e.AttributeInt("firstgid");

                // Check if external file.
                if (!string.IsNullOrEmpty(fileSource))
                {
                    if (filePath != null)
                    {
                        string directory = AssetLoader.GetDirectoryName(filePath);
                        fileSource = AssetLoader.GetNonRelativePath(directory, fileSource);
                    }
                    var textAsset = Engine.AssetLoader.Get <TextAsset>(fileSource);
                    if (textAsset?.Content == null)
                    {
                        Engine.Log.Warning("Couldn't load external tileset.", MessageSource.TMX);
                        continue;
                    }

                    var       externalReader = new XMLReader(textAsset.Content);
                    XMLReader?tileSetElement = externalReader.Element("tileset");
                    if (tileSetElement == null)
                    {
                        continue;
                    }
                    Tilesets.Add(new TmxTileset(firstGid, tileSetElement));
                    continue;
                }

                Tilesets.Add(new TmxTileset(firstGid, e));
            }

            foreach (XMLReader e in xMap.Elements().Where(x => x.Name == "layer" || x.Name == "objectgroup" || x.Name == "imagelayer" || x.Name == "group"))
            {
                TmxLayer layer;
                switch (e.Name)
                {
                case "layer":
                    var tileLayer = new TmxLayer(e, Width, Height);
                    layer = tileLayer;
                    TileLayers.Add(tileLayer);
                    break;

                case "objectgroup":
                    var objectLayer = new TmxObjectLayer(e);
                    layer = objectLayer;
                    ObjectLayers.Add(objectLayer);
                    break;

                case "imagelayer":
                    var imageLayer = new TmxImageLayer(e);
                    layer = imageLayer;
                    ImageLayers.Add(imageLayer);
                    break;

                case "group":
                    var group = new TmxGroupedLayers(e, Width, Height);
                    layer = group;
                    Groups.Add(group);
                    break;

                default:
                    Engine.Log.Warning($"Unknown TMX layer type {e.Name}.", MessageSource.TMX);
                    continue;
                }

                Layers.Add(layer);
            }
        }
Ejemplo n.º 33
0
 private void ModuleClosed()
 {
     Tilesets.Clear();
 }