-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAlternativeTracker.cs
153 lines (135 loc) · 6.03 KB
/
AlternativeTracker.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* Copyright 2016 Open University of the Netherlands
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* This project has received funding from the European Union’s Horizon
* 2020 research and innovation programme under grant agreement No 644187.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System.Collections;
using AssetPackage;
using AssetPackage.Utils;
using AssetPackage.Exceptions;
public class AlternativeTracker : TrackerAsset.IGameObjectTracker
{
private TrackerAsset tracker;
public void setTracker(TrackerAsset tracker)
{
this.tracker = tracker;
}
/* ALTERNATIVES */
public enum Alternative
{
Question,
Menu,
Dialog,
Path,
Arena,
Alternative
}
/// <summary>
/// Player selected an option in a presented alternative
/// Type = Alternative
/// </summary>
/// <param name="alternativeId">Alternative identifier.</param>
/// <param name="optionId">Option identifier.</param>
public void Selected(string alternativeId, string optionId)
{
bool check = true;
check &= tracker.Utils.check<TargetXApiException>(alternativeId, "xAPI Exception: Target ID is null or empty. Ignoring.", "xAPI Exception: Target ID can't be null or empty.");
check &= tracker.Utils.check<ValueExtensionException>(optionId, "xAPI Exception: Selected alternative is null or empty", "xAPI Exception: Selected alternative can't be null or empty");
if (check)
{
tracker.Trace(new TrackerAsset.TrackerEvent(tracker)
{
Event = new TrackerAsset.TrackerEvent.TraceVerb(TrackerAsset.Verb.Selected),
Target = new TrackerAsset.TrackerEvent.TraceObject(Alternative.Alternative.ToString().ToLower(), alternativeId),
Result = new TrackerAsset.TrackerEvent.TraceResult()
{
Response = optionId
}
});
}
}
/// <summary>
/// Player selected an option in a presented alternative
/// </summary>
/// <param name="alternativeId">Alternative identifier.</param>
/// <param name="optionId">Option identifier.</param>
/// <param name="type">Alternative type.</param>
public void Selected(string alternativeId, string optionId, Alternative type)
{
bool check = true;
check &= tracker.Utils.check<TargetXApiException>(alternativeId, "xAPI Exception: Target ID is null or empty. Ignoring.", "xAPI Exception: Target ID can't be null or empty.");
check &= tracker.Utils.check<ValueExtensionException>(optionId, "xAPI Exception: Selected alternative is null or empty", "xAPI Exception: Selected alternative can't be null or empty");
if (check)
{
tracker.Trace(new TrackerAsset.TrackerEvent(tracker)
{
Event = new TrackerAsset.TrackerEvent.TraceVerb(TrackerAsset.Verb.Selected),
Target = new TrackerAsset.TrackerEvent.TraceObject(type.ToString().ToLower(), alternativeId),
Result = new TrackerAsset.TrackerEvent.TraceResult()
{
Response = optionId
}
});
}
}
/// <summary>
/// Player unlocked an option
/// Type = Alternative
/// </summary>
/// <param name="alternativeId">Alternative identifier.</param>
/// <param name="optionId">Option identifier.</param>
public void Unlocked(string alternativeId, string optionId)
{
bool check = true;
check &= tracker.Utils.check<TargetXApiException>(alternativeId, "xAPI Exception: Target ID is null or empty. Ignoring.", "xAPI Exception: Target ID can't be null or empty.");
check &= tracker.Utils.check<ValueExtensionException>(optionId, "xAPI Exception: Selected alternative is null or empty", "xAPI Exception: Selected alternative can't be null or empty");
if (check)
{
tracker.Trace(new TrackerAsset.TrackerEvent(tracker)
{
Event = new TrackerAsset.TrackerEvent.TraceVerb(TrackerAsset.Verb.Unlocked),
Target = new TrackerAsset.TrackerEvent.TraceObject(Alternative.Alternative.ToString().ToLower(), alternativeId),
Result = new TrackerAsset.TrackerEvent.TraceResult()
{
Response = optionId
}
});
}
}
/// <summary>
/// Player unlocked an option
/// </summary>
/// <param name="alternativeId">Alternative identifier.</param>
/// <param name="optionId">Option identifier.</param>
/// <param name="type">Alternative type.</param>
public void Unlocked(string alternativeId, string optionId, Alternative type)
{
bool check = true;
check &= tracker.Utils.check<TargetXApiException>(alternativeId, "xAPI Exception: Target ID is null or empty. Ignoring.", "xAPI Exception: Target ID can't be null or empty.");
check &= tracker.Utils.check<ValueExtensionException>(optionId, "xAPI Exception: Selected alternative is null or empty", "xAPI Exception: Selected alternative can't be null or empty");
if (check)
{
tracker.Trace(new TrackerAsset.TrackerEvent(tracker)
{
Event = new TrackerAsset.TrackerEvent.TraceVerb(TrackerAsset.Verb.Unlocked),
Target = new TrackerAsset.TrackerEvent.TraceObject(type.ToString().ToLower(), alternativeId),
Result = new TrackerAsset.TrackerEvent.TraceResult()
{
Response = optionId
}
});
}
}
}