Skip to content

Conversation

@xchesh
Copy link

@xchesh xchesh commented Dec 21, 2025

No description provided.

Copilot AI review requested due to automatic review settings December 21, 2025 16:50
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the clock system by renaming IClockModel to IClockService and introduces a configurable time offset feature using Unity's ScriptableObject pattern. The configuration is loaded via Resources.Load and injected through the dependency injection container.

Key changes:

  • Renamed IClockModel/ClockModel to IClockService/ClockService for more accurate naming
  • Added IClockConfig interface and ClockConfig ScriptableObject to support time offset configuration
  • Integrated configuration loading through dependency injection using Resources.Load

Reviewed changes

Copilot reviewed 12 out of 14 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
IClockService.cs Renamed interface from IClockModel to IClockService
IClockConfig.cs New interface defining clock configuration contract with time offset
ClockService.cs New implementation replacing ClockModel, now accepts IClockConfig dependency
ClockConfig.cs ScriptableObject implementation of IClockConfig for Unity Editor configuration
Composition.cs Updated DI setup to load ClockConfig from Resources and bind ClockService
Clock.cs Updated to use IClockService instead of IClockModel
ClockModel.cs Removed (replaced by ClockService)
Resources/ClockConfig.asset New ScriptableObject asset with 15-second offset configuration
Various .meta files Unity metadata files for new assets and scripts

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

.Bind().As(Singleton).To<ClockModel>()
.Bind<IClockConfig>().To((ctx) =>
{
return Resources.Load<ClockConfig>("ClockConfig");
Copy link

Copilot AI Dec 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Resources.Load call could return null if the ClockConfig asset is missing or not found in the Resources folder. This would cause a null reference exception when ClockService attempts to access the config. Consider adding null checking and providing a meaningful error message or a default fallback configuration.

Suggested change
return Resources.Load<ClockConfig>("ClockConfig");
var config = Resources.Load<ClockConfig>("ClockConfig");
if (config == null)
{
Debug.LogError("ClockConfig asset not found in Resources. Using a default ClockConfig instance as fallback.");
config = ScriptableObject.CreateInstance<ClockConfig>();
}
return config;

Copilot uses AI. Check for mistakes.
public DateTime Now => DateTime.Now + _config.Offset;

public ClockService(IClockConfig config)
{
Copy link

Copilot AI Dec 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor does not validate that the config parameter is not null. If a null config is passed (which could happen if Resources.Load fails in Composition.cs), this will result in a NullReferenceException when accessing _config.Offset in the Now property. Consider adding validation or documenting the assumption that config must not be null.

Suggested change
{
{
if (config == null) throw new ArgumentNullException(nameof(config));

Copilot uses AI. Check for mistakes.
Comment on lines +2 to +4

public interface IClockConfig
{
Copy link

Copilot AI Dec 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IClockConfig interface and its Offset property lack documentation. Consider adding XML documentation comments to explain the purpose of the configuration and what the Offset represents (e.g., whether it's added to or subtracted from the current time, and what use cases it supports).

Suggested change
public interface IClockConfig
{
/// <summary>
/// Configuration settings for a clock abstraction, including any time adjustment
/// to apply to the underlying current time.
/// </summary>
public interface IClockConfig
{
/// <summary>
/// Gets the time offset to apply to the base current time.
/// </summary>
/// <remarks>
/// A positive value represents a clock that is ahead of the base time, and a
/// negative value represents a clock that is behind the base time. This can be
/// used for scenarios such as testing, time simulation, or compensating for
/// known time differences.
/// </remarks>

Copilot uses AI. Check for mistakes.
Comment on lines +3 to +8

[CreateAssetMenu(fileName = "ClockConfig", menuName = "Clock/Config")]
public class ClockConfig : ScriptableObject, IClockConfig
{
[SerializeField] private int _offsetSeconds;

Copy link

Copilot AI Dec 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ClockConfig class and its _offsetSeconds field lack documentation. Consider adding XML documentation comments to explain the purpose of the configuration, what the offset represents, and provide usage examples. This is especially important for a ScriptableObject that will be configured in the Unity Editor.

Suggested change
[CreateAssetMenu(fileName = "ClockConfig", menuName = "Clock/Config")]
public class ClockConfig : ScriptableObject, IClockConfig
{
[SerializeField] private int _offsetSeconds;
/// <summary>
/// Configuration asset that defines how much to offset a clock from a reference time.
/// </summary>
/// <remarks>
/// Create an instance of this asset via the Unity menu <c>Assets &gt; Create &gt; Clock &gt; Config</c>
/// and assign it to any component that requires an <see cref="IClockConfig"/>. The configured
/// offset is typically applied relative to the system time or another reference time source.
/// </remarks>
/// <example>
/// <code>
/// public class ClockDisplay : MonoBehaviour
/// {
/// [SerializeField] private ClockConfig _config;
///
/// private DateTime Now => DateTime.UtcNow + _config.Offset;
/// }
/// </code>
/// </example>
[CreateAssetMenu(fileName = "ClockConfig", menuName = "Clock/Config")]
public class ClockConfig : ScriptableObject, IClockConfig
{
/// <summary>
/// Time offset, in seconds, applied to the reference time.
/// </summary>
/// <remarks>
/// Positive values move the clock forward in time, while negative values move it backward.
/// This value is exposed in the Unity Inspector and converted to a <see cref="TimeSpan"/>
/// via the <see cref="Offset"/> property.
/// </remarks>
[SerializeField] private int _offsetSeconds;
/// <summary>
/// Gets the configured time offset as a <see cref="TimeSpan"/>.
/// </summary>

Copilot uses AI. Check for mistakes.
Comment on lines +3 to +13
public class ClockService : IClockService
{
private readonly IClockConfig _config;

public DateTime Now => DateTime.Now + _config.Offset;

public ClockService(IClockConfig config)
{
_config = config;
}
} No newline at end of file
Copy link

Copilot AI Dec 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ClockService class lacks documentation. Consider adding XML documentation comments to explain its purpose, how it differs from using DateTime.Now directly, and how the offset configuration affects the returned time.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant