removed external online services
This commit is contained in:
parent
a1e8e684d0
commit
84e709a3f3
9 changed files with 10 additions and 271 deletions
|
@ -1,18 +1,13 @@
|
|||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.Content.PM;
|
||||
using Android.Gms.Games;
|
||||
using Android.OS;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using GameAnalyticsSDK;
|
||||
using Java.Lang;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using MLEM.Extensions;
|
||||
using MLEM.Misc;
|
||||
using TouchyTickets;
|
||||
using static Android.Views.ViewGroup;
|
||||
using Uri = Android.Net.Uri;
|
||||
|
||||
namespace Android;
|
||||
|
@ -30,18 +25,14 @@ public class Activity1 : AndroidGameActivity {
|
|||
|
||||
private GameImpl game;
|
||||
private AndroidPlatform platform;
|
||||
private LinearLayout mainView;
|
||||
private View view;
|
||||
|
||||
protected override void OnCreate(Bundle bundle) {
|
||||
base.OnCreate(bundle);
|
||||
|
||||
// ad layout
|
||||
var adLayout = new LinearLayout(this) {Orientation = Orientation.Vertical};
|
||||
adLayout.SetGravity(GravityFlags.Bottom);
|
||||
|
||||
// set up the game
|
||||
MlemPlatform.Current = new MlemPlatform.Mobile(KeyboardInput.Show, l => this.StartActivity(new Intent(Intent.ActionView, Uri.Parse(l))));
|
||||
this.platform = new AndroidPlatform(this, adLayout);
|
||||
this.platform = new AndroidPlatform(this);
|
||||
this.game = new GameImpl(this.platform);
|
||||
this.game.GraphicsDeviceManager.ResetWidthAndHeight(this.game.Window);
|
||||
this.game.GraphicsDeviceManager.IsFullScreen = true;
|
||||
|
@ -59,30 +50,12 @@ public class Activity1 : AndroidGameActivity {
|
|||
if (Build.VERSION.SdkInt >= BuildVersionCodes.P)
|
||||
this.Window.Attributes.LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.Never;
|
||||
|
||||
// total layout that is displayed
|
||||
this.mainView = new LinearLayout(this) {Orientation = Orientation.Vertical};
|
||||
this.mainView.LayoutParameters = new LinearLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent);
|
||||
this.mainView.AddView(gameView);
|
||||
// height of 0 but high weight causes this element so scale based on the ad's height
|
||||
gameView.LayoutParameters = new LinearLayout.LayoutParams(LayoutParams.MatchParent, 0, 1);
|
||||
this.mainView.AddView(adLayout);
|
||||
adLayout.LayoutParameters = new LinearLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent);
|
||||
this.SetContentView(this.mainView);
|
||||
this.view = this.game.Services.GetService(typeof(View)) as View;
|
||||
this.SetContentView(this.view);
|
||||
|
||||
this.game.Run();
|
||||
}
|
||||
|
||||
protected override void OnActivityResult(int requestCode, Result result, Intent data) {
|
||||
base.OnActivityResult(requestCode, result, data);
|
||||
// Connect again after logging in to Google Play game services, but only if we haven't tried yet
|
||||
try {
|
||||
if (requestCode == AndroidPlatform.GooglePlayLoginRequest && (int) result != GamesActivityResultCodes.ResultSignInFailed)
|
||||
this.platform.GoogleApi.Connect();
|
||||
} catch (Exception e) {
|
||||
GameAnalytics.NewErrorEvent(GAErrorSeverity.Error, "OnActivityResult " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnWindowFocusChanged(bool hasFocus) {
|
||||
base.OnWindowFocusChanged(hasFocus);
|
||||
#pragma warning disable CS0618
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.1.303"/>
|
||||
<PackageReference Include="MonoGame.Framework.Android" Version="3.8.1.303"/>
|
||||
<PackageReference Include="Contentless" Version="3.0.7"/>
|
||||
<PackageReference Include="GameAnalytics.Xamarin.SDK" Version="5.2.5"/>
|
||||
<PackageReference Include="Xamarin.GooglePlayServices.Games" Version="123.1.0.1"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,110 +1,17 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.Gms.Common.Apis;
|
||||
using Android.Gms.Games;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using GameAnalyticsSDK;
|
||||
using GameAnalyticsSDK.Utilities;
|
||||
using Java.Lang;
|
||||
using TouchyTickets;
|
||||
using Achievement = TouchyTickets.Achievement;
|
||||
using Uri = Android.Net.Uri;
|
||||
|
||||
namespace Android;
|
||||
|
||||
public class AndroidPlatform : Platform {
|
||||
|
||||
public const int GooglePlayLoginRequest = 9001;
|
||||
public const int ShowAchievementsRequest = 9002;
|
||||
|
||||
private static readonly Dictionary<string, string> AchievementIds = new() {
|
||||
{"1Stars", "CgkI_Lyp7PcEEAIQAw"},
|
||||
{"10Stars", "CgkI_Lyp7PcEEAIQBA"},
|
||||
{"100Stars", "CgkI_Lyp7PcEEAIQBQ"},
|
||||
{"FullMap", "CgkI_Lyp7PcEEAIQBg"},
|
||||
{"OnlySmallRides", "CgkI_Lyp7PcEEAIQBw"},
|
||||
{"OnlyRelaxedRides", "CgkI_Lyp7PcEEAIQCA"},
|
||||
{"OnlyWalkingRides", "CgkI_Lyp7PcEEAIQCQ"},
|
||||
{"OnlyNonTechnologyRides", "CgkI_Lyp7PcEEAIQCg"},
|
||||
{"100Modifiers", "CgkI_Lyp7PcEEAIQCw"},
|
||||
{"500Modifiers", "CgkI_Lyp7PcEEAIQDA"},
|
||||
{"1000Modifiers", "CgkI_Lyp7PcEEAIQDQ"},
|
||||
{"5000Modifiers", "CgkI_Lyp7PcEEAIQDg"},
|
||||
{"1ExpTickets", "CgkI_Lyp7PcEEAIQDw"},
|
||||
{"2ExpTickets", "CgkI_Lyp7PcEEAIQEA"},
|
||||
{"3ExpTickets", "CgkI_Lyp7PcEEAIQEQ"},
|
||||
{"4ExpTickets", "CgkI_Lyp7PcEEAIQEg"},
|
||||
{"5ExpTickets", "CgkI_Lyp7PcEEAIQEw"},
|
||||
{"6ExpTickets", "CgkI_Lyp7PcEEAIQFA"},
|
||||
{"7ExpTickets", "CgkI_Lyp7PcEEAIQFQ"},
|
||||
{"8ExpTickets", "CgkI_Lyp7PcEEAIQFg"},
|
||||
{"9ExpTickets", "CgkI_Lyp7PcEEAIQFw"},
|
||||
{"10ExpTickets", "CgkI_Lyp7PcEEAIQGA"}
|
||||
};
|
||||
|
||||
private readonly Activity activity;
|
||||
private readonly LinearLayout adLayout;
|
||||
public GoogleApiClient GoogleApi { get; private set; }
|
||||
|
||||
public AndroidPlatform(Activity activity, LinearLayout adLayout) {
|
||||
public AndroidPlatform(Activity activity) {
|
||||
this.activity = activity;
|
||||
this.adLayout = adLayout;
|
||||
}
|
||||
|
||||
public override void SetupOnlineInteractions(Dictionary<string, object> analyticsJson) {
|
||||
// Analytics
|
||||
GameAnalytics.SetAutoDetectAppVersion(true);
|
||||
GameAnalytics.Initialize(this.activity, GA_MiniJSON.Serialize(new Hashtable(analyticsJson)));
|
||||
AndroidEnvironment.UnhandledExceptionRaiser += (_, args) => GameAnalytics.NewErrorEvent(GAErrorSeverity.Critical, args.Exception.ToString());
|
||||
|
||||
// TODO fix ads
|
||||
// Ads
|
||||
/*try {
|
||||
var ad = new AdView(this.activity) {
|
||||
AdUnitId = "ca-app-pub-5754829579653773/7841535920",
|
||||
AdSize = AdSize.SmartBanner
|
||||
};
|
||||
ad.LoadAd(new AdRequest.Builder()
|
||||
.AddTestDevice("14B965C6457E17D2808061ADF7E34923")
|
||||
.Build());
|
||||
this.adLayout.AddView(ad);
|
||||
} catch (Exception e) {
|
||||
GameAnalytics.NewErrorEvent(GAErrorSeverity.Error, "Ads " + e);
|
||||
}*/
|
||||
|
||||
// TODO fix google play game services
|
||||
/*// Google Play game services
|
||||
try {
|
||||
this.GoogleApi = new GoogleApiClient.Builder(this.activity)
|
||||
.AddApi(GamesClass.API)
|
||||
.AddScope(GamesClass.ScopeGames)
|
||||
.AddOnConnectionFailedListener(res => {
|
||||
if (res.HasResolution) {
|
||||
res.StartResolutionForResult(this.activity, GooglePlayLoginRequest);
|
||||
} else {
|
||||
throw new GoogleApiClientConnectionException(res);
|
||||
}
|
||||
})
|
||||
.Build();
|
||||
this.GoogleApi.Connect();
|
||||
} catch (Exception e) {
|
||||
GameAnalytics.NewErrorEvent(GAErrorSeverity.Error, "GoogleApiClient " + e);
|
||||
}*/
|
||||
|
||||
#if DEBUG
|
||||
// Sanity check to ensure that all achievements are mapped
|
||||
foreach (var achievement in Achievement.Achievements.Values) {
|
||||
var _ = AndroidPlatform.AchievementIds[achievement.Name];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void AddResourceEvent(bool sink, string currency, float amount, string itemType, string itemId) {
|
||||
GameAnalytics.NewResourceEvent(sink ? GAResourceFlowType.Sink : GAResourceFlowType.Source, currency, amount, itemType, itemId);
|
||||
}
|
||||
|
||||
public override void SetKeepScreenOn(bool keep) {
|
||||
|
@ -119,27 +26,4 @@ public class AndroidPlatform : Platform {
|
|||
this.activity.StartActivity(new Intent(Intent.ActionView, Uri.Parse("https://play.google.com/store/apps/details?id=de.ellpeck.touchytickets")));
|
||||
}
|
||||
|
||||
public override bool GainAchievement(Achievement achievement) {
|
||||
try {
|
||||
if (this.GoogleApi != null && this.GoogleApi.IsConnected) {
|
||||
GamesClass.Achievements.Unlock(this.GoogleApi, AndroidPlatform.AchievementIds[achievement.Name]);
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
GameAnalytics.NewErrorEvent(GAErrorSeverity.Error, "GainAchievement " + e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void ShowAchievements() {
|
||||
try {
|
||||
if (this.GoogleApi == null || !this.GoogleApi.IsConnected)
|
||||
return;
|
||||
var intent = GamesClass.Achievements.GetAchievementsIntent(this.GoogleApi);
|
||||
this.activity.StartActivityForResult(intent, AndroidPlatform.ShowAchievementsRequest);
|
||||
} catch (Exception e) {
|
||||
GameAnalytics.NewErrorEvent(GAErrorSeverity.Error, "ShowAchievements " + e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using TouchyTickets.Attractions;
|
||||
|
||||
namespace TouchyTickets;
|
||||
|
||||
public class Achievement {
|
||||
|
||||
public static readonly Dictionary<string, Achievement> Achievements = new();
|
||||
|
||||
static Achievement() {
|
||||
foreach (var amount in new[] {1, 10, 100})
|
||||
Achievement.Register(new Achievement($"{amount}Stars", g => g.Stars >= amount));
|
||||
Achievement.Register(new Achievement("FullMap", g => {
|
||||
for (var x = 0; x < g.Map.Width; x++) {
|
||||
for (var y = 0; y < g.Map.Height; y++) {
|
||||
if (g.Map.GetAttractionAt(new Point(x, y)) == null)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}));
|
||||
foreach (var flag in new[] {AttractionFlags.Small, AttractionFlags.Relaxed, AttractionFlags.Walking, AttractionFlags.NonTechnology})
|
||||
Achievement.Register(new Achievement($"Only{flag}Rides", g => g.Map.GetAttractionAmount(null) >= 100 && g.Map.GetAttractions().All(a => a.Item2.Type.Flags.HasFlag(flag))));
|
||||
foreach (var amount in new[] {100, 500, 1000, 5000})
|
||||
Achievement.Register(new Achievement($"{amount}Modifiers", g => g.Map.GetAttractionAmount(null) > 0 && g.Map.GetAttractions().All(a => a.Item2.GetModifierAmount(null) >= amount)));
|
||||
for (var i = 1; i <= 10; i++) {
|
||||
var amount = BigInteger.Pow(1000, i + 1);
|
||||
Achievement.Register(new Achievement($"{i}ExpTickets", g => g.Tickets >= amount));
|
||||
}
|
||||
}
|
||||
|
||||
public readonly string Name;
|
||||
private readonly Func<GameImpl, bool> condition;
|
||||
// this value doesn't save between game runs, since achievements
|
||||
// are only displayed inside of the respective stores anyway
|
||||
private bool unlocked;
|
||||
|
||||
public Achievement(string name, Func<GameImpl, bool> condition) {
|
||||
this.Name = name;
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
public void Update() {
|
||||
if (this.unlocked)
|
||||
return;
|
||||
if (!this.condition.Invoke(GameImpl.Instance))
|
||||
return;
|
||||
if (GameImpl.Instance.Platform.GainAchievement(this))
|
||||
this.unlocked = true;
|
||||
}
|
||||
|
||||
public static void Register(Achievement achievement) {
|
||||
Achievement.Achievements.Add(achievement.Name, achievement);
|
||||
}
|
||||
|
||||
}
|
|
@ -44,7 +44,6 @@ public class AttractionModifier {
|
|||
if (GameImpl.Instance.Tickets < price)
|
||||
return false;
|
||||
GameImpl.Instance.Tickets -= price;
|
||||
GameImpl.Instance.Platform.AddResourceEvent(true, "Tickets", (float) price, "Modifier", this.Name);
|
||||
attraction.ApplyModifier(this);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ public class GameImpl : MlemGame {
|
|||
public DateTime LastUpdate;
|
||||
public TimeSpan PlayTime;
|
||||
private double saveCounter;
|
||||
private double achievementCounter;
|
||||
|
||||
public GameImpl(Platform platform) {
|
||||
this.Platform = platform;
|
||||
|
@ -45,17 +44,6 @@ public class GameImpl : MlemGame {
|
|||
}
|
||||
|
||||
private void LoadGame() {
|
||||
// set up online stuff
|
||||
var analytics = new Dictionary<string, object>();
|
||||
analytics["InfoLog"] = true;
|
||||
analytics["VerboseLog"] = true;
|
||||
analytics["ResourceCurrencies"] = new[] {"Tickets", "Stars"};
|
||||
analytics["ResourceItemTypes"] = new[] {"Attraction", "Restart", "Upgrade", "Modifier"};
|
||||
// ios comes first, then android. For now they're the same
|
||||
analytics["GameKey"] = new[] {"cc18de06eebbc5d5e987c384fcd28000", "cc18de06eebbc5d5e987c384fcd28000"};
|
||||
analytics["SecretKey"] = new[] {"82ca1a930ee38e2383ffb02db7631e16033b511d", "82ca1a930ee38e2383ffb02db7631e16033b511d"};
|
||||
this.Platform.SetupOnlineInteractions(analytics);
|
||||
|
||||
this.Tutorial = new Tutorial();
|
||||
|
||||
if (!SaveHandler.Load(this))
|
||||
|
@ -82,14 +70,6 @@ public class GameImpl : MlemGame {
|
|||
// update the map
|
||||
this.UpdateMapOnce();
|
||||
|
||||
// achievements
|
||||
this.achievementCounter += gameTime.ElapsedGameTime.TotalSeconds;
|
||||
if (this.achievementCounter >= 5) {
|
||||
this.achievementCounter = 0;
|
||||
foreach (var achievement in Achievement.Achievements.Values)
|
||||
achievement.Update();
|
||||
}
|
||||
|
||||
// save every 3 seconds
|
||||
this.saveCounter += gameTime.ElapsedGameTime.TotalSeconds;
|
||||
if (this.saveCounter >= 3) {
|
||||
|
|
|
@ -1,19 +1,10 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace TouchyTickets;
|
||||
|
||||
public abstract class Platform {
|
||||
|
||||
public abstract void SetupOnlineInteractions(Dictionary<string, object> analyticsJson);
|
||||
|
||||
public abstract void AddResourceEvent(bool sink, string currency, float amount, string itemType, string itemId);
|
||||
|
||||
public abstract void SetKeepScreenOn(bool keep);
|
||||
|
||||
public abstract void OpenRateLink();
|
||||
|
||||
public abstract bool GainAchievement(Achievement achievement);
|
||||
|
||||
public abstract void ShowAchievements();
|
||||
|
||||
}
|
|
@ -5,9 +5,9 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Coroutine" Version="2.1.4"/>
|
||||
<PackageReference Include="MLEM.Startup" Version="6.1.0"/>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.2"/>
|
||||
<PackageReference Include="Coroutine" Version="2.1.4" />
|
||||
<PackageReference Include="MLEM.Startup" Version="6.1.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
|
||||
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.1.303">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
|
|
|
@ -175,7 +175,6 @@ public class Ui {
|
|||
ActionSound = new SoundEffectInfo(Assets.PlaceSound),
|
||||
OnPressed = e2 => {
|
||||
GameImpl.Instance.Tickets -= price;
|
||||
GameImpl.Instance.Platform.AddResourceEvent(true, "Tickets", (float) price, "Attraction", attraction.Key);
|
||||
|
||||
map.Place(map.PlacingPosition, map.PlacingAttraction);
|
||||
map.PlacingAttraction.Wobble();
|
||||
|
@ -342,9 +341,6 @@ public class Ui {
|
|||
this.uiSystem.Remove(e2.Root.Name);
|
||||
|
||||
var game = GameImpl.Instance;
|
||||
game.Platform.AddResourceEvent(true, "Tickets", (float) game.Tickets, "Restart", "Restart" + game.TimesRestarted);
|
||||
game.Platform.AddResourceEvent(false, "Stars", game.GetBuyableStars(), "Restart", "Restart" + game.TimesRestarted);
|
||||
|
||||
game.Stars += game.GetBuyableStars();
|
||||
game.TimesRestarted++;
|
||||
game.Tickets = 0;
|
||||
|
@ -393,10 +389,6 @@ public class Ui {
|
|||
}
|
||||
}));
|
||||
num.PositionOffset = new Vector2(0, 1);
|
||||
optionList.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 30), Localization.Get("Achievements")) {
|
||||
PositionOffset = new Vector2(0, 1),
|
||||
OnPressed = _ => GameImpl.Instance.Platform.ShowAchievements()
|
||||
});
|
||||
|
||||
optionList.AddChild(new Paragraph(Anchor.AutoCenter, 1, Localization.Get("OtherOptions"), true) {
|
||||
PositionOffset = new Vector2(0, 10),
|
||||
|
@ -553,22 +545,6 @@ public class Ui {
|
|||
}
|
||||
yield return new Wait(0.5);
|
||||
|
||||
var analyticsFlag = new FileInfo(Path.Combine(SaveHandler.GetGameDirectory(true).FullName, "_ReadGdpr"));
|
||||
if (!analyticsFlag.Exists) {
|
||||
var evt = new Event();
|
||||
var panel = splash.AddChild(new Panel(Anchor.Center, new Vector2(0.8F), Vector2.Zero, true));
|
||||
panel.AddChild(new Paragraph(Anchor.AutoLeft, 1, Localization.Get("GDPRInfo")));
|
||||
panel.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 30), Localization.Get("Okay")) {
|
||||
OnPressed = _ => {
|
||||
// create the (empty) flag file
|
||||
using (analyticsFlag.Create()) {}
|
||||
splash.RemoveChild(panel);
|
||||
CoroutineHandler.RaiseEvent(evt);
|
||||
}
|
||||
});
|
||||
yield return new Wait(evt);
|
||||
}
|
||||
|
||||
yield return new Wait(0.25);
|
||||
loadGame();
|
||||
yield return new Wait(0.25);
|
||||
|
@ -699,8 +675,6 @@ public class Ui {
|
|||
ActionSound = new SoundEffectInfo(Assets.BuySound),
|
||||
OnPressed = _ => {
|
||||
GameImpl.Instance.Stars -= upgrade.Price;
|
||||
GameImpl.Instance.Platform.AddResourceEvent(true, "Stars", upgrade.Price, "Upgrade", upgrade.Name);
|
||||
|
||||
GameImpl.Instance.AppliedUpgrades.Add(upgrade);
|
||||
upgrade.OnApplied();
|
||||
Ui.PopulateUpgradeList(upgradeList);
|
||||
|
|
Loading…
Reference in a new issue