Skip to content

Commit e3effb1

Browse files
committed
feat: Add functionality to catch when editing productconfig results in edits being made to platformconfigs - and properly update the user interface to reflect the changes.
1 parent f5777f5 commit e3effb1

File tree

3 files changed

+82
-7
lines changed

3 files changed

+82
-7
lines changed

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

Lines changed: 41 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 NEW_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)))

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,9 @@ protected virtual void OnWriteCompleted()
541541
// take no action.
542542
}
543543

544-
#endregion
544+
#endif
545+
546+
#endregion
545547

546548
/// <summary>
547549
/// Determines whether the values in the Config have their
@@ -555,7 +557,6 @@ public bool IsDefault()
555557
return IsDefault(this);
556558
}
557559

558-
559560
/// <summary>
560561
/// Returns member-wise clone of configuration data
561562
/// (copies the values).
@@ -811,6 +812,4 @@ private static IEnumerable<MemberInfo> IteratePropertiesAndFields<T>(
811812
#pragma warning restore CS0414
812813
// Field is never assigned to, and will always have its default value.
813814
#pragma warning restore CS0649
814-
#endif
815-
816815
#endif

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,25 @@ public class ProductConfig : Config
110110
[JsonIgnore]
111111
private bool _deploymentDefined;
112112

113+
/// <summary>
114+
/// Used to store information about what platform configs have been
115+
/// updated.
116+
/// </summary>
117+
public sealed class PlatformConfigsDeploymentUpdatedEventArgs : EventArgs
118+
{
119+
/// <summary>
120+
/// A list of all the platform configs that have been updated.
121+
/// </summary>
122+
public readonly IEnumerable<PlatformManager.Platform> PlatformConfigsUpdated;
123+
124+
public PlatformConfigsDeploymentUpdatedEventArgs(IEnumerable<PlatformManager.Platform> platformConfigsUpdated)
125+
{
126+
PlatformConfigsUpdated = platformConfigsUpdated;
127+
}
128+
}
129+
130+
public static event EventHandler<PlatformConfigsDeploymentUpdatedEventArgs> PlatformConfigsDeploymentUpdatedEvent;
131+
113132
static ProductConfig()
114133
{
115134
RegisterFactory(() => new ProductConfig());
@@ -147,6 +166,8 @@ protected override void OnWriteCompleted()
147166
// platform configs to use.
148167
Named<Deployment> deploymentToSetPlatformsTo = Environments.Deployments[0];
149168

169+
List<PlatformManager.Platform> platformConfigsUpdated = new();
170+
150171
// For each platform for which configuration can be done
151172
foreach (var platform in PlatformManager.ConfigurablePlatforms)
152173
{
@@ -157,6 +178,16 @@ protected override void OnWriteCompleted()
157178
continue;
158179
}
159180

181+
// If the config already has a completely defined deployment,
182+
// then do not override, and move to the next platform config
183+
if (config.deployment.IsComplete)
184+
{
185+
continue;
186+
}
187+
188+
// Add to the list of platform configs that have been updated
189+
platformConfigsUpdated.Add(platform);
190+
160191
// Set the deployment.
161192
config.deployment = deploymentToSetPlatformsTo.Value;
162193

@@ -168,6 +199,13 @@ protected override void OnWriteCompleted()
168199
// Save the config
169200
config.Write();
170201
}
202+
203+
// If at least one platform config was updated as a result, trigger
204+
// the event that indicates as much
205+
if (platformConfigsUpdated.Count > 0)
206+
{
207+
PlatformConfigsDeploymentUpdatedEvent?.Invoke(this, new PlatformConfigsDeploymentUpdatedEventArgs(platformConfigsUpdated));
208+
}
171209
}
172210

173211
#endif

0 commit comments

Comments
 (0)