Example #1
0
    /// <summary>
    /// To read the existing level file and set the scene for edit it
    /// </summary>
    /// <param name="editionInfo"></param>
    public void readLevelFile(EditionInfo editionInfo)
    {
        StreamReader sr      = new StreamReader(SettingsManager.LevelsFilesPath + "/" + editionInfo.levelName + ".txt");
        string       line    = sr.ReadLine();
        int          columns = int.Parse(line.Split('x')[0]);
        int          rows    = int.Parse(line.Split('x')[1]);//if needs

        editionInfo.levelSize = new Vector2(columns, rows);
        generateBackTiles(editionInfo.levelSize);
        int row = 0;

        while (!sr.EndOfStream)
        {
            line = sr.ReadLine();
            string[] cells = line.Split(';');
            for (int colum = 0; colum < columns; colum++)
            {
                string   tileName;
                string[] cellsTiles = cells[colum].Split('-');//The two tiles in this position: 0 if there is nothing
                if (cellsTiles[0] != "0")
                {
                    tileName = TileCodification.getTileName(cellsTiles[0]);
                    instantiateTile(tileName, new Vector3(TileCodification.TileSize * (colum), TileCodification.TileSize * ((rows - 1) - row), 0f));
                    if (cellsTiles[1] != "0")
                    {
                        tileName = TileCodification.getTileName(cellsTiles[1]);
                        instantiateTile(tileName, new Vector3(TileCodification.TileSize * (colum), TileCodification.TileSize * ((rows - 1) - row), 0f));
                    }
                    else
                    {
                        //Instantiate nothing
                    }
                }
                else
                {
                    if (cellsTiles[1] != "0")
                    {
                        tileName = TileCodification.getTileName(cellsTiles[1]);
                        instantiateTile(tileName, new Vector3(TileCodification.TileSize * (colum), TileCodification.TileSize * ((rows - 1) - row), 0f));
                    }
                    else
                    {
                        //Instantiate nothing
                    }
                }
            }
            row++;
        }
        sr.Close();
    }
        public MainWindowViewModel(IModuleManager moduleManager, IRegionManager regionmanager, IUnityContainer container)
        {
            this.menuService = new MenuService();
            EditionInfoManager mgr         = new EditionInfoManager();
            EditionInfo        editioninfo = mgr.ReadFromFile();



            foreach (var section in editioninfo.Sections)
            {
                Section_MenuItem section_Menu = new Section_MenuItem(section.Name);
                this.menuService.AddMenuItem(section_Menu);

                foreach (var module in section.Modules)
                {
                    Modules_MenuItem item = new Modules_MenuItem(module, moduleManager, regionmanager, container);
                    this.menuService.AddMenuItem(item, section.Name);
                }
            }
        }
Example #3
0
    /// <summary>
    /// To save the level
    /// </summary>
    /// <param name="levelName">the level name</param>
    /// <param name="levelSize">level size in terms of number of rows and columns</param>
    /// <param name="tilesPlaced">The tiles placed</param>
    public bool saveLevel(EditionInfo editInformation)
    {
        //string levelName, Vector2 levelSize, List<TileInEditorWorldSpace.TileInWorldSpace> tilesPlaced
        if (verifSpawnPoint(editInformation.tilesPlaced))//If there is one spawn point
        {
            if (verifCratesPointAndCrates(editInformation.tilesPlaced))
            {
                if (editInformation.reeditingLevel)
                {
                    setLevelPath("temp_");
                }
                try
                {
                    StreamWriter sw = new StreamWriter(levelPath);
                    sw.WriteLine(editInformation.levelSize.x + "x" + editInformation.levelSize.y);

                    for (int row = (int)editInformation.levelSize.y - 1; row >= 0; row--)
                    {
                        string line = "";
                        for (int colum = 0; colum <= editInformation.levelSize.x - 1; colum++)
                        {
                            bool    swt1                 = false;
                            int     tileIndex            = 0;
                            Vector3 searchTileOnPosition = new Vector3(TileCodification.TileSize * colum, TileCodification.TileSize * row, 0);
                            while (tileIndex < editInformation.tilesPlaced.Count && swt1 == false)
                            {
                                if (editInformation.tilesPlaced[tileIndex].position == searchTileOnPosition)//Look for the actual tile, placed at the position (tileSize*row,tileSize*colum,0)
                                {
                                    swt1 = true;
                                }
                                else
                                {
                                    tileIndex++;
                                }
                            }
                            if (swt1)                                                                      //If found one
                            {
                                if (editInformation.tilesPlaced[tileIndex].tileGameObject.tag == "Ground") //Only if the Tile is a Ground Tile, we search again for another possible tile that could be over it
                                {
                                    //We make the second Search omiting the one we found
                                    bool swt2           = false;
                                    int  otherTileIndex = 0;
                                    while (otherTileIndex < editInformation.tilesPlaced.Count && !swt2)
                                    {
                                        if (editInformation.tilesPlaced[otherTileIndex].position == searchTileOnPosition && otherTileIndex != tileIndex)//Look for the actual tile, placed at the same position
                                        {
                                            swt2 = true;
                                        }
                                        else
                                        {
                                            otherTileIndex++;
                                        }
                                    }

                                    if (swt2)//if we found another tile over the first one
                                    {
                                        string fistTileCode   = TileCodification.getTileCode(editInformation.tilesPlaced[tileIndex].tileName);
                                        string secondTileCode = TileCodification.getTileCode(editInformation.tilesPlaced[otherTileIndex].tileName);
                                        if (colum == 0)
                                        {
                                            line = fistTileCode + "-" + secondTileCode;
                                        }
                                        else
                                        {
                                            line = line + ";" + fistTileCode + "-" + secondTileCode;
                                        }
                                    }
                                    else//Dind't found the posible second Tile
                                    {
                                        if (colum == 0)
                                        {
                                            line = TileCodification.getTileCode(editInformation.tilesPlaced[tileIndex].tileName) + "-0";
                                        }
                                        else
                                        {
                                            line = line + ";" + TileCodification.getTileCode(editInformation.tilesPlaced[tileIndex].tileName) + "-0";
                                        }
                                    }
                                }
                                else//Found a tile that isn't a ground tile
                                {
                                    if (colum == 0)
                                    {
                                        line = "0-" + TileCodification.getTileCode(editInformation.tilesPlaced[tileIndex].tileName);
                                    }
                                    else
                                    {
                                        line = line + ";0-" + TileCodification.getTileCode(editInformation.tilesPlaced[tileIndex].tileName);
                                    }
                                }
                            }
                            else//There is no tile there, so it's 0
                            {
                                if (colum == 0)
                                {
                                    line = "0-0";
                                }
                                else
                                {
                                    line = line + ";0-0";
                                }
                            }
                        }
                        //Debug.Log(line);
                        sw.WriteLine(line);
                    }
                    sw.Close();

                    if (editInformation.reeditingLevel)
                    {
                        string sourceFileName = levelPath;
                        setLevelPath(editionInfo.levelName);
                        string destFileName = levelPath;
                        File.Delete(destFileName);
                        File.Move(sourceFileName, destFileName);
                        File.Delete(sourceFileName);
                    }
                    ShowMessage.showMessageText("World Saved Succesfully", MessageType.Confirmation);
                    return(true);
                }
                catch (Exception e)
                {
                    Debug.Log(e.ToString());
                    ShowMessage.showMessageText(e.ToString(), MessageType.Error);
                }
            }
        }

        return(false);
    }
Example #4
0
 /// <summary>
 /// Constructor method of Editor Assistant
 /// </summary>
 public LevelEditorAssistant()
 {
     this.editionInfo = new EditionInfo();//Here we create the instance of edition info class we will need;
 }
Example #5
0
        public string GetEditionUrl(Guid secretkey)
        {
            var customer = _unitOfWork.CustomerRepository.GetBySecretKey(secretkey);

            Guid editionid = customer.EditionId.Value;

            //dir on webapi project where all editions zip files will be present.

            var dir = HttpContext.Current.Server.MapPath("~/Editions/");

            //dir of a edition

            var editionid_dir         = dir + editionid;
            var editition_modules_dir = editionid_dir + "//Modules";

            //dir where modules files are uploaded


            var modulesdir = System.IO.Path.Combine(HttpContext.Current.Server.MapPath("~/Modules/"));

            if (!System.IO.Directory.Exists(editionid_dir))
            {
                System.IO.Directory.CreateDirectory(editionid_dir);
                System.IO.Directory.CreateDirectory(editition_modules_dir);
                var edition = _unitOfWork.EditionRepository.Get(editionid, true);


                EditionInfo edition_info = new EditionInfo();

                foreach (var section in edition.Sections)
                {
                    var sectionvm = new SectionVm();

                    sectionvm.Name = section.Name;

                    foreach (var module in section.Modules)
                    {
                        ModuleVm module_vm = new ModuleVm();

                        string mdouleFile = module.TypeName + ".dll";

                        module_vm.TypeName = mdouleFile;
                        module_vm.Name     = module.Name;

                        string mdouleFilepath      = System.IO.Path.Combine(modulesdir, mdouleFile);;
                        string destinationFilepath = System.IO.Path.Combine(editition_modules_dir, mdouleFile);;

                        if (System.IO.File.Exists(mdouleFilepath))
                        {
                            System.IO.File.Copy(mdouleFilepath, destinationFilepath, true);
                        }


                        sectionvm.Modules.Add(module_vm);
                    }
                    edition_info.Sections.Add(sectionvm);
                }

                //create customer modules  information json file.
                string startPath = editionid_dir;

                var json = JsonHelper.Serialize(edition_info);

                System.IO.File.WriteAllText(startPath + "//edition_info.json", json);


                string zipPath = dir + editionid + ".zip";

                ZipFile.CreateFromDirectory(startPath, zipPath);
            }

            string baseUrl = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath.TrimEnd('/') + "/";

            return(baseUrl + "Editions/" + editionid + ".zip");
        }