示例#1
0
    private void ParseTileImages(Lisp.Parser parser, ArrayList ImagesList)
    {
        if (parser.Type == Parser.LispType.END_LIST)
        {
            return;
        }

        int d = parser.Depth;

        do
        {
            ImageRegion region = new ImageRegion();
            if (parser.Type == Parser.LispType.STRING)
            {
                region.ImageFile = parser.StringValue;
            }
            else if (parser.Type == Parser.LispType.START_LIST)
            {
                ParseImageRegion(parser, region);
            }
            else
            {
                throw new Exception("unexpected lisp data: " + parser.Type);
            }
            ImagesList.Add(region);
        } while(parser.Parse() && parser.Depth >= d);
    }
示例#2
0
    public void Parse(string filename)
    {
        FileStream   fs     = new FileStream(filename, FileMode.Open);
        StreamReader stream = new StreamReader(fs);

        Lisp.Parser parser = new Lisp.Parser(stream);
        parser.Parse();
        if (parser.Type != Parser.LispType.START_LIST)
        {
            throw new Exception("Expected START_LIST");
        }
        parser.Parse();
        if (parser.Type != Parser.LispType.SYMBOL)
        {
            throw new Exception("Expected symbol");
        }
        if (parser.SymbolValue != "supertux-tiles")
        {
            throw new Exception("not a supertux tile files but " +
                                parser.SymbolValue);
        }
        ParseTiles(parser);

        stream.Close();
        fs.Close();
    }
示例#3
0
    public void Parse(Lisp.Parser parser)
    {
        int d = parser.Depth;

        while (parser.Parse() && parser.Depth >= d)
        {
            if (parser.Depth == d + 1)
            {
                if (parser.Type != Parser.LispType.SYMBOL)
                {
                    throw new Exception("expected SYMBOL at supertux-tiles level, but got \"" + parser.StringValue + "\"");
                }
                string symbol = parser.SymbolValue;
                parser.Parse();
                switch (symbol)
                {
                case "name":
                    Name = parser.StringValue;
                    break;

                case "tiles":
                    do
                    {
                        Tiles.Add(parser.IntegerValue);
                    } while(parser.Parse() &&
                            parser.Type == Parser.LispType.INTEGER);
                    break;

                default:
                    Console.WriteLine("Unknown section " + symbol);
                    break;
                }
            }
        }
    }
示例#4
0
    private void SkipList(Lisp.Parser parser)
    {
        int d = parser.Depth;

        while (parser.Parse() && parser.Depth >= d)
        {
            ;
        }
    }
示例#5
0
    public void ParseTiles(Lisp.Parser parser)
    {
        isNew = false;
        int d = parser.Depth;

        while (parser.Parse() && parser.Depth >= d)
        {
            if (parser.Depth == d && parser.Type != Parser.LispType.START_LIST)
            {
                Console.WriteLine("non-cons type in list...");
                continue;
            }

            if (parser.Depth == d + 1)
            {
                if (parser.Type != Parser.LispType.SYMBOL)
                {
                    throw new Exception("Expected symbol in list element");
                }
                switch (parser.SymbolValue)
                {
                case "properties":
                    SkipList(parser);
                    break;

                case "tilegroup":
                    TileGroup tilegroup = new TileGroup();
                    tilegroup.Parse(parser);
                    TileGroups.Add(tilegroup);
                    break;

                case "tile":
                    Tile tile = new Tile();
                    tile.Parse(parser);

                    while (tile.ID >= Tiles.Count)
                    {
                        Tiles.Add(null);
                    }
                    Tiles[tile.ID] = tile;
                    break;

                case "tiles":
                    ParseMoreTiles(parser);
                    isNew = true;
                    break;

                default:
                    throw new Exception("Unexpected listentry: " +
                                        parser.SymbolValue);
                }
            }
        }
    }
示例#6
0
    private void ParseImageRegion(Lisp.Parser parser, ImageRegion region)
    {
        parser.Parse();
        if (parser.Type != Parser.LispType.SYMBOL)
        {
            throw new Exception("expected symbol");
        }
        if (parser.SymbolValue != "region")
        {
            throw new Exception("expected region symbol");
        }
        parser.Parse();
        if (parser.Type != Parser.LispType.STRING)
        {
            throw new Exception("expected string");
        }
        region.ImageFile = parser.StringValue;

        parser.Parse();
        if (parser.Type != Parser.LispType.INTEGER)
        {
            throw new Exception("expected integer");
        }
        region.Region.X = parser.IntegerValue;

        parser.Parse();
        if (parser.Type != Parser.LispType.INTEGER)
        {
            throw new Exception("expected integer");
        }
        region.Region.Y = parser.IntegerValue;

        parser.Parse();
        if (parser.Type != Parser.LispType.INTEGER)
        {
            throw new Exception("expected integer");
        }
        region.Region.Width = parser.IntegerValue;

        parser.Parse();
        if (parser.Type != Parser.LispType.INTEGER)
        {
            throw new Exception("expected integer");
        }
        region.Region.Height = parser.IntegerValue;

        parser.Parse();
        if (parser.Type != Parser.LispType.END_LIST)
        {
            throw new Exception("expected END_LIST");
        }
    }
示例#7
0
    public void Parse(string filename)
    {
        FileStream fs = new FileStream(filename, FileMode.Open);
        StreamReader stream = new StreamReader(fs);

        Lisp.Parser parser = new Lisp.Parser(stream);
        parser.Parse();
        if(parser.Type != Parser.LispType.START_LIST)
            throw new Exception("Expected START_LIST");
        parser.Parse();
        if(parser.Type != Parser.LispType.SYMBOL)
            throw new Exception("Expected symbol");
        if(parser.SymbolValue != "supertux-tiles")
            throw new Exception("not a supertux tile files but " +
                    parser.SymbolValue);
        ParseTiles(parser);

        stream.Close();
        fs.Close();
    }
 public Background(Parser parser)
 {
     int d = parser.Depth;
     while (parser.Parse() && parser.Depth >= d) {
         if (parser.Depth == d + 1) {
             if (parser.Type != Parser.LispType.SYMBOL)
                 throw new Exception("expected SYMBOL");
             string symbol = parser.SymbolValue;
             parser.Parse();
             switch (symbol) {
                 case "image":
                     this.image = parser.StringValue;
                     break;
                 case "speed":
                     this.speed = parser.FloatValue;
                     break;
                 default:
                     throw new Exception("Unexpected entry in background list: " + parser.SymbolValue);
             }
         }
     }
 }
示例#9
0
        //FIXME: More to come
        public Sector(Parser parser)
        {
            this.tilemaps = new List<Tilemap>();
            this.gameObjects = new List<GameObject>();

            int d = parser.Depth;
            while (parser.Parse() && parser.Depth >= d) {
                if (parser.Depth == d + 1) {
                    if (parser.Type != Parser.LispType.SYMBOL)
                        throw new Exception("expected SYMBOL");
                    string symbol = parser.SymbolValue;
                    parser.Parse();
                    switch (symbol) {
                        case "name":
                            this.name = parser.StringValue;
                            break;
                        case "music":
                            this.music = parser.StringValue;
                            break;
                        case "gravity":
                            this.gravity = parser.FloatValue;
                            break;
                        case "tilemap":
                            this.tilemaps.Add(new Tilemap(parser));
                            break;
                        case "background":
                            this.background = new Background(parser);
                            break;
                        default:
                            //this.gameObjects.Add(new GameObject(symbol, parser));
                            this.gameObjects.Add(GameObject.Parse(symbol, parser));
                            //Console.WriteLine("WARNING: Unknown tile element " + symbol + ", skipping");
                            //SkipList(parser);
                            break;
                    }
                }
            }
        }
示例#10
0
    public void Parse(Lisp.Parser parser)
    {
        int d = parser.Depth;

        while (parser.Parse() && parser.Depth >= d)
        {
            if (parser.Depth == d + 1)
            {
                if (parser.Type != Parser.LispType.SYMBOL)
                {
                    throw new Exception("expected SYMBOL at single tile deserialization level, but found \"" + parser.StringValue + "\"");
                }
                string symbol = parser.SymbolValue;
                parser.Parse();
                switch (symbol)
                {
                case "id":
                    ID = parser.IntegerValue;
                    break;

                case "images":
                    ParseTileImages(parser, Images);
                    break;

                case "editor-images":
                    ParseTileImages(parser, EditorImages);
                    break;

                case "anim-fps":
                    AnimFps = parser.FloatValue;
                    break;

                case "one-way":
                    OneWayString = parser.StringValue;
                    break;

                case "data":
                    Data = parser.IntegerValue;
                    break;

                case "next-tile":
                    NextTile = parser.IntegerValue;
                    break;

                case "hidden":
                    Hidden = parser.BoolValue;
                    break;

                case "solid":
                    SetAttribute(Attribute.SOLID, parser.BoolValue);
                    break;

                case "unisolid":
                    SetAttribute(Attribute.UNISOLID, parser.BoolValue);
                    break;

                case "ice":
                    SetAttribute(Attribute.ICE, parser.BoolValue);
                    break;

                case "water":
                    SetAttribute(Attribute.WATER, parser.BoolValue);
                    break;

                case "slope-type":
                    SetAttribute(Attribute.SLOPE, true);
                    Data = parser.IntegerValue;
                    break;

                case "hurts":
                    SetAttribute(Attribute.HURTS, parser.BoolValue);
                    break;

                case "fire":
                    SetAttribute(Attribute.FIRE, parser.BoolValue);
                    break;

                case "brick":
                    SetAttribute(Attribute.BRICK, parser.BoolValue);
                    break;

                case "fullbox":
                    SetAttribute(Attribute.FULLBOX, parser.BoolValue);
                    break;

                case "coin":
                    SetAttribute(Attribute.COIN, parser.BoolValue);
                    break;

                case "goal":
                    SetAttribute(Attribute.GOAL, parser.BoolValue);
                    break;

                //Worldmap attributes section - these are stored in Data
                case "north":
                    SetWMAttribute(Attribute.WORLDMAP_NORTH, parser.BoolValue);
                    break;

                case "south":
                    SetWMAttribute(Attribute.WORLDMAP_SOUTH, parser.BoolValue);
                    break;

                case "west":
                    SetWMAttribute(Attribute.WORLDMAP_WEST, parser.BoolValue);
                    break;

                case "east":
                    SetWMAttribute(Attribute.WORLDMAP_EAST, parser.BoolValue);
                    break;

                case "stop":
                    SetWMAttribute(Attribute.WORLDMAP_STOP, parser.BoolValue);
                    break;

                default:
                    Console.WriteLine("Unknown tile element " + symbol);
                    break;
                }
            }
        }
    }
示例#11
0
        public static GameObject Parse(string name, Parser parser)
        {
            foreach (GameObject gameObject in exponents.Values) {
                if (gameObject.Type == name) {
                    return gameObject.ParseAsThis(name, parser);
                }
            }

            return new SpatialGameObject(name, parser);
        }
示例#12
0
    public void Parse(Lisp.Parser parser)
    {
        int d = parser.Depth;

        while (parser.Parse() && parser.Depth >= d)
        {
            if (parser.Depth == d + 1)
            {
                if (parser.Type != Parser.LispType.SYMBOL)
                {
                    throw new Exception("expected SYMBOL");
                }
                string symbol = parser.SymbolValue;
                parser.Parse();
                switch (symbol)
                {
                case "id":
                    ID = parser.IntegerValue;
                    break;

                case "images":
                    ParseTileImages(parser);
                    break;

                case "editor-images":
                    EditorImage = parser.StringValue;
                    break;

                case "solid":
                    Solid = parser.BoolValue;
                    break;

                case "unisolid":
                    UniSolid = parser.BoolValue;
                    break;

                case "ice":
                    Ice = parser.BoolValue;
                    break;

                case "water":
                    Water = parser.BoolValue;
                    break;

                case "slope-type":
                    Slope = true;
                    Data  = parser.IntegerValue;
                    break;

                case "anim-fps":
                    AnimFps = parser.FloatValue;
                    break;

                case "hurts":
                    Hurts = parser.BoolValue;
                    break;

                case "hidden":
                    Hidden = parser.BoolValue;
                    break;

                case "data":
                    Data = parser.IntegerValue;
                    break;

                case "next-tile":
                    NextTile = parser.IntegerValue;
                    break;

                case "brick":
                    Brick = parser.BoolValue;
                    break;

                case "fullbox":
                    FullBox = parser.BoolValue;
                    break;

                case "coin":
                    Coin = parser.BoolValue;
                    break;

                case "goal":
                    Goal = parser.BoolValue;
                    break;

                default:
                    Console.WriteLine("Unknown tile element " + symbol);
                    break;
                }
            }
        }
    }
示例#13
0
 protected override bool tryParse(string symbol, Parser parser)
 {
     switch (symbol) {
         case "stay-on-platform":
             this.stayonplatform = parser.BoolValue;
             return true;
         default:
             return base.tryParse(symbol, parser);
     }
 }
示例#14
0
 public override GameObject ParseAsThis(string name, Parser parser)
 {
     return new Badguy(name, parser);
 }
示例#15
0
 public PowerUp(string name, Parser parser)
     : base(name, parser)
 {
 }
        public object Read(TextReader Reader, string Source)
        {
            LispRootAttribute RootAttrib = (LispRootAttribute)
                Attribute.GetCustomAttribute(RootType, typeof(LispRootAttribute));
            if(RootAttrib == null)
                throw new LispException("Type needs to have LispRoot attribute");

            Lexer Lexer = new Lexer(Reader);
            Parser Parser = new Parser(Lexer);

            List Root = Parser.Parse();
            Properties RootP = new Properties(Root);

            List List = null;
            if(!RootP.Get(RootAttrib.Name, ref List))
                throw new LispException("'" + Source + "' is not a " + RootAttrib.Name + " file");

            return ReadType(RootType, List);
        }
示例#17
0
 public override GameObject ParseAsThis(string name, Parser parser)
 {
     return new Spawnpoint(name, parser);
 }
示例#18
0
 public Spawnpoint(string name, Parser parser)
     : base(name, parser)
 {
 }
示例#19
0
        public Level(string filename)
        {
            this.sectors = new List <Sector>();

            FileStream   fs     = new FileStream(filename, FileMode.Open);
            StreamReader stream = new StreamReader(fs);

            Lisp.Parser parser = new Lisp.Parser(stream);
            parser.Parse();
            if (parser.Type != Parser.LispType.START_LIST)
            {
                throw new Exception("Expected START_LIST");
            }
            parser.Parse();
            if (parser.Type != Parser.LispType.SYMBOL)
            {
                throw new Exception("Expected symbol");
            }
            if (parser.SymbolValue != "supertux-level")
            {
                throw new Exception("not a supertux level file. (" + parser.SymbolValue + ")");
            }

            int d = parser.Depth;

            while (parser.Parse() && parser.Depth >= d)
            {
                if (parser.Depth == d && parser.Type != Parser.LispType.START_LIST)
                {
                    Console.WriteLine("non-cons type in list...");
                    continue;
                }

                if (parser.Depth == d + 1)
                {
                    if (parser.Type != Parser.LispType.SYMBOL)
                    {
                        throw new Exception("Expected symbol in list element");
                    }
                    switch (parser.SymbolValue)
                    {
                    case "version":
                        parser.Parse();
                        this.version = parser.IntegerValue;
                        break;

                    case "name":
                        parser.Parse();
                        parser.Parse();
                        parser.Parse();
                        this.name = parser.StringValue;
                        parser.Parse();
                        break;

                    case "author":
                        parser.Parse();
                        this.author = parser.StringValue;
                        break;

                    case "extro":
                        SkipList(parser);
                        break;

                    case "sector":
                        this.sectors.Add(new Sector(parser));
                        break;

                    default:
                        throw new Exception("Unexpected entry in level list: " + parser.SymbolValue);
                    }
                }
            }

            stream.Close();
            fs.Close();
        }
示例#20
0
 public SpatialGameObject(string name, Parser parser)
     : base(name, parser)
 {
 }
示例#21
0
 protected override bool tryParse(string symbol, Parser parser)
 {
     switch (symbol) {
         case "sprite":
             this.sprite = parser.StringValue;
             return true;
         case "script":
             this.script = parser.StringValue;
             return true;
         default:
             return base.tryParse(symbol, parser);
     }
 }
示例#22
0
 public override GameObject ParseAsThis(string name, Parser parser)
 {
     return new PowerUp(name, parser);
 }
示例#23
0
 public GameObject(string name, Parser parser)
 {
     this.typename = name;
     int d = parser.Depth;
     while (parser.Parse() && parser.Depth >= d) {
         if (parser.Depth == d + 1) {
             if (parser.Type != Parser.LispType.SYMBOL)
                 throw new Exception("expected SYMBOL");
             string symbol = parser.SymbolValue;
             parser.Parse();
             if (!tryParse(symbol, parser)) {
                 Console.WriteLine("WARNING: Unknown object property: \"" + symbol + "\", skipping");
                 SkipList(parser);
             }
         }
     }
 }
示例#24
0
 public virtual GameObject ParseAsThis(string name, Parser parser)
 {
     return new GameObject(name, parser);
 }
示例#25
0
 public Badguy(string name, Parser parser)
     : base(name, parser)
 {
 }
示例#26
0
 protected override bool tryParse(string symbol, Parser parser)
 {
     switch (symbol) {
         case "x":
             this.x = parser.FloatValue;
             return true;
         case "y":
             this.y = parser.FloatValue;
             return true;
         default:
             return base.tryParse(symbol, parser);
     }
 }
示例#27
0
 /**
  * <returns>true if token was successfully consumed</returns>
  */
 protected virtual bool tryParse(string symbol, Parser parser)
 {
     return false;
 }
示例#28
0
 protected override bool tryParse(string symbol, Parser parser)
 {
     switch (symbol) {
         case "name":
             this.name = parser.StringValue;
             return true;
         default:
             return base.tryParse(symbol, parser);
     }
 }
示例#29
0
        private void ParseTiles(Parser parser)
        {
            this.tiles = new List<int>();

            if (parser.Type == Parser.LispType.END_LIST) return;

            int d = parser.Depth;
            do {
                if (parser.Type != Parser.LispType.INTEGER) throw new Exception("unexpected lisp data: " + parser.Type);
                this.tiles.Add(parser.IntegerValue);
            } while (parser.Parse() && parser.Depth >= d);
        }
示例#30
0
    public void ParseMoreTiles(Lisp.Parser parser)
    {
        int           blockWidth  = 0;
        int           blockHeight = 0;
        List <int>    ids         = new List <int>();
        List <int>    attributes  = new List <int>();
        List <int>    datas       = new List <int>();
        List <string> imageNames  = new List <string>();
        float         animFps     = 0;

        int d = parser.Depth;

        while (parser.Parse() && parser.Depth >= d)
        {
            if (parser.Depth == d + 1)
            {
                if (parser.Type != Parser.LispType.SYMBOL)
                {
                    throw new Exception("expected SYMBOL at supertux-tiles---tiles level, but got \"" + parser.StringValue + "\"");
                }
                string symbol = parser.SymbolValue;
                parser.Parse();
                switch (symbol)
                {
                case "width":
                    blockWidth = parser.IntegerValue;
                    break;

                case "height":
                    blockHeight = parser.IntegerValue;
                    break;

                case "ids":
                    Parser.ParseIntList(parser, ids);
                    break;

                case "attributes":
                    Parser.ParseIntList(parser, attributes);
                    break;

                case "datas":
                    Parser.ParseIntList(parser, datas);
                    break;

                case "anim-fps":
                    animFps = parser.FloatValue;
                    break;

                case "image":
                    int subDepth = parser.Depth;
                    while (parser.Depth >= subDepth)
                    {
                        imageNames.Add(parser.StringValue);
                        parser.Parse();
                    }
                    break;

                default:
                    Console.WriteLine("Unknown tiles element " + symbol);
                    break;
                }
            }
        }
        if (ids.Count != blockWidth * blockHeight)
        {
            throw new ApplicationException("Must have width*height ids in tiles block, but found " + ids.Count.ToString());
        }
        if ((attributes.Count != blockWidth * blockHeight) && attributes.Count > 0)             //missing atributes == all-are-0-attributes
        {
            throw new ApplicationException("Must have width*height attributes in tiles block");
        }
        if ((datas.Count != blockWidth * blockHeight) && datas.Count > 0)               //missing DATAs == all-are-0-DATAs
        {
            throw new ApplicationException("Must have width*height DATAs in tiles block");
        }

        int id = 0;

        for (int y = 0; y < blockHeight; ++y)
        {
            for (int x = 0; x < blockWidth; ++x)
            {
                if (ids[id] != 0)
                {
                    Tile tile = new Tile();

                    tile.Images = new ArrayList();
                    foreach (string str in imageNames)
                    {
                        ImageRegion region = new ImageRegion();
                        region.ImageFile     = str;
                        region.Region.X      = x * TILE_WIDTH;
                        region.Region.Y      = y * TILE_HEIGHT;
                        region.Region.Width  = TILE_WIDTH;
                        region.Region.Height = TILE_HEIGHT;
                        tile.Images.Add(region);
                    }
                    tile.ID         = ids[id];
                    tile.Attributes = (attributes.Count > 0)?attributes[id]:0;          //missing atributes == all-are-0-attributes
                    tile.Data       = (datas.Count > 0)?datas[id]:0;                    //missing DATAs == all-are-0-DATAs
                    tile.AnimFps    = animFps;

                    while (Tiles.Count <= tile.ID)
                    {
                        Tiles.Add(null);
                    }

                    Tiles[tile.ID] = tile;
                }

                id++;
            }
        }
    }
示例#31
-1
    public static void ParseIntList(Parser parser, System.Collections.Generic.List<int> intList) {
	int d = parser.Depth;
	while(parser.Depth >= d) {
		intList.Add(parser.IntegerValue);
		parser.Parse();
	}
    }
示例#32
-1
 public Tilemap(Parser parser)
 {
     int d = parser.Depth;
     while (parser.Parse() && parser.Depth >= d) {
         if (parser.Depth == d + 1) {
             if (parser.Type != Parser.LispType.SYMBOL)
                 throw new Exception("expected SYMBOL");
             string symbol = parser.SymbolValue;
             parser.Parse();
             switch (symbol) {
                 case "z-pos":
                     this.layer = parser.IntegerValue;
                     break;
                 case "solid":
                     this.solid = parser.BoolValue;
                     break;
                 case "speed":
                     this.speed = parser.FloatValue;
                     break;
                 case "width":
                     this.width = parser.IntegerValue;
                     break;
                 case "height":
                     this.height = parser.IntegerValue;
                     break;
                 case "tiles":
                     ParseTiles(parser);
                     break;
                 default:
                     throw new Exception("Unexpected entry in tilemap list: " + parser.SymbolValue);
             }
         }
     }
 }
示例#33
-1
        public Level(string filename)
        {
            this.sectors = new List<Sector>();

            FileStream fs = new FileStream(filename, FileMode.Open);
            StreamReader stream = new StreamReader(fs);

            Lisp.Parser parser = new Lisp.Parser(stream);
            parser.Parse();
            if (parser.Type != Parser.LispType.START_LIST)
                throw new Exception("Expected START_LIST");
            parser.Parse();
            if (parser.Type != Parser.LispType.SYMBOL)
                throw new Exception("Expected symbol");
            if (parser.SymbolValue != "supertux-level")
                throw new Exception("not a supertux level file. (" + parser.SymbolValue + ")");

            int d = parser.Depth;
            while (parser.Parse() && parser.Depth >= d) {
                if (parser.Depth == d && parser.Type != Parser.LispType.START_LIST) {
                    Console.WriteLine("non-cons type in list...");
                    continue;
                }

                if (parser.Depth == d + 1) {
                    if (parser.Type != Parser.LispType.SYMBOL) throw new Exception("Expected symbol in list element");
                    switch (parser.SymbolValue) {
                        case "version":
                            parser.Parse();
                            this.version = parser.IntegerValue;
                            break;
                        case "name":
                            parser.Parse();
                            parser.Parse();
                            parser.Parse();
                            this.name = parser.StringValue;
                            parser.Parse();
                            break;
                        case "author":
                            parser.Parse();
                            this.author = parser.StringValue;
                            break;
                        case "extro":
                            SkipList(parser);
                            break;
                        case "sector":
                            this.sectors.Add(new Sector(parser));
                            break;
                        default:
                            throw new Exception("Unexpected entry in level list: " + parser.SymbolValue);
                    }
                }
            }

            stream.Close();
            fs.Close();
        }