Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/articles/cameras.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Each `CameraFrame` (delivered via `OnCameraRaysReceived`) contains:
- `Entities` — list of `CameraEntity` objects visible in the frame (id, type, position/rotation/size, name).
- `TimeOfDay` — in-game time of day when captured (`null` if not reported).
- `CameraPosition` / `CameraRotation` — world-space position and rotation (`null` if not reported).
- `SampleRotation` — world-space rotation the frame's rays were sampled with (`null` if not reported).

## CameraController

Expand Down
3 changes: 3 additions & 0 deletions src/RustPlusApi/Data/Cameras/CameraFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ public record CameraFrame

/// <summary>World-space rotation of the camera, if reported.</summary>
public Vector3? CameraRotation { get; init; }

/// <summary>World-space rotation the frame's rays were sampled with, if reported.</summary>
public Vector3? SampleRotation { get; init; }
}
3 changes: 3 additions & 0 deletions src/RustPlusApi/Data/VendingMachineItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ public sealed record VendingMachineItem

/// <summary>Price multiplier applied to the order, if reported.</summary>
public float? PriceMultiplier { get; init; }

/// <summary>Multiplier applied to the quantity actually received per transaction, if reported.</summary>
public float? ReceivedQuantityMultiplier { get; init; }
}
6 changes: 4 additions & 2 deletions src/RustPlusApi/Extensions/AppCameraToModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public static CameraFrame ToCameraFrame(this AppCameraRays appCameraRays)
Entities = appCameraRays.Entities.ToCameraEntities(),
TimeOfDay = appCameraRays.ShouldSerializeTimeOfDay() ? appCameraRays.TimeOfDay : null,
CameraPosition = appCameraRays.CameraPosition?.ToVector3(),
CameraRotation = appCameraRays.CameraRotation?.ToVector3()
CameraRotation = appCameraRays.CameraRotation?.ToVector3(),
SampleRotation = appCameraRays.SampleRotation?.ToVector3()
};
}

Expand All @@ -56,7 +57,8 @@ public static CameraRaysEventArg ToCameraRaysEvent(this AppCameraRays appCameraR
Entities = appCameraRays.Entities.ToCameraEntities(),
TimeOfDay = appCameraRays.ShouldSerializeTimeOfDay() ? appCameraRays.TimeOfDay : null,
CameraPosition = appCameraRays.CameraPosition?.ToVector3(),
CameraRotation = appCameraRays.CameraRotation?.ToVector3()
CameraRotation = appCameraRays.CameraRotation?.ToVector3(),
SampleRotation = appCameraRays.SampleRotation?.ToVector3()
};
}

Expand Down
5 changes: 4 additions & 1 deletion src/RustPlusApi/Extensions/AppMarkerToModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ public static VendingMachineItem ToVendingMachineItem(this SellOrder sellOrder)
IsCurrencyBlueprint = sellOrder.CurrencyIsBlueprint,
ItemLife = sellOrder.ItemCondition,
ItemMaxLife = sellOrder.ItemConditionMax,
PriceMultiplier = sellOrder.ShouldSerializePriceMultiplier() ? sellOrder.PriceMultiplier : null
PriceMultiplier = sellOrder.ShouldSerializePriceMultiplier() ? sellOrder.PriceMultiplier : null,
ReceivedQuantityMultiplier = sellOrder.ShouldSerializeReceivedQuantityMultiplier()
? sellOrder.ReceivedQuantityMultiplier
: null
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/RustPlusApi/Protobuf/RustPlusContracts.proto
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ message AppMarker {
optional float item_condition = 8;
optional float item_condition_max = 9;
optional float price_multiplier = 10;
optional float received_quantity_multiplier = 11;
}
}

Expand Down Expand Up @@ -424,6 +425,7 @@ message AppCameraRays {
optional float time_of_day = 6;
optional Vector3 camera_position = 7;
optional Vector3 camera_rotation = 8;
optional Vector3 sample_rotation = 9;

enum EntityType {
Tree = 1;
Expand Down
12 changes: 12 additions & 0 deletions tests/RustPlusApi.UnitTests/CameraModelMapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public void ToCameraFrame_NullRayData_BecomesEmpty_AndNullVectorsStayNull()
Assert.Null(frame.TimeOfDay);
Assert.Null(frame.CameraPosition);
Assert.Null(frame.CameraRotation);
Assert.Null(frame.SampleRotation);
Assert.Empty(frame.Entities);
}

Expand All @@ -50,6 +51,10 @@ public void ToCameraFrame_WithTimeOfDayAndCameraVectors_MapsThem()
CameraRotation = new ProtoVector3
{
X = 4, Y = 5, Z = 6
},
SampleRotation = new ProtoVector3
{
X = 7, Y = 8, Z = 9
}
};

Expand All @@ -58,6 +63,7 @@ public void ToCameraFrame_WithTimeOfDayAndCameraVectors_MapsThem()
Assert.Equal(0.5f, frame.TimeOfDay);
Assert.Equal(1, frame.CameraPosition!.X);
Assert.Equal(6, frame.CameraRotation!.Z);
Assert.Equal(9, frame.SampleRotation!.Z);
}

[Fact]
Expand All @@ -74,6 +80,7 @@ public void ToCameraRaysEvent_NullRayData_BecomesEmpty_AndNullVectorsStayNull()
Assert.Null(frame.TimeOfDay);
Assert.Null(frame.CameraPosition);
Assert.Null(frame.CameraRotation);
Assert.Null(frame.SampleRotation);
}

[Fact]
Expand All @@ -91,6 +98,10 @@ public void ToCameraRaysEvent_WithTimeOfDayAndCameraVectors_MapsThem()
CameraRotation = new ProtoVector3
{
X = 1, Y = 2, Z = 3
},
SampleRotation = new ProtoVector3
{
X = 4, Y = 5, Z = 6
}
};

Expand All @@ -99,5 +110,6 @@ public void ToCameraRaysEvent_WithTimeOfDayAndCameraVectors_MapsThem()
Assert.Equal(0.75f, frame.TimeOfDay);
Assert.Equal(10, frame.CameraPosition!.X);
Assert.Equal(3, frame.CameraRotation!.Z);
Assert.Equal(6, frame.SampleRotation!.Z);
}
}
32 changes: 31 additions & 1 deletion tests/RustPlusApi.UnitTests/MarkerMapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace RustPlusApi.UnitTests;

/// <summary>Locks every projection in <see cref="AppMarkerToModel"/>, including the sell-order
/// presence fork on <c>PriceMultiplier</c>.</summary>
/// presence forks on <c>PriceMultiplier</c> and <c>ReceivedQuantityMultiplier</c>.</summary>
public class MarkerMapperTests
{
private static AppMarker Marker(AppMarkerType type) => new()
Expand Down Expand Up @@ -78,6 +78,36 @@ public void ToVendingMachineItem_WhenPriceMultiplierUnset_IsNull()
Assert.Null(item.PriceMultiplier);
}

[Fact]
public void ToVendingMachineItem_WhenReceivedQuantityMultiplierSet_MapsValue()
{
var order = new SellOrder
{
ItemId = 9,
Quantity = 1,
CostPerItem = 1,
AmountInStock = 1,
ReceivedQuantityMultiplier = 2.5f
};

var item = order.ToVendingMachineItem();

Assert.Equal(2.5f, item.ReceivedQuantityMultiplier);
}

[Fact]
public void ToVendingMachineItem_WhenReceivedQuantityMultiplierUnset_IsNull()
{
var order = new SellOrder
{
ItemId = 9, Quantity = 1, CostPerItem = 1, AmountInStock = 1
};

var item = order.ToVendingMachineItem();

Assert.Null(item.ReceivedQuantityMultiplier);
}

[Theory]
[InlineData(AppMarkerType.Ch47)]
[InlineData(AppMarkerType.CargoShip)]
Expand Down
Loading