Skip to content

Commit

Permalink
* survey timing
Browse files Browse the repository at this point in the history
* ensure surveys pause all game input
  • Loading branch information
BeauchesneFieldDay committed Sep 5, 2024
1 parent 202f2c5 commit ecd06c3
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 11 deletions.
1 change: 1 addition & 0 deletions Assets/_Assets/Prefabs/_System/Bootstrap.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ MonoBehaviour:
m_AppVersion: 10.1
m_SurveyPrefab: {fileID: 2400622096144153359, guid: a196add77bdc99a448d3b2a6ecaa3f64,
type: 3}
m_SurveyData: {fileID: 4900000, guid: db0d9216062b6c8498f47ff3f55b0c31, type: 3}
m_Firebase:
ApiKey: AIzaSyDM8z5Q3ydHPPTXu374ZF_5Uwc6rX2B7q4
ProjectId: aqualab-57f88
Expand Down
3 changes: 2 additions & 1 deletion Assets/_Code/Data/Profile/SavePatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ static public class SavePatcher {
// 3: fix for softlock in first job
// 4: exp->levels, adjusting starting exp
// 5: story
public const uint CurrentVersion = 5;
// 6: surveys
public const uint CurrentVersion = 6;

private const uint ValidVersionThreshold = 5;

Expand Down
10 changes: 8 additions & 2 deletions Assets/_Code/UI/UIMgr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,14 @@ protected override void Initialize()
SceneHelper.OnSceneUnload += CleanupFromScene;

Services.Events.Register(GameEvents.OptionsUpdated, OnOptionsUpdated)
.Register(GameEvents.SurveyStart, () => m_SurveyCounter++, this)
.Register(GameEvents.SurveyEnd, () => m_SurveyCounter--, this);
.Register(GameEvents.SurveyStart, () => {
m_SurveyCounter++;
Services.Input.PauseAll();
}, this)
.Register(GameEvents.SurveyEnd, () => {
m_SurveyCounter--;
Services.Input.ResumeAll();
}, this);

BindCamera(Camera.main);
transform.FlattenHierarchy();
Expand Down
71 changes: 71 additions & 0 deletions Assets/_Content/DefaultSurveys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"package_config_id": "wake_survey_testing",
"surveys": [
{
"display_event_id": "first-launch",
"header": "Welcome To Wake",
"pages": [
{
"items": [
{
"prompt": "Is this your first player code?",
"responses": [
"Yes", "No"
]
},
{
"prompt": "Are you playing this as an assignment, or for fun?",
"responses": [
"Assignment", "Fun", "Other"
]
}
]
},
{
"items": [
{
"prompt": "About how old are you?",
"responses": [
"0-10", "11-14", "15-18", "19-25", "26+", "Prefer Not to Answer"
]
},
{
"prompt": "What grade level are you in?",
"responses": [
"Elementary", "6th", "7th", "8th", "9th", "10th", "11th", "12th", "College", "N/a"
]
},
{
"prompt": "What gender are you?",
"responses": [
"Male", "Female", "Nonbinary", "Other", "Prefer Not To Answer"
]
}
]
}
]
},
{
"display_event_id": "completed-jobs-1",
"header": "Welcome To Wake (pt. 2)",
"pages": [
{
"items": [
{
"prompt": "How was that job?",
"responses": [
"Good", "Bad", "What?"
]
},
{
"prompt": "Do you trust Mom?",
"responses": [
"Of course!", "Not quite", "Definitely not", "That's a leading question..."
]
}
]
}
]
}
]
}
7 changes: 7 additions & 0 deletions Assets/_Content/DefaultSurveys.json.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Assets/_Modules/Analytics/AlternateJobGraphFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,25 @@ public enum Status {

static public Status GetStatus(SaveData saveData) {
#if ANALYTICS_ABTEST_ALTJOBGRAPH
return ResearchTests.IsABC(saveData, 2) ? Status.Active : Status.Inactive;
return ResearchTests.IsABC(saveData, 2) || ResearchTests.IsFlagged(saveData, 0) ? Status.Active : Status.Inactive;
#else
return Status.Invalid;
#endif // ANALYTICS_ABTEST_ALTJOBGRAPH
}

static public void TryApplyPatch() {
#if ANALYTICS_ABTEST_ALTJOBGRAPH
if (Save.Current == null) {
return;
}

if (GetStatus(Save.Current) != Status.Active) {
ContentPatcher.Undo();
return;
}

Save.Current.ResearchFlags.Set(0);

if (ContentPatcher.IsPatched()) {
return;
}
Expand Down
12 changes: 9 additions & 3 deletions Assets/_Modules/Analytics/AnalyticsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public partial class AnalyticsService : ServiceBehaviour, IDebuggable
[SerializeField, Required] private string m_AppId = "AQUALAB";
[SerializeField, Required] private string m_AppVersion = "6.2";
[SerializeField, Required] private SurveyPanel m_SurveyPrefab;
[SerializeField] private TextAsset m_SurveyData;
[SerializeField] private FirebaseConsts m_Firebase = default(FirebaseConsts);

#endregion // Inspector
Expand Down Expand Up @@ -152,12 +153,17 @@ protected override void Initialize()
Services.Events.Dispatch(GameEvents.SurveyEnd, EvtArgs.Ref(s));
};

if (m_SurveyData != null) {
m_Survey.LoadSurveyPackageFromString(m_SurveyData.text);
Assets.FullyUnload(ref m_SurveyData);
}

RefreshGameState();
}

private void OnProfileStarting(string userCode) {
SetUserCode(userCode);
ResearchTests.HandleProfileStart();
ResearchTests.HandleProfileStart(m_Survey);
}

private void SetUserCode(string userCode)
Expand Down Expand Up @@ -509,9 +515,9 @@ private void LogCompleteJob(StringHash32 jobId)
e.Param("job_name", parsedJobName);
}

if (!job.HasFlags(JobDescFlags.None)) {
if (!job.HasFlags(JobDescFlags.Hidden | JobDescFlags.NoPopup)) {
int jobCount = Save.Current.Jobs.CompletedJobIds().Count;
string surveyName = string.Format("completed-{0}-jobs", jobCount);
string surveyName = string.Concat("completed-jobs-", jobCount.ToStringLookup());
Services.Script.QueueInvoke(() => {
m_Survey.TryDisplaySurvey(surveyName);
}, -10);
Expand Down
29 changes: 27 additions & 2 deletions Assets/_Modules/Analytics/ResearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
#define DEVELOPMENT
#endif

using System.Collections;
using System.Runtime.CompilerServices;
using Aqua.Profile;
using OGD;

namespace Aqua.Analytics {
static public class ResearchTests {
Expand Down Expand Up @@ -53,6 +55,14 @@ static public bool IsABC(SaveData save, int index) {
#endif // ABTESTS_ALLOWED
}

static public bool IsFlagged(SaveData save, int flag) {
#if ABTESTS_ALLOWED
return save != null && save.ResearchFlags.IsSet(flag);
#else
return false;
#endif // ABTESTS_ALLOWED
}

#endregion // Tests

#region Modifying Branch Name
Expand Down Expand Up @@ -82,9 +92,13 @@ static internal void DEBUGRefreshAllTests() {
}
#endif // DEVELOPMENT

static public void HandleProfileStart() {
static public void HandleProfileStart(OGDSurvey surveyDisplayer) {
#if ABTESTS_ALLOWED
UserCodeReminderFeature.TryQueueDisplay();
if (IsNewSave(Save.Current)) {
Services.State.OnSceneLoadReady(() => InitialSurvey(surveyDisplayer));
} else {
UserCodeReminderFeature.TryQueueDisplay();
}
JobPredictionFeature.TryLoadTable();
AlternateJobGraphFeature.TryApplyPatch();
#endif // ABTESTS_ALLOWED
Expand All @@ -93,5 +107,16 @@ static public void HandleProfileStart() {
static public void HandleProfileEnd() {
ContentPatcher.Undo();
}

static private bool IsNewSave(SaveData saveData) {
return saveData.LaunchCount == 1 && saveData.Script.ProfileNodeHistory.Count == 0;
}

static private IEnumerator InitialSurvey(OGDSurvey survey) {
survey.TryDisplaySurvey("first-launch");
while(Services.UI.IsDisplayingSurvey) {
yield return null;
}
}
}
}
5 changes: 3 additions & 2 deletions Assets/_Modules/Analytics/UserCodeReminderFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ static public string GetModifiedBranchName(string branchName, Status active) {
}
}

static public void TryQueueDisplay() {
static public bool TryQueueDisplay() {
if (GetStatus(Save.Current) != Status.Active) {
return;
return false;
}

Services.State.OnSceneLoadReady(DisplayReminder);
return true;
}

static private IEnumerator DisplayReminder() {
Expand Down

0 comments on commit ecd06c3

Please sign in to comment.