Example #1
0
    IEnumerator LoadingFile()
    {
        while (SavingMapProcess)
            yield return null;

        Undo.Current.Clear();

        bool AllFilesExists = true;
        string Error = "";
        if (!System.IO.Directory.Exists(FolderParentPath))
        {
            Error = "Map folder does not exist:\n" + FolderParentPath;
            Debug.LogWarning(Error);
            AllFilesExists = false;
        }

        if (AllFilesExists && !System.IO.File.Exists(LoadedMapFolderPath + ScenarioFileName + ".lua"))
        {
            AllFilesExists = SearchForScenario();

            if (!AllFilesExists)
            {
                Error = "Scenario.lua does not exist:\n" + LoadedMapFolderPath + ScenarioFileName + ".lua";
                Debug.LogWarning(Error);
            }
        }

        if (AllFilesExists)
        {
            string ScenarioText = System.IO.File.ReadAllText(LoadedMapFolderPath + ScenarioFileName + ".lua");

            if (!ScenarioText.StartsWith("version = 3") && ScenarioText.StartsWith("version ="))
            {
                AllFilesExists = SearchForScenario();

                if (!AllFilesExists)
                {
                    Error = "Wrong scenario file version. Should be 3, is " + ScenarioText.Remove(11).Replace("version =", "");
                    Debug.LogWarning(Error);
                }
            }

            if (AllFilesExists && !ScenarioText.StartsWith("version = 3"))
            {
                AllFilesExists = SearchForScenario();

                if (!AllFilesExists)
                {
                    Error = "Selected file is not a proper scenario.lua file. ";
                    Debug.LogWarning(Error);
                }
            }
        }

        if (AllFilesExists && !System.IO.File.Exists(EnvPaths.GamedataPath + "/env.scd"))
        {
            Error = "No source files in gamedata folder: " + EnvPaths.GamedataPath;
            Debug.LogWarning(Error);
            AllFilesExists = false;
        }

        if (AllFilesExists)
        {
            // Begin load
            LoadRecentMaps.MoveLastMaps(ScenarioFileName, FolderName, FolderParentPath);
            LoadingMapProcess = true;
            InfoPopup.Show(true, "Loading map...\n( " + ScenarioFileName + ".lua" + " )");
            EditMenu.gameObject.SetActive(true);
            Background.SetActive(false);
            yield return null;

            ScenarioLuaFile = new ScenarioLua();
            SaveLuaFile = new SaveLua();
            TablesLuaFile = new TablesLua();
            AsyncOperation ResUn = Resources.UnloadUnusedAssets();
            while (!ResUn.isDone)
            {
                yield return null;
            }

            // Scenario LUA
            if (ScenarioLuaFile.Load(FolderName, ScenarioFileName, FolderParentPath))
            {
                //Map Loaded
                MapCenterPoint = Vector3.zero;
                MapCenterPoint.x = (GetMapSizeX() / 20f);
                MapCenterPoint.z = -1 * (GetMapSizeY() / 20f);
            }

            CameraControler.Current.MapSize = Mathf.Max(ScenarioLuaFile.Data.Size[0], ScenarioLuaFile.Data.Size[1]);
            CameraControler.Current.RestartCam();

            InfoPopup.Show(true, "Loading map...\n(" + ScenarioLuaFile.Data.map + ")");
            yield return null;

            // SCMAP
            LoadScmapFile = HeightmapControler.StartCoroutine(ScmapEditor.Current.LoadScmapFile());
            System.GC.Collect();

            yield return LoadScmapFile;

            if(ScmapEditor.Current.map.VersionMinor == 0)
            {
                Error = "scmap file not loaded!\n" + MapLuaParser.Current.ScenarioLuaFile.Data.map;

                InfoPopup.Show(false);
                LoadingMapProcess = false;
                ResetUI();
                ReturnLoadingWithError(Error);

                yield return null;
                StopCoroutine(LoadingFileCoroutine);
            }

            CameraControler.Current.RestartCam();

            if (HeightmapControler.map.VersionMinor >= 60)
                EditMenu.MapInfoMenu.SaveAsFa.isOn = true;
            else
                EditMenu.MapInfoMenu.SaveAsSc.isOn = true;

            InfoPopup.Show(true, "Loading map...\n(" + ScenarioLuaFile.Data.save + ")");
            yield return null;

            if (loadSave)
            {
                // Save LUA
                SaveLuaFile.Load();
                SetSaveLua();
                System.GC.Collect();
                //LoadSaveLua();
                yield return null;

                Coroutine UnitsLoader = StartCoroutine(SaveLuaFile.LoadUnits());
                yield return UnitsLoader;
            }

            // Load Props
            if (LoadProps)
            {
                PropsMenu.gameObject.SetActive(true);

                PropsMenu.AllowBrushUpdate = false;
                PropsMenu.StartCoroutine(PropsMenu.LoadProps());
                while (PropsMenu.LoadingProps)
                {
                    InfoPopup.Show(true, "Loading map...\n( Loading props " + PropsMenu.LoadedCount + "/" + ScmapEditor.Current.map.Props.Count + ")");
                    yield return null;
                }
                System.GC.Collect();
                PropsMenu.gameObject.SetActive(false);
            }

            if (LoadDecals)
            {
                DecalsMenu.gameObject.SetActive(true);

                //DecalsMenu.AllowBrushUpdate = false;
                DecalsMenu.StartCoroutine(DecalsMenu.LoadDecals());
                while (DecalsInfo.LoadingDecals)
                {
                    InfoPopup.Show(true, "Loading map...\n( Loading decals " + DecalsMenu.LoadedCount + "/" + ScmapEditor.Current.map.Decals.Count + ")");
                    yield return null;
                }
                System.GC.Collect();
                DecalsMenu.gameObject.SetActive(false);
            }

            if (TablesLuaFile.Load(FolderName, ScenarioFileName, FolderParentPath))
            {
                //Map Loaded
            }

            int ParsedVersionValue = AppMenu.GetVersionControll(FolderName);

            if(ParsedVersionValue > 0)
            {
                ScenarioLuaFile.Data.map_version = ParsedVersionValue;
            }

            InfoPopup.Show(false);
            WindowStateSever.WindowStateSaver.ChangeWindowName(FolderName);
            LoadingMapProcess = false;

            RenderMarkersConnections.Current.UpdateConnections();

            EditMenu.Categorys[0].GetComponent<MapInfo>().UpdateFields();

            MapLuaParser.Current.UpdateArea();

            GenericInfoPopup.ShowInfo("Map successfully loaded!\n" + FolderName + "/" + ScenarioFileName + ".lua");
        }
        else
        {
            ResetUI();
            ReturnLoadingWithError(Error);

        }
    }
Example #2
0
    IEnumerator LoadingFile()
    {
        while (SavingMapProcess)
        {
            yield return(null);
        }

        Undo.Current.Clear();

        bool   AllFilesExists = true;
        string Error          = "";

        if (!System.IO.Directory.Exists(FolderParentPath))
        {
            Error = "Map folder does not exist:\n" + FolderParentPath;
            Debug.LogWarning(Error);
            AllFilesExists = false;
        }

        if (AllFilesExists && !System.IO.File.Exists(LoadedMapFolderPath + ScenarioFileName + ".lua"))
        {
            AllFilesExists = SearchForScenario();

            if (!AllFilesExists)
            {
                Error = "Scenario.lua does not exist:\n" + LoadedMapFolderPath + ScenarioFileName + ".lua";
                Debug.LogWarning(Error);
            }
        }

        if (AllFilesExists)
        {
            string ScenarioText = System.IO.File.ReadAllText(LoadedMapFolderPath + ScenarioFileName + ".lua");

            if (!ScenarioText.StartsWith("version = 3") && ScenarioText.StartsWith("version ="))
            {
                AllFilesExists = SearchForScenario();

                if (!AllFilesExists)
                {
                    Error = "Wrong scenario file version. Should be 3, is " + ScenarioText.Remove(11).Replace("version =", "");
                    Debug.LogWarning(Error);
                }
            }


            if (AllFilesExists && !ScenarioText.StartsWith("version = 3"))
            {
                AllFilesExists = SearchForScenario();

                if (!AllFilesExists)
                {
                    Error = "Selected file is not a proper scenario.lua file. ";
                    Debug.LogWarning(Error);
                }
            }
        }

        if (AllFilesExists && !System.IO.File.Exists(EnvPaths.GamedataPath + "/env.scd"))
        {
            Error = "No source files in gamedata folder: " + EnvPaths.GamedataPath;
            Debug.LogWarning(Error);
            AllFilesExists = false;
        }

        if (AllFilesExists)
        {
            // Begin load
            LoadRecentMaps.MoveLastMaps(ScenarioFileName, FolderName, FolderParentPath);
            LoadingMapProcess = true;
            InfoPopup.Show(true, "Loading map...\n( " + ScenarioFileName + ".lua" + " )");
            EditMenu.gameObject.SetActive(true);
            Background.SetActive(false);
            yield return(null);

            ScenarioLuaFile = new ScenarioLua();
            SaveLuaFile     = new SaveLua();
            TablesLuaFile   = new TablesLua();
            AsyncOperation ResUn = Resources.UnloadUnusedAssets();
            while (!ResUn.isDone)
            {
                yield return(null);
            }

            // Scenario LUA
            if (ScenarioLuaFile.Load(FolderName, ScenarioFileName, FolderParentPath))
            {
                //Map Loaded
            }


            CameraControler.Current.MapSize = Mathf.Max(ScenarioLuaFile.Data.Size[0], ScenarioLuaFile.Data.Size[1]);
            CameraControler.Current.RestartCam();


            InfoPopup.Show(true, "Loading map...\n(" + ScenarioLuaFile.Data.map + ")");
            yield return(null);

            // SCMAP
            LoadScmapFile = HeightmapControler.StartCoroutine(ScmapEditor.Current.LoadScmapFile());
            yield return(LoadScmapFile);

            CameraControler.Current.RestartCam();

            EditMenu.MapInfoMenu.SaveAsFa.isOn = HeightmapControler.map.VersionMinor >= 60;
            EditMenu.MapInfoMenu.SaveAsSc.isOn = !EditMenu.MapInfoMenu.SaveAsFa.isOn;

            InfoPopup.Show(true, "Loading map...\n(" + ScenarioLuaFile.Data.save + ")");
            yield return(null);

            if (loadSave)
            {
                // Save LUA
                SaveLuaFile.Load();
                SetSaveLua();
                //LoadSaveLua();
                yield return(null);

                Coroutine UnitsLoader = StartCoroutine(SaveLuaFile.LoadUnits());
                yield return(UnitsLoader);
            }

            //GetGamedataFile.LoadUnit("XEL0209").CreateUnitObject(MapLuaParser.Current.MapCenterPoint, Quaternion.identity);

            //GetGamedataFile.LoadUnit("UEB0201").CreateUnitObject(MapLuaParser.Current.MapCenterPoint + Vector3.forward * 0.7f, Quaternion.identity);

            //GetGamedataFile.LoadUnit("UEL0001").CreateUnitObject(MapLuaParser.Current.MapCenterPoint + Vector3.left * 0.3f, Quaternion.identity);

            /*
             * //4k Sparkys with GPU instancing
             * for (int x = 0; x < 63; x++)
             * {
             *      for(int y = 0; y < 63; y++)
             *      {
             *              Vector3 Pos = MapLuaParser.Current.MapCenterPoint + new Vector3(x * -0.1f, 0, y * -0.1f);
             *              GetGamedataFile.LoadUnit("XEL0209").CreateUnitObject(Pos, Quaternion.identity);
             *      }
             * }
             */

            // Load Props
            if (LoadProps)
            {
                PropsMenu.gameObject.SetActive(true);

                PropsMenu.AllowBrushUpdate = false;
                PropsMenu.StartCoroutine(PropsMenu.LoadProps());
                while (PropsMenu.LoadingProps)
                {
                    InfoPopup.Show(true, "Loading map...\n( Loading props " + PropsMenu.LoadedCount + "/" + ScmapEditor.Current.map.Props.Count + ")");
                    yield return(null);
                }

                PropsMenu.gameObject.SetActive(false);
            }

            if (LoadDecals)
            {
                DecalsMenu.gameObject.SetActive(true);

                //DecalsMenu.AllowBrushUpdate = false;
                DecalsMenu.StartCoroutine(DecalsMenu.LoadDecals());
                while (DecalsInfo.LoadingDecals)
                {
                    InfoPopup.Show(true, "Loading map...\n( Loading decals " + DecalsMenu.LoadedCount + "/" + ScmapEditor.Current.map.Decals.Count + ")");
                    yield return(null);
                }

                DecalsMenu.gameObject.SetActive(false);
            }

            if (TablesLuaFile.Load(FolderName, ScenarioFileName, FolderParentPath))
            {
                //Map Loaded
            }

            InfoPopup.Show(false);
            WindowStateSever.WindowStateSaver.ChangeWindowName(FolderName);
            LoadingMapProcess = false;


            RenderMarkersConnections.Current.UpdateConnections();

            EditMenu.Categorys[0].GetComponent <MapInfo>().UpdateFields();

            MapLuaParser.Current.UpdateArea();

            GenericInfoPopup.ShowInfo("Map successfully loaded!\n" + FolderName + "/" + ScenarioFileName + ".lua");
        }
        else
        {
            ResetUI();
            ReturnLoadingWithError(Error);
        }
    }