com.amanotes.gdk 0.1.15 → 0.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.16 - 2023-03-10]
4
+ ### Release AmaGDK v0.1.16
5
+ ### SemVer supports 4 parts
6
+ ### Analytics supports event config
7
+
3
8
  ## [0.1.15 - 2023-03-06]
4
9
  ### Release AmaGDK v0.1.15
5
10
  ### Fix null exception in VersionExtractor
Binary file
Binary file
@@ -54,7 +54,7 @@ namespace Amanotes.Core
54
54
  get { return !string.IsNullOrEmpty(funnelSignature); }
55
55
  }
56
56
 
57
- public bool IsForbidden(string adapterId)
57
+ public bool IsForbiddenByAdapterConfig(string adapterId)
58
58
  {
59
59
  if (ignoreAdapterIds.Count > 0)
60
60
  {
@@ -69,10 +69,24 @@ namespace Amanotes.Core
69
69
  Debug.LogWarning("[AmaGDK] Should never be here: overrideConfig == true but no id in listAdapterIds!");
70
70
  return false;
71
71
  }
72
+
73
+ public bool IsForbiddenByLogAtCountConfig()
74
+ {
75
+ if (!logAtCount.TryGetValue(eventName, out var logAtCountConfig)) return false;
76
+
77
+ int accumulatedCount = GetAccumulatedCount(eventName, logAtCountConfig.withinSession);
78
+ return !logAtCountConfig.listCount.Contains(accumulatedCount);
79
+ }
72
80
  }
73
81
 
74
82
  public static IEventParamsBuilder LogEvent(string eventName)
75
83
  {
84
+ if (string.IsNullOrWhiteSpace(eventName))
85
+ {
86
+ LogWarningOnce($"Invalid EventName: <{eventName}> ");
87
+ return null;
88
+ }
89
+
76
90
  var result = new EventParams(eventName);
77
91
  eventQueue.Enqueue(result);
78
92
  return result;
@@ -80,20 +94,16 @@ namespace Amanotes.Core
80
94
 
81
95
  public static IEventParamsBuilder LogEvent(string eventName, Dictionary<string, object> parameters)
82
96
  {
83
- var result = new EventParams(eventName);
84
- result.AddParam(parameters);
85
- eventQueue.Enqueue(result);
86
- return result;
97
+ return LogEvent(eventName).AddParam(parameters);
87
98
  }
88
99
 
89
100
  public static IEventParamsBuilder LogEvent(string eventName, params (string, object)[] parameters)
90
101
  {
91
- var result = new EventParams(eventName);
102
+ var result = LogEvent(eventName);
92
103
  for (var i = 0;i < parameters.Length; i++)
93
104
  {
94
105
  result.AddParam(parameters[i].Item1, parameters[i].Item2);
95
- }
96
- eventQueue.Enqueue(result);
106
+ }
97
107
  return result;
98
108
  }
99
109
 
@@ -233,11 +243,41 @@ namespace Amanotes.Core
233
243
  adapter?.SetForbiddenEvents(eventNames);
234
244
  }
235
245
  }
246
+
247
+ public static void SetLogAtCount(string eventName, List<int> listCount, bool withinSession = false, bool appendCountToEventName = false, string numberFormat = "00")
248
+ {
249
+ var config = new EventConfig
250
+ {
251
+ listCount = listCount,
252
+ withinSession = withinSession,
253
+ appendCountToEventName = appendCountToEventName,
254
+ numberFormat = numberFormat
255
+ };
256
+
257
+ if (logAtCount.ContainsKey(eventName))
258
+ {
259
+ LogWarning($"{eventName} has already been set list of count number to log.");
260
+ logAtCount[eventName] = config;
261
+ }
262
+ else
263
+ {
264
+ logAtCount.Add(eventName, config);
265
+ }
266
+ }
236
267
  }
237
268
 
238
269
  //INTERNAL
239
270
  public static partial class Analytics
240
271
  {
272
+ internal class EventConfig
273
+ {
274
+ public List<int> listCount;
275
+ public bool withinSession;
276
+ public bool appendCountToEventName;
277
+ public string numberFormat;
278
+ }
279
+
280
+ internal static readonly Dictionary<string, EventConfig> logAtCount = new Dictionary<string, EventConfig>();
241
281
  internal static Predicate<EventDetail> logEventHook = null;
242
282
  internal static readonly Queue<EventParams> eventQueue = new Queue<EventParams>();
243
283
  internal static readonly List<AdapterInfo> listAdapters = new List<AdapterInfo>();
@@ -260,10 +300,6 @@ namespace Amanotes.Core
260
300
  while (eventQueue.Count > 0)
261
301
  {
262
302
  var eventData = eventQueue.Dequeue();
263
-
264
- if (!NormalizeEventName(ref eventData.eventName))
265
- continue;
266
-
267
303
  var (countInSession, totalCount) = localData.IncreaseCounter(eventData.eventName);
268
304
 
269
305
  if (!ShouldSendEvent(eventData))
@@ -274,24 +310,29 @@ namespace Amanotes.Core
274
310
  eventData.AddParam("accumulated_count", eventData.withinSession ? countInSession : totalCount);
275
311
  }
276
312
 
277
- if (showAnalyticsLog) Debug.Log($"[AmaGDK] Event <{eventData.eventName}> (in session: {countInSession}, total: {totalCount})");
313
+ var eventNameToSend = GetEventNameToSend(eventData.eventName, countInSession, totalCount);
314
+ NormalizeEventName(ref eventNameToSend);
315
+
316
+ if (showAnalyticsLog) Debug.Log($"[AmaGDK] Event <{eventNameToSend}> (in session: {countInSession}, total: {totalCount})");
278
317
  foreach (var m in listAdapters)
279
318
  {
280
- m.GetAdapterApi<IAnalyticAdapter>().LogEvent(eventData);
319
+ m.GetAdapterApi<IAnalyticAdapter>().LogEvent(eventNameToSend, eventData);
281
320
  }
282
321
  }
283
322
 
284
323
  localData.SaveIfDirty();
285
324
  }
286
325
 
287
- internal static bool NormalizeEventName(ref string eventName)
326
+ internal static string GetEventNameToSend(string eventName, int countInSession, int totalCount)
288
327
  {
289
- if (string.IsNullOrWhiteSpace(eventName))
290
- {
291
- LogWarningOnce($"Invalid EventName: <{eventName}> ");
292
- return false;
293
- }
328
+ if (!logAtCount.TryGetValue(eventName, out var config)) return eventName;
329
+ if (!config.appendCountToEventName) return eventName;
294
330
 
331
+ return $"{eventName}_{(config.withinSession ? countInSession : totalCount).ToString(config.numberFormat)}";
332
+ }
333
+
334
+ internal static bool NormalizeEventName(ref string eventName)
335
+ {
295
336
  var sb = tmpWarningSB;
296
337
  sb.Clear();
297
338
 
@@ -325,10 +366,20 @@ namespace Amanotes.Core
325
366
  return localData.AddFunnelSignature(eventData.funnelSignature);
326
367
  }
327
368
 
369
+ //Check predefined event count config
370
+ if (eventData.IsForbiddenByLogAtCountConfig())
371
+ {
372
+ return false;
373
+ }
374
+
328
375
  //Check the rule to log event
329
- if (logEventHook == null) return true;
330
- var eventDetail = localData.GetEventDetail(eventData.eventName, true);
331
- return logEventHook(eventDetail);
376
+ if (logEventHook != null)
377
+ {
378
+ var eventDetail = localData.GetEventDetail(eventData.eventName, true);
379
+ return logEventHook(eventDetail);
380
+ }
381
+
382
+ return true;
332
383
  }
333
384
  }
334
385
 
@@ -584,7 +635,7 @@ namespace Amanotes.Core
584
635
  }
585
636
 
586
637
  return true;
587
- }
638
+ }
588
639
 
589
640
  }
590
641
  }
@@ -600,7 +651,7 @@ namespace Amanotes.Core.Internal
600
651
 
601
652
  public interface IAnalyticAdapter
602
653
  {
603
- void LogEvent(EventParams eventData);
654
+ void LogEvent(string eventNameToSend, EventParams eventData);
604
655
 
605
656
  void SetUserId(string userId);
606
657
 
@@ -12,12 +12,14 @@ namespace Amanotes.Core.Internal
12
12
  public int major;
13
13
  public int minor;
14
14
  public int patch;
15
+ public int extra;
15
16
 
16
- public SemVer(int major, int minor, int patch)
17
+ public SemVer(int major, int minor, int patch, int extra = -1)
17
18
  {
18
19
  this.major = major;
19
20
  this.minor = minor;
20
21
  this.patch = patch;
22
+ this.extra = extra;
21
23
  }
22
24
 
23
25
  public SemVer(string version)
@@ -25,6 +27,7 @@ namespace Amanotes.Core.Internal
25
27
  major = 0;
26
28
  minor = 0;
27
29
  patch = 0;
30
+ extra = -1;
28
31
 
29
32
  if (string.IsNullOrEmpty(version))
30
33
  {
@@ -33,7 +36,7 @@ namespace Amanotes.Core.Internal
33
36
 
34
37
  version = version.Trim();
35
38
 
36
- Regex regex = new Regex(@"^(\d+)\.(\d+)\.(\d+)$");
39
+ Regex regex = new Regex(@"^(\d+)\.(\d+)\.(\d+)(?:\.(\d+))?$");
37
40
  Match match = regex.Match(version);
38
41
  if (!match.Success)
39
42
  {
@@ -43,6 +46,12 @@ namespace Amanotes.Core.Internal
43
46
  major = int.Parse(match.Groups[1].Value);
44
47
  minor = int.Parse(match.Groups[2].Value);
45
48
  patch = int.Parse(match.Groups[3].Value);
49
+ if (match.Groups.Count > 3)
50
+ {
51
+ if (!int.TryParse(match.Groups[4].Value, out extra))
52
+ extra = -1;
53
+ }
54
+
46
55
  }
47
56
 
48
57
  public bool isValid { get { return this != ZERO; } }
@@ -50,6 +59,7 @@ namespace Amanotes.Core.Internal
50
59
  public override string ToString()
51
60
  {
52
61
  if (this == ZERO) return "-";
62
+ if (extra != -1) return $"{major}.{minor}.{patch}.{extra}";
53
63
  return $"{major}.{minor}.{patch}";
54
64
  }
55
65
 
@@ -67,6 +77,10 @@ namespace Amanotes.Core.Internal
67
77
  {
68
78
  return patch.CompareTo(other.patch);
69
79
  }
80
+ if (extra != other.extra)
81
+ {
82
+ return extra.CompareTo(other.extra);
83
+ }
70
84
  return 0;
71
85
  }
72
86
 
@@ -82,7 +96,7 @@ namespace Amanotes.Core.Internal
82
96
  return false;
83
97
  }
84
98
  SemVer other = (SemVer)obj;
85
- return major == other.major && minor == other.minor && patch == other.patch;
99
+ return major == other.major && minor == other.minor && patch == other.patch && extra == other.extra;
86
100
  }
87
101
 
88
102
  public static bool operator >(SemVer x, SemVer y)
@@ -117,7 +131,7 @@ namespace Amanotes.Core.Internal
117
131
 
118
132
  public override int GetHashCode()
119
133
  {
120
- return (major << 16) | (minor << 8) | patch;
134
+ return (major << 24) | (minor << 16) | (patch << 8) | extra;
121
135
  }
122
136
  }
123
137
  }
@@ -1,4 +1,5 @@
1
1
  using System;
2
+ using System.Collections.Generic;
2
3
  using System.IO;
3
4
  using UnityEngine;
4
5
 
@@ -75,7 +76,7 @@ namespace Amanotes.Core.Internal
75
76
  catch (Exception ex)
76
77
  {
77
78
  LogWarningOnce(path + "\n" + ex);
78
- }
79
+ }
79
80
  }
80
81
 
81
82
  private static string _basePath;
@@ -92,7 +93,73 @@ namespace Amanotes.Core.Internal
92
93
  return _basePath;
93
94
  }
94
95
  }
95
- }
96
+ }
97
+
98
+ public class ActionQueue
99
+ {
100
+ private Queue<Action<Action>> queue;
101
+ private bool isProcessing = false;
102
+ private Action onComplete;
103
+
104
+ public ActionQueue(Action onComplete)
105
+ {
106
+ queue = new Queue<Action<Action>>();
107
+ this.onComplete = onComplete;
108
+ }
109
+
110
+ public void EnqueueAction(params Action<Action>[] actions)
111
+ {
112
+ if (isProcessing)
113
+ {
114
+ LogWarning("queue is processing!");
115
+ return;
116
+ }
117
+
118
+ foreach (var action in actions)
119
+ {
120
+ if (action == null)
121
+ {
122
+ LogWarning("action is null!");
123
+ continue;
124
+ }
125
+ queue.Enqueue(action);
126
+ }
127
+
128
+ ProcessQueue();
129
+ }
130
+
131
+ private void ProcessQueue()
132
+ {
133
+ if (isProcessing)
134
+ return;
135
+ if (queue.Count == 0)
136
+ {
137
+ onComplete?.Invoke();
138
+ return;
139
+ }
140
+
141
+ Action<Action> nextAction = null;
142
+ while (queue.Count > 0)
143
+ {
144
+ nextAction = queue.Dequeue();
145
+ if (nextAction != null)
146
+ {
147
+ isProcessing = true;
148
+ nextAction.Invoke(ActionCompleted);
149
+ return;
150
+ }
151
+ }
152
+
153
+ if(nextAction == null)
154
+ onComplete?.Invoke();
155
+ }
156
+
157
+ private void ActionCompleted()
158
+ {
159
+ isProcessing = false;
160
+ ProcessQueue();
161
+ }
162
+ }
96
163
 
97
164
  internal interface IJsonFile { }
98
165
 
package/Runtime/AmaGDK.cs CHANGED
@@ -12,7 +12,7 @@ namespace Amanotes.Core
12
12
  {
13
13
  public partial class AmaGDK : MonoBehaviour
14
14
  {
15
- public const string VERSION = "0.1.15";
15
+ public const string VERSION = "0.1.16";
16
16
 
17
17
  internal static AmaGDK _instance;
18
18
  internal static event Action _frameUpdate;
@@ -100,7 +100,7 @@ namespace Amanotes.Core
100
100
 
101
101
  // Init modules (Adapter managers)
102
102
  Analytics.Init();
103
- Ads.Init();
103
+ //Ads.Init();
104
104
 
105
105
  _status = Status.Ready;
106
106
  _onReadyCallback?.Invoke();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.amanotes.gdk",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "displayName": "AmaGDK",
5
5
  "description": "Amanotes Game Development Kit",
6
6
  "unity": "2020.3",