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

No files matched your search

+12
View File
@@ -26,6 +26,16 @@ public class LapService {
public Lap Pb;
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) {
_mapName = mapName;
LoadPlayerData();
@@ -54,11 +64,13 @@ public class LapService {
_pb = dto.Pb;
_lr = dto.LapRecord;
if (dto.Pb != null)
Pb = new Lap {
Map = _pb.Map,
Sectors = _pb.Sectors.Select((d, i) => new SectorTime { Sector = i + 1, Seconds = d }).ToList(),
};
if (dto.LapRecord != null)
LapRecord = new Lap {
Map = _lr.Map,
Sectors = _lr.Sectors.Select((d, i) => new SectorTime { Sector = i + 1, Seconds = d }).ToList(),
+3 -3
View File
@@ -18,10 +18,10 @@ public class TimingNotice {
NoticeCategory Category = NoticeCategory.Initial;
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 {
double pb when seconds < pb => new TimingNotice { Seconds = 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.Faster },
double pb when seconds >= pb => new TimingNotice { Seconds = Math.Abs(pb - seconds), Category = NoticeCategory.Slower },
_ => new TimingNotice { Seconds = seconds, Category = NoticeCategory.Initial },
}
};
+14
View File
@@ -200,6 +200,20 @@ public class ShipControls : MonoBehaviour {
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) {
Vector2 str = ctx.ReadValue<Vector2>();
strafe = new Vector3(str.x, str.y, 0f) * powerUnit.Strafing;
+3
View File
@@ -26,6 +26,8 @@ public class Timing: MonoBehaviour {
IEnumerator noticeLifecycle;
public string Position => $"{lapService.Position} / {lapService.Completions}";
void Awake() {
ui = GetComponent<TimingUI>();
sectorTimes = new List<SectorTime>();
@@ -42,6 +44,7 @@ public class Timing: MonoBehaviour {
}
void Start() {
Debug.Log("Timing Starting...");
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">
<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="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="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="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: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: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 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 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: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" />
+12
View File
@@ -16,11 +16,13 @@ public class TimingUI : MonoBehaviour {
VisualElement timerSectors;
Label timerTime;
Label timerPb;
Label timerPosition;
VisualElement notice;
VisualElement noticeSectors;
VisualElement noticeDiff;
Label noticeTime;
Label noticePosition;
void OnEnable() {
Init();
@@ -42,7 +44,12 @@ public class TimingUI : MonoBehaviour {
timerTime = uiDocument.rootVisualElement.Q<Label>("timerTime");
timerPb = uiDocument.rootVisualElement.Q<Label>("timerPb");
noticePosition = uiDocument.rootVisualElement.Q<Label>("noticePosition");
timerPosition = uiDocument.rootVisualElement.Q<Label>("timerPosition");
timerPb.text = "-";
noticePosition.text = "- / -";
timerPosition.text = "- / -";
notice.AddToClassList("hidden");
}
@@ -79,9 +86,13 @@ public class TimingUI : MonoBehaviour {
timerSectors.Add(l);
}
noticePosition.text = timing.Position;
timerPosition.text = timing.Position;
}
public void ShowRecentLap(Lap lap) {
Init();
timer.AddToClassList("hidden");
notice.RemoveFromClassList("hidden");
@@ -97,6 +108,7 @@ public class TimingUI : MonoBehaviour {
}
public void HideRecentLap() {
Init();
timer.RemoveFromClassList("hidden");
notice.AddToClassList("hidden");
}
+22
View File
@@ -72,3 +72,25 @@ BoostIndicator {
margin-top: 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
loadStoreDebugModeEnabled: 0
bundleVersion: 0.1
preloadedAssets: []
preloadedAssets:
- {fileID: 11400000, guid: 020903acd8b50dd45a683fb9312ba7af, type: 2}
metroInputSource: 0
wsaTransparentSwapchain: 0
m_HolographicPauseOnTrackingLoss: 1
+2 -1
View File
@@ -1,7 +1,8 @@
# SpaceRace!
- post times to server
- compare diffs to lap record
- rank
- backup store to json on disk in case server down
- controls
- mouse / controller sens