/// <summary> /// Autodetect the ExeFile and CdPath of 'gi' only if no ExeFile given yet. /// Store the detected ExeFile/CdPath into gi. /// PRECONDITION: caller has changed / cd'ed to folder gi.GameFolder already. /// </summary> /// <param name="gi"></param> protected void AutoDetectExeFileIfNeeded(GardenItem gi) { // check if autodetection is needed - only if exe not given if (gi.ExeFile.Length > 0) return; // search for .exe files in gamefolder, recursively DirectoryInfo gameFolderInfo = new DirectoryInfo("."); if(!gameFolderInfo.Exists) return; FileInfo[] aFi = gameFolderInfo.GetFiles("*.exe", SearchOption.AllDirectories); if (aFi.Length == 0) return; // get the exe's name and store in gi FileInfo exeFile = aFi[0]; gi.ExeFile = exeFile.Name; // get the CD path and store in gi DirectoryInfo cdPathInfo = exeFile.Directory; List<string> dirs = new List<string>(); while (cdPathInfo.FullName != gameFolderInfo.FullName) { dirs.Insert(0, cdPathInfo.Name); cdPathInfo = cdPathInfo.Parent; } if (dirs.Count > 0) gi.CdPath = Path.Combine(dirs.ToArray()); }
/// <summary> /// (re)load information from default binary (protocol buffers) config file(s) of a specific version number /// </summary> /// <param name="version">version number is required since there may be multiple gamelib versions on disk to choose from</param> /// <exception cref="">various IO exceptions may occur when library file could not be found/loaded</exception> public void LoadBin(int version) { GardenItem g = GardenItem.ConstructGameLibItem(version); string fn = g.GameFolder + "\\" + GardenConfig.Instance.GameLibraryFilenameBin; LoadBin(fn); this.version = version; }
public static GardenItem ConstructGameLibItem(int version) { GardenItem g = new GardenItem(); g.Version = version; g.GameID = "gwg_gamelib_fmt4"; // TODO to config constants? g.ExeFile = "gamelib.bin"; g.PackedFileURL = GardenConfig.Instance.ConfigFilesServerURL + "gamelib.zip"; return(g); }
public List <GardenItem> GetItemsAround(int x, int y, int range) { int x1 = x - range; int x2 = x + range; int y1 = y - range; int y2 = y + range; if (x1 < 0) { x1 = 0; } if (x2 < 0) { x2 = 0; } if (y1 < 0) { y1 = 0; } if (y2 < 0) { y2 = 0; } if (x1 >= sizeX) { x1 = sizeX - 1; } if (x2 >= sizeX) { x2 = sizeX - 1; } if (y1 >= sizeY) { y1 = sizeY - 1; } if (y2 >= sizeY) { y2 = sizeY - 1; } List <GardenItem> l = new List <GardenItem>(); for (int ix = x1; ix < x2; ix++) { for (int iy = y1; iy < y2; iy++) { GardenItem g = matrix[ix, iy]; if (g != null) { l.Add(g); } } } return(l); }
/// <summary> /// Autodetect the ExeFile and CdPath of 'gi' only if no ExeFile given yet. /// Store the detected ExeFile/CdPath into gi. /// PRECONDITION: caller has changed / cd'ed to folder gi.GameFolder already. /// </summary> /// <param name="gi"></param> protected void AutoDetectExeFileIfNeeded(GardenItem gi) { // check if autodetection is needed - only if exe not given if (gi.ExeFile.Length > 0) { return; } // search for .exe files in gamefolder, recursively DirectoryInfo gameFolderInfo = new DirectoryInfo("."); if (!gameFolderInfo.Exists) { return; } // try various executable types string[] aExeTypes = { "*.exe", "*.bat", "*.swf", "*.jar", "index.html", "*.html", "*.zip", "README*" }; FileInfo[] aFi = new FileInfo[] { }; for (int i = 0; i < aExeTypes.Length; i++) { aFi = gameFolderInfo.GetFiles("*.exe", SearchOption.AllDirectories); if (aFi.Length > 0) { break; // exit loop if an item found } } // stop trying if no items found if (aFi.Length == 0) { return; } // get the exe's name and store in gi FileInfo exeFile = aFi[0]; gi.ExeFile = exeFile.Name; // get the CD path and store in gi DirectoryInfo cdPathInfo = exeFile.Directory; List <string> dirs = new List <string>(); while (cdPathInfo.FullName != gameFolderInfo.FullName) { dirs.Insert(0, cdPathInfo.Name); cdPathInfo = cdPathInfo.Parent; } if (dirs.Count > 0) { gi.CdPath = Path.Combine(dirs.ToArray()); } }
public SiteLauncherTask(GardenItem g, string url) { this.Game = g; if (url.Length > 0) { if (!url.ToLower().StartsWith("http://")) { url = "http://" + url; } filePath = url; } }
public GameThumbnail(GardenItem game) : base((Texture2D) null, "GameThumbnail") { ColorB = new ColorChangeBehavior(); Add(ColorB); Motion.Scale = GardenGamesPanel.THUMBNAIL_SCALE_UNSELECTED; Game = game; // effect is still off if no bitmap loaded yet EffectEnabled = false; // first-time texture init if (DefaultTexture == null) { DefaultTexture = GardenGame.Instance.Content.Load<Texture2D>("ball-supernova2"); } // use default texture as long as thumbnail not loaded yet Texture = DefaultTexture; }
/// <summary> /// get file path to locally stored thumbnail file for game /// </summary> /// <param name="g"></param> /// <returns>by default a .png thumbnail for a game (whether file exists or not) /// but if a .jpg thumbnail exists, it is chosen.</returns> public string GetThumbnailFilepath(GardenItem g) { string p1 = Path.Combine(ThumbnailsFolder, g.GameIDwithVersion); string p2 = p1; p1 += ".jpg"; p2 += ".png"; if (File.Exists(p2)) { return(p2); } else if (File.Exists(p1)) { return(p1); } else { return(p2); } }
/// <summary> /// Autodetect the ExeFile and CdPath of 'gi' only if no ExeFile given yet. /// Store the detected ExeFile/CdPath into gi. /// PRECONDITION: caller has changed / cd'ed to folder gi.GameFolder already. /// </summary> /// <param name="gi"></param> protected void AutoDetectExeFileIfNeeded(GardenItem gi) { // check if autodetection is needed - only if exe not given if (gi.ExeFile.Length > 0) { return; } // search for .exe files in gamefolder, recursively DirectoryInfo gameFolderInfo = new DirectoryInfo("."); if (!gameFolderInfo.Exists) { return; } FileInfo[] aFi = gameFolderInfo.GetFiles("*.exe", SearchOption.AllDirectories); if (aFi.Length == 0) { return; } // get the exe's name and store in gi FileInfo exeFile = aFi[0]; gi.ExeFile = exeFile.Name; // get the CD path and store in gi DirectoryInfo cdPathInfo = exeFile.Directory; List <string> dirs = new List <string>(); while (cdPathInfo.FullName != gameFolderInfo.FullName) { dirs.Insert(0, cdPathInfo.Name); cdPathInfo = cdPathInfo.Parent; } if (dirs.Count > 0) { gi.CdPath = Path.Combine(dirs.ToArray()); } }
/// <summary> /// specify which game the info box should show status/info of /// </summary> /// <param name="g"></param> public void SetGameInfo(GardenItem g) { game = g; }
public InstallTask(GardenItem game) { this.game = game; }
/// <summary> /// start a site-launcher task using the standard GardenItem.DeveloperWebsiteURL /// </summary> /// <param name="g">the GardenItem whose website to start</param> public SiteLauncherTask(GardenItem g) : this(g.DeveloperWebsiteURL) { }
/// <summary> /// called by a child GUI component to install a game /// </summary> /// <param name="g">game to install</param> public void ActionDownloadAndInstallGame(GardenItem g) { // check if download+install task needs to start or not. Can start if not already started before (and game's not installed) // OR if the previous install attempt failed. if ( (g.ThreadedDlAndInstallTask == null && !g.IsInstalled) || (g.ThreadedDlAndInstallTask != null && g.ThreadedDlAndInstallTask.IsFinished() && !g.ThreadedDlAndInstallTask.IsSuccess()) ) { g.DlAndInstallTask = new GameDownloadAndInstallTask(g); g.ThreadedDlAndInstallTask = new ThreadedTask(g.DlAndInstallTask); g.ThreadedDlAndInstallTask.Start(); } }
/// <summary> /// last init steps that are taken after loading a gamelib into gamesCollection /// </summary> void FinalizeGamelibForUse() { GardenItem g = gamesCollection.FindGameNamed("igg_controls"); g.DeveloperWebsiteURL = "file://" + GardenConfig.Instance.DataPath.Replace("\\", "/"); }
/// <summary> /// parse a JsonArray (array of items) or JsonObject (single game/item) /// </summary> protected GardenItem ParseJson(IJsonType j, Vector2 posOffset) { if (j is JsonArray) { JsonArray ja = j as JsonArray; Vector2 childPosOffset = posOffset; Vector2 posPrevious = Vector2.Zero; //Vector2 childPosPrevious = Vector2.Zero; Vector2 sectionWidthHeight = new Vector2(999f, 999f); GardenItem gi = null; foreach (IJsonType jChild in ja) { // parse each subitem and add to gamelist gi = ParseJson(jChild, childPosOffset); if (gi == null) continue; // optional first SectionID item of a JsonArray may contain position offset info for all items if (gi.IsSectionId) { childPosOffset += gi.Position; // WARNING mis-use the posdelta field for section width/height!! sectionWidthHeight = gi.PositionDelta; //childPosPrevious = Vector2.Zero; posPrevious = Vector2.Zero - Vector2.UnitX; // for first item of a section, apply a shift to align item to (0,0) continue; } // calculate correct item position if (!gi.IsPositionGiven) { gi.Position = posPrevious; do { if (gi.IsPositionDeltaGiven) gi.Position += gi.PositionDelta; else gi.Position += Vector2.UnitX; // advance in standard way to the right // checking the automatic calculated game position with section width if (gi.PositionX >= sectionWidthHeight.X) { gi.PositionY += 1; gi.PositionX = 0; } } while (gamesCollection.FindGameAt(gi.Position + childPosOffset) != null); } // update prev item position posPrevious = gi.Position; // apply the section position offset gi.PositionX += (int) childPosOffset.X; gi.PositionY += (int) childPosOffset.Y; // add to collection at specified position gamesCollection.Add(gi); } return null; // indicate array was last item. } else if (j is JsonObject) { // process single leaf item GardenItem ig = new GardenItem((JsonObject)j); return ig; } else throw new NotImplementedException("Unknown JSON type " + j + " found."); }
public void ActionLaunchWebsitePlayGame(GardenItem g, GameThumbnail thumb) { ITask t = new ThreadedTask(new SiteLauncherTask(g, g.ExeFile)); t.Start(); loadingDisplay.SetLoadingGame(g, thumb); music.FadeOut(); TreeRoot.SetNextState(new StatePlayingGame(2f,false)); }
public string GetPackedFilepath(GardenItem g) { return Path.Combine(PackedFilesFolder, GetPackedFileName(g)); }
public string GetPackedFilepath(GardenItem g) { return(Path.Combine(PackedFilesFolder, GetPackedFileName(g))); }
/// <summary> /// create new Download and Install task /// </summary> /// <param name="game">info of game to download and install</param> public GameDownloadAndInstallTask(GardenItem game) { this.game = game; status = ITaskStatus.CREATED; }
/// <summary> /// the name of the packed file (eg .zip or .rar) once it is downloaded. May differ /// from the name of the archive as stored on the web which is included in PackedFileURL. /// </summary> public string GetPackedFileName(GardenItem g) { return(g.GameIDwithVersion + "." + g.PackedFileExtension); }
/// <summary> /// called by a child GUI component to launch a game /// </summary> /// <param name="g">game to launch</param> public void ActionLaunchGame(GardenItem g, GameThumbnail thumb) { if (g.IsInstalled) { if (g.IsPlayable) { // if installed, then launch it if possible if ((launcher == null || launcher.IsFinished() == true) && (launchGameThread == null || launchGameThread.IsFinished())) { loadingDisplay.SetLoadingGame(g, thumb); // set state of game to 'game playing state' TreeRoot.SetNextState(new StatePlayingGame()); launcher = new GameLauncherTask(g); launchGameThread = new ThreadedTask(launcher); launchGameThread.TaskSuccessEvent += new TaskEventHandler(taskThread_TaskFinishedEvent); launchGameThread.TaskFailEvent += new TaskEventHandler(taskThread_TaskFinishedEvent); launchGameThread.Start(); } } if (g.IsMusic) { music.Play(g.ExeFilepath , 0.5f , 0f); // TODO vary audio volume per track. } } }
public GameDownloader(GardenItem game) : base() { this.game= game; this.segmentsUsedInDownload = 3; }
/// <summary> /// construct a new thumbnail downloader for game; downloading from default server /// location. /// </summary> public ThumbnailDownloader(GardenItem g) { this.gi = g; }
public static GardenItem ConstructGameLibItem(int version) { GardenItem g = new GardenItem(); g.Version = version; g.GameID = "igg_gamelib_fmt3"; // TODO to config constants? g.ExeFile = "gamelib.bin"; g.PackedFileURL = GardenConfig.Instance.ConfigFilesServerURL + "gamelib.zip"; return g; }
/// <summary> /// the name of the packed file (eg .zip or .rar) once it is downloaded. May differ /// from the name of the archive as stored on the web which is included in PackedFileURL. /// </summary> public string GetPackedFileName(GardenItem g) { return g.GameIDwithVersion + "." + g.PackedFileExtension; }
/// <summary> /// set state to loading game and display given game name /// </summary> /// <param name="g">game whose name/info to display while loading</param> public void SetLoadingGame(GardenItem g, GameThumbnail thumb) { SetNextState(new StateLoadingDisplay_Loading(this)); game = g; gameIcon.Texture = thumb.Texture; //gameIcon.Motion.Scale = thumb.Motion.Scale * 1.4f * g.ScaleIcon; gameIcon.Motion.Scale = Screen.Width / gameIcon.DrawInfo.Width; }
/// <summary> /// get file path to locally stored thumbnail file for game /// </summary> /// <param name="g"></param> /// <returns>by default a .png thumbnail for a game (whether file exists or not) /// but if a .jpg thumbnail exists, it is chosen.</returns> public string GetThumbnailFilepath(GardenItem g) { string p1 = Path.Combine(ThumbnailsFolder , g.GameIDwithVersion); string p2 = p1; p1 += ".jpg"; p2 += ".png"; if (File.Exists(p2)) return p2; else if (File.Exists(p1)) return p1; else return p2; }
/// <summary> /// add a new GardenItem to the collection at position (gi.PositionX,gi.PositionY) /// </summary> /// <param name="gi"></param> public void Add(GardenItem gi) { matrix[gi.PositionX,gi.PositionY] = gi; gamesList.Add(gi); }
/// <summary> /// parse a JsonArray (array of items) or JsonObject (single game/item) /// </summary> protected GardenItem ParseJson(IJsonType j, Vector2 posOffset) { if (j is JsonArray) { JsonArray ja = j as JsonArray; Vector2 childPosOffset = posOffset; Vector2 posPrevious = Vector2.Zero; //Vector2 childPosPrevious = Vector2.Zero; Vector2 sectionWidthHeight = new Vector2(999f, 999f); GardenItem gi = null; foreach (IJsonType jChild in ja) { // parse each subitem and add to gamelist gi = ParseJson(jChild, childPosOffset); if (gi == null) { continue; } // optional first SectionID item of a JsonArray may contain position offset info for all items if (gi.IsSectionId) { childPosOffset += gi.Position; // WARNING mis-use the posdelta field for section width/height!! sectionWidthHeight = gi.PositionDelta; //childPosPrevious = Vector2.Zero; posPrevious = Vector2.Zero - Vector2.UnitX; // for first item of a section, apply a shift to align item to (0,0) continue; } // calculate correct item position if (!gi.IsPositionGiven) { gi.Position = posPrevious; do { if (gi.IsPositionDeltaGiven) { gi.Position += gi.PositionDelta; } else { gi.Position += Vector2.UnitX; // advance in standard way to the right } // checking the automatic calculated game position with section width if (gi.PositionX >= sectionWidthHeight.X) { gi.PositionY += 1; gi.PositionX = 0; } } while (gamesCollection.FindGameAt(gi.Position + childPosOffset) != null); } // update prev item position posPrevious = gi.Position; // apply the section position offset gi.PositionX += (int)childPosOffset.X; gi.PositionY += (int)childPosOffset.Y; // add to collection at specified position gamesCollection.Add(gi); } return(null); // indicate array was last item. } else if (j is JsonObject) { // process single leaf item GardenItem ig = new GardenItem((JsonObject)j); ig.WreckProcessing(); // return null to indicate skip, if not valid 'trainwreck' that this client can handle. if (!ig.IsValidWreck) { return(null); } return(ig); } else { throw new NotImplementedException("Unknown JSON type " + j + " found."); } }
public override void OnChangedSelectedGame(GardenItem newSel, GardenItem oldSel) { // }
/// <summary> /// set cursor to select a given game. It will move there in next Update()s. /// </summary> /// <param name="g"></param> public void SetToGame(GardenItem g) { Motion.TargetPos = g.Position; Motion.TargetPosSpeed = 4f; // TODO constant? GridPosition = g.Position; }
/// <summary> /// add a new GardenItem to the collection at position (gi.PositionX,gi.PositionY) /// </summary> /// <param name="gi"></param> public void Add(GardenItem gi) { matrix[gi.PositionX, gi.PositionY] = gi; gamesList.Add(gi); }
/// <summary> /// user action triggered a changed selection event /// </summary> /// <param name="newSel">previously selected game</param> /// <param name="oldSel">newly selected game</param> public abstract void OnChangedSelectedGame(GardenItem newSel, GardenItem oldSel);
public SiteLauncherTask(GardenItem g) : this(g,g.DeveloperWebsiteURL) { }
public GameLauncherTask(GardenItem g) { this.Game = g; }