Example #1
0
        public Properties(List List)
        {
            for(int i = 0; i < List.Length; ++i) {
            object o = List[i];
            if(i == 0 && o is Symbol)
                continue;

            List ChildList = o as List;
            if(o == null)
                throw new LispException("Child of properties lisp is not a list");
            if(ChildList.Length > 0) {
                Symbol name = ChildList[0] as Symbol;
                if(name == null)
                    throw new LispException("property has no symbol as name");

                object old = Props[name.Name];
                if(old == null) {
                    ArrayList AList = new ArrayList();
                    AList.Add(ChildList);
                    Props[name.Name] = AList;
                } else {
                    ((ArrayList) old).Add(ChildList);
                }
            }
            }
        }
            public Action(List Data, string BaseDir, SpriteData spriteData)
            {
                Properties Props = new Properties(Data);

                if(!Props.Get("name", ref Name))
                throw new Exception("Action without name specified");
                Props.Get("fps", ref Speed);
                Props.Get("x-offset", ref Offset.X);
                Props.Get("y-offset", ref Offset.Y);
                List<string> ImageFileNames = new List<string>();
                Props.GetStringList("images", ImageFileNames);

                Props.PrintUnusedWarnings();

                foreach(string ImageFile in ImageFileNames) {
                Surface surface = new Surface(BaseDir + "/" + ImageFile);
                Width = Math.Max(Width, surface.Width);
                Height = Math.Max(Height, surface.Height);
                Frames.Add(surface);
                }

                string MirrorActionName = null;
                Props.Get("mirror-action", ref MirrorActionName);
                if(MirrorActionName != null) {
                Action MirrorAction = spriteData.Actions[MirrorActionName];
                foreach(Surface surface in MirrorAction.Frames) {
                    Surface flippedSurface = new Surface(surface);
                    flippedSurface.Left = surface.Right;
                    flippedSurface.Right = surface.Left;
                    Width = Math.Max(Width, surface.Width);
                    Height = Math.Max(Height, surface.Height);
                    Frames.Add(flippedSurface);
                }
                }
            }
 public SpriteData(List Data, string BaseDir)
 {
     LispIterator iter = new LispIterator(Data);
     while(iter.MoveNext()) {
     if(iter.Key == "action") {
         Action Action = new Action(iter.List, BaseDir, this);
         Actions.Add(Action.Name, Action);
     } else {
         Console.WriteLine("Unknown tag in sprite: " + iter.Key);
     }
     }
 }
Example #4
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;
                    }
                }
            }
        }
Example #5
0
        public static bool hasValidSubExpressions(this string expr)
        {
            if (!expr.allCharsAreValid()) return false;

            int numOfOpenRoundBrakets = expr.Count(c => c == (int)'(');
            int numOfClosedRoundBrakets = expr.Count(c => c == (int)')');

            int openRoundBraketIndexes = expr.nthIndexOf('(',2);

            List<Char> opList = new List<Char>();
            foreach (ListOp op in Enum.GetValues(typeof(ListOp)))
                opList.Add((char)op);
        
            int numOfoperators = expr.Count(c => opList.Contains(c));
            bool allOperatorsHaveEqualCardinality = new[] { numOfOpenRoundBrakets, numOfClosedRoundBrakets, numOfoperators }.All(v => v == numOfOpenRoundBrakets);

            if (!allOperatorsHaveEqualCardinality) return false;

            for (int i = 0; i < numOfOpenRoundBrakets; i++)
                if (expr.nthIndexOf('(', i) > expr.nthIndexOf(')', i)) return false;
            
            return true;
        } 
Example #6
0
 public bool GetUIntList(string Name, List<uint> AList)
 {
     List list = Find(Name);
     if(list == null)
     return false;
     for(int i = 1; i < list.Length; ++i) {
     int v = (int) list[i];
     AList.Add((uint) v);
     }
     return true;
 }
Example #7
0
 public bool GetStringList(string Name, List<string> AList)
 {
     List list = Find(Name);
     if(list == null)
     return false;
     for(int i = 1; i < list.Length; ++i) {
     try {
         AList.Add((string) list[i]);
     }
     catch(InvalidCastException) {
         AList.Add(((Lisp.Symbol)list[i]).Name);
     }
     }
     return true;
 }
Example #8
0
 public bool GetFloatList(string Name, List<float> AList)
 {
     List list = Find(Name);
     if(list == null)
     return false;
     for(int i = 1; i < list.Length; ++i) {
     if( list[i] is float) {
         AList.Add((float) list[i]);
     } else if(list[1] is int) {
         AList.Add((float) ((int) list[i]));
     } else {
         return false;
     }
     }
     return true;
 }
Example #9
0
 public bool Get(string Name, ref List Val)
 {
     List list = Find(Name);
     if(list == null)
     return false;
     Val = list;
     return true;
 }
Example #10
0
            public Action(List Data, string BaseDir, SpriteData spriteData)
            {
                Properties Props = new Properties(Data);
                if(!Props.Get("name", ref Name))
                throw new Exception("Action without name specified");
                Props.Get("fps", ref Speed);
                if(Props.Exists("hitbox")) {
                List<float> hitbox = new List<float>();
                Props.GetFloatList("hitbox", hitbox);
                if (hitbox.Count != 4)
                    throw new Exception("hitbox must specify exactly 4 coordinates");
                Hitbox = new RectangleF(hitbox[0], hitbox[1], hitbox[2], hitbox[3]);
                Offset.X = Hitbox.Left;
                Offset.Y = Hitbox.Top;
                }
                List<string> ImageFileNames = new List<string>();
                Props.GetStringList("images", ImageFileNames);

                Props.PrintUnusedWarnings();

                foreach(string ImageFile in ImageFileNames) {
                Surface surface = new Surface(BaseDir + "/" + ImageFile);
                Width = Math.Max(Width, surface.Width);
                Height = Math.Max(Height, surface.Height);
                Frames.Add(surface);
                }

                string MirrorActionName = null;
                Props.Get("mirror-action", ref MirrorActionName);
                if(MirrorActionName != null) {
                Action MirrorAction = spriteData.Actions[MirrorActionName];
                foreach(Surface surface in MirrorAction.Frames) {
                    Surface flippedSurface = new Surface(surface);
                    flippedSurface.Left = surface.Right;
                    flippedSurface.Right = surface.Left;
                    Width = Math.Max(Width, surface.Width);
                    Height = Math.Max(Height, surface.Height);
                    Frames.Add(flippedSurface);
                }
                }
            }
Example #11
0
 public void ResizeTo(int newWidth, int newHeight)
 {
     List<int> newTiles = new List<int>();
     for (int i = 0; i < newWidth * newHeight; i++) newTiles.Add(0);
     for (int ty = 0; ty < newHeight; ty++) {
         for (int tx = 0; tx < newWidth; tx++) {
             newTiles[(newWidth * ty) + tx] = getTileAt(tx, ty);
         }
     }
     this.width = newWidth;
     this.height = newHeight;
     this.tiles = newTiles;
 }
Example #12
0
 public Tilemap(int layer, bool solid, int width, int height)
 {
     this.layer = layer;
     this.solid = solid;
     this.speed = 1.0F;
     this.width = width;
     this.height = height;
     this.tiles = new List<int>(width * height);
     for (int i = 0; i < width * height; i++) this.tiles.Add(0);
 }
Example #13
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);
        }
Example #14
0
 protected Package(string name, string [] nicknames)
 {
     this.name = String.Intern(name);
     this.nicknames = new List<string> ();
     this.PresentSymbolList = new List<Symbol> ();
     this.ExternalSymbolList = new List<Symbol> ();
     this.PackageUseList = new List<Package> ();
     if (nicknames != null)
         foreach (string nickname in nicknames)
             this.nicknames.Add (nickname);
     AllPackages.Add (this);
 }
        private static object ReadType(Type type, List list)
        {
            ILispSerializer serializer = GetSerializer(type);
            if(serializer == null)
                serializer = CreateRootSerializer(type);

            return serializer.Read(list);
        }
 public object Read(List List)
 {
     return ReadType(RootType, List);
 }
Example #17
0
        /// <summary>
        /// Create List# Tree
        /// </summary>
        /// <param name="Item">Current list</param>
        /// <param name="expression">Tokenized source code.</param>
        /// <param name="cur">Current parsing position in tokenized source code.</param>
        /// <param name="sourceCode">Original source code.</param>
        /// <returns>Completed parsing position in tokenized source code.</returns>
        /// <exception cref="SyntaxError" />
        /// <exception cref="SymbolizingError" />
        /// <exception cref="ParenthesisError" />
        /// <exception cref="NumberError" />
        /// <exception cref="UnexpectedTokenError" />
        static int TreeAnalyze(List<object> Item, Token[] expression, int cur, string sourceCode)
        {
            int i;
            if (expression[cur].Type != TokenType.OpenParenthesis)
                throw new ParenthesisError(expression[cur]);

            for (i = cur + 1; i < expression.Length; ++i)
            {
                switch (expression[i].Type)
                {
                    case TokenType.OpenParenthesis:
                        List<object> child = new List<object>();
                        Item.Add(child);
                        i = TreeAnalyze(child, expression, i, sourceCode);
                        break;
                    case TokenType.CloseParenthesis:
                        return i;
                    case TokenType.Number:
                        try
                        {
                            long result = 0;
                            if (long.TryParse(expression[i].Value, out result))
                            {
                                Item.Add(result);
                            }
                            else
                            {
                                Item.Add(double.Parse(expression[i].Value));
                            }
                        }
                        catch
                        {
                            throw new NumberError(expression[i]);
                        }
                        break;
                    case TokenType.String:
                        Item.Add(expression[i].Value);
                        break;
                    case TokenType.Symbol:
                        Item.Add(new Symbol(expression[i].Value));
                        break;
                    case TokenType.Unknown:
                        throw new UnexpectedTokenError(expression[i]);
                }
            }
            return expression.Length;
        }
Example #18
0
        /// <summary>
        /// Parse Lisp# source code
        /// </summary>
        /// <param name="expression">Lisp# source code</param>
        /// <returns>Parsed Lisp# lists</returns>
        /// <example>Usage:
        /// <code>
        ///     LispParser parser = new LispParser( );
        ///     List&lt;object&gt; parsed = parser.Parse( "(a ((b c) d) e)" );
        /// </code>
        /// </example>
        public static List<object> Parse(string expression)
        {
            List<object> root = new List<object>();
            Token[] equ = null;
            int res;

            equ = PreProcess(expression);

            res = TreeAnalyze(root, equ, 0, expression);
            if (res + 1 < equ.Length) throw new SymbolizingError(equ[res - 1], "Source code cannot reach to the end. Open parenthesises may be missed.");
            else if (res + 1 > equ.Length) throw new SymbolizingError(equ[res - 1], "Source code does not reach to the end. Close parenthesises may be missed.");

            return root;
        }
Example #19
0
 public Level()
 {
     this.version = 2;
     this.name = "Unnamed Level";
     this.author = "Anonymous";
     this.sectors = new List<Sector>();
     this.sectors.Add(new Sector("main"));
 }
Example #20
0
 public Sector(string name)
 {
     this.name = name;
     this.music = "music/chipdisko.ogg";
     this.gravity = 10.0F;
     this.tilemaps = new List<Tilemap>();
     this.tilemaps.Add(new Tilemap(-100, false, 310, 19));
     this.tilemaps.Add(new Tilemap(0, true, 310, 19));
     this.tilemaps.Add(new Tilemap(100, false, 310, 19));
     this.background = new Background("images/background/arctis.jpg", 0.5F);
     this.gameObjects = new List<GameObject>();
     this.gameObjects.Add(new Spawnpoint("main", 100, 100));
 }
        public object Read(List list)
        {
            object result = CreateObject(type);

            Properties props = new Properties(list);
            // iterate over all fields and properties
            foreach(FieldOrProperty field in FieldOrProperty.GetFieldsAndProperties(type)) {
                LispChildAttribute ChildAttrib = (LispChildAttribute)
                    field.GetCustomAttribute(typeof(LispChildAttribute));
                if(ChildAttrib != null) {
                    string Name = ChildAttrib.Name;
                    if(field.Type == typeof(int)) {
                        int val = 0;
                        if(!props.Get(Name, ref val)) {
                            if(!ChildAttrib.Optional)
                                Console.WriteLine("Field '" + Name + "' not in lisp");
                        } else {
                            field.SetValue(result, val);
                        }
                    } else if(field.Type == typeof(string)) {
                        string val = null;
                        if(!props.Get(Name, ref val)) {
                            if(!ChildAttrib.Optional)
                                Console.WriteLine("Field '" + Name + "' not in lisp");
                        } else {
                            field.SetValue(result, val);
                        }
                    } else if(field.Type == typeof(float)) {
                        float val = 0;
                        if(!props.Get(Name, ref val)) {
                            if(!ChildAttrib.Optional)
                                Console.WriteLine("Field '" + Name + "' not in lisp");
                        } else {
                            field.SetValue(result, val);
                        }
                    } else if (field.Type.IsEnum) {
                        Enum val = null;
                        if (!props.Get(Name, ref val, field.Type)) {
                            if (!ChildAttrib.Optional)
                                Console.WriteLine("Field '" + Name + "' not in lisp");
                        } else {
                            field.SetValue(result, val);
                        }
                    } else if(field.Type == typeof(bool)) {
                        bool val = false;
                        if(!props.Get(Name, ref val)) {
                            if(!ChildAttrib.Optional)
                                Console.WriteLine("Field '" + Name + "' not in lisp");
                        } else {
                            field.SetValue(result, val);
                        }
                    } else if(field.Type == typeof(List<int>)) {
                        List<int> val = new List<int>();
                        if(!props.GetIntList(Name, val)) {
                            if(!ChildAttrib.Optional)
                                Console.WriteLine("Field '" + Name + "' not in lisp");
                        } else {
                            field.SetValue(result, val);
                        }
                    } else {
                        ILispSerializer serializer = LispSerializer.GetSerializer(field.Type);
                        if(serializer == null)
                            throw new LispException("Type " + field.Type + " not supported for serialization");

                        List val = null;
                        if(!props.Get(Name, ref val)) {
                            if(!ChildAttrib.Optional)
                                Console.WriteLine("Field '" + Name + "' not in lisp");
                        } else {
                            object oval = serializer.Read(val);
                            field.SetValue(result, oval);
                        }
                    }
                }

                foreach(LispChildsAttribute childsAttrib in
                        field.GetCustomAttributes(typeof(LispChildsAttribute))) {
                    object objectList = field.GetValue(result);
                    Type ListType = field.Type;
                    MethodInfo AddMethod = ListType.GetMethod(
                            "Add", new Type[] { childsAttrib.ListType }, null);
                    if(AddMethod == null)
                        throw new LispException("No Add method found for field " + field.Name);

                    ILispSerializer serializer = LispSerializer.GetSerializer(childsAttrib.Type);
                    if(serializer == null)
                        serializer = LispSerializer.CreateRootSerializer(childsAttrib.Type);

                    foreach(List childList in props.GetList(childsAttrib.Name)) {
                        object child = serializer.Read(childList);
                        AddMethod.Invoke(objectList, new object[] { child } );
                    }
                }
            }

            if(result is ICustomLispSerializer) {
                ICustomLispSerializer custom = (ICustomLispSerializer) result;
                custom.CustomLispRead(props);
                custom.FinishRead();
            }

            return result;
        }
 public static List<GameObject> getExponents()
 {
     List<GameObject> gameObjects = new List<GameObject>();
     foreach (GameObject gameObject in exponents.Values) gameObjects.Add(gameObject);
     return gameObjects;
 }
 public bool GetStringList(string Name, List<string> AList)
 {
     List list = Find(Name);
     if(list == null)
     return false;
     for(int i = 1; i < list.Length; ++i) {
     AList.Add((string) list[i]);
     }
     return true;
 }
Example #24
0
 public void OffsetBy(int offsetX, int offsetY)
 {
     List<int> newTiles = new List<int>();
     for (int i = 0; i < width * height; i++) newTiles.Add(0);
     for (int ty = 0; ty < height; ty++) {
         for (int tx = 0; tx < width; tx++) {
             newTiles[(width * ty) + tx] = getTileAt((tx+2*width-offsetX)%width, (ty+2*height-offsetY)%height);
         }
     }
     this.tiles = newTiles;
 }
Example #25
-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();
        }