This commit is contained in:
ntr committed 2023-09-01 22:27:50 +10:00
1 parent cffe1930a0
commit 9f5ce196cc
9 files changed
+90 -17

No files matched your search

+20 -8
View File
@@ -26,6 +26,16 @@ public class LapService {
public Lap Pb; public Lap Pb;
public Lap LapRecord; public Lap LapRecord;
public string Position => _pb switch {
PbDTO pb => pb.Position.ToString(),
null => "-",
};
public string Completions => _lr switch {
PbDTO lr => lr.Completions.ToString(),
null => "-",
};
public LapService(string mapName) { public LapService(string mapName) {
_mapName = mapName; _mapName = mapName;
LoadPlayerData(); LoadPlayerData();
@@ -54,15 +64,17 @@ public class LapService {
_pb = dto.Pb; _pb = dto.Pb;
_lr = dto.LapRecord; _lr = dto.LapRecord;
Pb = new Lap { if (dto.Pb != null)
Map = _pb.Map, Pb = new Lap {
Sectors = _pb.Sectors.Select((d, i) => new SectorTime { Sector = i + 1, Seconds = d }).ToList(), Map = _pb.Map,
}; Sectors = _pb.Sectors.Select((d, i) => new SectorTime { Sector = i + 1, Seconds = d }).ToList(),
};
LapRecord = new Lap { if (dto.LapRecord != null)
Map = _lr.Map, LapRecord = new Lap {
Sectors = _lr.Sectors.Select((d, i) => new SectorTime { Sector = i + 1, Seconds = d }).ToList(), Map = _lr.Map,
}; Sectors = _lr.Sectors.Select((d, i) => new SectorTime { Sector = i + 1, Seconds = d }).ToList(),
};
} catch (Exception e) { } catch (Exception e) {
Debug.LogWarning($"Failed to set lap times {e}"); Debug.LogWarning($"Failed to set lap times {e}");
_pb = null; _pb = null;
+3 -3
View File
@@ -18,10 +18,10 @@ public class TimingNotice {
NoticeCategory Category = NoticeCategory.Initial; NoticeCategory Category = NoticeCategory.Initial;
public static TimingNotice Compare(double seconds, double? pbSeconds = null, double? lrSeconds = null) => lrSeconds switch { public static TimingNotice Compare(double seconds, double? pbSeconds = null, double? lrSeconds = null) => lrSeconds switch {
double lr when seconds < lr => new TimingNotice { Seconds = seconds, Category = NoticeCategory.Fastest }, double lr when seconds < lr => new TimingNotice { Seconds = Math.Abs(lr - seconds), Category = NoticeCategory.Fastest },
_ => pbSeconds switch { _ => pbSeconds switch {
double pb when seconds < pb => new TimingNotice { Seconds = seconds, Category = NoticeCategory.Faster }, double pb when seconds < pb => new TimingNotice { Seconds = Math.Abs(pb - seconds), Category = NoticeCategory.Faster },
double pb when seconds >= pb => new TimingNotice { Seconds = seconds, Category = NoticeCategory.Slower }, double pb when seconds >= pb => new TimingNotice { Seconds = Math.Abs(pb - seconds), Category = NoticeCategory.Slower },
_ => new TimingNotice { Seconds = seconds, Category = NoticeCategory.Initial }, _ => new TimingNotice { Seconds = seconds, Category = NoticeCategory.Initial },
} }
}; };
+14
View File
@@ -200,6 +200,20 @@ public class ShipControls : MonoBehaviour {
input.ship.powerUnit4.started += OnPowerUnit4; input.ship.powerUnit4.started += OnPowerUnit4;
} }
void OnDestroy() {
input.ship.strafe.started -= OnStrafe;
input.ship.strafe.performed -= OnStrafe;
input.ship.strafe.canceled -= OnStrafe;
// these we only care about the initial press
input.ship.respawn.started -= OnRespawn;
input.ship.quit.started -= OnQuit;
input.ship.powerUnit1.started -= OnPowerUnit1;
input.ship.powerUnit2.started -= OnPowerUnit2;
input.ship.powerUnit3.started -= OnPowerUnit3;
input.ship.powerUnit4.started -= OnPowerUnit4;
}
void OnStrafe(InputAction.CallbackContext ctx) { void OnStrafe(InputAction.CallbackContext ctx) {
Vector2 str = ctx.ReadValue<Vector2>(); Vector2 str = ctx.ReadValue<Vector2>();
strafe = new Vector3(str.x, str.y, 0f) * powerUnit.Strafing; strafe = new Vector3(str.x, str.y, 0f) * powerUnit.Strafing;
+3
View File
@@ -26,6 +26,8 @@ public class Timing: MonoBehaviour {
IEnumerator noticeLifecycle; IEnumerator noticeLifecycle;
public string Position => $"{lapService.Position} / {lapService.Completions}";
void Awake() { void Awake() {
ui = GetComponent<TimingUI>(); ui = GetComponent<TimingUI>();
sectorTimes = new List<SectorTime>(); sectorTimes = new List<SectorTime>();
@@ -42,6 +44,7 @@ public class Timing: MonoBehaviour {
} }
void Start() { void Start() {
Debug.Log("Timing Starting...");
StartCoroutine(lapService.GetLapTimes()); StartCoroutine(lapService.GetLapTimes());
} }
+12 -4
View File
@@ -1,14 +1,18 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False"> <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<Style src="project://database/Assets/Src/UI/TimingUi.uss?fileID=7433441132597879392&amp;guid=cf92f075876ddf7ffb4cd5c59633ad7b&amp;type=3#TimingUi" /> <Style src="project://database/Assets/Src/UI/TimingUi.uss?fileID=7433441132597879392&amp;guid=cf92f075876ddf7ffb4cd5c59633ad7b&amp;type=3#TimingUi" />
<ui:VisualElement name="shipUi" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); color: rgb(255, 255, 255); font-size: 28px; -unity-font: url(&apos;project://database/Assets/UI%20Toolkit/Fonts/Jura-Medium.otf?fileID=12800000&amp;guid=65648a14640996362a6b0929c723b6e4&amp;type=3#Jura-Medium&apos;); -unity-font-definition: initial;"> <ui:VisualElement name="shipUi" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); color: rgb(255, 255, 255); font-size: 28px; -unity-font: url(&apos;project://database/Assets/UI%20Toolkit/Fonts/Jura-Medium.otf?fileID=12800000&amp;guid=65648a14640996362a6b0929c723b6e4&amp;type=3#Jura-Medium&apos;); -unity-font-definition: initial;">
<ui:VisualElement name="Top" style="flex-grow: 1;" /> <ui:VisualElement name="Top" style="flex-grow: 1; font-size: 12px;" />
<ui:VisualElement name="Middle" style="flex-grow: 1; align-items: center;" /> <ui:VisualElement name="Middle" style="flex-grow: 1; align-items: center;" />
<ui:VisualElement name="Bottom" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0.26); flex-direction: column; align-items: stretch; justify-content: flex-end; color: rgb(255, 255, 255); width: 33%; align-self: center;"> <ui:VisualElement name="Bottom" class="bottom">
<ui:VisualElement name="notice" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0);"> <ui:VisualElement name="notice" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0);">
<ui:VisualElement name="timerDesc" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); flex-direction: row; justify-content: space-between; align-items: auto; width: auto; align-self: stretch; flex-shrink: 0; font-size: 14px; color: rgb(245, 245, 245);">
<ui:Label tabindex="-1" display-tooltip-when-elided="true" name="msg" style="align-self: flex-end; align-items: auto;" />
<ui:Label tabindex="-1" display-tooltip-when-elided="true" name="noticePosition" text="5 / 128" />
</ui:VisualElement>
<ui:VisualElement name="noticeLap" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); flex-direction: row; justify-content: space-between; align-items: auto; width: auto; align-self: stretch; flex-shrink: 0;"> <ui:VisualElement name="noticeLap" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); flex-direction: row; justify-content: space-between; align-items: auto; width: auto; align-self: stretch; flex-shrink: 0;">
<ui:Label tabindex="-1" display-tooltip-when-elided="true" name="noticeTime" style="align-self: flex-end; align-items: auto;" /> <ui:Label tabindex="-1" display-tooltip-when-elided="true" name="noticeTime" text="1:12.888" style="align-self: flex-end; align-items: auto;" />
<ui:VisualElement name="noticeDiff" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); -unity-text-align: upper-right;"> <ui:VisualElement name="noticeDiff" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); -unity-text-align: upper-right;">
<ui:Label tabindex="-1" display-tooltip-when-elided="true" /> <ui:Label tabindex="-1" display-tooltip-when-elided="true" text="+0.128" />
</ui:VisualElement> </ui:VisualElement>
</ui:VisualElement> </ui:VisualElement>
<ui:VisualElement name="noticeSectors" class="sectors" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0); flex-direction: row; -unity-text-align: upper-left;"> <ui:VisualElement name="noticeSectors" class="sectors" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0); flex-direction: row; -unity-text-align: upper-left;">
@@ -18,6 +22,10 @@
</ui:VisualElement> </ui:VisualElement>
</ui:VisualElement> </ui:VisualElement>
<ui:VisualElement name="timer" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0);"> <ui:VisualElement name="timer" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0);">
<ui:VisualElement name="timerDesc" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); flex-direction: row; justify-content: space-between; align-items: auto; width: auto; align-self: stretch; flex-shrink: 0; font-size: 14px; color: rgb(245, 245, 245);">
<ui:Label tabindex="-1" display-tooltip-when-elided="true" name="msg" style="align-self: flex-end; align-items: auto;" />
<ui:Label tabindex="-1" display-tooltip-when-elided="true" name="timerPosition" text="5 / 128" />
</ui:VisualElement>
<ui:VisualElement name="timerLap" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); flex-direction: row; justify-content: space-between; align-items: auto; width: auto; align-self: stretch; flex-shrink: 0;"> <ui:VisualElement name="timerLap" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); flex-direction: row; justify-content: space-between; align-items: auto; width: auto; align-self: stretch; flex-shrink: 0;">
<ui:Label tabindex="-1" display-tooltip-when-elided="true" name="timerTime" style="align-self: flex-end; align-items: auto;" /> <ui:Label tabindex="-1" display-tooltip-when-elided="true" name="timerTime" style="align-self: flex-end; align-items: auto;" />
<ui:Label tabindex="-1" display-tooltip-when-elided="true" name="timerPb" /> <ui:Label tabindex="-1" display-tooltip-when-elided="true" name="timerPb" />
+12
View File
@@ -16,11 +16,13 @@ public class TimingUI : MonoBehaviour {
VisualElement timerSectors; VisualElement timerSectors;
Label timerTime; Label timerTime;
Label timerPb; Label timerPb;
Label timerPosition;
VisualElement notice; VisualElement notice;
VisualElement noticeSectors; VisualElement noticeSectors;
VisualElement noticeDiff; VisualElement noticeDiff;
Label noticeTime; Label noticeTime;
Label noticePosition;
void OnEnable() { void OnEnable() {
Init(); Init();
@@ -42,7 +44,12 @@ public class TimingUI : MonoBehaviour {
timerTime = uiDocument.rootVisualElement.Q<Label>("timerTime"); timerTime = uiDocument.rootVisualElement.Q<Label>("timerTime");
timerPb = uiDocument.rootVisualElement.Q<Label>("timerPb"); timerPb = uiDocument.rootVisualElement.Q<Label>("timerPb");
noticePosition = uiDocument.rootVisualElement.Q<Label>("noticePosition");
timerPosition = uiDocument.rootVisualElement.Q<Label>("timerPosition");
timerPb.text = "-"; timerPb.text = "-";
noticePosition.text = "- / -";
timerPosition.text = "- / -";
notice.AddToClassList("hidden"); notice.AddToClassList("hidden");
} }
@@ -79,9 +86,13 @@ public class TimingUI : MonoBehaviour {
timerSectors.Add(l); timerSectors.Add(l);
} }
noticePosition.text = timing.Position;
timerPosition.text = timing.Position;
} }
public void ShowRecentLap(Lap lap) { public void ShowRecentLap(Lap lap) {
Init();
timer.AddToClassList("hidden"); timer.AddToClassList("hidden");
notice.RemoveFromClassList("hidden"); notice.RemoveFromClassList("hidden");
@@ -97,6 +108,7 @@ public class TimingUI : MonoBehaviour {
} }
public void HideRecentLap() { public void HideRecentLap() {
Init();
timer.RemoveFromClassList("hidden"); timer.RemoveFromClassList("hidden");
notice.AddToClassList("hidden"); notice.AddToClassList("hidden");
} }
+22
View File
@@ -72,3 +72,25 @@ BoostIndicator {
margin-top: 12px; margin-top: 12px;
margin-bottom: 12px; margin-bottom: 12px;
} }
.bottom {
flex-grow: 0;
background-color: rgba(0, 0, 0, 0.26);
flex-direction: column;
align-items: stretch;
justify-content: flex-end;
color: rgb(255, 255, 255);
width: 33%;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
align-self: center;
padding-left: 8px;
padding-right: 8px;
padding-top: 8px;
}
.bottom Label {
padding: 0;
margin-left: 0;
margin-right: 0;
}
+2 -1
View File
@@ -134,7 +134,8 @@ PlayerSettings:
vulkanEnableCommandBufferRecycling: 1 vulkanEnableCommandBufferRecycling: 1
loadStoreDebugModeEnabled: 0 loadStoreDebugModeEnabled: 0
bundleVersion: 0.1 bundleVersion: 0.1
preloadedAssets: [] preloadedAssets:
- {fileID: 11400000, guid: 020903acd8b50dd45a683fb9312ba7af, type: 2}
metroInputSource: 0 metroInputSource: 0
wsaTransparentSwapchain: 0 wsaTransparentSwapchain: 0
m_HolographicPauseOnTrackingLoss: 1 m_HolographicPauseOnTrackingLoss: 1
+2 -1
View File
@@ -1,7 +1,8 @@
# SpaceRace! # SpaceRace!
- post times to server - post times to server
- compare diffs to lap record - rank
- backup store to json on disk in case server down
- controls - controls
- mouse / controller sens - mouse / controller sens