Skip to content

Commit 42a643d

Browse files
refactor(audience-sample): centralise UXML / CSS / message strings into SampleAppUi
Moves the SampleAppUi catalogue from Tests/Runtime to Scripts so non-test code can reference it, and expands it to cover every UXML element name, CSS class, button caption, resource path, and side string the sample manipulates. - Moves SampleAppUi.cs from Tests/Runtime to Scripts so AudienceSample.cs / .UI.cs / .Events.cs can reference it. - SampleAppUi gains AliasFromType / AliasToType identity-field names. - SampleAppUi.Layout names the layout-internal elements (sdk-version, tab-bar, typed-events-host, log-resize-handle, page-scroll, controls-column, log-column, sample-app-grid, log-count, accordion-{item, title, content}). - SampleAppUi.Css names every CSS class the sample manipulates (state-*, accordion-*, log-*, badge-*, status-value, field-*, etc.). - SampleAppUi.ButtonText (Send / Copy / Copied) names dynamically-built button captions. - SampleAppUi.Resources names the four Resources.Load asset paths. - SampleAppUi.Messages holds six human-readable side strings used in consent / identity flows. - SampleAppUi.LogLabels gains Ready / Sdk / OnError / Init / Shutdown / Reset / Flush / DeleteData / Page / Track / SetConsent. - SampleAppUi.LogBadgeText names the two-letter SDK / APP pill text. - SampleAppUi.StatusBar.EmptyText replaces six hardcoded em-dash placeholder glyphs. - AudienceSample.cs / .UI.cs / .Events.cs read UXML element names, CSS classes, dynamic button captions, resource paths, and log labels from SampleAppUi. - SampleAppLiveFireTests.cs reads UXML element names, log labels, and the env-var key from SampleAppUi.
1 parent 153f25f commit 42a643d

7 files changed

Lines changed: 524 additions & 380 deletions

File tree

examples/audience/Assets/SampleApp/Scripts/AudienceSample.Events.cs

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Globalization;
6+
using System.Linq;
67
using UnityEngine.UIElements;
78

89
namespace Immutable.Audience.Samples.SampleApp
@@ -38,6 +39,18 @@ internal readonly struct EventSpec
3839

3940
private const string OptionalEnumSentinel = "(not set)";
4041

42+
private static readonly string[] ProgressionStatusValues =
43+
Enum.GetValues(typeof(ProgressionStatus))
44+
.Cast<ProgressionStatus>()
45+
.Select(s => s.ToLowercaseString())
46+
.ToArray();
47+
48+
private static readonly string[] ResourceFlowValues =
49+
Enum.GetValues(typeof(ResourceFlow))
50+
.Cast<ResourceFlow>()
51+
.Select(f => f.ToLowercaseString())
52+
.ToArray();
53+
4154
// ---- Event catalogue ----
4255

4356
internal static readonly EventSpec[] Catalogue =
@@ -63,15 +76,15 @@ internal readonly struct EventSpec
6376
// it as auto-tracked on Init with no public typed class; firing it
6477
// from the Send button would double-emit.
6578
new EventSpec(EventNames.Progression, new[] {
66-
EventField.Enum(EventPropertyKeys.Status, new[] { "start", "complete", "fail" }),
79+
EventField.Enum(EventPropertyKeys.Status, ProgressionStatusValues),
6780
EventField.Text(EventPropertyKeys.World, optional: true),
6881
EventField.Text(EventPropertyKeys.Level, optional: true),
6982
EventField.Text(EventPropertyKeys.Stage, optional: true),
7083
EventField.Number(EventPropertyKeys.Score, optional: true),
7184
EventField.Number(EventPropertyKeys.DurationSec, optional: true),
7285
}),
7386
new EventSpec(EventNames.Resource, new[] {
74-
EventField.Enum(EventPropertyKeys.Flow, new[] { "sink", "source" }),
87+
EventField.Enum(EventPropertyKeys.Flow, ResourceFlowValues),
7588
EventField.Text(EventPropertyKeys.Currency),
7689
EventField.Number(EventPropertyKeys.Amount),
7790
EventField.Text(EventPropertyKeys.ItemType, optional: true),
@@ -103,61 +116,54 @@ internal readonly struct EventSpec
103116
return new Progression
104117
{
105118
Status = ParseProgressionStatus(props),
106-
World = OptionalString(props, "world"),
107-
Level = OptionalString(props, "level"),
108-
Stage = OptionalString(props, "stage"),
109-
Score = OptionalInt(props, "score"),
110-
DurationSec = OptionalFloat(props, "durationSec"),
119+
World = OptionalString(props, EventPropertyKeys.World),
120+
Level = OptionalString(props, EventPropertyKeys.Level),
121+
Stage = OptionalString(props, EventPropertyKeys.Stage),
122+
Score = OptionalInt(props, EventPropertyKeys.Score),
123+
DurationSec = OptionalFloat(props, EventPropertyKeys.DurationSec),
111124
};
112125
case EventNames.Resource:
113126
return new Resource
114127
{
115128
Flow = ParseResourceFlow(props),
116-
Currency = OptionalString(props, "currency") ?? "",
117-
Amount = OptionalFloat(props, "amount") ?? 0f,
118-
ItemType = OptionalString(props, "itemType"),
119-
ItemId = OptionalString(props, "itemId"),
129+
Currency = OptionalString(props, EventPropertyKeys.Currency) ?? "",
130+
Amount = OptionalFloat(props, EventPropertyKeys.Amount) ?? 0f,
131+
ItemType = OptionalString(props, EventPropertyKeys.ItemType),
132+
ItemId = OptionalString(props, EventPropertyKeys.ItemId),
120133
};
121134
case EventNames.Purchase:
122135
return new Purchase
123136
{
124-
Currency = OptionalString(props, "currency") ?? "",
125-
Value = OptionalDecimal(props, "value") ?? 0m,
126-
ItemId = OptionalString(props, "itemId"),
127-
ItemName = OptionalString(props, "itemName"),
128-
Quantity = OptionalInt(props, "quantity"),
129-
TransactionId = OptionalString(props, "transactionId"),
137+
Currency = OptionalString(props, EventPropertyKeys.Currency) ?? "",
138+
Value = OptionalDecimal(props, EventPropertyKeys.Value) ?? 0m,
139+
ItemId = OptionalString(props, EventPropertyKeys.ItemId),
140+
ItemName = OptionalString(props, EventPropertyKeys.ItemName),
141+
Quantity = OptionalInt(props, EventPropertyKeys.Quantity),
142+
TransactionId = OptionalString(props, EventPropertyKeys.TransactionId),
130143
};
131144
case EventNames.MilestoneReached:
132-
return new MilestoneReached { Name = OptionalString(props, "name") ?? "" };
145+
return new MilestoneReached { Name = OptionalString(props, EventPropertyKeys.Name) ?? "" };
133146
default:
134147
return null;
135148
}
136149
}
137150

138151
private static ProgressionStatus? ParseProgressionStatus(Dictionary<string, object> props)
139152
{
140-
var s = OptionalString(props, "status");
153+
var s = OptionalString(props, EventPropertyKeys.Status);
141154
if (string.IsNullOrEmpty(s)) return null;
142-
return s switch
143-
{
144-
"start" => ProgressionStatus.Start,
145-
"complete" => ProgressionStatus.Complete,
146-
"fail" => ProgressionStatus.Fail,
147-
_ => (ProgressionStatus?)null,
148-
};
155+
foreach (ProgressionStatus value in Enum.GetValues(typeof(ProgressionStatus)))
156+
if (value.ToLowercaseString() == s) return value;
157+
return null;
149158
}
150159

151160
private static ResourceFlow? ParseResourceFlow(Dictionary<string, object> props)
152161
{
153-
var s = OptionalString(props, "flow");
162+
var s = OptionalString(props, EventPropertyKeys.Flow);
154163
if (string.IsNullOrEmpty(s)) return null;
155-
return s switch
156-
{
157-
"source" => ResourceFlow.Source,
158-
"sink" => ResourceFlow.Sink,
159-
_ => (ResourceFlow?)null,
160-
};
164+
foreach (ResourceFlow value in Enum.GetValues(typeof(ResourceFlow)))
165+
if (value.ToLowercaseString() == s) return value;
166+
return null;
161167
}
162168

163169
private static string? OptionalString(Dictionary<string, object> props, string key) =>

0 commit comments

Comments
 (0)