Skip to content

Commit

Permalink
🔩📦 2.2.0 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanMCarter authored Mar 31, 2024
2 parents 99d35a9 + 392483f commit b1eb079
Show file tree
Hide file tree
Showing 18 changed files with 1,240 additions and 1,151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

using System.Collections.Generic;
using System.Linq;
using CarterGames.Assets.LeaderboardManager.Serialization;
using UnityEditor;
using UnityEngine;

Expand Down Expand Up @@ -125,7 +126,16 @@ public void DrawTab()
EditorGUILayout.BeginHorizontal();
EditorGUILayout.TextField(boards[i].BoardData[j].EntryUuid);
EditorGUILayout.TextField(boards[i].BoardData[j].EntryName);
EditorGUILayout.TextField(boards[i].BoardData[j].EntryValue.ToString());

if (boards[i].Type.Equals(LeaderboardType.Time))
{
EditorGUILayout.TextField(((SerializableTime) boards[i].BoardData[j].EntryValue).ToString("dd:hh:mm:ss.fff"));
}
else
{
EditorGUILayout.TextField(boards[i].BoardData[j].EntryValue.ToString());
}

EditorGUILayout.EndHorizontal();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ private static LegacyBoardStore LoadData(string path)
private static void ConvertAndSave(LegacyBoardDataClass legacyBoardDataClass, LeaderboardType convertTo)
{
LeaderboardManager.Load();
LeaderboardManager.CreateLeaderboard(legacyBoardDataClass.BoardID);
LeaderboardManager.CreateLeaderboard(legacyBoardDataClass.BoardID, convertTo);

foreach (var entry in legacyBoardDataClass.BoardData)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static class AssetVersionData
/// <summary>
/// The version number of the asset.
/// </summary>
public static string VersionNumber => "2.1.0";
public static string VersionNumber => "2.2.0";


/// <summary>
Expand All @@ -40,6 +40,6 @@ public static class AssetVersionData
/// <remarks>
/// Asset owner is in the UK, so its D/M/Y format.
/// </remarks>
public static string ReleaseDate => "14/03/2024";
public static string ReleaseDate => "31/03/2024";
}
}
27 changes: 16 additions & 11 deletions Carter Games/Leaderboard Manager/Code/Runtime/Data/Leaderboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public sealed class Leaderboard
───────────────────────────────────────────────────────────────────────────────────────────────────────────── */

[SerializeField] private string boardID;
[SerializeField] private LeaderboardType type;
[SerializeField] private List<LeaderboardEntry> boardData;

/* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
Expand All @@ -53,6 +54,16 @@ public string Id
get => boardID;
set => boardID = value;
}


/// <summary>
/// The type the leaderboard is for.
/// </summary>
public LeaderboardType Type
{
get => type;
set => type = value;
}


/// <summary>
Expand All @@ -69,20 +80,14 @@ public List<LeaderboardEntry> BoardData
───────────────────────────────────────────────────────────────────────────────────────────────────────────── */

/// <summary>
/// Blank constructor which just makes a new data list when used...
/// </summary>
public Leaderboard()
{
boardData = new List<LeaderboardEntry>();
}


/// <summary>
/// Blank constructor which just makes a new data list when used...
/// Makes a new leaderboard based on the entered data.
/// </summary>
public Leaderboard(string id)
/// <param name="id">The id to assign.</param>
/// <param name="type">The type of leaderboard to make.</param>
public Leaderboard(string id, LeaderboardType type)
{
boardID = id;
this.type = type;
boardData = new List<LeaderboardEntry>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,7 @@ public class LeaderboardSaveData
public LeaderboardSaveData(Leaderboard leaderboard)
{
id = leaderboard.Id;

type = leaderboard.GetType().FullName switch
{
var x when x.Contains("Score") => LeaderboardType.Score,
var x when x.Contains("Time") => LeaderboardType.Time,
_ => type
};

type = leaderboard.Type;
entriesJson = new List<string>();

foreach (var v in leaderboard.BoardData)
Expand All @@ -75,7 +68,7 @@ var x when x.Contains("Time") => LeaderboardType.Time,
/// <returns>A leaderboard from the save dat in this class instance.</returns>
public Leaderboard ToLeaderboard()
{
var board = new Leaderboard(id);
var board = new Leaderboard(id, type);
board.BoardData = new List<LeaderboardEntry>();

foreach (var entry in entriesJson)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,34 +126,34 @@ public LeaderboardEntryTime(string name, SerializableTime time)
/// <returns>The formatted string.</returns>
public string ValueFormatted(DisplayTimeFormat format)
{
Debug.Log(EntryValueAsTime.TotalSeconds);

switch (format)
{
case DisplayTimeFormat.SecondsOnly:
return TimeSpan.FromSeconds(EntryValueAsTime.Seconds).ToString("ss");
return EntryValueAsTime.TotalSeconds.ToString(CultureInfo.InvariantCulture);
case DisplayTimeFormat.MinutesOnly:
return TimeSpan.FromSeconds(EntryValueAsTime.Seconds).ToString("mm");
return EntryValueAsTime.TotalMinutes.ToString(CultureInfo.InvariantCulture);
case DisplayTimeFormat.MinutesSeconds:
return TimeSpan.FromSeconds(EntryValueAsTime.Seconds).ToString("mm':'ss");
return EntryValueAsTime.ToString($"{EntryValueAsTime.TotalMinutes}':'ss");
case DisplayTimeFormat.HoursOnly:
return TimeSpan.FromSeconds(EntryValueAsTime.Seconds).ToString("hh");
return EntryValueAsTime.TotalHours.ToString(CultureInfo.InvariantCulture);
case DisplayTimeFormat.HoursMinutes:
return TimeSpan.FromSeconds(EntryValueAsTime.Seconds).ToString("hh':'mm");
return EntryValueAsTime.ToString($"{EntryValueAsTime.TotalHours}':'mm");
case DisplayTimeFormat.HoursMinutesSeconds:
return TimeSpan.FromSeconds(EntryValueAsTime.Seconds).ToString("hh':'mm':'ss");
return EntryValueAsTime.ToString($"{EntryValueAsTime.TotalHours}':'mm':'ss");
case DisplayTimeFormat.MillisecondsOnly:
return TimeSpan.FromMilliseconds(EntryValueAsTime.Seconds).ToString("fff");
return EntryValueAsTime.TotalMilliSeconds.ToString(CultureInfo.InvariantCulture);
case DisplayTimeFormat.SecondsMilliseconds:
return TimeSpan.FromMilliseconds(EntryValueAsTime.Seconds).ToString("ss':'fff");
return EntryValueAsTime.ToString($"{EntryValueAsTime.TotalSeconds}'.'fff");
case DisplayTimeFormat.MinutesSecondsMilliseconds:
return TimeSpan.FromMilliseconds(EntryValueAsTime.Seconds)
.ToString("mm':'ss':'fff");
return EntryValueAsTime.ToString($"{EntryValueAsTime.TotalMinutes}':'ss'.'fff");
case DisplayTimeFormat.HoursMinutesSecondsMilliseconds:
return TimeSpan.FromMilliseconds(EntryValueAsTime.Seconds)
.ToString("hh':'mm':'ss':'fff");
return EntryValueAsTime.ToString($"{EntryValueAsTime.TotalHours}':'mm':'ss'.'fff");
case DisplayTimeFormat.Unassigned:
default:
LbmLogs.Normal("[LeaderboardEntryTime] No valid time format selected.");
return (EntryValueAsTime.Seconds.ToString(CultureInfo.InvariantCulture));
LbmLogger.Normal("[LeaderboardEntryTime] No valid time format selected.");
return EntryValueAsTime.ToString($"{EntryValueAsTime.TotalHours}':'mm':'ss");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/

using System;
using System.Globalization;
using UnityEngine;

namespace CarterGames.Assets.LeaderboardManager.Serialization
Expand All @@ -36,6 +37,12 @@ public struct SerializableTime
| Fields
───────────────────────────────────────────────────────────────────────────────────────────────────────────── */

public const long TicksPerMillisecond = 10000;
public const long TicksPerSecond = 10000000;
public const long TicksPerMinute = 600000000;
public const long TicksPerHour = 36000000000;
public const long TicksPerDay = 864000000000;

[SerializeField] private int days;
[SerializeField] private int hours;
[SerializeField] private int minutes;
Expand Down Expand Up @@ -81,37 +88,37 @@ public struct SerializableTime
/// <summary>
/// The ticks stored in the time value.
/// </summary>
public long Ticks => ticks;
public long Ticks => GetTicks();


/// <summary>
/// The total number of days stored.
/// </summary>
public double TotalDays => TimeSpan.FromTicks(ticks).TotalDays;
public double TotalDays => Math.Floor(TimeSpan.FromTicks(Ticks).TotalDays);


/// <summary>
/// The total number of hours stored.
/// </summary>
public double TotalHours => TimeSpan.FromTicks(ticks).TotalHours;
public double TotalHours => Math.Floor(TimeSpan.FromTicks(Ticks).TotalHours);


/// <summary>
/// The total number of minutes stored.
/// </summary>
public double TotalMinutes => TimeSpan.FromTicks(ticks).TotalMinutes;
public double TotalMinutes => Math.Floor(TimeSpan.FromTicks(Ticks).TotalMinutes);


/// <summary>
/// The total number of seconds stored.
/// </summary>
public double TotalSeconds => TimeSpan.FromTicks(ticks).TotalSeconds;
public double TotalSeconds => Math.Floor(TimeSpan.FromTicks(Ticks).TotalSeconds);


/// <summary>
/// The total number of milliseconds stored.
/// </summary>
public double TotalMilliSeconds => TimeSpan.FromTicks(ticks).TotalMilliseconds;
public double TotalMilliSeconds => TimeSpan.FromTicks(Ticks).TotalMilliseconds;

/* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
| Operators
Expand Down Expand Up @@ -224,5 +231,74 @@ public static SerializableTime FromDateTime(DateTime dateTime)

return time;
}


/// <summary>
/// Gets the ticks based on the time data stored.
/// </summary>
/// <returns>The ticks for this data.</returns>
private long GetTicks()
{
if (ticks > 0) return ticks;

if (milliseconds > 0)
{
ticks += milliseconds * TicksPerMillisecond;
}

if (seconds > 0)
{
ticks += seconds * TicksPerSecond;
}

if (minutes > 0)
{
ticks += minutes * TicksPerMinute;
}

if (hours > 0)
{
ticks += hours * TicksPerHour;
}

if (days > 0)
{
ticks += days * TicksPerDay;
}

return ticks;
}


public override string ToString()
{
var date = new DateTime();
date = date.AddTicks(Ticks);
return date.ToString(CultureInfo.InvariantCulture);
}


public string ToString(string format)
{
var date = new DateTime();
date = date.AddTicks(Ticks);
return date.ToString(format, CultureInfo.InvariantCulture);
}


public string ToString(IFormatProvider provider)
{
var date = new DateTime();
date = date.AddTicks(Ticks);
return date.ToString(provider);
}


public string ToString(string format, IFormatProvider provider)
{
var date = new DateTime();
date = date.AddTicks(Ticks);
return date.ToString(format, provider);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void UpdateDisplay()
{
if (customisations.StartingAt < 1)
{
LbmLogs.Error("[LeaderboardDisplay] Start at index must be greater than or equal to 1.");
LbmLogger.Error("[LeaderboardDisplay] Start at index must be greater than or equal to 1.");
return;
}

Expand All @@ -100,7 +100,7 @@ public void UpdateDisplay()
switch (DisplayOption)
{
case DisplayOption.Unassigned:
LbmLogs.Warning("[LeaderboardDisplay] Display option cannot be Unassigned");
LbmLogger.Warning("[LeaderboardDisplay] Display option cannot be Unassigned");
break;
case DisplayOption.Top3Ascending:
case DisplayOption.Top3Descending:
Expand Down Expand Up @@ -163,7 +163,7 @@ private void SpawnRows(int numberToShow)
switch (DisplayOption)
{
case DisplayOption.Unassigned:
LbmLogs.Warning("[LeaderboardDisplay] Display option cannot be Unassigned.");
LbmLogger.Warning("[LeaderboardDisplay] Display option cannot be Unassigned.");
break;
case DisplayOption.AsWritten:
entries = Base.BoardData.ToArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public override void UpdateDisplay(LeaderboardEntry entry, int entryPosition, Le

if (HasScore)
{
switch (entry.EntryType.FullName)
switch (entry.EntryType.Name)
{
case nameof(LeaderboardEntryTime):
scoreLabel.text = ((LeaderboardEntryTime) entry).ValueFormatted(customisations.TimeFormat);
Expand All @@ -108,7 +108,6 @@ public override void UpdateDisplay(LeaderboardEntry entry, int entryPosition, Le
scoreLabel.text = entry.EntryValue.ToString();
break;
}

}

gameObject.SetActive(true);
Expand Down
Loading

0 comments on commit b1eb079

Please sign in to comment.