server post wip
This commit is contained in:
1 parent
ef95f63d14
commit
d6445332be
13 files changed
+239
-30
No files matched your search
@@ -0,0 +1,54 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e627c538dce2b838d8702905b032ac82
|
||||||
|
ScriptedImporter:
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
script: {fileID: 11500000, guid: a57477913897c46af95d590f580878bd, type: 3}
|
||||||
|
svgType: 0
|
||||||
|
texturedSpriteMeshType: 0
|
||||||
|
svgPixelsPerUnit: 100
|
||||||
|
gradientResolution: 64
|
||||||
|
alignment: 0
|
||||||
|
customPivot: {x: 0, y: 0}
|
||||||
|
generatePhysicsShape: 0
|
||||||
|
viewportOptions: 0
|
||||||
|
preserveViewport: 0
|
||||||
|
advancedMode: 0
|
||||||
|
predefinedResolutionIndex: 1
|
||||||
|
targetResolution: 1080
|
||||||
|
resolutionMultiplier: 1
|
||||||
|
stepDistance: 10
|
||||||
|
samplingStepDistance: 100
|
||||||
|
maxCordDeviationEnabled: 0
|
||||||
|
maxCordDeviation: 1
|
||||||
|
maxTangentAngleEnabled: 0
|
||||||
|
maxTangentAngle: 5
|
||||||
|
keepTextureAspectRatio: 1
|
||||||
|
textureSize: 256
|
||||||
|
textureWidth: 256
|
||||||
|
textureHeight: 256
|
||||||
|
wrapMode: 0
|
||||||
|
filterMode: 1
|
||||||
|
sampleCount: 4
|
||||||
|
preserveSVGImageAspect: 0
|
||||||
|
useSVGPixelsPerUnit: 0
|
||||||
|
spriteData:
|
||||||
|
TessellationDetail: 0
|
||||||
|
SpriteRect:
|
||||||
|
name:
|
||||||
|
originalName:
|
||||||
|
pivot: {x: 0, y: 0}
|
||||||
|
alignment: 0
|
||||||
|
border: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
rect:
|
||||||
|
serializedVersion: 2
|
||||||
|
x: 0
|
||||||
|
y: 0
|
||||||
|
width: 0
|
||||||
|
height: 0
|
||||||
|
spriteID: 974c0935effe6880abbfb6994005227d
|
||||||
|
PhysicsOutlines: []
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class SectorTime {
|
||||||
|
public int Sector;
|
||||||
|
public double Seconds;
|
||||||
|
public override string ToString() => $"{Seconds:0.000}";
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class Lap {
|
||||||
|
public string Map;
|
||||||
|
public List<SectorTime> Sectors;
|
||||||
|
|
||||||
|
// 0:1:39
|
||||||
|
public override string ToString() {
|
||||||
|
return $"{TimeSpan.FromSeconds(TotalTime):m\\:ss\\.fff}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public double TotalTime => Sectors.Sum(s => s.Seconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class PlayerData {
|
||||||
|
public Guid Id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LapStorage {
|
||||||
|
public string Map = "unset";
|
||||||
|
public List<Lap> Laps = new();
|
||||||
|
public int Completions = 0;
|
||||||
|
public int Position = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static class LapStorageService {
|
||||||
|
static string playerDataPath = Path.Combine(Application.persistentDataPath, "playerData.json");
|
||||||
|
PlayerData player;
|
||||||
|
|
||||||
|
LapStorage lapStorage;
|
||||||
|
|
||||||
|
static LapStorageService() {
|
||||||
|
try {
|
||||||
|
string json = File.ReadAllText(playerDataPath);
|
||||||
|
JsonUtility.FromJsonOverwrite(json, player);
|
||||||
|
} catch {
|
||||||
|
Debug.Log("No existing playerData.json");
|
||||||
|
CreatePlayerData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LapJSON GetPlayerLaps(string mapName) {
|
||||||
|
// get
|
||||||
|
return new Lap;
|
||||||
|
}
|
||||||
|
|
||||||
|
// laps.count
|
||||||
|
public static int NumberOfCompletions() { return 0; }
|
||||||
|
|
||||||
|
// finds your PB in all completions
|
||||||
|
public static int Position() { return 1; }
|
||||||
|
|
||||||
|
public static void PersistLap(Lap lap) {
|
||||||
|
Debug.Log(JsonUtility.ToJson(lap));
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerData CreatePlayerData() {
|
||||||
|
player = new PlayerData { Id = Guid.NewGuid() }
|
||||||
|
File.WriteAllText(playerDataPath, JsonUtility.ToJson(data));
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Lap PB(string mapName) {
|
||||||
|
return lapsByMap[mapName].Laps
|
||||||
|
.MinBy(l => l.TotalTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -131,7 +131,7 @@ static class LapStorageService {
|
|||||||
public static int NumberOfCompletions() { return 0; }
|
public static int NumberOfCompletions() { return 0; }
|
||||||
|
|
||||||
// finds your PB in all completions
|
// finds your PB in all completions
|
||||||
public static int Rank() { return 1; }
|
public static int Position() { return 1; }
|
||||||
|
|
||||||
public static void PersistLap(Lap lap) {
|
public static void PersistLap(Lap lap) {
|
||||||
LapJSON lapJson = GetPlayerLaps(lap.Map);
|
LapJSON lapJson = GetPlayerLaps(lap.Map);
|
||||||
|
|||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="description" content="SpaceRace">
|
||||||
|
<title>SpaceRace Information</title>
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Jura" rel="stylesheet">
|
||||||
|
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background: black;
|
||||||
|
color: #f5f5f5;
|
||||||
|
font-family: "Jura";
|
||||||
|
font-size: 2rem;
|
||||||
|
}
|
||||||
|
img {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1, div {
|
||||||
|
margin-left: 2rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<img src="./controls.png" title="Controls" />
|
||||||
|
|
||||||
|
<h1>Go!</h1>
|
||||||
|
<div>Run SpaceRace.exe to start the game.</div>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
using Server.Models;
|
using Server.Models;
|
||||||
|
|
||||||
namespace Server.Controllers;
|
namespace Server.Controllers;
|
||||||
@@ -22,18 +21,44 @@ public class LapController : ControllerBase {
|
|||||||
UserId = c.UserId,
|
UserId = c.UserId,
|
||||||
Map = c.Map,
|
Map = c.Map,
|
||||||
Time = c.Time,
|
Time = c.Time,
|
||||||
Date = c.Date,
|
Created = c.Created,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// [HttpGet()]
|
||||||
|
// public LapStorageDTO UserLaps(Guid userId, string mapName) {
|
||||||
|
// List<Lap> laps = _db.Laps
|
||||||
|
// .Where(l => l.Id == userId)
|
||||||
|
// .Where(l => l.Map == mapName);
|
||||||
|
|
||||||
|
// int completions = _db.Laps
|
||||||
|
// .Where(l => l.Map == mapName)
|
||||||
|
// .Count();
|
||||||
|
|
||||||
|
// int position = _db.Database<Laps>.sql("""
|
||||||
|
// SELECT
|
||||||
|
// """);
|
||||||
|
|
||||||
|
// return new LapStorageDTO {
|
||||||
|
// Map = mapName,
|
||||||
|
// Laps = laps,
|
||||||
|
// public int Completions { get; set; }
|
||||||
|
// public int Position { get; set; }
|
||||||
|
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
[HttpPost()]
|
[HttpPost()]
|
||||||
public async Task<Lap> Post(LapDTO dto) {
|
public async Task<Lap> Post(LapDTO dto) {
|
||||||
|
Lap existing = _db.Laps
|
||||||
|
.SingleOrDefault(l => l.UserId == dto.UserId && l.Map == dto.Map);
|
||||||
|
|
||||||
Lap v = new Lap {
|
Lap v = new Lap {
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.NewGuid(),
|
||||||
UserId = Guid.NewGuid(),
|
UserId = dto.UserId,
|
||||||
Map = dto.Map,
|
Map = dto.Map,
|
||||||
Time = dto.Time,
|
Time = dto.Time,
|
||||||
Date = DateTimeOffset.UtcNow,
|
Created = DateTimeOffset.UtcNow,
|
||||||
};
|
};
|
||||||
|
|
||||||
_db.Laps.Add(v);
|
_db.Laps.Add(v);
|
||||||
|
|||||||
+4
-3
@@ -12,7 +12,7 @@ using Server;
|
|||||||
namespace Server.Migrations
|
namespace Server.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(SpaceRaceDbContext))]
|
[DbContext(typeof(SpaceRaceDbContext))]
|
||||||
[Migration("20230823032740_Beginninging")]
|
[Migration("20230828112623_Beginninging")]
|
||||||
partial class Beginninging
|
partial class Beginninging
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -31,7 +31,7 @@ namespace Server.Migrations
|
|||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("uuid");
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
b.Property<DateTimeOffset>("Date")
|
b.Property<DateTimeOffset>("Created")
|
||||||
.HasColumnType("timestamp with time zone");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
b.Property<string>("Map")
|
b.Property<string>("Map")
|
||||||
@@ -48,7 +48,8 @@ namespace Server.Migrations
|
|||||||
|
|
||||||
b.HasIndex("Map");
|
b.HasIndex("Map");
|
||||||
|
|
||||||
b.HasIndex("UserId");
|
b.HasIndex("UserId", "Map")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
b.ToTable("Laps");
|
b.ToTable("Laps");
|
||||||
});
|
});
|
||||||
+6
-5
@@ -16,10 +16,10 @@ namespace Server.Migrations
|
|||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
Date = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
Created = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||||
UserId = table.Column<Guid>(type: "uuid", nullable: false),
|
UserId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
Map = table.Column<string>(type: "text", nullable: false),
|
Time = table.Column<double>(type: "double precision", nullable: false),
|
||||||
Time = table.Column<double>(type: "double precision", nullable: false)
|
Map = table.Column<string>(type: "text", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
@@ -32,9 +32,10 @@ namespace Server.Migrations
|
|||||||
column: "Map");
|
column: "Map");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_Laps_UserId",
|
name: "IX_Laps_UserId_Map",
|
||||||
table: "Laps",
|
table: "Laps",
|
||||||
column: "UserId");
|
columns: new[] { "UserId", "Map" },
|
||||||
|
unique: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -28,7 +28,7 @@ namespace Server.Migrations
|
|||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("uuid");
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
b.Property<DateTimeOffset>("Date")
|
b.Property<DateTimeOffset>("Created")
|
||||||
.HasColumnType("timestamp with time zone");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
b.Property<string>("Map")
|
b.Property<string>("Map")
|
||||||
@@ -45,7 +45,8 @@ namespace Server.Migrations
|
|||||||
|
|
||||||
b.HasIndex("Map");
|
b.HasIndex("Map");
|
||||||
|
|
||||||
b.HasIndex("UserId");
|
b.HasIndex("UserId", "Map")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
b.ToTable("Laps");
|
b.ToTable("Laps");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
namespace Server.Models;
|
|
||||||
|
|
||||||
public class LapDTO {
|
|
||||||
public DateTimeOffset Date { get; set; }
|
|
||||||
public Guid Id { get; set; }
|
|
||||||
public Guid UserId { get; set; }
|
|
||||||
public string Map { get; set; }
|
|
||||||
public double Time { get; set; }
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace Server.Models;
|
||||||
|
|
||||||
|
public class LapDTO {
|
||||||
|
public DateTimeOffset Created { get; set; }
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public Guid UserId { get; set; }
|
||||||
|
public string Map { get; set; }
|
||||||
|
public double Time { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
namespace Server.Models;
|
||||||
|
|
||||||
|
public class PbDTO {
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public Guid UserId { get; set; }
|
||||||
|
public double Time { get; set; }
|
||||||
|
public string Map { get; set; }
|
||||||
|
public int Completions { get; set; }
|
||||||
|
public int Position { get; set; }
|
||||||
|
}
|
||||||
@@ -8,12 +8,12 @@ public class SpaceRaceDbContext : DbContext {
|
|||||||
public SpaceRaceDbContext(DbContextOptions<SpaceRaceDbContext> options) : base(options) {}
|
public SpaceRaceDbContext(DbContextOptions<SpaceRaceDbContext> options) : base(options) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Index(nameof(UserId))]
|
[Index(nameof(UserId), nameof(Map), IsUnique = true)]
|
||||||
[Index(nameof(Map))]
|
[Index(nameof(Map))]
|
||||||
public class Lap {
|
public class Lap {
|
||||||
public DateTimeOffset Date { get; set; }
|
public DateTimeOffset Created { get; set; }
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
public Guid UserId { get; set; }
|
public Guid UserId { get; set; }
|
||||||
[Required] public string Map { get; set; }
|
public double Time { get; set; }
|
||||||
public double Time { get; set; }
|
[Required] public string Map { get; set; }
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,7 @@ services:
|
|||||||
- '40080:80'
|
- '40080:80'
|
||||||
environment:
|
environment:
|
||||||
CONNECTIONSTRINGS__SPACERACE: "Server=pg;Port=5432;Database=${POSTGRES_DB};User Id=${POSTGRES_USER};Password=${POSTGRES_PASSWORD}"
|
CONNECTIONSTRINGS__SPACERACE: "Server=pg;Port=5432;Database=${POSTGRES_DB};User Id=${POSTGRES_USER};Password=${POSTGRES_PASSWORD}"
|
||||||
|
DOTNET_WATCH_RESTART_ON_RUDE_EDIT: 1
|
||||||
command: dotnet watch
|
command: dotnet watch
|
||||||
working_dir: "/Server"
|
working_dir: "/Server"
|
||||||
volumes:
|
volumes:
|
||||||
|
|||||||
Reference in new issue
Block a user