private static void MakeCanon() { try { Manager.CheckDirectory("projects/" + cur, true); Manager.CheckDirectory("projects/" + cur + "/data", true); Manager.CheckDirectory("projects/" + cur + "/res", true); Manager.CheckDirectory("projects/" + cur + "/res/lynx2d", true); ExportHTML(); using (FileStream fs = new FileStream("projects/" + cur + "/data/game.js", FileMode.Create)) using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8)) { w.Write("lx.Initialize('" + cur + "'); lx.Smoothing(false); lx.Start(60);"); w.Close(); fs.Close(); } DownloadFramework(false); InstallResources(false); Engine.ClearEngine(); Engine.SaveEngineState(); } catch (Exception exc) { Feed.GiveException("Canon Creation", exc); } finally { Load(false); } }
public static void DownloadFramework(bool setsStatus) { if (!Feed.CheckOnline()) { MessageBox.Show("Reloading the framework requires a valid internet connection. The Lynx2D framework could not be downloaded.", "Lynx2D Engine - Message"); return; } try { using (WebClient client = new WebClient()) { client.DownloadFileCompleted += (object s, AsyncCompletedEventArgs e) => { if (setsStatus) { form.SetStatus("Downloaded Lynx2D framework.", Main.StatusType.Message); } form.RefreshBrowser(); client.Dispose(); }; client.DownloadFile(new Uri("http://www.lynx2d.com/res/lynx2d-min.js"), "projects/" + cur + "/data/lynx2d.js"); } } catch (Exception exc) { Feed.GiveException("Framework Reload", exc); } }
public static void OpenDirectory(string path) { try { Process.Start(path); } catch (Exception exc) { Feed.GiveException("Directory", exc); } }
public static void InstallResources(bool setsStatus) { try { int installed = 0; if (!File.Exists("projects/" + cur + "/res/lynx2d/sprite.png")) { Properties.Resources.sprite.Save("projects/" + cur + "/res/lynx2d/sprite.png"); installed++; } if (!File.Exists("projects/" + cur + "/res/lynx2d/pointer.png")) { Properties.Resources.pointer.Save("projects/" + cur + "/res/lynx2d/pointer.png"); installed++; } if (!File.Exists("projects/" + cur + "/res/lynx2d/particle.png")) { Properties.Resources.particle.Save("projects/" + cur + "/res/lynx2d/particle.png"); installed++; } if (!File.Exists("projects/" + cur + "/res/lynx2d/location.png")) { Properties.Resources.location.Save("projects/" + cur + "/res/lynx2d/location.png"); installed++; } if (setsStatus) { if (installed != 0) { form.SetStatus(installed + " Lynx2D resource(s) reloaded.", Main.StatusType.Message); } else { form.SetStatus("No Lynx2D resources are missing.", Main.StatusType.Message); } } } catch (Exception exc) { Feed.GiveException("Resources Reload", exc); } }
public void RemoveTile(int x, int y, int w, int h, bool converts) { x -= this.x; y -= this.y; try { if (x < 0 || y < 0) { return; } if (w == tilesize && h == tilesize) { if (map[x, y] != null && !map[x, y].build) { return; } map[x, y] = new Tile(); } else { for (int yy = 0; yy < h / tilesize; yy++) { for (int xx = 0; xx < w / tilesize; xx++) { RemoveTile(x + xx, y + yy, tilesize, tilesize, false); } } } if (converts) { Tilemapper.ConvertAndSetMap(this); } } catch (Exception exc) { Engine.ExecuteScript("lx.StopMouse(2);"); Feed.GiveException("Tile Remove", exc); } }
public static bool CopyFile(string source, string dest) { try { if (File.Exists(dest)) { return(false); } File.Copy(source, dest, true); return(true); } catch (Exception exc) { Feed.GiveException("File Copy", exc); } return(false); }
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); } }
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); } }