Skip to content

Commit 14826ee

Browse files
authored
Merge pull request #1085 from PlayEveryWare/fix/populate-platform-deployment-from-product
fix: Set default deployment and sandbox values for platforms for first-time user scenarios
2 parents 5a6a11b + f07bb89 commit 14826ee

File tree

13 files changed

+418
-32
lines changed

13 files changed

+418
-32
lines changed

Assets/Plugins/Source/Editor/ConfigEditors/IPlatformConfigEditor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public interface IPlatformConfigEditor : IConfigEditor
3636
/// </returns>
3737
bool IsPlatformAvailable();
3838

39+
void SetDeployment(Deployment deployment);
40+
41+
PlatformManager.Platform GetPlatform();
42+
3943
Texture GetPlatformIconTexture();
4044
}
4145
}

Assets/Plugins/Source/Editor/ConfigEditors/PlatformConfigEditor.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ public Texture GetPlatformIconTexture()
5454
return PlatformManager.GetPlatformIcon(config.Platform);
5555
}
5656

57+
public void SetDeployment(Deployment deployment)
58+
{
59+
config.deployment = deployment;
60+
}
61+
62+
public PlatformManager.Platform GetPlatform()
63+
{
64+
return config.Platform;
65+
}
66+
5767
public override sealed void RenderContents()
5868
{
5969
GUIEditorUtility.RenderInputs(ref config);

Assets/Plugins/Source/Editor/EditorWindows/EOSEditorWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected EOSEditorWindow(string windowTitle, float minimumHeight = 50f, float m
122122
/// </summary>
123123
public string WindowTitle { get; }
124124

125-
private void OnEnable()
125+
protected virtual void OnEnable()
126126
{
127127
_initializeTask = Initialize();
128128
EditorApplication.update += CheckForInitialized;
@@ -288,7 +288,7 @@ public void OnGUI()
288288
}
289289
}
290290

291-
public void OnDestroy()
291+
protected virtual void OnDestroy()
292292
{
293293
Teardown();
294294
}

Assets/Plugins/Source/Editor/EditorWindows/EOSSettingsWindow.cs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ namespace PlayEveryWare.EpicOnlineServices.Editor.Windows
3434
using PlayEveryWare.EpicOnlineServices.Utility;
3535
using System;
3636
using System.Collections.Generic;
37-
using System.Threading.Tasks;
37+
using System.Linq;
38+
using System.Threading.Tasks;
3839
using UnityEditor;
3940
using UnityEngine;
4041

@@ -54,7 +55,7 @@ public class EOSSettingsWindow : EOSEditorWindow
5455
/// <summary>
5556
/// Stores the config editors for each of the platforms.
5657
/// </summary>
57-
private readonly IList<IConfigEditor> _platformConfigEditors = new List<IConfigEditor>();
58+
private readonly IList<IPlatformConfigEditor> _platformConfigEditors = new List<IPlatformConfigEditor>();
5859

5960
/// <summary>
6061
/// Contains the GUIContent that represents the set of tabs that contain
@@ -92,10 +93,47 @@ public static void ShowWindow()
9293
window.SetIsEmbedded(false);
9394
}
9495

96+
protected override void OnEnable()
97+
{
98+
base.OnEnable();
99+
ProductConfig.PlatformConfigsDeploymentUpdatedEvent += ReloadDeploymentSettingsForPlatformConfigEditors;
100+
}
101+
102+
protected override void OnDestroy()
103+
{
104+
ProductConfig.PlatformConfigsDeploymentUpdatedEvent -= ReloadDeploymentSettingsForPlatformConfigEditors;
105+
base.OnDestroy();
106+
}
107+
108+
private void ReloadDeploymentSettingsForPlatformConfigEditors(object sender, ProductConfig.PlatformConfigsDeploymentUpdatedEventArgs e)
109+
{
110+
// For each of the platform config editors
111+
foreach (IPlatformConfigEditor platformConfigEditor in _platformConfigEditors)
112+
{
113+
// If the platform config was not one of the ones updated, then skip it.
114+
if (!e.PlatformConfigsUpdated.Contains(platformConfigEditor.GetPlatform()))
115+
{
116+
continue;
117+
}
118+
119+
// If the platform config could not be read from disk
120+
if (!PlatformManager.TryGetConfig(platformConfigEditor.GetPlatform(),
121+
out PlatformConfig platformConfigFromDisk))
122+
{
123+
// TODO: Log warning?
124+
continue;
125+
}
126+
127+
// Update the deployment for the cached instance of the config
128+
// within the PlatformConfigEditor.
129+
platformConfigEditor.SetDeployment(platformConfigFromDisk.deployment);
130+
}
131+
}
132+
95133
protected override async Task AsyncSetup()
96134
{
97135
await _productConfigEditor.LoadAsync();
98-
136+
99137
List<GUIContent> tabContents = new();
100138
int tabIndex = 0;
101139
foreach (PlatformManager.Platform platform in Enum.GetValues(typeof(PlatformManager.Platform)))
@@ -178,6 +216,9 @@ private void Save()
178216
// Save the product config editor
179217
_productConfigEditor.Save();
180218

219+
// reload the product config editor
220+
_productConfigEditor.Load();
221+
181222
// Save each of the platform config editors.
182223
foreach (IConfigEditor editor in _platformConfigEditors)
183224
{

Assets/Plugins/Source/Editor/Utility/GUIEditorUtility.cs

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -975,9 +975,9 @@ private static void RenderSandboxInputs(ref ProductionEnvironments value)
975975
}
976976

977977
item.Value.Value = RenderFieldWithHint(
978-
EditorGUI.TextField,
978+
EditorGUI.DelayedTextField,
979979
new Rect(currentX, rect.y, remainingWidth - 10f, rect.height),
980-
string.IsNullOrEmpty,
980+
SandboxId.IsNullOrEmpty,
981981
item.Value.Value,
982982
"Sandbox Id");
983983
},
@@ -1079,6 +1079,13 @@ public static EOSClientCredentials RenderInput(ConfigFieldAttribute configFieldA
10791079
int currentIndex = 0;
10801080
foreach (Named<EOSClientCredentials> cred in credentials)
10811081
{
1082+
// Do not display incomplete client credentials as options
1083+
// for selection
1084+
if (!cred.Value.IsComplete)
1085+
{
1086+
continue;
1087+
}
1088+
10821089
if (cred.Value.Equals(value))
10831090
{
10841091
selectedIndex = currentIndex;
@@ -1089,11 +1096,22 @@ public static EOSClientCredentials RenderInput(ConfigFieldAttribute configFieldA
10891096
currentIndex++;
10901097
}
10911098

1099+
string additionalTooltip = "";
1100+
// If there are no credentials to select, then disable the popup.
1101+
if (credentialsLabels.Count == 0)
1102+
{
1103+
additionalTooltip =
1104+
"\nTo select a client credential for this platform, you must first add a valid one above.";
1105+
GUI.enabled = false;
1106+
}
1107+
10921108
int newIndex = EditorGUILayout.Popup(
1093-
CreateGUIContent(configFieldAttribute.Label, configFieldAttribute.ToolTip),
1109+
CreateGUIContent(configFieldAttribute.Label, configFieldAttribute.ToolTip + additionalTooltip),
10941110
selectedIndex,
10951111
credentialsLabels.ToArray());
10961112

1113+
GUI.enabled = true;
1114+
10971115
return (newIndex >= 0 && newIndex < credentials.Count) ? credentials[newIndex].Value : value;
10981116
});
10991117
}
@@ -1155,6 +1173,13 @@ public static Deployment RenderInput(ConfigFieldAttribute configFieldAttribute,
11551173
int currentIndex = 0;
11561174
foreach (Named<Deployment> deployment in deployments)
11571175
{
1176+
// Do not display incomplete deployments as options for
1177+
// selection.
1178+
if (!deployment.Value.IsComplete)
1179+
{
1180+
continue;
1181+
}
1182+
11581183
if (value.DeploymentId == deployment.Value.DeploymentId)
11591184
selectedIndex = currentIndex;
11601185

@@ -1163,11 +1188,23 @@ public static Deployment RenderInput(ConfigFieldAttribute configFieldAttribute,
11631188
currentIndex++;
11641189
}
11651190

1191+
// If there are no deployments to select, don't enable the
1192+
// popup.
1193+
string additionalTooltip = "";
1194+
if (deploymentLabels.Count == 0)
1195+
{
1196+
additionalTooltip = "\nTo select a deployment, you must define a valid one above.";
1197+
GUI.enabled = false;
1198+
}
1199+
11661200
int newIndex = EditorGUILayout.Popup(
1167-
CreateGUIContent(configFieldAttribute.Label, configFieldAttribute.ToolTip),
1201+
CreateGUIContent(configFieldAttribute.Label, configFieldAttribute.ToolTip + additionalTooltip),
11681202
selectedIndex,
11691203
deploymentLabels.ToArray());
11701204

1205+
// Re-enable the GUI
1206+
GUI.enabled = true;
1207+
11711208
return (newIndex >= 0 && newIndex < deployments.Count) ? deployments[newIndex].Value : value;
11721209
});
11731210
}

com.playeveryware.eos/Runtime/Core/Common/Named.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public override int GetHashCode()
130130

131131
public override string ToString()
132132
{
133-
return $"{Name} : {Value}";
133+
return $"\"{Name}\" : ({Value})";
134134
}
135135
}
136136
}

com.playeveryware.eos/Runtime/Core/Config/Config.cs

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ public string FilePath
409409
}
410410
}
411411

412+
#region Reading
413+
412414
// NOTE: This compile conditional is here because Async IO does not work
413415
// well on Android.
414416
#if !UNITY_ANDROID || UNITY_EDITOR
@@ -425,6 +427,7 @@ protected virtual async Task ReadAsync()
425427
{
426428
_lastReadJsonString = await FileSystemUtility.ReadAllTextAsync(FilePath);
427429
JsonUtility.FromJsonOverwrite(_lastReadJsonString, this);
430+
OnReadCompleted();
428431
}
429432
}
430433
#endif
@@ -442,11 +445,24 @@ protected virtual void Read()
442445

443446
_lastReadJsonString = FileSystemUtility.ReadAllText(FilePath);
444447
JsonUtility.FromJsonOverwrite(_lastReadJsonString, this);
448+
OnReadCompleted();
449+
}
450+
451+
protected virtual void OnReadCompleted()
452+
{
453+
// Optionally override for deriving classes. Default behavior is to
454+
// take no action.
445455
}
446456

457+
#endregion
458+
447459
/// <summary>
448460
/// Determines if the config file exists, and if it does not, and the
449461
/// editor is running, then create the file.
462+
/// TODO: Consider whether this function should be removed - there is
463+
/// no equivalent function for non-async contexts - and the
464+
/// difference in implementation between async and non-async could
465+
/// lead to confusion later on.
450466
/// </summary>
451467
/// <returns>Task.</returns>
452468
protected virtual async Task EnsureConfigFileExistsAsync()
@@ -468,6 +484,8 @@ protected virtual async Task EnsureConfigFileExistsAsync()
468484
}
469485
}
470486

487+
#region Writing
488+
471489
// Functions declared below should only ever be utilized in the editor.
472490
// They are so divided to guarantee separation of concerns.
473491
#if UNITY_EDITOR
@@ -481,6 +499,8 @@ protected virtual async Task EnsureConfigFileExistsAsync()
481499
/// <returns>Task</returns>
482500
public virtual async Task WriteAsync(bool prettyPrint = true)
483501
{
502+
BeforeWrite();
503+
484504
// Set the schema version to the current before writing.
485505
schemaVersion = CURRENT_SCHEMA_VERSION;
486506

@@ -492,6 +512,7 @@ public virtual async Task WriteAsync(bool prettyPrint = true)
492512
return;
493513

494514
await FileSystemUtility.WriteFileAsync(FilePath, json);
515+
OnWriteCompleted();
495516
}
496517

497518
/// <summary>
@@ -502,6 +523,8 @@ public virtual async Task WriteAsync(bool prettyPrint = true)
502523
/// </param>
503524
public virtual void Write(bool prettyPrint = true)
504525
{
526+
BeforeWrite();
527+
505528
// Set the schema version to the current before writing.
506529
schemaVersion = CURRENT_SCHEMA_VERSION;
507530

@@ -513,8 +536,25 @@ public virtual void Write(bool prettyPrint = true)
513536
return;
514537

515538
FileSystemUtility.WriteFile(FilePath, json);
539+
OnWriteCompleted();
540+
}
541+
542+
protected virtual void BeforeWrite()
543+
{
544+
// Optionally override this function in a deriving class. Default
545+
// behavior is to take no action.
546+
}
547+
548+
protected virtual void OnWriteCompleted()
549+
{
550+
// Optionally override for deriving classes. Default behavior is to
551+
// take no action.
516552
}
517553

554+
#endif
555+
556+
#endregion
557+
518558
/// <summary>
519559
/// Determines whether the values in the Config have their
520560
/// default values
@@ -527,7 +567,6 @@ public bool IsDefault()
527567
return IsDefault(this);
528568
}
529569

530-
531570
/// <summary>
532571
/// Returns member-wise clone of configuration data
533572
/// (copies the values).
@@ -783,6 +822,4 @@ private static IEnumerable<MemberInfo> IteratePropertiesAndFields<T>(
783822
#pragma warning restore CS0414
784823
// Field is never assigned to, and will always have its default value.
785824
#pragma warning restore CS0649
786-
#endif
787-
788825
#endif

com.playeveryware.eos/Runtime/Core/Config/Deployment.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,36 @@
2222

2323
namespace PlayEveryWare.EpicOnlineServices
2424
{
25-
using PlayEveryWare.EpicOnlineServices.Utility;
25+
using Newtonsoft.Json;
26+
using Utility;
2627
using System;
2728

2829
public struct Deployment : IEquatable<Deployment>
2930
{
31+
/// <summary>
32+
/// The SandboxId for the deployment.
33+
/// </summary>
3034
public SandboxId SandboxId;
3135

36+
/// <summary>
37+
/// The DeploymentId.
38+
/// </summary>
3239
public Guid DeploymentId;
3340

41+
/// <summary>
42+
/// Indicates whether a deployment is completely defined or not. A
43+
/// deployment is completely defined if neither the sandbox id nor the
44+
/// deployment id are empty.
45+
/// </summary>
46+
[JsonIgnore]
47+
public readonly bool IsComplete
48+
{
49+
get
50+
{
51+
return !DeploymentId.Equals(Guid.Empty) && !SandboxId.IsEmpty;
52+
}
53+
}
54+
3455
public bool Equals(Deployment other)
3556
{
3657
return SandboxId.Equals(other.SandboxId) && DeploymentId.Equals(other.DeploymentId);
@@ -45,6 +66,11 @@ public override int GetHashCode()
4566
{
4667
return HashUtility.Combine(SandboxId, DeploymentId);
4768
}
69+
70+
public override string ToString()
71+
{
72+
return $"DeploymentId: {DeploymentId.ToString("N").ToLower()}, SandboxId: {SandboxId}";
73+
}
4874
}
4975

5076
}

0 commit comments

Comments
 (0)