Example #1
0
        private static void ReadComponent(SaveReader sr)
        {
            String s = sr.ReadLine();

            if (s == "")
            {
                return;
            }
            int l = Convert.ToInt32(s.Substring(0, s.Length));

            if (l == 0)
            {
                return;
            }
            s = ReadBlock(sr, l + 2);
            //important
            //important
            if (s == "")
            {
                return;
            }
            ComponentData c = new ComponentData(s);

            s = sr.ReadLine();
            //s = sr.ReadLine();
            c.Load();
            System.Threading.Thread.Sleep(1);//TODO mb remove. for decoration
        }
Example #2
0
        internal static String ReadBlock(SaveReader sr, int n)
        {
            char[] buf = new char[n];
            sr.ReadBlock(buf, 0, n);
            String r = "";

            for (int i = 0; i < n; i++)
            {
                r += buf[i];
            }
            return(r);
        }
Example #3
0
        public static void loadAllDefault(String filename)
        {
            LastLoadedFile = filename;

            if (!System.IO.File.Exists(filename))
            {
                return;
            }
            isLoading = true;

            Graphics.GUI.GUIEngine.s_loading.LoadingMainText = "Reading components from file...";

            SaveReader sr = new SaveReader(filename);

            //version check
            String tvc = sr.ReadLine();

            if (!IsVersionCompatable(tvc))
            {
                Graphics.GUI.Scene.OKMessageBox.Show("Incompatible saves file!");
                isLoading = false;
                return;
            }

            ReadCameraInfo(sr);

            LoadPlacableAreas(ref sr);
            Components.ComponentsManager.Clear();
            int c = 0;

            while (sr.Peek() > -1)
            {
                System.Threading.Thread.Sleep(1);
                c++;
                Graphics.GUI.GUIEngine.s_loading.LoadingDescriptiveText = c.ToString() + " Component(s) found...";
                ReadComponent(sr);
            }
            Graphics.GUI.GUIEngine.s_loading.LoadingDescriptiveText = "Post-Loading components...";
            Components.ComponentsManager.PostLoad();
            Components.ComponentsManager.InitAllComponents();
            Components.ComponentsManager.PostPostLoad();
            isLoading = false;
            GlobalEvents.OnLevelLoaded();
            Logics.GameLogicsHelper.GameStart();
        }
Example #4
0
        private static void ReadCameraInfo(SaveReader sr)
        {
            Shortcuts.camera.Scale = (float)Convert.ToDouble(sr.ReadLine());

            Shortcuts.camera.Center = new Microsoft.Xna.Framework.Vector2((float)Convert.ToDouble(sr.ReadLine()), (float)Convert.ToDouble(sr.ReadLine()));

            int x = Convert.ToInt32(sr.ReadLine()),
                y = Convert.ToInt32(sr.ReadLine()),
                w = Convert.ToInt32(sr.ReadLine()),
                h = Convert.ToInt32(sr.ReadLine());

            if (w < 0 || h < 0)
            {
                Shortcuts.camera.AllowedVisibleRectangle = null;
            }
            else
            {
                Shortcuts.camera.AllowedVisibleRectangle = new Microsoft.Xna.Framework.Rectangle(x, y, w, h);
            }
        }
Example #5
0
        private static void LoadPlacableAreas(ref SaveReader sr)//TODO move to PlacableAreasManager
        {
            Logics.PlacableAreasManager.Clear();
            String s = sr.ReadLine();

            if (s == "0")
            {
                return;
            }
            s = ReadBlock(sr, Convert.ToInt32(s));
            var a = s.Split('\n');

            for (int i = 0; i < a.Length; i++)
            {
                if (a[i].Length < 2)
                {
                    continue;
                }
                var b = a[i].Split(';');
                Logics.PlacableAreasManager.Add(new Microsoft.Xna.Framework.Rectangle(
                                                    Convert.ToInt32(b[0]), Convert.ToInt32(b[1]), Convert.ToInt32(b[2]), Convert.ToInt32(b[3])));
            }
        }
Example #6
0
        public static void loadAllLevelDesigner(String filename)
        {
            LastLoadedFile = filename;

            if (!System.IO.File.Exists(filename))
            {
                return;
            }
            isLoading = true;

            Graphics.GUI.GUIEngine.s_loading.LoadingMainText = "Reading components from file...";

            SaveReader sr = new SaveReader(filename);

            //version check
            String tvc = sr.ReadLine();

            if (!IsVersionCompatable(tvc))
            {
                Graphics.GUI.Scene.OKMessageBox.Show("Incompatible saves file!");
                isLoading = false;
                return;
            }

            ReadCameraInfo(sr);
            Shortcuts.camera.AllowedVisibleRectangle = null;

            if (sr.ReadLine() != "l")
            {
                sr.Close();
                Main.Close();
                isLoading = false;
                return;
            }
            if (!Graphics.GUI.GUIEngine.s_levelSelection.ReadSaveInfo(ref sr, false))
            {
                isLoading = false;
                return;
            }
            else
            {
                if (System.IO.File.Exists(filename.Substring(0, filename.Length - 4) + ".lua"))
                {
                    SaveReader tssr = new SaveReader(filename.Substring(0, filename.Length - 4) + ".lua");
                    Graphics.GUI.GUIEngine.s_scriptEditor.Text = tssr.ReadToEnd();
                    tssr.Close();
                }
                Logics.LevelEngine.Stop();
            }
            Logics.LevelEngine.Load(ref sr);
            LoadPlacableAreas(ref sr);
            Components.ComponentsManager.Clear();
            int c = 0;

            while (sr.Peek() > -1)
            {
                System.Threading.Thread.Sleep(1);
                c++;
                Graphics.GUI.GUIEngine.s_loading.LoadingDescriptiveText = c.ToString() + " Component(s) found...";
                ReadComponent(sr);
            }
            Graphics.GUI.GUIEngine.s_loading.LoadingDescriptiveText = "Post-Loading components...";
            Components.ComponentsManager.PostLoad();
            Components.ComponentsManager.InitAllComponents();
            Components.ComponentsManager.PostPostLoad();
            isLoading = false;
            GlobalEvents.OnLevelLoaded();
            Logics.GameLogicsHelper.GameStart();
        }
Example #7
0
        public static void loadAllDefault(String filename)
        {
            LastLoadedFile = filename;

            if (!System.IO.File.Exists(filename)) return;
            isLoading = true;

            Graphics.GUI.GUIEngine.s_loading.LoadingMainText = "Reading components from file...";

            SaveReader sr = new SaveReader(filename);

            //version check
            String tvc = sr.ReadLine();
            if (!IsVersionCompatable(tvc))
            {
                Graphics.GUI.Scene.OKMessageBox.Show("Incompatible saves file!");
                isLoading = false;
                return;
            }

            ReadCameraInfo(sr);

            LoadPlacableAreas(ref sr);
            Components.ComponentsManager.Clear();
            int c = 0;
            while (sr.Peek() > -1)
            {
                System.Threading.Thread.Sleep(1);
                c++;
                Graphics.GUI.GUIEngine.s_loading.LoadingDescriptiveText = c.ToString() + " Component(s) found...";
                ReadComponent(sr);
            }
            Graphics.GUI.GUIEngine.s_loading.LoadingDescriptiveText = "Post-Loading components...";
            Components.ComponentsManager.PostLoad();
            Components.ComponentsManager.InitAllComponents();
            Components.ComponentsManager.PostPostLoad();
            isLoading = false;
            GlobalEvents.OnLevelLoaded();
            Logics.GameLogicsHelper.GameStart();
        }
Example #8
0
 private static void ReadComponent(SaveReader sr)
 {
     String s = sr.ReadLine();
     if (s == "") return;
     int l = Convert.ToInt32(s.Substring(0, s.Length));
     if (l == 0) return;
     s = ReadBlock(sr, l + 2);
     //important
     //important
     if (s == "") return;
     ComponentData c = new ComponentData(s);
     s = sr.ReadLine();
     //s = sr.ReadLine();
     c.Load();
     System.Threading.Thread.Sleep(1);//TODO mb remove. for decoration
 }
Example #9
0
        private static void ReadCameraInfo(SaveReader sr)
        {
            Shortcuts.camera.Scale = (float)Convert.ToDouble(sr.ReadLine());

            Shortcuts.camera.Center = new Microsoft.Xna.Framework.Vector2((float)Convert.ToDouble(sr.ReadLine()), (float)Convert.ToDouble(sr.ReadLine()));

            int x = Convert.ToInt32(sr.ReadLine()),
                y = Convert.ToInt32(sr.ReadLine()),
                w = Convert.ToInt32(sr.ReadLine()),
                h = Convert.ToInt32(sr.ReadLine());
            if (w < 0 || h < 0)
                Shortcuts.camera.AllowedVisibleRectangle = null;
            else
                Shortcuts.camera.AllowedVisibleRectangle = new Microsoft.Xna.Framework.Rectangle(x, y, w, h);
        }
Example #10
0
 //TODO move to PlacableAreasManager
 private static void LoadPlacableAreas(ref SaveReader sr)
 {
     Logics.PlacableAreasManager.Clear();
     String s = sr.ReadLine();
     if (s == "0") return;
     s = ReadBlock(sr, Convert.ToInt32(s));
     var a = s.Split('\n');
     for (int i = 0; i < a.Length; i++)
     {
         if (a[i].Length < 2) continue;
         var b = a[i].Split(';');
         Logics.PlacableAreasManager.Add(new Microsoft.Xna.Framework.Rectangle(
             Convert.ToInt32(b[0]), Convert.ToInt32(b[1]), Convert.ToInt32(b[2]), Convert.ToInt32(b[3])));
     }
 }
Example #11
0
 internal static String ReadBlock(SaveReader sr, int n)
 {
     char[] buf = new char[n];
     sr.ReadBlock(buf, 0, n);
     String r = "";
     for (int i = 0; i < n; i++)
     {
         r += buf[i];
     }
     return r;
 }
Example #12
0
        public static void loadAllLevelDesigner(String filename)
        {
            LastLoadedFile = filename;

            if (!System.IO.File.Exists(filename)) return;
            isLoading = true;

            Graphics.GUI.GUIEngine.s_loading.LoadingMainText = "Reading components from file...";

            SaveReader sr = new SaveReader(filename);

            //version check
            String tvc = sr.ReadLine();
            if (!IsVersionCompatable(tvc))
            {
                Graphics.GUI.Scene.OKMessageBox.Show("Incompatible saves file!");
                isLoading = false;
                return;
            }

            ReadCameraInfo(sr);
            Shortcuts.camera.AllowedVisibleRectangle = null;

            if (sr.ReadLine() != "l")
            {
                sr.Close();
                Main.Close();
                isLoading = false;
                return;
            }
            if (!Graphics.GUI.GUIEngine.s_levelSelection.ReadSaveInfo(ref sr, false))
            {
                isLoading = false;
                return;
            }
            else
            {
                if (System.IO.File.Exists(filename.Substring(0, filename.Length - 4) + ".lua"))
                {
                    SaveReader tssr = new SaveReader(filename.Substring(0, filename.Length - 4) + ".lua");
                    Graphics.GUI.GUIEngine.s_scriptEditor.Text = tssr.ReadToEnd();
                    tssr.Close();
                }
                Logics.LevelEngine.Stop();
            }
            Logics.LevelEngine.Load(ref sr);
            LoadPlacableAreas(ref sr);
            Components.ComponentsManager.Clear();
            int c = 0;
            while (sr.Peek() > -1)
            {
                System.Threading.Thread.Sleep(1);
                c++;
                Graphics.GUI.GUIEngine.s_loading.LoadingDescriptiveText = c.ToString() + " Component(s) found...";
                ReadComponent(sr);
            }
            Graphics.GUI.GUIEngine.s_loading.LoadingDescriptiveText = "Post-Loading components...";
            Components.ComponentsManager.PostLoad();
            Components.ComponentsManager.InitAllComponents();
            Components.ComponentsManager.PostPostLoad();
            isLoading = false;
            GlobalEvents.OnLevelLoaded();
            Logics.GameLogicsHelper.GameStart();
        }