added analytics!

This commit is contained in:
Ellpeck 2020-06-05 16:14:10 +02:00
parent 7e399acf9b
commit 864760ab0e
10 changed files with 5907 additions and 26 deletions

View file

@ -29,7 +29,7 @@ namespace Android {
this.Window.Attributes.LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.ShortEdges;
TextInputWrapper.Current = new TextInputWrapper.Mobile();
this.game = new GameImpl();
this.game = new GameImpl(new AndroidAnalytics(this));
this.game.GraphicsDeviceManager.ResetWidthAndHeight(this.game.Window);
this.game.OnLoadContent += game => game.InputHandler.HandleMouse = false;
this.game.GraphicsDeviceManager.IsFullScreen = true;

View file

@ -47,31 +47,33 @@
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
</PropertyGroup>
<ItemGroup>
<Reference Include="System"/>
<Reference Include="System.Core"/>
<Reference Include="System.Xml"/>
<Reference Include="Mono.Android"/>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml" />
<Reference Include="Mono.Android" />
</ItemGroup>
<ItemGroup>
<Compile Include="Activity1.cs"/>
<Compile Include="Resources\Resource.Designer.cs"/>
<Compile Include="Properties\AssemblyInfo.cs"/>
<Compile Include="Activity1.cs" />
<Compile Include="AndroidAnalytics.cs" />
<Compile Include="Resources\Resource.Designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\Drawable\Icon.png"/>
<AndroidResource Include="Resources\Values\Strings.xml"/>
<AndroidResource Include="Resources\Drawable\Icon.png" />
<AndroidResource Include="Resources\Values\Strings.xml" />
</ItemGroup>
<ItemGroup>
<None Include="Properties\AndroidManifest.xml"/>
<None Include="Properties\AndroidManifest.xml" />
<MonoGameContentReference Include="..\TouchyTickets\Content\Content.mgcb">
<Link>Content\Content.mgcb</Link>
</MonoGameContentReference>
<None Include="..\TouchyTickets\Content\*\**"/>
<None Include="..\TouchyTickets\Content\*\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Contentless" Version="2.0.6"/>
<PackageReference Include="MonoGame.Content.Builder" Version="3.7.0.9"/>
<PackageReference Include="MonoGame.Framework.Android" Version="3.7.1.189"/>
<PackageReference Include="Contentless" Version="2.0.6" />
<PackageReference Include="GameAnalytics.Xamarin.SDK" Version="4.1.0" />
<PackageReference Include="MonoGame.Content.Builder" Version="3.7.0.9" />
<PackageReference Include="MonoGame.Framework.Android" Version="3.7.1.189" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TouchyTickets\TouchyTickets.csproj">
@ -79,5 +81,5 @@
<Name>TouchyTickets</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets"/>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
</Project>

View file

@ -0,0 +1,26 @@
using System.Collections;
using System.Collections.Generic;
using Android.App;
using GameAnalyticsSDK;
using GameAnalyticsSDK.Utilities;
using TouchyTickets;
namespace Android {
public class AndroidAnalytics : Analytics {
private readonly Activity activity;
public AndroidAnalytics(Activity activity) {
this.activity = activity;
}
public override void Setup(Dictionary<string, object> json) {
GameAnalytics.Initialize(this.activity, GA_MiniJSON.JsonEncode(new Hashtable(json)));
}
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);
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,11 @@
using System.Collections.Generic;
namespace TouchyTickets {
public abstract class Analytics {
public abstract void Setup(Dictionary<string, object> json);
public abstract void AddResourceEvent(bool sink, string currency, float amount, string itemType, string itemId);
}
}

View file

@ -5,10 +5,7 @@ using Coroutine;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Cameras;
using MLEM.Extensions;
using MLEM.Font;
using MLEM.Startup;
using TouchyTickets.Attractions;
namespace TouchyTickets {
public class GameImpl : MlemGame {
@ -16,6 +13,7 @@ namespace TouchyTickets {
public static GameImpl Instance { get; private set; }
public readonly ISet<Upgrade> AppliedUpgrades = new HashSet<Upgrade>();
public readonly Tutorial Tutorial = new Tutorial();
public readonly Analytics Analytics;
public BigInteger Tickets;
public int TimesRestarted;
public int Stars;
@ -26,13 +24,26 @@ namespace TouchyTickets {
public DateTime LastUpdate;
private double saveCounter;
public GameImpl() {
public GameImpl(Analytics analytics) {
this.Analytics = analytics;
Instance = this;
}
protected override void LoadContent() {
base.LoadContent();
// set up analytics
var settings = new Dictionary<string, object>();
settings["InfoLog"] = true;
settings["VerboseLog"] = true;
settings["SubmitErrors"] = true;
settings["ResourceCurrencies"] = new[] {"Tickets", "Stars"};
settings["ResourceItemTypes"] = new[] {"Attraction", "Restart", "Upgrade"};
// ios comes first, then android. For now they're the same
settings["GameKey"] = new[] {"cc18de06eebbc5d5e987c384fcd28000", "cc18de06eebbc5d5e987c384fcd28000"};
settings["SecretKey"] = new[] {"82ca1a930ee38e2383ffb02db7631e16033b511d", "82ca1a930ee38e2383ffb02db7631e16033b511d"};
this.Analytics.Setup(settings);
if (!SaveHandler.Load(this))
this.Map = new ParkMap(12, 12);

View file

@ -147,6 +147,8 @@ namespace TouchyTickets {
yesNoUi.AddChild(new Button(Anchor.AutoInlineIgnoreOverflow, new Vector2(0.5F, 30), Localization.Get("Place")) {
OnPressed = e2 => {
GameImpl.Instance.Tickets -= price;
GameImpl.Instance.Analytics.AddResourceEvent(true, "Tickets", (long) price, "Attraction", attraction.Key);
map.Place(map.PlacingPosition, map.PlacingAttraction);
this.FadeUi(false, () => this.uiSystem.Remove(e2.Root.Name));
},
@ -197,7 +199,11 @@ namespace TouchyTickets {
panel.AddChild(new Button(Anchor.AutoInlineIgnoreOverflow, new Vector2(0.5F, 30), Localization.Get("Yes")) {
OnPressed = e2 => {
this.uiSystem.Remove(e2.Root.Name);
var game = GameImpl.Instance;
game.Analytics.AddResourceEvent(true, "Tickets", (long) game.Tickets, "Restart", "Restart" + game.TimesRestarted);
game.Analytics.AddResourceEvent(false, "Stars", (long) game.Tickets, "Restart", "Restart" + game.TimesRestarted);
game.Stars += (int) (game.Tickets / game.GetStarPrice());
game.TimesRestarted++;
game.Tickets = 0;
@ -337,6 +343,8 @@ namespace TouchyTickets {
ChildPadding = new Vector2(4),
OnPressed = e => {
GameImpl.Instance.Stars -= upgrade.Price;
GameImpl.Instance.Analytics.AddResourceEvent(true, "Stars", upgrade.Price, "Upgrade", upgrade.Name);
GameImpl.Instance.AppliedUpgrades.Add(upgrade);
upgrade.OnApplied();
PopulateUpgradeList(upgradeList);

19
iOS/IosAnalytics.cs Normal file
View file

@ -0,0 +1,19 @@
using System.Collections;
using System.Collections.Generic;
using GameAnalyticsSDK;
using GameAnalyticsSDK.Utilities;
using TouchyTickets;
namespace iOS {
public class IosAnalytics : Analytics {
public override void Setup(Dictionary<string, object> json) {
GameAnalytics.Initialize(GA_MiniJSON.JsonEncode(new Hashtable(json)));
}
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);
}
}
}

View file

@ -1,5 +1,9 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Foundation;
using GameAnalyticsSDK;
using Newtonsoft.Json;
using TouchyTickets;
using UIKit;
@ -10,7 +14,7 @@ namespace iOS {
private static GameImpl game;
private static void RunGame() {
game = new GameImpl();
game = new GameImpl(new IosAnalytics());
game.Run();
}

View file

@ -107,6 +107,7 @@
<Reference Include="Xamarin.iOS" />
</ItemGroup>
<ItemGroup>
<Compile Include="IosAnalytics.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
@ -116,7 +117,7 @@
<MonoGameContentReference Include="..\TouchyTickets\Content\Content.mgcb">
<Link>Content\Content.mgcb</Link>
</MonoGameContentReference>
<None Include="..\TouchyTickets\Content\*\**"/>
<None Include="..\TouchyTickets\Content\*\**" />
</ItemGroup>
<ItemGroup>
<BundleResource Include="Default.png" />
@ -126,6 +127,7 @@
<InterfaceDefinition Include="LaunchScreen.storyboard" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="GameAnalytics.Xamarin.SDK" Version="4.1.0" />
<PackageReference Include="MonoGame.Content.Builder" Version="3.7.0.9" />
<PackageReference Include="MonoGame.Framework.iOS" Version="3.7.1.189" />
</ItemGroup>