Exemple #1
0
 public string NameFromState(TileTemplate t, int state)
 {
     var info = self.Info.Traits.Get<BridgeInfo>();
     if (info.UseAlternateNames)
         return t.Bridge + new[] { "", "h", "d" }[state];
     else
         return t.Bridge + (char)(state + 'a');
 }
Exemple #2
0
        void ExportClicked(object sender, EventArgs e)
        {
            var dir = Path.Combine(Path.GetDirectoryName(srcfile), "output");
            Directory.CreateDirectory(dir);

            // Create a Tileset definition
            // Todo: Pull this info from the gui
            var tilesetFile = "tileset-arrakis.yaml";
            var mixFile = "arrakis.mix";
            var tileset = new TileSet()
            {
                Name = "Arrakis",
                Id = "ARRAKIS",
                Palette = "arrakis.pal",
                Extensions = new string[] {".arr", ".shp"}
            };

            // List of files to add to the mix file
            List<string> fileList = new List<string>();

            // Export palette (use the embedded palette)
            var p = surface1.Image.Palette.Entries.ToList();
            fileList.Add(ExportPalette(p, Path.Combine(dir, tileset.Palette)));

            // Export tile artwork
            foreach (var t in surface1.Templates)
                fileList.Add(ExportTemplate(t, surface1.Templates.IndexOf(t), tileset.Extensions.First(), dir));

            // Add the terraintypes
            // Todo: add support for multiple/different terraintypes
            var terraintype = new TerrainTypeInfo()
            {
                Type = "clear",
                Buildable = true,
                AcceptSmudge = true,
                IsWater = false,
                Color = Color.White
            };
            tileset.Terrain.Add("clear", terraintype);

            // Add the templates
            ushort cur = 0;
            foreach (var tp in surface1.Templates)
            {
                var template = new TileTemplate()
                {
                    Id = cur,
                    Image = "t{0:00}".F(cur),
                    Size = new int2(tp.Width,tp.Height),
                };

                // Todo: add support for different terraintypes
                // Todo: restrict cells? this doesn't work: .Where( c => surface1.TerrainTypes[c.Key.X, c.Key.Y] != 0 )
                foreach (var t in tp.Cells)
                    template.Tiles.Add((byte)((t.Key.X - tp.Left) + tp.Width * (t.Key.Y - tp.Top)), "clear");

                tileset.Templates.Add(cur, template);
                cur++;
            }

            tileset.Save(Path.Combine(dir, tilesetFile));
            PackageWriter.CreateMix(Path.Combine(dir, mixFile),fileList);

            // Cleanup
            foreach (var file in fileList)
                File.Delete(file);

            Console.WriteLine("Finished export");
        }
Exemple #3
0
        public void Export(string OutputDir)
        {
            var dir = Path.Combine(Path.GetDirectoryName(srcfile), Platform.SupportDir+OutputDir);
            Directory.CreateDirectory(dir);
            var tilesetName = txtTilesetName.Text;
            var tilesetID = txtID.Text;
            var tilesetPalette = txtPal.Text;
            var tilesetExt = txtExt.Text;

            if (tilesetName.Length < 1) { tilesetName = "Temperat"; }
            if (tilesetID.Length < 1) { tilesetID = "TEMPERAT"; }
            if (tilesetPalette.Length < 1) { tilesetPalette = "temperat"; }
            if (tilesetExt.Length < 1) { tilesetExt = ".tem,.shp"; }
            // Create a Tileset definition
            // TODO: Pull this info from the GUI
            var tilesetFile = "";
            //var mixFile = "";
            tilesetFile = tilesetName.ToLower();
            if (tilesetFile.Length < 8)
            {
                tilesetFile = tilesetName.ToLower() + ".yaml";
                //mixFile = tilesetName.ToLower() + ".mix";
            }
            else
            {
                tilesetFile = tilesetName.ToLower().Substring(0, 8) + ".yaml";
                //mixFile = tilesetName.ToLower().Substring(0, 8) + ".mix";
            }

            string[] Ext = tilesetExt.Split(',');
            var tileset = new TileSet()
            {
                Name = tilesetName,
                Id = tilesetID.ToUpper(),
                TileSize = size,
                Palette = tilesetPalette.ToLower(),
                Extensions = new string[] { Ext[0], Ext[1] }
            };

            // List of files to add to the mix file
            List<string> fileList = new List<string>();

            // Export palette (use the embedded palette)
            var p = surface1.Image.Palette.Entries.ToList();
            fileList.Add(ExportPalette(p, Path.Combine(dir, tileset.Palette)));

            // Export tile artwork
            foreach (var t in surface1.Templates)
                fileList.Add(ExportTemplate(t, surface1.Templates.IndexOf(t), tileset.Extensions.First(), dir));

            // Add the terraintypes
            foreach (var tt in TerrainType)
            {
                tileset.Terrain.Add(tt.Type, tt);
            }

            // Add the templates
            ushort cur = 0;
            foreach (var tp in surface1.Templates)
            {
                var template = new TileTemplate()
                {
                    Id = cur,
                    Image = "{0}{1:00}".F(txtTilesetName.Text, cur),
                    Size = new int2(tp.Width,tp.Height),
                };

                foreach (var t in tp.Cells)
                {
                    string ttype = "Clear";
                    ttype = TerrainType[surface1.TerrainTypes[t.Key.X, t.Key.Y]].Type;
                    var idx = ((t.Key.X - tp.Left) + tp.Width * (t.Key.Y - tp.Top));
                    template.Tiles.Add((byte)idx, ttype);
                }

                tileset.Templates.Add(cur, template);
                cur++;
            }

            tileset.Save(Path.Combine(dir, tilesetFile));
            //throw new NotImplementedException("NotI");
            //PackageWriter.CreateMix(Path.Combine(dir, mixFile),fileList);

            // Cleanup
            //foreach (var file in fileList)
                //File.Delete(file);

            Console.WriteLine("Finished export");
        }
Exemple #4
0
        public void SetTiles(World world, TileTemplate template, Dictionary<int2, int> replacedTiles)
        {
            Tiles = replacedTiles;
            state = StateFromTemplate(template);

            foreach (var t in replacedTiles.Keys)
                world.customTerrain[t.X, t.Y] = this;

            if (cachedTheater != world.Map.Theater)
            {
                cachedTheater = world.Map.Theater;
                sprites = new Cache<TileReference, Sprite>(
                x => SheetBuilder.SharedInstance.Add(world.TileSet.GetBytes(x),
                    new Size(Game.CellSize, Game.CellSize)));
            }

            var numStates = self.Info.Traits.Get<BridgeInfo>().Long ? 6 : 3;
            for (var n = 0; n < numStates; n++)
            {
                var stateTemplate = world.TileSet.Walkability.GetTileTemplate(NameFromState(template, n));
                Templates.Add( stateTemplate );

                TileSprites.Add(replacedTiles.ToDictionary(
                    a => a.Key,
                    a => sprites[new TileReference { tile = (ushort)stateTemplate.Index, image = (byte)a.Value }]));
            }

            self.Health = (int)(self.GetMaxHP() * template.HP);
        }
Exemple #5
0
 public int StateFromTemplate(TileTemplate t)
 {
     var info = self.Info.Traits.Get<BridgeInfo>();
     if (info.UseAlternateNames)
     {
         if (t.Name.EndsWith("d")) return 2;
         if (t.Name.EndsWith("h")) return 1;
         return 0;
     }
     else
         return t.Name[t.Name.Length - 1] - 'a';
 }
Exemple #6
0
        public Walkability(string templatesFile)
        {
            var file = new IniFile( FileSystem.Open( templatesFile ) );

            foreach (var section in file.Sections)
            {
                var tile = new TileTemplate
                {
                    Size = new int2(
                        int.Parse(section.GetValue("width", "0")),
                        int.Parse(section.GetValue("height", "0"))),
                    TerrainType = section
                        .Where(p => p.Key.StartsWith("tiletype"))
                        .ToDictionary(
                            p => int.Parse(p.Key.Substring(8)),
                            p => (TerrainType)Enum.Parse(typeof(TerrainType),p.Value)),
                    Name = section.GetValue("Name", null).ToLowerInvariant(),
                    Bridge = section.GetValue("bridge", null),
                    HP = float.Parse(section.GetValue("hp", "0"))
                };

                tile.Index = -1;
                int.TryParse(section.Name.Substring(3), out tile.Index);

                templates[tile.Name] = tile;
            }
        }