예제 #1
0
        public Container(string name, List <Token> contents)
        {
            Token      = new Token();
            Token.Text = name;
            var c = new Token("contents");

            if (contents != null)
            {
                c.AddSet(contents);
            }
            Token.Tokens.Add(c);
            Blocking = false;
        }
예제 #2
0
        public DroppedItem(InventoryItem item, Token carriedItem)
        {
            Item  = item;
            Token = new Token(item.ID);
            if (carriedItem != null)
            {
                Token.AddSet(carriedItem.Tokens);
            }

            this.Glyph           = '?';
            this.ForegroundColor = Color.Silver;
            this.BackgroundColor = Color.Black;
            this.Blocking        = false;
            AdjustView();
        }
예제 #3
0
 /// <summary>
 /// Recursively adds a list of Tokens to this Token's children, by cloning.
 /// </summary>
 /// <param name="otherSet">The list of Tokens to add.</param>
 public void AddSet(List <Token> otherSet)
 {
     //this.Tokens.AddRange(otherSet);
     foreach (var toAdd in otherSet)
     {
         var newToken = new Token(toAdd.Name, toAdd.Value, toAdd.Text);
         if (toAdd.Tokens.Count > 0)
         {
             newToken.AddSet(toAdd.Tokens);
         }
         this.Tokens.Add(newToken);
         //this.AddToken(toAdd.Name, toAdd.Value, toAdd.Text);
         //if (toAdd.Tokens.Count > 0)
         //	this.GetToken(toAdd.Name).AddSet(toAdd.Tokens);
     }
 }
예제 #4
0
        public void MergeBitmap(string fileName, string tiledefs)
        {
            var bitmap  = Mix.GetBitmap(fileName);
            var tileset = new Token();

            tileset.AddSet(Mix.GetTokenTree(tiledefs, true));
            var width  = Width;
            var height = Height;

            if (width > bitmap.Width)
            {
                width = bitmap.Width;
            }
            if (height > bitmap.Height)
            {
                height = bitmap.Height;
            }
            for (var y = 0; y < height; y++)
            {
                for (var x = 0; x < width; x++)
                {
                    var color = bitmap.GetPixel(x, y);
                    if (color.Name == "ff000000" || color.A == 0)
                    {
                        continue;
                    }
                    var key = color.Name.Substring(2).ToUpperInvariant();
                    if (!tileset.HasToken(key))
                    {
                        continue;
                    }
                    var tile = tileset.GetToken(key);

                    //Keep the original tile, but drain it.
                    if (tile.Text == "drain")
                    {
                        this.Tilemap[x, y].Fluid = Fluids.Dry;
                        continue;
                    }

                    this.Tilemap[x, y].Index = TileDefinition.Find(tile.Text).Index;

                    if (tile.Text.StartsWith("doorway"))
                    {
                        var door = new Door()
                        {
                            XPosition       = x,
                            YPosition       = y,
                            ForegroundColor = this.Tilemap[x, y].Definition.Background,
                            BackgroundColor = this.Tilemap[x, y].Definition.Background.Darken(),
                            ID          = "mergeBitmap_Door" + x + "_" + y,
                            ParentBoard = this,
                            Closed      = tile.Text.EndsWith("Closed"),
                            Glyph       = '+'
                        };
                        this.Entities.Add(door);
                    }

                    if (tile.HasToken("clutter"))
                    {
                        var nc = new Clutter()
                        {
                            XPosition   = x,
                            YPosition   = y,
                            ParentBoard = this
                        };
                        this.Entities.Add(nc);
                        var properties = tile.GetToken("clutter");
                        foreach (var property in properties.Tokens)
                        {
                            switch (property.Name)
                            {
                            case "id": nc.ID = property.Text; break;

                            case "name": nc.Name = property.Text; break;

                            case "desc": nc.Description = property.Text; break;

                            case "glyph": nc.Glyph = (int)property.Value; break;

                            case "fg":
                                if (property.Text.StartsWith('#'))
                                {
                                    nc.ForegroundColor = Color.FromCSS(property.Text);
                                }
                                else
                                {
                                    nc.ForegroundColor = Color.FromName(property.Text);
                                }
                                break;

                            case "bg":
                                if (property.Text.StartsWith('#'))
                                {
                                    nc.BackgroundColor = Color.FromCSS(property.Text);
                                }
                                else
                                {
                                    nc.BackgroundColor = Color.FromName(property.Text);
                                }
                                break;

                            case "block": nc.Blocking = true; break;

                            case "burns": nc.CanBurn = true; break;
                            }
                        }
                    }

                    if (tile.HasToken("unique"))
                    {
                        var unique  = tile.GetToken("unique");
                        var newChar = new BoardChar(Character.GetUnique(unique.Text))
                        {
                            XPosition   = x,
                            YPosition   = y,
                            ParentBoard = this
                        };
                        this.Entities.Add(newChar);
                        newChar.AssignScripts(unique.Text);
                        newChar.ReassignScripts();
                    }

                    if (!tile.HasToken("fluid"))
                    {
                        this.Tilemap[x, y].Fluid = Fluids.Dry;
                    }
                    else
                    {
                        this.Tilemap[x, y].Fluid = (Fluids)Enum.Parse(typeof(Fluids), tile.GetToken("fluid").Text, true);
                    }
                }
            }
            this.ResolveVariableWalls();
        }