The knife: a pixel cursor in the office, CutAt through the camera ray and Office.Pick, a plain left press cuts and Alt+left stays the camera's

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-27 03:17:20 +01:00
commit 8c4eb92806
3 changed files with 77 additions and 0 deletions

View file

@ -20,6 +20,8 @@ public static class Look
public static readonly Color Grout = Color.Color8(0x0d, 0x15, 0x1d);
public static readonly Color Skin = Color.Color8(196, 146, 120);
public static readonly Color Glow = new(0.85f, 0.95f, 1f);
/// <summary>Blood: a saturated red, a placeholder tuned by eye later.</summary>
public static readonly Color Blood = new(0.78f, 0.04f, 0.05f);
/// <summary>The key light's direction (where it comes from, in the world), its colour and the ambient: ps1.js's.</summary>
public static readonly Vector3 KeyDirection = new Vector3(-0.4f, 0.8f, 0.45f).Normalized();
@ -86,6 +88,32 @@ public static class Look
return material;
}
/// <summary>
/// The office's mouse cursor: a knife, tip at the top left corner (the hotspot), blade running down to the right into a handle, 32 x 32,
/// drawn pixel by pixel here so the client carries no art file. The blade is steel with a dark edge; the handle is brown.
/// </summary>
public static Image KnifeCursor()
{
const int size = 32;
var image = Image.CreateEmpty(size, size, false, Image.Format.Rgba8);
image.Fill(new Color(0, 0, 0, 0));
var steel = Color.Color8(0xc8, 0xd0, 0xd8);
var edge = Color.Color8(0x20, 0x24, 0x2a);
var grip = Color.Color8(0x5a, 0x34, 0x1c);
for (int y = 0; y < size; y++)
for (int x = 0; x < size; x++)
{
// Distance from the pixel to the knife's axis, the diagonal x = y, and the position along it.
float along = (x + y) / 2f, across = Math.Abs(x - y) / 1.4142135f;
if (along > 29f) continue;
bool handle = along > 17f;
float half = handle ? 3f : 4.2f * (1f - 0.2f * along / 17f) * Math.Min(1f, along / 3f + 0.15f);
if (across > half) continue;
image.SetPixel(x, y, handle ? grip : across > half - 1f || along < 1f ? edge : steel);
}
return image;
}
private static ImageTexture Noise(int w, int h, Color baseColour, float spread, ulong seed, Func<int, int, bool>? grouted = null, Color? groutColour = null)
{
var rng = new RandomNumberGenerator { Seed = seed };

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using BadDay.Core;
using Lodur;
using BadDay.Ymir;
using Godot;
@ -119,6 +120,7 @@ public partial class Main : Node3D
{
if (IsInstanceValid(GetWindow())) GetWindow().SizeChanged -= SetLines;
Engine.PhysicsTicksPerSecond = StepsPerSecond(1.0);
Input.SetCustomMouseCursor(null);
_run?.Dispose();
_run = null;
}
@ -134,9 +136,37 @@ public partial class Main : Node3D
public void SetScenario(Scenario scenario)
{
Scenario = scenario;
if (scenario == Scenario.Office) Input.SetCustomMouseCursor(ImageTexture.CreateFromImage(Look.KnifeCursor()), Input.CursorShape.Arrow, Vector2.Zero);
else Input.SetCustomMouseCursor(null);
Reset(Seed);
}
public override void _UnhandledInput(InputEvent e)
{
// The knife takes plain left presses; Alt+left is the camera's emulated middle button, and the camera never binds a plain left.
if (Scenario == Scenario.Office && e is InputEventMouseButton { Pressed: true, ButtonIndex: MouseButton.Left, AltPressed: false } press)
{
CutAt(press.Position);
GetViewport().SetInputAsHandled();
}
}
/// <summary>
/// The knife at a screen point: the camera's ray through it (20 m), the office's pick, and a cut where it hit. True when a cut opened;
/// then the part and the tick are appended to <see cref="Cuts"/>. A miss, a refusal and any other scenario do nothing.
/// </summary>
public bool CutAt(Vector2 screenPoint)
{
if (Scenario != Scenario.Office || _run is not OfficeBodySession office) return false;
var origin = _camera.ProjectRayOrigin(screenPoint);
var translation = _camera.ProjectRayNormal(screenPoint) * 20f;
if (office.Pick(new BodyPoint(origin.X, origin.Y, origin.Z), new BodyPoint(translation.X, translation.Y, translation.Z)) is not { } hit) return false;
if (!office.Wound(hit, WoundTool.Knife)) return false;
var part = SeatedPuppet.Plan.Parts[hit.Part];
_cuts.Add(new Cut(part.Side switch { Lodur.Side.Left => part.Label + " L", Lodur.Side.Right => part.Label + " R", _ => part.Label }, office.TickIndex));
return true;
}
/// <summary>Starts a new run of the current scenario from <paramref name="seed"/> (the box at the current intensity), replacing the live run.</summary>
public void Reset(ulong seed)
{

View file

@ -177,6 +177,18 @@ public partial class Smoke : Node
Check(_main.Scenario == Scenario.Office && _main.Seed == Seed, $"the picker left Main in {_main.Scenario}, seed {_main.Seed}");
var office = Office;
Check(!_main.Chamber.Visible && _main.Chamber.Glow == 0f, "the chamber is drawn in the office");
await UntilTick(120);
// The knife: where the player clicks. An Alt+left press is the camera's emulated middle button and cuts nothing; a plain left press on
// LowerArm L's drawn centre opens one cut there, through the same CutAt a direct call takes.
int arm = SeatedPuppet.Plan.PartIndex("LowerArm", Lodur.Side.Left);
var camera = _main.GetNode<OrbitCamera>("Camera");
Vector2 at = camera.UnprojectPosition(_main.Bodies.PoseOf(SeatedPuppet.FirstStableId + (ulong)arm)!.Value.Origin);
Click(at, alt: true);
Check(_main.Cuts.Count == 0, "an Alt+left press cut");
Click(at, alt: false);
Check(_main.Cuts.Count == 1 && _main.Cuts[0].Part == "LowerArm L", $"a left press on LowerArm L's centre left cuts [{string.Join(", ", _main.Cuts)}]");
Check(office.Result().Timeline.Count > 0, "no timeline after a cut");
await UntilTick(600);
// The bars are the session's will and arousal, to the bit, once a frame has drawn them (stepping paused so the session holds still).
@ -204,6 +216,13 @@ public partial class Smoke : Node
Check(Throws(() => _ = office.TickIndex), "the office run was not disposed by the switch");
}
/// <summary>A left press and release at <paramref name="at"/> (viewport coordinates), pushed through the viewport like the mouse's.</summary>
private void Click(Vector2 at, bool alt)
{
foreach (bool pressed in new[] { true, false })
GetViewport().PushInput(new InputEventMouseButton { ButtonIndex = MouseButton.Left, Pressed = pressed, Position = at, GlobalPosition = at, AltPressed = alt, ButtonMask = pressed ? MouseButtonMask.Left : 0 }, inLocalCoords: true);
}
private static bool Throws(Action a)
{
try { a(); return false; }