Author SHA1 Message Date
pillboxstyx 2d27e4254e Merge pull request 'Starting to add a sprint, will figure out how to hook in the run animation next' (#7) from pillboxstyx/addingSprint into main
Deploy Promiscuity Auth API / deploy (push) Successful in 46s
Deploy Promiscuity Character API / deploy (push) Successful in 44s
Deploy Promiscuity Locations API / deploy (push) Successful in 45s
k8s smoke test / test (push) Successful in 7s
Reviewed-on: #7
2026-02-13 02:50:06 -06:00
pillboxstyx b3287ccf6f Starting to add a sprint, will figure out how to hook in the run animation next 2026-02-13 02:48:07 -06:00
18 changed files with 200 additions and 393 deletions
+12 -2
View File
@@ -4,11 +4,11 @@ extends RigidBody3D
# of collisions. So that's why we're using a RigidBody3D instead. # of collisions. So that's why we're using a RigidBody3D instead.
const MOVE_SPEED := 8.0 const MOVE_SPEED := 8.0
const SPRINT_MOVE_SPEED :=13
const ACCELLERATION := 30.0 const ACCELLERATION := 30.0
const DECELLERATION := 40.0 const DECELLERATION := 40.0
const JUMP_SPEED := 4.0 const JUMP_SPEED := 4.0
const MAX_NUMBER_OF_JUMPS := 2 const MAX_NUMBER_OF_JUMPS := 2
const MIN_FOV := 10 const MIN_FOV := 10
const MAX_FOV := 180 const MAX_FOV := 180
const ZOOM_FACTOR := 1.1 # Zoom out when >1, in when < 1 const ZOOM_FACTOR := 1.1 # Zoom out when >1, in when < 1
@@ -37,7 +37,9 @@ var _jump_triggered := false
@export var anim_idle_name := "Idle" @export var anim_idle_name := "Idle"
@export var anim_walk_name := "Walk" @export var anim_walk_name := "Walk"
@export var anim_jump_name := "Jump" @export var anim_jump_name := "Jump"
@export var anim_run_name := "Run"
@export var anim_walk_speed_threshold := 0.25 @export var anim_walk_speed_threshold := 0.25
@export var anim_sprint_speed_threshold := 10.0
var jump_sound = preload("res://assets/audio/jump.ogg") var jump_sound = preload("res://assets/audio/jump.ogg")
var audio_player = AudioStreamPlayer.new() var audio_player = AudioStreamPlayer.new()
@@ -117,8 +119,13 @@ func _integrate_forces(state):
right = _last_move_right right = _last_move_right
var dir := (right * input2v.x + forward * input2v.y).normalized() var dir := (right * input2v.x + forward * input2v.y).normalized()
var target_v := dir * MOVE_SPEED var target_v := dir * MOVE_SPEED
# Sprinting
if Input.is_key_pressed(KEY_SHIFT):
target_v = dir * SPRINT_MOVE_SPEED
var ax := ACCELLERATION if dir != Vector3.ZERO else DECELLERATION var ax := ACCELLERATION if dir != Vector3.ZERO else DECELLERATION
linear_velocity.x = move_toward(linear_velocity.x, target_v.x, ax * state.step) linear_velocity.x = move_toward(linear_velocity.x, target_v.x, ax * state.step)
linear_velocity.z = move_toward(linear_velocity.z, target_v.z, ax * state.step) linear_velocity.z = move_toward(linear_velocity.z, target_v.z, ax * state.step)
@@ -188,6 +195,10 @@ func _update_animation(on_floor: bool, velocity: Vector3) -> void:
if _anim_player.current_animation != anim_jump_name: if _anim_player.current_animation != anim_jump_name:
_anim_player.play(anim_jump_name) _anim_player.play(anim_jump_name)
return return
if on_floor and horizontal_speed > anim_sprint_speed_threshold and _anim_player.has_animation(anim_run_name):
if _anim_player.current_animation != anim_walk_name:
_anim_player.play(anim_walk_name)
return
if horizontal_speed > anim_walk_speed_threshold and _anim_player.has_animation(anim_walk_name): if horizontal_speed > anim_walk_speed_threshold and _anim_player.has_animation(anim_walk_name):
if _anim_player.current_animation != anim_walk_name: if _anim_player.current_animation != anim_walk_name:
_anim_player.play(anim_walk_name) _anim_player.play(anim_walk_name)
@@ -233,4 +244,3 @@ func exit_vehicle(exit_point: Node3D, vehicle_camera: Camera3D) -> void:
vehicle_camera.current = false vehicle_camera.current = false
if cam: if cam:
cam.current = true cam.current = true
@@ -11,12 +11,10 @@ namespace CharacterApi.Controllers;
public class CharactersController : ControllerBase public class CharactersController : ControllerBase
{ {
private readonly CharacterStore _characters; private readonly CharacterStore _characters;
private readonly LocationsClient _locations;
public CharactersController(CharacterStore characters, LocationsClient locations) public CharactersController(CharacterStore characters)
{ {
_characters = characters; _characters = characters;
_locations = locations;
} }
[HttpPost] [HttpPost]
@@ -69,39 +67,4 @@ public class CharactersController : ControllerBase
return Ok("Deleted"); return Ok("Deleted");
} }
[HttpPut("{id}/move")]
[Authorize(Roles = "USER,SUPER")]
public async Task<IActionResult> Move(string id, [FromBody] MoveCharacterRequest req, CancellationToken ct)
{
if (req?.Coord is null)
return BadRequest("Coord required");
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (string.IsNullOrWhiteSpace(userId))
return Unauthorized();
var allowAnyOwner = User.IsInRole("SUPER");
var existing = await _characters.GetForOwnerByIdAsync(id, userId, allowAnyOwner);
if (existing is null)
return NotFound();
var presence = await _locations.UpdatePresenceAsync(id, req.Coord, ct);
if (!presence.Ok)
{
var message = string.IsNullOrWhiteSpace(presence.Body)
? "Location presence update failed"
: presence.Body;
return StatusCode((int)presence.Status, message);
}
var updated = await _characters.UpdateCoordAsync(id, userId, allowAnyOwner, req.Coord);
if (!updated)
{
await _locations.UpdatePresenceAsync(id, existing.Coord, ct);
return StatusCode(500, "Failed to update character coord");
}
return Ok("Moved");
}
} }
-9
View File
@@ -10,15 +10,6 @@ Inbound JSON documents
"name": "string" "name": "string"
} }
``` ```
- MoveCharacterRequest (`PUT /api/characters/{id}/move`)
```json
{
"coord": {
"x": 0,
"y": 0
}
}
```
Stored documents (MongoDB) Stored documents (MongoDB)
- Character - Character
@@ -1,6 +0,0 @@
namespace CharacterApi.Models;
public class MoveCharacterRequest
{
public Coord? Coord { get; set; }
}
-5
View File
@@ -9,11 +9,6 @@ builder.Services.AddControllers();
// DI // DI
builder.Services.AddSingleton<CharacterStore>(); builder.Services.AddSingleton<CharacterStore>();
builder.Services.AddHttpClient<LocationsClient>(client =>
{
var baseUrl = builder.Configuration["LocationsApi:BaseUrl"] ?? "http://localhost:5002";
client.BaseAddress = new Uri(baseUrl);
});
// Swagger + JWT auth in Swagger // Swagger + JWT auth in Swagger
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
-1
View File
@@ -7,4 +7,3 @@ See `DOCUMENTS.md` for request payloads and stored document shapes.
- `POST /api/characters` Create a character. - `POST /api/characters` Create a character.
- `GET /api/characters` List characters for the current user. - `GET /api/characters` List characters for the current user.
- `DELETE /api/characters/{id}` Delete a character owned by the current user. - `DELETE /api/characters/{id}` Delete a character owned by the current user.
- `PUT /api/characters/{id}/move` Move a character to a new coord.
@@ -24,36 +24,6 @@ public class CharacterStore
public Task<List<Character>> GetForOwnerAsync(string ownerUserId) => public Task<List<Character>> GetForOwnerAsync(string ownerUserId) =>
_col.Find(c => c.OwnerUserId == ownerUserId).ToListAsync(); _col.Find(c => c.OwnerUserId == ownerUserId).ToListAsync();
public async Task<Character?> GetForOwnerByIdAsync(string id, string ownerUserId, bool allowAnyOwner)
{
var filter = Builders<Character>.Filter.Eq(c => c.Id, id);
if (!allowAnyOwner)
{
filter = Builders<Character>.Filter.And(
filter,
Builders<Character>.Filter.Eq(c => c.OwnerUserId, ownerUserId)
);
}
return await _col.Find(filter).FirstOrDefaultAsync();
}
public async Task<bool> UpdateCoordAsync(string id, string ownerUserId, bool allowAnyOwner, Coord coord)
{
var filter = Builders<Character>.Filter.Eq(c => c.Id, id);
if (!allowAnyOwner)
{
filter = Builders<Character>.Filter.And(
filter,
Builders<Character>.Filter.Eq(c => c.OwnerUserId, ownerUserId)
);
}
var update = Builders<Character>.Update.Set(c => c.Coord, coord);
var result = await _col.UpdateOneAsync(filter, update);
return result.ModifiedCount > 0;
}
public async Task<bool> DeleteForOwnerAsync(string id, string ownerUserId, bool allowAnyOwner) public async Task<bool> DeleteForOwnerAsync(string id, string ownerUserId, bool allowAnyOwner)
{ {
var filter = Builders<Character>.Filter.Eq(c => c.Id, id); var filter = Builders<Character>.Filter.Eq(c => c.Id, id);
@@ -1,35 +0,0 @@
using CharacterApi.Models;
using System.Net;
using System.Net.Http.Json;
namespace CharacterApi.Services;
public class LocationsClient
{
private readonly HttpClient _http;
private readonly string _internalKey;
public LocationsClient(HttpClient http, IConfiguration cfg)
{
_http = http;
_internalKey = cfg["LocationsApi:InternalKey"] ?? string.Empty;
}
public async Task<(bool Ok, HttpStatusCode Status, string? Body)> UpdatePresenceAsync(
string characterId,
Coord coord,
CancellationToken ct = default)
{
using var request = new HttpRequestMessage(HttpMethod.Post, "api/locations/presence")
{
Content = JsonContent.Create(new { characterId, coord })
};
if (!string.IsNullOrWhiteSpace(_internalKey))
request.Headers.TryAddWithoutValidation("X-Internal-Key", _internalKey);
using var response = await _http.SendAsync(request, ct);
var body = await response.Content.ReadAsStringAsync(ct);
return (response.IsSuccessStatusCode, response.StatusCode, body);
}
}
@@ -1,7 +1,6 @@
{ {
"Kestrel": { "Endpoints": { "Http": { "Url": "http://0.0.0.0:5001" } } }, "Kestrel": { "Endpoints": { "Http": { "Url": "http://0.0.0.0:5001" } } },
"MongoDB": { "ConnectionString": "mongodb://192.168.86.50:27017", "DatabaseName": "promiscuity" }, "MongoDB": { "ConnectionString": "mongodb://192.168.86.50:27017", "DatabaseName": "promiscuity" },
"LocationsApi": { "BaseUrl": "http://localhost:5002", "InternalKey": "dev-internal-key" },
"Jwt": { "Key": "SuperUltraSecureJwtKeyWithAtLeast32Chars!!", "Issuer": "promiscuity", "Audience": "promiscuity-auth-api" }, "Jwt": { "Key": "SuperUltraSecureJwtKeyWithAtLeast32Chars!!", "Issuer": "promiscuity", "Audience": "promiscuity-auth-api" },
"Logging": { "LogLevel": { "Default": "Information" } } "Logging": { "LogLevel": { "Default": "Information" } }
} }
@@ -1,7 +1,6 @@
{ {
"Kestrel": { "Endpoints": { "Http": { "Url": "http://0.0.0.0:5001" } } }, "Kestrel": { "Endpoints": { "Http": { "Url": "http://0.0.0.0:5001" } } },
"MongoDB": { "ConnectionString": "mongodb://192.168.86.50:27017", "DatabaseName": "promiscuity" }, "MongoDB": { "ConnectionString": "mongodb://192.168.86.50:27017", "DatabaseName": "promiscuity" },
"LocationsApi": { "BaseUrl": "http://localhost:5002", "InternalKey": "dev-internal-key" },
"Jwt": { "Key": "SuperUltraSecureJwtKeyWithAtLeast32Chars!!", "Issuer": "promiscuity", "Audience": "promiscuity-auth-api" }, "Jwt": { "Key": "SuperUltraSecureJwtKeyWithAtLeast32Chars!!", "Issuer": "promiscuity", "Audience": "promiscuity-auth-api" },
"Logging": { "LogLevel": { "Default": "Information" } }, "Logging": { "LogLevel": { "Default": "Information" } },
"AllowedHosts": "*" "AllowedHosts": "*"
@@ -11,12 +11,10 @@ namespace LocationsApi.Controllers;
public class LocationsController : ControllerBase public class LocationsController : ControllerBase
{ {
private readonly LocationStore _locations; private readonly LocationStore _locations;
private readonly IConfiguration _cfg;
public LocationsController(LocationStore locations, IConfiguration cfg) public LocationsController(LocationStore locations)
{ {
_locations = locations; _locations = locations;
_cfg = cfg;
} }
[HttpPost] [HttpPost]
@@ -33,7 +31,6 @@ public class LocationsController : ControllerBase
{ {
Name = req.Name.Trim(), Name = req.Name.Trim(),
Coord = req.Coord, Coord = req.Coord,
CharacterIds = new List<string>(),
CreatedUtc = DateTime.UtcNow CreatedUtc = DateTime.UtcNow
}; };
@@ -88,28 +85,4 @@ public class LocationsController : ControllerBase
return Ok("Updated"); return Ok("Updated");
} }
[HttpPost("presence")]
[AllowAnonymous]
public async Task<IActionResult> UpdatePresence([FromBody] UpdateLocationPresenceRequest req)
{
var internalKey = _cfg["Internal:Key"];
if (!string.IsNullOrWhiteSpace(internalKey))
{
if (!Request.Headers.TryGetValue("X-Internal-Key", out var provided) || provided != internalKey)
return Unauthorized();
}
if (string.IsNullOrWhiteSpace(req.CharacterId))
return BadRequest("CharacterId required");
if (req.Coord is null)
return BadRequest("Coord required");
var updated = await _locations.UpdatePresenceAsync(req.CharacterId.Trim(), req.Coord);
if (!updated)
return NotFound("Location not found");
return Ok("Updated");
}
} }
-11
View File
@@ -21,16 +21,6 @@ Inbound JSON documents
} }
``` ```
`coord` cannot be updated. `coord` cannot be updated.
- UpdateLocationPresenceRequest (`POST /api/locations/presence`)
```json
{
"characterId": "string",
"coord": {
"x": 0,
"y": 0
}
}
```
Stored documents (MongoDB) Stored documents (MongoDB)
- Location - Location
@@ -42,7 +32,6 @@ Stored documents (MongoDB)
"x": 0, "x": 0,
"y": 0 "y": 0
}, },
"characterIds": ["string"],
"createdUtc": "string (ISO-8601 datetime)" "createdUtc": "string (ISO-8601 datetime)"
} }
``` ```
@@ -15,9 +15,6 @@ public class Location
[BsonElement("coord")] [BsonElement("coord")]
public required Coord Coord { get; set; } public required Coord Coord { get; set; }
[BsonElement("characterIds")]
public List<string> CharacterIds { get; set; } = new();
[BsonElement("createdUtc")] [BsonElement("createdUtc")]
public DateTime CreatedUtc { get; set; } = DateTime.UtcNow; public DateTime CreatedUtc { get; set; } = DateTime.UtcNow;
} }
@@ -1,8 +0,0 @@
namespace LocationsApi.Models;
public class UpdateLocationPresenceRequest
{
public string CharacterId { get; set; } = string.Empty;
public Coord? Coord { get; set; }
}
-1
View File
@@ -8,4 +8,3 @@ See `DOCUMENTS.md` for request payloads and stored document shapes.
- `GET /api/locations` List all locations (SUPER only). - `GET /api/locations` List all locations (SUPER only).
- `DELETE /api/locations/{id}` Delete a location (SUPER only). - `DELETE /api/locations/{id}` Delete a location (SUPER only).
- `PUT /api/locations/{id}` Update a location name (SUPER only). - `PUT /api/locations/{id}` Update a location name (SUPER only).
- `POST /api/locations/presence` Update which characters are present at a coord (internal).
@@ -54,13 +54,6 @@ public class LocationStore
} }
} }
}, },
{
"characterIds", new BsonDocument
{
{ "bsonType", "array" },
{ "items", new BsonDocument { { "bsonType", "string" } } }
}
},
{ "createdUtc", new BsonDocument { { "bsonType", "date" } } } { "createdUtc", new BsonDocument { { "bsonType", "date" } } }
} }
} }
@@ -110,24 +103,6 @@ public class LocationStore
return result.ModifiedCount > 0; return result.ModifiedCount > 0;
} }
public async Task<bool> UpdatePresenceAsync(string characterId, Coord coord)
{
if (string.IsNullOrWhiteSpace(characterId))
return false;
var pullFilter = Builders<Location>.Filter.AnyEq(l => l.CharacterIds, characterId);
var pullUpdate = Builders<Location>.Update.Pull(l => l.CharacterIds, characterId);
await _col.UpdateManyAsync(pullFilter, pullUpdate);
var targetFilter = Builders<Location>.Filter.And(
Builders<Location>.Filter.Eq(l => l.Coord.X, coord.X),
Builders<Location>.Filter.Eq(l => l.Coord.Y, coord.Y)
);
var addUpdate = Builders<Location>.Update.AddToSet(l => l.CharacterIds, characterId);
var result = await _col.UpdateOneAsync(targetFilter, addUpdate);
return result.MatchedCount > 0;
}
private void EnsureOriginLocation() private void EnsureOriginLocation()
{ {
var filter = Builders<Location>.Filter.And( var filter = Builders<Location>.Filter.And(
@@ -142,7 +117,6 @@ public class LocationStore
{ {
Name = "Origin", Name = "Origin",
Coord = new Coord { X = 0, Y = 0 }, Coord = new Coord { X = 0, Y = 0 },
CharacterIds = new List<string>(),
CreatedUtc = DateTime.UtcNow CreatedUtc = DateTime.UtcNow
}; };
@@ -1,7 +1,6 @@
{ {
"Kestrel": { "Endpoints": { "Http": { "Url": "http://0.0.0.0:5002" } } }, "Kestrel": { "Endpoints": { "Http": { "Url": "http://0.0.0.0:5002" } } },
"MongoDB": { "ConnectionString": "mongodb://192.168.86.50:27017", "DatabaseName": "promiscuity" }, "MongoDB": { "ConnectionString": "mongodb://192.168.86.50:27017", "DatabaseName": "promiscuity" },
"Internal": { "Key": "dev-internal-key" },
"Jwt": { "Key": "SuperUltraSecureJwtKeyWithAtLeast32Chars!!", "Issuer": "promiscuity", "Audience": "promiscuity-auth-api" }, "Jwt": { "Key": "SuperUltraSecureJwtKeyWithAtLeast32Chars!!", "Issuer": "promiscuity", "Audience": "promiscuity-auth-api" },
"Logging": { "LogLevel": { "Default": "Information" } } "Logging": { "LogLevel": { "Default": "Information" } }
} }
@@ -1,7 +1,6 @@
{ {
"Kestrel": { "Endpoints": { "Http": { "Url": "http://0.0.0.0:5002" } } }, "Kestrel": { "Endpoints": { "Http": { "Url": "http://0.0.0.0:5002" } } },
"MongoDB": { "ConnectionString": "mongodb://192.168.86.50:27017", "DatabaseName": "promiscuity" }, "MongoDB": { "ConnectionString": "mongodb://192.168.86.50:27017", "DatabaseName": "promiscuity" },
"Internal": { "Key": "dev-internal-key" },
"Jwt": { "Key": "SuperUltraSecureJwtKeyWithAtLeast32Chars!!", "Issuer": "promiscuity", "Audience": "promiscuity-auth-api" }, "Jwt": { "Key": "SuperUltraSecureJwtKeyWithAtLeast32Chars!!", "Issuer": "promiscuity", "Audience": "promiscuity-auth-api" },
"Logging": { "LogLevel": { "Default": "Information" } }, "Logging": { "LogLevel": { "Default": "Information" } },
"AllowedHosts": "*" "AllowedHosts": "*"