Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "Assets/WebGLTemplates/FloatingDropdown"]
path = Assets/WebGLTemplates/FloatingDropdown
url = https://github.com/fielddaylab/FloatingDropdown.git
[submodule "Assets/WebGLTemplates/FieldDay/FloatingDropdown"]
path = Assets/WebGLTemplates/FieldDay/FloatingDropdown
url = https://github.com/fielddaylab/FloatingDropdown.git
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"visualstudiotoolsforunity.vstuc"
]
}
20 changes: 10 additions & 10 deletions Assets/Code/Advisor/PolicyState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@ public class PolicyState : SharedStateComponent, IRegistrationCallbacks, ISaveSt
// TODO: There is probably a cleaner way to do this. Does it belong in a system?
public bool SetPolicyByIndex(PolicyType policyType, int policyIndex, int region, bool forced) {
if (policyIndex < 0 || policyIndex > 3) { return false; }

using (TempVarTable varTable = TempVarTable.Alloc()) {
varTable.Set("policyType", policyType.ToString());
varTable.Set("policyIndex", policyIndex);
varTable.Set("alertRegion", region+1); // 0-indexed to 1-indexed
varTable.Set("policyForced", forced);
ScriptUtility.Trigger(GameTriggers.PolicySet, varTable);
}
ZavalaGame.Events.Dispatch(GameEvents.PolicySet, EvtArgs.Box(new PolicyData(policyType, policyIndex)));

Policies[region].Map[(int) policyType] = (PolicyLevel)policyIndex;
Policies[region].EverSet[(int) policyType] = true; // this policy has now been set
bool policySetSuccessful = false;
Expand Down Expand Up @@ -87,6 +77,16 @@ public bool SetPolicyByIndex(PolicyType policyType, int policyIndex, int region,

OnPolicyUpdated?.Invoke();

ZavalaGame.Events.Dispatch(GameEvents.PolicySet, EvtArgs.Box(new PolicyData(policyType, policyIndex)));

using (TempVarTable varTable = TempVarTable.Alloc()) {
varTable.Set("policyType", policyType.ToString());
varTable.Set("policyIndex", policyIndex);
varTable.Set("alertRegion", region + 1); // 0-indexed to 1-indexed
varTable.Set("policyForced", forced);
ScriptUtility.Trigger(GameTriggers.PolicySet, varTable);
}

return policySetSuccessful;
}

Expand Down
2 changes: 1 addition & 1 deletion Assets/Code/Alerts/GlobalAlertButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private void HandleButtonClicked() {
actor.QueuedEvents.MoveFrontToBackWhere(e => e.Alert == EventActorAlertType.Dialogue);
}

EventActorUtility.TriggerActorAlert(actor);
EventActorUtility.TriggerActorAlert(actor, false);
UIAlertUtility.ClearAlert(actor.DisplayingEvent);
TicksSinceFired = 0;
UpdateButtonRoutine();
Expand Down
121 changes: 72 additions & 49 deletions Assets/Code/Data/Logging/AnalyticsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#endif

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using BeauData;
Expand All @@ -13,6 +14,7 @@
using FieldDay.Data;
using FieldDay.Rendering;
using FieldDay.Scripting;
using Leaf.Runtime;
using OGD;
using UnityEngine;
using Zavala.Advisor;
Expand Down Expand Up @@ -453,7 +455,7 @@ public enum EndConditionType {
}

public class AnalyticsService : MonoBehaviour {
private const ushort CLIENT_LOG_VERSION = 3;
private const ushort CLIENT_LOG_VERSION = 4;

private static class Mode {
public static readonly string View = "VIEW";
Expand All @@ -466,7 +468,7 @@ private static class Mode {
[SerializeField, Required] private string m_AppVersion = "1.1";
// TODO: set up firebase consts in inspector
[SerializeField] private FirebaseConsts m_Firebase = default;
[SerializeField] private bool m_Testing = false;
[SerializeField] private bool m_Testing = true;

#endregion // Inspector

Expand Down Expand Up @@ -498,7 +500,7 @@ private struct PolicyLevelData {
public bool is_locked;

public readonly JsonBuilder Append(JsonBuilder json) {
json.Field("policy_choice", policy_choice.ToStringLookup());
json.Field("policy_choice", policy_choice);
json.Field("is_locked", is_locked);
return json;
}
Expand All @@ -523,12 +525,15 @@ public readonly JsonBuilder Append(JsonBuilder json) {
}
}


#region Logging Variables

private OGDLog m_Log;
[NonSerialized] private bool m_Debug;

static private OGDSurvey s_Survey;
[SerializeField] private SurveyPanel SurveyPrefab;
[SerializeField] private TextAsset SurveyText;

[NonSerialized] private float m_MusicVolume;
[NonSerialized] private bool m_IsFullscreen;
[NonSerialized] private bool m_IsQuality;
Expand All @@ -555,8 +560,6 @@ public readonly JsonBuilder Append(JsonBuilder json) {
#region Register and Deregister

private void Start() {


ZavalaGame.Events
// Main Menu
.Register<MenuInteractionType>(GameEvents.MainMenuInteraction, HandleMenuInteraction)
Expand All @@ -574,7 +577,7 @@ private void Start() {
.Register<AlertData>(GameEvents.GlobalAlertAppeared, LogGlobalAlertDisplayed)
.Register<AlertData>(GameEvents.GlobalAlertClicked, LogGlobalAlertClicked)
.Register<ExportDepotData>(GameEvents.ExportDepotUnlocked, LogExportDepot)
.Register<AlgaeData>(GameEvents.SimAlgaeChanged, HandleAlgaeChanged)
//.Register<AlgaeData>(GameEvents.SimAlgaeChanged, HandleAlgaeChanged)
// TODO: do we want to log every pause or just player pause?
.Register(GameEvents.SimPaused, LogGamePaused)
.Register(GameEvents.SimResumed, LogGameResumed)
Expand Down Expand Up @@ -610,7 +613,8 @@ private void Start() {
.Register<ushort>(GameEvents.RegionUnlocked, LogRegionUnlocked)
.Register<ZoomVolData>(GameEvents.SimZoomChanged, LogZoom)
// Inspect
.Register<BuildingLocation>(GameEvents.InspectorOpened, LogInspectBuilding)
.Register<BuildingLocation>(GameEvents.PlayerClickedInspector, LogClickInspectBuilding)
.Register<BuildingLocation>(GameEvents.InspectorForceOpened, UpdateInspectingBuilding)
.Register(GameEvents.GenericInspectorDisplayed, LogCommonInspectorDisplayed)
.Register<CityData>(GameEvents.CityInspectorDisplayed, LogCityInspectorDisplayed)
.Register<GrainFarmData>(GameEvents.GrainFarmInspectorDisplayed, LogGrainFarmInspectorDisplayed)
Expand Down Expand Up @@ -650,6 +654,12 @@ private void Start() {
m_Log.UseFirebase(m_Firebase);
}
m_Log.SetDebug(m_Debug);

// Create an OGDSurvey instance for survey functionality
s_Survey = new OGDSurvey(SurveyPrefab, m_Log);
// Initalize the surveys with a public TextAsset on the script
s_Survey.LoadSurveyPackageFromString(SurveyText.text);

#if UNITY_EDITOR
if (!m_Testing) {
m_Log.AddSettings(OGDLog.SettingsFlags.SkipOGDUpload);
Expand Down Expand Up @@ -828,6 +838,14 @@ private void UpdatePhosState(bool toggle) {

#region Log Events

#region Surveys
[LeafMember("RequestSurvey")]
static private IEnumerator RequestSurvey(string surveryId) {
Debug.Log("[Analytics > RequestSurvey] Requested survey: " + surveryId);
yield return s_Survey.DisplaySurveyAndWait(surveryId);
Debug.Log("[Analytics] Survey Complete.");
}
#endregion

#region Menu

Expand Down Expand Up @@ -1461,16 +1479,22 @@ private void LogGlobalAlertClicked(AlertData data) {
#endregion // Alert

#region Inspector
private void LogInspectBuilding(BuildingLocation data) {

private void UpdateInspectingBuilding(BuildingLocation data) {
m_InspectingBuilding = data;
}


private void LogClickInspectBuilding(BuildingLocation data) {
// click_inspect_building { building_type : enum(GATE, CITY, DAIRY_FARM, GRAIN_FARM, STORAGE, PROCESSOR, EXPORT_DEPOT), building_id, tile_index : int // index in the county map }
// save this building for inspector dismiss and inspector displayed events
m_InspectingBuilding = data;

using (var e = m_Log.NewEvent("click_inspect_building")) {
e.Param("building_type", EnumLookup.BuildingType[(int)data.Type]);
e.Param("building_id", data.Id);
e.Param("tile_index", data.TileIndex);
}

// save this building for inspector dismiss and inspector displayed events
m_InspectingBuilding = data;
}

private void LogDismissInspector() {
Expand Down Expand Up @@ -1506,7 +1530,6 @@ private void LogCityInspectorDisplayed(CityData data) {
e.Param("building_id", m_InspectingBuilding.Id);
e.Param("tile_index", m_InspectingBuilding.TileIndex);
e.Param("city_name", data.Name);
// TODO: convert enum tostring to string lookup array?
e.Param("population", EnumLookup.Get(data.Population));
e.Param("water", EnumLookup.Get(data.Water));
e.Param("milk", EnumLookup.Get(data.Milk));
Expand Down Expand Up @@ -1652,30 +1675,30 @@ private void LogClickInspectorTab(string name) {

#endregion //Inspector

private void HandleAlgaeChanged(AlgaeData data) {
if (data.IsGrowing) {
LogStartGrowAlgae(data);
} else {
LogEndGrowAlgae(data);
}
}
private void LogStartGrowAlgae(AlgaeData data) {
// algae_growth_begin { tile_index, phosphorus_value, algae_percent }
using (var e = m_Log.NewEvent("algae_growth_begin")) {
e.Param("tile_index", data.TileIndex);
e.Param("phosphorus_value", data.Phosphorus);
e.Param("algae_percent", data.Algae);
}
}

private void LogEndGrowAlgae(AlgaeData data) {
// algae_growth_end { tile_index, phosphorus_value, algae_percent }
using (var e = m_Log.NewEvent("algae_growth_end")) {
e.Param("tile_index", data.TileIndex);
e.Param("phosphorus_value", data.Phosphorus);
e.Param("algae_percent", data.Algae);
}
}
//private void HandleAlgaeChanged(AlgaeData data) {
// if (data.IsGrowing) {
// LogStartGrowAlgae(data);
// } else {
// LogEndGrowAlgae(data);
// }
//}
//private void LogStartGrowAlgae(AlgaeData data) {
// // algae_growth_begin { tile_index, phosphorus_value, algae_percent }
// using (var e = m_Log.NewEvent("algae_growth_begin")) {
// e.Param("tile_index", data.TileIndex);
// e.Param("phosphorus_value", data.Phosphorus);
// e.Param("algae_percent", data.Algae);
// }
//}

//private void LogEndGrowAlgae(AlgaeData data) {
// // algae_growth_end { tile_index, phosphorus_value, algae_percent }
// using (var e = m_Log.NewEvent("algae_growth_end")) {
// e.Param("tile_index", data.TileIndex);
// e.Param("phosphorus_value", data.Phosphorus);
// e.Param("algae_percent", data.Algae);
// }
//}

#endregion // Sim

Expand Down Expand Up @@ -1797,25 +1820,25 @@ private void LogFailedGame(LossData data) {

private void LogConditionMet(EndConditionData data) {
// end_condition_achieved: { end_type: enum, condition_type: enum, county: int }
m_JsonBuilder.Begin();
m_JsonBuilder.Field("end_type", data.EndType);
m_JsonBuilder.Field("condition_type", data.ConditionType);
m_JsonBuilder.Field("county_name", EnumLookup.RegionName[data.Region]);
m_JsonBuilder.EndObject();
m_Log.Log("end_condition_achieved", m_JsonBuilder.End());
using (var e = m_Log.NewEvent("end_condition_achieved", m_JsonBuilder)) {
e.Field("end_type", data.EndType);
e.Field("condition_type", data.ConditionType);
e.Field("county_name", EnumLookup.RegionName[data.Region]);
e.EndObject();
}
if (data.EndType.Equals(EnumLookup.Get(EndType.Succeeded))) {
UpdateWinConditionState(data.ConditionType, true);
}
}

private void LogConditionLost(EndConditionData data) {
// end_condition_lost: { end_type: enum, condition_type: enum, county: int }
m_JsonBuilder.Begin();
m_JsonBuilder.Field("end_type", data.EndType);
m_JsonBuilder.Field("condition_type", data.ConditionType);
m_JsonBuilder.Field("county_name", EnumLookup.RegionName[data.Region]);
m_JsonBuilder.EndObject();
m_Log.Log("end_condition_lost", m_JsonBuilder.End());
using (var e = m_Log.NewEvent("end_condition_lost", m_JsonBuilder)) {
e.Field("end_type", data.EndType);
e.Field("condition_type", data.ConditionType);
e.Field("county_name", EnumLookup.RegionName[data.Region]);
e.EndObject();
}
if (data.EndType.Equals(EnumLookup.Get(EndType.Succeeded))) {
UpdateWinConditionState(data.ConditionType, false);
}
Expand Down

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

8 changes: 5 additions & 3 deletions Assets/Code/Scripting/Actors/EventActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ static public void QueueDialogueAlert(int regionOneIndexed, string type, StringH
QueueDialogueAlert("region" + regionOneIndexed + "_" + type + "1", targetNode);
}

public static void TriggerActorAlert(EventActor actor) {
public static void TriggerActorAlert(EventActor actor, bool sendEvent = true) {

// Activate queued script node event
using (TempVarTable varTable = TempVarTable.Alloc()) {
Expand All @@ -256,9 +256,11 @@ public static void TriggerActorAlert(EventActor actor) {
varTable.Set(newEvent.SecondArg.Id, newEvent.SecondArg.Value);
}

ZavalaGame.Events.Dispatch(GameEvents.AlertClicked, EvtArgs.Box(new AlertData(actor, newEvent)));
if (sendEvent) {
ZavalaGame.Events.Dispatch(GameEvents.AlertClicked, EvtArgs.Box(new AlertData(actor, newEvent)));
}

// TODD: shift screen focus to this event, updating current region index (may need to store the occupies tile index or region number in the queued event)
// shift screen focus to this event, updating current region index (may need to store the occupies tile index or region number in the queued event)
WorldCameraUtility.PanCameraToTransform(actor.transform, -1.5f);

// Use region index as a condition for alerts
Expand Down
3 changes: 2 additions & 1 deletion Assets/Code/Scripting/Consts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ static public class GameEvents
static public readonly StringHash32 DestroyModeExited = "destroy:cancel";
static public readonly StringHash32 DestroyModeEnded = "destroy:ended";

static public readonly StringHash32 InspectorOpened = "inspector:opened";
static public readonly StringHash32 PlayerClickedInspector = "inspector:opened";
static public readonly StringHash32 InspectorForceOpened = "inspector:force-opened";
static public readonly StringHash32 InspectorClosed = "inspector:closed";
static public readonly StringHash32 InspectorTabClicked = "inspector:tab";

Expand Down
8 changes: 7 additions & 1 deletion Assets/Code/Scripting/Data/ScriptNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ private void SetForcePolicyEarly(AdvisorType advisorType, ScriptNodeMemoryTarget
PersistenceType = target;
}

[BlockMeta("doNotLog")]
private void SetDoNotLog() {
Flags |= ScriptNodeFlags.DoNotLog;
}

#endregion // Internal
}

Expand All @@ -113,7 +118,8 @@ public enum ScriptNodeFlags : uint {
InterruptSamePriority = 0x40,
AnyTarget = 0x80,
ForcePolicy = 0x100,
ForcePolicyEarly = 0x200
ForcePolicyEarly = 0x200,
DoNotLog = 0x400
}

/// <summary>
Expand Down
14 changes: 11 additions & 3 deletions Assets/Code/Scripting/Runtime/ScriptPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,20 @@ public override void OnNodeEnter(ScriptNode inNode, LeafThreadState<ScriptNode>
}
if (Game.Gui.TryGetShared(out InfoPopup ip)) {
ip.HoldOpen = false;
ip.Hide();
if (ip.IsVisible()) {
ZavalaGame.Events.Dispatch(GameEvents.InspectorClosed);
ip.Hide();
}
}

m_RuntimeState.DefaultDialogue.MarkNodeEntered();

// reset pin overrides at the start of a new node
m_RuntimeState.DefaultDialogue.ClearPinForces();

ZavalaGame.Events.Dispatch(GameEvents.DialogueStarted, EvtArgs.Box(new Zavala.Data.ScriptNodeData(inNode.FullName, !cutscene)));
if ((inNode.Flags & ScriptNodeFlags.DoNotLog) == 0) {
ZavalaGame.Events.Dispatch(GameEvents.DialogueStarted, EvtArgs.Box(new Zavala.Data.ScriptNodeData(inNode.FullName, !cutscene)));
}
}

public override void OnNodeExit(ScriptNode inNode, LeafThreadState<ScriptNode> inThreadState) {
Expand All @@ -122,7 +128,9 @@ public override void OnNodeExit(ScriptNode inNode, LeafThreadState<ScriptNode> i
if (Game.Gui.TryGetShared(out InfoPopup ip) && ip.HoldOpen) {
ip.HoldOpen = false;
}
ZavalaGame.Events.Dispatch(GameEvents.DialogueClosing, EvtArgs.Box(new Zavala.Data.ScriptNodeData(inNode.FullName, !cutscene)));
if ((inNode.Flags & ScriptNodeFlags.DoNotLog) == 0) {
ZavalaGame.Events.Dispatch(GameEvents.DialogueClosing, EvtArgs.Box(new Zavala.Data.ScriptNodeData(inNode.FullName, !cutscene)));
}

}

Expand Down
Loading
Loading