Exemplo n.º 1
0
		/// <summary>
		/// Save the specified name and autosaving.
		/// </summary>
		/// <param name="name">Name of savefile.</param>
		/// <param name="autosaving">If set to <c>true</c> autosaving.</param>
		/// <returns>CartridgeSavegame to savegame object.</returns>
		public CartridgeSavegame Save(string name = "Ingame saving", bool autosaving = false)
		{
			App.GameNavigation.CurrentPage.IsBusy = true;

			// Create a new savegame name for this cartridge tag
			var cs = new CartridgeSavegame(this.cartridgeTag);
			var filename = cs.Filename;

			if (autosaving)
			{
				filename = Path.Combine(App.PathForSavegames, "autosave.gws");
			}

			// Save game
			this.engine.Save(new FileStream(filename, FileMode.Create), name);

			// Add savegame, which is now in store, to cartridge tag
			if (!autosaving)
			{
				this.cartridgeTag.AddSavegame(cs);
			}

			App.GameNavigation.CurrentPage.IsBusy = false;

			return cs;
		}
Exemplo n.º 2
0
		/// <summary>
		/// Start this instance.
		/// </summary>
		/// <returns>The task.</returns>
		/// <param name="savegame">Savegame object.</param> 
		public async System.Threading.Tasks.Task StartAsync(CartridgeSavegame savegame = null)
		{
			App.GameNavigation.CurrentPage.IsBusy = true;

			App.GameNavigation.Popped += (sender, e) => this.HandlePagePopped();
			App.GameNavigation.PoppedToRoot += (sender, e) => this.HandlePagePopped();
			App.GameNavigation.Pushed += (sender, e) => this.HandlePagePushed();

			// Create Engine
			await this.CreateEngine(this.cartridgeTag.Cartridge);

			var pos = App.GPS.LastKnownPosition ?? new Position(0, 0);
			this.engine.RefreshLocation(pos.Latitude, pos.Longitude, pos.Altitude ?? 0, pos.Accuracy ?? double.NaN);

			App.GPS.PositionChanged += this.OnPositionChanged;

			// If there is a valid savefile, than open it
			if (savegame != null && File.Exists(Path.Combine(App.PathForSavegames, savegame.Filename)))
			{
				await System.Threading.Tasks.Task.Run(() => this.engine.Restore(new FileStream(savegame.Filename, FileMode.Open)));
			}
			else
			{
				await System.Threading.Tasks.Task.Run(() => this.engine.Start());
			}

			App.GameNavigation.CurrentPage.IsBusy = false;
		}
Exemplo n.º 3
0
		/// <summary>
		/// Exports a savegame to the isolated storage and adds it to this tag.
		/// </summary>
		/// <param name="cs">The savegame to add.</param>
		public void AddSavegame(CartridgeSavegame cs)
		{
			// Sanity check: a savegame with similar name should
			// not exist.
			CartridgeSavegame sameNameCS;
			if ((sameNameCS = this.Savegames.SingleOrDefault(c => c.Metadata != null && cs.Metadata != null && c.Metadata.SaveName == cs.Metadata.SaveName)) != null)
			{
				System.Diagnostics.Debug.WriteLine("CartridgeTag: Removing savegame to make room for new one: " + sameNameCS.Metadata.SaveName);
				// Removes the previous savegame that bears the same name.
				this.RemoveSavegame(sameNameCS);
			}
			// Adds the savegame.
			this.savegames.Add(cs);
			// Notifies of a change.
			this.RaisePropertyChanged("Savegames");
		}
Exemplo n.º 4
0
		/// <summary>
		/// Removes a savegame's contents from the isolated storage and removes
		/// it from this tag.
		/// </summary>
		/// <param name="cs">Cartridge savegame to remove.</param>">
		public void RemoveSavegame(CartridgeSavegame cs)
		{
			// Removes the savegame.
			this.savegames.Remove(cs);
			// Makes sure the savegame is cleared from cache.
			cs.RemoveFromStore();
			// Notifies of a change.
			this.RaisePropertyChanged("Savegames");
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="WF.Player.GameCheckLocationViewModel"/> class.
		/// </summary>
		/// <param name="tag">CartridgeTag to use.</param>
		/// <param name="savegame">Savegame object to use for restore.</param>
		/// <param name="lastPage">Info about which was the last page before call of check location</param>
		public GameCheckLocationViewModel(CartridgeTag tag, CartridgeSavegame savegame = null, Page lastPage = null)
		{
			this.cartridgeTag = tag;
			this.savegame = savegame;

			// Is GPS running?
			if (!App.GPS.IsListening)
			{
				// Start listening when app is on screen
				App.GPS.StartListening(500, 2.0, true);
			}

			App.GPS.PositionChanged += OnPositionChanged;
			Position = App.GPS.LastKnownPosition;
		}