Fixed current day of week calculation

This commit is contained in:
Simon Lübeß
2024-04-05 13:54:38 +02:00
parent 81cbff9cab
commit b42ba4a9b1
13 changed files with 1981 additions and 187 deletions

View File

@ -57,7 +57,7 @@ public partial class GameManager : MonoBehaviourSingleton<GameManager>
{
TimeManager.Instance.Init();
_totalGameDurationSeconds = TimeManager.Instance.CalculateActualDeveloperTime(_difficulty);
_totalGameDurationSeconds = TimeManager.Instance.CalculateActualDeveloperTime(_difficulty, 4);
_remainingGameDurationSeconds = _totalGameDurationSeconds;

View File

@ -16,15 +16,12 @@ public class TimeManager : MonoBehaviourSingleton<TimeManager>
[SerializeField] private Light _sun;
[SerializeField]
private Weekday _currentWeekday;
private DateTime _startDate;
private DateTime _deadline;
public int DaysLeft => _daysUntilRelease;
public Weekday CurrentWeekday => _currentWeekday;
public DayOfWeek CurrentDayOfWeek => CurrentDate.DayOfWeek;
public TimeSpan TimeOfDay => CurrentDate.TimeOfDay;
@ -48,9 +45,6 @@ public class TimeManager : MonoBehaviourSingleton<TimeManager>
/// </summary>
public bool MissedDeadline => CurrentDate > Deadline;
[SerializeField, ShowOnly]
private string stringgy;
public void Init()
{
_startDate = new DateTime(2024, 4, 2, 12, 0, 0);
@ -60,11 +54,11 @@ public class TimeManager : MonoBehaviourSingleton<TimeManager>
/// <summary>
/// Berechnet die (real life) Sekunden, die die Entwickler bei 100% Effizienz benötigen um das Spiel bei gegebener Schwierigkeit zu entwickeln.
/// </summary>
public double CalculateActualDeveloperTime(Difficulty difficulty)
public double CalculateActualDeveloperTime(Difficulty difficulty, int developerCount)
{
DifficultySettings settings = difficulty.GetSettings();
return _daysUntilRelease * _secondsPerDay / settings.DaysUntilReleaseFactor;
return (_daysUntilRelease * _secondsPerDay * developerCount) / settings.DaysUntilReleaseFactor;
}
void Update()
@ -84,10 +78,7 @@ public class TimeManager : MonoBehaviourSingleton<TimeManager>
{
_totalTime -= 1.0;
_daysUntilRelease--;
_currentWeekday = _currentWeekday.GetNext();
}
stringgy = TimeOfDay.ToString();
}
private void UpdateSun()

View File

@ -1,4 +1,5 @@
using UnityEngine;
using UnityEditor;
using UnityEngine;
namespace Utility
{
@ -23,7 +24,15 @@ namespace Utility
else if (_instance != value)
{
Debug.LogError("Instance already exists. Deleting duplicate.");
Destroy(value.gameObject);
if (Application.isEditor)
{
DestroyImmediate(value.gameObject);
}
else
{
Destroy(value.gameObject);
}
}
}
}
@ -41,8 +50,11 @@ namespace Utility
public void OnAfterDeserialize()
{
// The value of Instance is lost after deserialization, so we need to set it again.
Instance = (T)this;
if (!Application.isEditor)
{
// The value of Instance is lost after deserialization, so we need to set it again.
Instance = (T)this;
}
}
}
}

View File

@ -0,0 +1,28 @@
using System;
using UnityEngine;
namespace Utility
{
[Serializable]
public struct SimpleTime
{
[SerializeField, Range(0, 23)]
private byte _hour;
[SerializeField, Range(0, 59)]
private byte _minutes;
public int Hour
{
get => _hour;
set => _hour = (byte)value;
}
public int Minute
{
get => _minutes;
set => _minutes = (byte)value;
}
public TimeSpan ToTimeSpan() => new(_hour, _minutes, 0);
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 012fa3bc180f42f396fca3a7a6c4fb5b
timeCreated: 1712316058

View File

@ -0,0 +1,17 @@
using System;
namespace Utility
{
public static class TimeSpanExtension
{
public static bool IsBetween(this TimeSpan value, TimeSpan start, TimeSpan end)
{
if (start > end)
{
throw new ArgumentException(nameof(start), "start must be before end.");
}
return value >= start && value <= end;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d76aeb99bb254637b57aa6f86d764c01
timeCreated: 1712316955

View File

@ -1,4 +1,6 @@
namespace Utility
using System;
namespace Utility
{
public enum Weekday
{
@ -41,4 +43,35 @@
_ => "Unbekannt"
};
}
public static class DayOfWeekExtension
{
/// <summary>
/// Gibt den Wochentag zurück, der auf den gegebenen Wochentag folgt.
/// </summary>
public static DayOfWeek GetNext(this DayOfWeek current) => GetFutureDay(current, 1);
/// <summary>
/// Gibt den Wochentag zurück, der in der gegebenen Anzahl an Tagen auf den gegebenen Wochentag folgt.
/// </summary>
/// <param name="current">Der aktuelle Wochentag.</param>
/// <param name="days">Die Anzahl an Tagen, die vergehen sollen.</param>
public static DayOfWeek GetFutureDay(this DayOfWeek current, int days) =>
(DayOfWeek)(((int)current + days) % 7);
/// <summary>
/// Gibt den deutschen Namen des Wochentags zurück.
/// </summary>
public static string GetName(this DayOfWeek weekday) => weekday switch
{
DayOfWeek.Monday => "Montag",
DayOfWeek.Tuesday => "Dienstag",
DayOfWeek.Wednesday => "Mittwoch",
DayOfWeek.Thursday => "Donnerstag",
DayOfWeek.Friday => "Freitag",
DayOfWeek.Saturday => "Samstag",
DayOfWeek.Sunday => "Sonntag",
_ => "Unbekannt"
};
}
}