Example #1
0
 public TileMap(string name, Tile[,,] tiles, IEvent[,,] events, Building[] buildings, int numNonNull, int eventNonNull)
 {
     this.name = name;
     this.tiles = tiles;
     this.events = events;
     this.buildings = buildings;
     this.numNonNull = numNonNull;
     this.eventNonNull = eventNonNull;
 }
        private TileMap ParseFile(HashSet<string> input)
        {
            Tile[, ,] tiles;
            IEvent[,,] events;
            Building[] buildings;
            ScriptedEvent[, ,] se;
            string mapName, line;
            int mapL, mapW, mapH, numNonNull, numEvents, numBuildings, buildingNum = 0;

            line = input.ElementAt(0);
            line = line.Substring(line.IndexOf('(') + 1).Trim();
            mapName = line.Substring(0, line.IndexOf(','));
            line = line.Substring(line.IndexOf('[') + 1).Trim();
            mapL = System.Convert.ToInt32(line.Substring(0, line.IndexOf(',')));
            line = line.Substring(line.IndexOf(',') + 1).Trim();
            mapW = System.Convert.ToInt32(line.Substring(0, line.IndexOf(',')));
            line = line.Substring(line.IndexOf(',') + 1).Trim();
            mapH = System.Convert.ToInt32(line.Substring(0, line.IndexOf(']')));
            line = line.Substring(line.IndexOf(',') + 1).Trim();
            numNonNull = System.Convert.ToInt32(line.Substring(0, line.IndexOf(',')));
            line = line.Substring(line.IndexOf(',') + 1).Trim();
            numEvents = System.Convert.ToInt32(line.Substring(0, line.IndexOf(',')));
            line = line.Substring(line.IndexOf(',') + 1).Trim();
            numBuildings = System.Convert.ToInt32(line.Substring(0, line.IndexOf(')')));

            tiles = new Tile[mapL, mapW, mapH];
            events = new IEvent[mapL, mapW, mapH];
            buildings = new Building[numBuildings];
            se = ScriptInvoke.GetScriptedEvents(mapName, new int[3] { events.GetLength(0), events.GetLength(1), events.GetLength(2) });
            numEvents += ScriptInvoke.GetNumEvents(mapName);

            //Basic Data down!

            for (int i = 1; i < input.Count; i++){
                line = input.ElementAt(i).Trim();

                if (line[0] == 'T'){
                    int[] arrayPos = new int[3];
                    int[] mapPos = new int[3];
                    Tile.TileStyle style = Tile.TileStyle.FLAT;
                    Tile.Direction dir, secondDir;
                    line = line.Substring(line.IndexOf('[') + 1).Trim();

                    arrayPos[0] = System.Convert.ToInt32(line.Substring(0, line.IndexOf(',')).Trim());
                    line = line.Substring(line.IndexOf(',') + 1).Trim();
                    arrayPos[1] = System.Convert.ToInt32(line.Substring(0, line.IndexOf(',')).Trim());
                    line = line.Substring(line.IndexOf(',') + 1).Trim();
                    arrayPos[2] = System.Convert.ToInt32(line.Substring(0, line.IndexOf(']')).Trim());
                    line = line.Substring(line.IndexOf('(') + 1).Trim();

                    style = (Tile.TileStyle)Enum.Parse(typeof(Tile.TileStyle),
                        line.Substring(0, line.IndexOf(',')).Trim(), true);
                    line = line.Substring(line.IndexOf('{') + 1).Trim();
                    mapPos[0] = System.Convert.ToInt32(line.Substring(0, line.IndexOf(',')).Trim());
                    line = line.Substring(line.IndexOf(',') + 1).Trim();
                    mapPos[1] = System.Convert.ToInt32(line.Substring(0, line.IndexOf(',')).Trim());
                    line = line.Substring(line.IndexOf(',') + 1).Trim();
                    mapPos[2] = System.Convert.ToInt32(line.Substring(0, line.IndexOf('}')).Trim());

                    if (line.IndexOf(',') == -1){
                        tiles[arrayPos[0], arrayPos[1], arrayPos[2]] = new Tile(
                            style,
                            mapPos,
                            null,
                            null);
                    }else{
                        line = line.Substring(line.IndexOf(',') + 1).Trim();
                        if (line.IndexOf(',') == -1){
                            dir = (Tile.Direction)Enum.Parse(typeof(Tile.Direction), line.Substring(0, line.IndexOf(')')).Trim(), true);
                            tiles[arrayPos[0], arrayPos[1], arrayPos[2]] = new Tile(
                            style,
                            mapPos,
                            dir,
                            null);
                        }else{
                            dir = (Tile.Direction)Enum.Parse(typeof(Tile.Direction), line.Substring(0, line.IndexOf(',')).Trim(), true);
                            line = line.Substring(line.IndexOf(',') + 1).Trim();
                            if (line.IndexOf(',') == -1){
                                secondDir = (Tile.Direction)Enum.Parse(typeof(Tile.Direction), line.Substring(0, line.IndexOf(')')).Trim(), true);
                                tiles[arrayPos[0], arrayPos[1], arrayPos[2]] = new Tile(
                                style,
                                mapPos,
                                dir,
                                secondDir);
                            }else{
                                secondDir = (Tile.Direction)Enum.Parse(typeof(Tile.Direction), line.Substring(0, line.IndexOf(',')).Trim(), true);
                                line = line.Substring(line.IndexOf('{') + 1).Trim();
                                bool[] passage = new bool[4];
                                passage[0] = System.Convert.ToBoolean(line.Substring(0, line.IndexOf(',')).Trim());
                                line = line.Substring(line.IndexOf(',') + 1).Trim();
                                passage[1] = System.Convert.ToBoolean(line.Substring(0, line.IndexOf(',')).Trim());
                                line = line.Substring(line.IndexOf(',') + 1).Trim();
                                passage[2] = System.Convert.ToBoolean(line.Substring(0, line.IndexOf(',')).Trim());
                                line = line.Substring(line.IndexOf(',') + 1).Trim();
                                passage[3] = System.Convert.ToBoolean(line.Substring(0, line.IndexOf('}')).Trim());
                                if(line.IndexOf(',') == -1){
                                    tiles[arrayPos[0], arrayPos[1], arrayPos[2]] = new Tile(
                                        style,
                                        mapPos,
                                        dir,
                                        secondDir
                                        );
                                        tiles[arrayPos[0], arrayPos[1], arrayPos[2]].passage = passage;
                                    }else{
                                        line = line.Substring(line.IndexOf('\'')).Trim();
                                        string tPath = line.Substring(0, line.IndexOf('\'')).Trim();
                                        tiles[arrayPos[0], arrayPos[1], arrayPos[2]] = new Tile(
                                            style,
                                            tPath,
                                            mapPos,
                                            passage,
                                            dir,
                                            secondDir
                                            );
                                    }
                                }
                            }
                        }

                }else if (line[0] == 'C'){
                    //make me a character!
                    string texturePath = "";
                    int[] mapPos = new int[3];
                    Tile.Direction dir;

                    line = line.Substring(line.IndexOf('\'') + 1).Trim();
                    texturePath = line.Substring(0, line.IndexOf('\'')).Trim();
                    line = line.Substring(line.IndexOf('{') + 1).Trim();

                    mapPos[0] = System.Convert.ToInt32(line.Substring(0, line.IndexOf(',')).Trim());
                    line = line.Substring(line.IndexOf(',') + 1).Trim();
                    mapPos[1] = System.Convert.ToInt32(line.Substring(0, line.IndexOf(',')).Trim());
                    line = line.Substring(line.IndexOf(',') + 1).Trim();
                    mapPos[2] = System.Convert.ToInt32(line.Substring(0, line.IndexOf('}')).Trim());
                    line = line.Substring(line.IndexOf(',') + 1).Trim();

                    dir = (Tile.Direction)Enum.Parse(typeof(Tile.Direction), line.Substring(0, line.IndexOf(')')).Trim(), true);
                    events[mapPos[0], mapPos[1], mapPos[2]] = new OWPlayer(texturePath, mapPos, dir);
                }else if (line[0] == 'S' && line[1] == 'D'){
                    //make me a sliding door!
                    //SD('Images/Events/slidingDoor',{3,2,0},SOUTH,[],'stairMap');
                    string texturePath = "";
                    int[] mapPos = new int[3];
                    int[] destPos = new int[3];
                    Tile.Direction dir, playerDir;
                    bool givenSect;
                    Rectangle section = new Rectangle(0, 0, 0, 0);
                    string mapDestKey = "";

                    line = line.Substring(line.IndexOf('\'') + 1).Trim();
                    texturePath = line.Substring(0, line.IndexOf('\'')).Trim();
                    line = line.Substring(line.IndexOf('{') + 1).Trim();

                    mapPos[0] = System.Convert.ToInt32(line.Substring(0, line.IndexOf(',')).Trim());
                    line = line.Substring(line.IndexOf(',') + 1).Trim();
                    mapPos[1] = System.Convert.ToInt32(line.Substring(0, line.IndexOf(',')).Trim());
                    line = line.Substring(line.IndexOf(',') + 1).Trim();
                    mapPos[2] = System.Convert.ToInt32(line.Substring(0, line.IndexOf('}')).Trim());
                    line = line.Substring(line.IndexOf('{') + 1).Trim();

                    destPos[0] = System.Convert.ToInt32(line.Substring(0, line.IndexOf(',')).Trim());
                    line = line.Substring(line.IndexOf(',') + 1).Trim();
                    destPos[1] = System.Convert.ToInt32(line.Substring(0, line.IndexOf(',')).Trim());
                    line = line.Substring(line.IndexOf(',') + 1).Trim();
                    destPos[2] = System.Convert.ToInt32(line.Substring(0, line.IndexOf('}')).Trim());
                    line = line.Substring(line.IndexOf(',') + 1).Trim();

                    dir = (Tile.Direction)Enum.Parse(typeof(Tile.Direction), line.Substring(0, line.IndexOf(',')).Trim(), true);
                    line = line.Substring(line.IndexOf(',') + 1).Trim();
                    playerDir = (Tile.Direction)Enum.Parse(typeof(Tile.Direction), line.Substring(0, line.IndexOf(',')).Trim(), true);
                    line = line.Substring(line.IndexOf('[') + 1).Trim();

                    givenSect = (line[0] != ']');

                    if (givenSect){
                        float x = System.Convert.ToSingle(line.Substring(0,line.IndexOf(',')).Trim());
                        line = line.Substring(line.IndexOf(',') + 1).Trim();
                        float y = System.Convert.ToSingle(line.Substring(0, line.IndexOf(',')).Trim());
                        line = line.Substring(line.IndexOf(',') + 1).Trim();
                        float w = System.Convert.ToSingle(line.Substring(0, line.IndexOf(',')).Trim());
                        line = line.Substring(line.IndexOf(',') + 1).Trim();
                        float h = System.Convert.ToSingle(line.Substring(0, line.IndexOf(']')).Trim());
                        section = new Rectangle((int)x, (int)y, (int)w, (int)h);
                    }
                    line = line.Substring(line.IndexOf('\'') + 1).Trim();
                    mapDestKey = line.Substring(0, line.IndexOf('\'')).Trim();

                    if (givenSect)
                        events[mapPos[0], mapPos[1], mapPos[2]] = new SlidingDoor(texturePath, mapPos, destPos, dir, playerDir, section, mapDestKey);
                    else
                        events[mapPos[0], mapPos[1], mapPos[2]] = new SlidingDoor(texturePath, mapPos, destPos, dir, playerDir, mapDestKey);
                }else if (line[0] == 'B'){
                    //make me a building
                    //"B(Block264Tex,{5,6,0});"+
                    Name name;
                    int[] mapPos = new int[3];
                    line = line.Substring(line.IndexOf('(') + 1).Trim();
                    string str = line.Substring(0, line.IndexOf(',')).Trim();
                    name = (Name)Enum.Parse(typeof(Name), str, true);
                    line = line.Substring(line.IndexOf('{') + 1).Trim();
                    mapPos[0] = System.Convert.ToInt32(line.Substring(0, line.IndexOf(',')).Trim());
                    line = line.Substring(line.IndexOf(',') + 1).Trim();
                    mapPos[1] = System.Convert.ToInt32(line.Substring(0, line.IndexOf(',')).Trim());
                    line = line.Substring(line.IndexOf(',') + 1).Trim();
                    mapPos[2] = System.Convert.ToInt32(line.Substring(0, line.IndexOf('}')).Trim());

                    buildings[buildingNum] = new Building(name, mapPos);
                    buildingNum++;
                }
            }

            for (int i = 0; i < se.GetLength(0); i++){
                for (int j = 0; j < se.GetLength(1); j++){
                    for (int k = 0; k < se.GetLength(2); k++){
                        if (se[i, j, k] != null)
                            events[i, j, k] = se[i, j, k];
                    }
                }
            }
            return new TileMap(mapName, tiles, events, buildings, numNonNull, numEvents);
        }