Exemple #1
0
        public static async void Export()
        {
            if (cur == string.Empty || cur == "HAS_BEEN_CLOSED")
            {
                return;
            }

            bool obfuscated = false;

            form.SetStatus("Started exporting project.", Main.StatusType.Message);

            Save();
            ExportHTML();

            gameCode = (Engine.bSettings.mergeFramework ? File.ReadAllText("projects/" + cur + "/data/lynx2d.js") : "") + "lx.Initialize('" + cur + "'); lx.Smoothing(" + Engine.bSettings.imageSmoothing.ToString().ToLower() + ");";
            Engine.BuildEngineCode(true);

            gameCode += "lx.Start(" + Engine.bSettings.initialFramerate + ")";

            using (FileStream fs = new FileStream("projects/" + cur + "/data/game.js", FileMode.Create))
                using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8))
                {
                    if (Engine.bSettings.obfuscates)
                    {
                        if (!Feed.CheckOnline())
                        {
                            form.SetStatus("Game obfuscation requires a internet connection.", Main.StatusType.Warning);
                        }
                        else
                        {
                            form.SetStatus("Obfuscating game code.", Main.StatusType.Message);

                            try
                            {
                                string r = await Obfuscator.Encode(gameCode);

                                gameCode = r;

                                obfuscated = true;
                            }
                            catch
                            {
                                form.SetStatus("Could not obfuscate game code.", Main.StatusType.Warning);
                            }
                        }
                    }

                    w.Write(gameCode);

                    w.Close();
                    fs.Close();
                }

            gameCode = "lx.Initialize('" + cur + "'); lx.Smoothing(true); lx.Start(60);";

            if (obfuscated || !Engine.bSettings.obfuscates)
            {
                form.SetStatus("'" + cur + "' has been exported.", Main.StatusType.Message);

                Manager.OpenDirectory(@WorkDirectory());
            }
        }
Exemple #2
0
        public static void Load(bool needsName)
        {
            form.killChildren();
            string old_cur = cur;

            if (!Manager.CheckDirectory("projects", false) || Directory.GetDirectories("projects/").Length == 0)
            {
                MessageBox.Show("No projects could be found. Please create a project first.", "Lynx2D Engine - Error");
                return;
            }

            if (cur != string.Empty)
            {
                RemoveEngineHTML();

                if (needsName)
                {
                    RequestSave();
                }
            }

            string[] projects = Directory.GetDirectories("projects/");
            for (int i = 0; i < projects.Length; i++)
            {
                projects[i] = projects[i].Substring(9, projects[i].Length - 9);
            }

            if (needsName)
            {
                cur = Input.Selection("Choose an existing project", "Load Project", projects);
            }

            if (cur == "HAS_BEEN_CLOSED")
            {
                cur = old_cur;

                return;
            }

            if (!Manager.CheckDirectory("projects/" + cur, false))
            {
                cur = old_cur;

                Load(needsName);
                return;
            }

            try
            {
                InstallEngineHTML();

                if (!Engine.LoadEngineState())
                {
                    cur = string.Empty;

                    RemoveEngineHTML();

                    return;
                }

                gameCode = "lx.Initialize('" + cur + "'); lx.Smoothing(true); lx.Start(60);";

                Manager.ClearAppData();
                Backup.Disable();
                Backup.Enable();

                form.CreateBrowser();

                form.LoadEngineSettings();

                form.SetTitle();
                form.SetStatus("'" + cur + "' has been loaded.", Main.StatusType.Message);

                form.SetGameAvailability(true);
                form.RefreshBrowser();

                Feed.CheckFrameworkDate();
            }
            catch (Exception exc)
            {
                Feed.GiveException("Project Load", exc);
            }
        }
Exemple #3
0
        public void SetTile(int x, int y, Tile t, bool converts)
        {
            x -= this.x;
            y -= this.y;

            try
            {
                if (x < 0 || y < 0)
                {
                    return;
                }

                if (x >= map.GetLength(0))
                {
                    Resize(x + 1, map.GetLength(1));
                }
                if (y >= map.GetLength(1))
                {
                    Resize(map.GetLength(0), y + 1);
                }

                if (map[x, y] != null &&
                    map[x, y].build &&
                    map[x, y].cX == Tilemapper.selected.cX &&
                    map[x, y].cY == Tilemapper.selected.cY &&
                    map[x, y].r == Tilemapper.selected.r)
                {
                    return;
                }

                if (t.cW == tilesize && t.cH == tilesize)
                {
                    t.build   = true;
                    map[x, y] = t;
                }
                else
                {
                    for (int yy = 0; yy < t.cH / tilesize; yy++)
                    {
                        for (int xx = 0; xx < t.cW / tilesize; xx++)
                        {
                            Tile tt = new Tile()
                            {
                                sprite = t.sprite,
                                cX     = t.cX + xx * tilesize,
                                cY     = t.cY + yy * tilesize,
                                cW     = tilesize,
                                cH     = tilesize,
                                build  = true
                            };

                            SetTile(x + this.x + xx, y + this.y + yy, tt, false);
                        }
                    }
                }

                if (converts)
                {
                    Tilemapper.ConvertAndSetMap(this);
                }
            }
            catch (Exception exc)
            {
                Engine.ExecuteScript("lx.StopMouse(0);");

                Feed.GiveException("Tile Set", exc);
            }
        }