Update wire protocol to version 5, introducing pupil slots and item counts in map snapshots. Enhance UI components to display pupil slots and item counts in game screens and map editors. Revise localization strings for improved user guidance. Update tests to validate new functionalities and ensure robustness in handling room and item data.
This commit is contained in:
@@ -106,6 +106,10 @@ public class GameSocketTests(AppHostFixture fixture)
|
||||
Assert.Equal("floor-1", office.ParentId);
|
||||
Assert.Contains("Директор", office.Positions);
|
||||
Assert.NotEmpty(office.Items);
|
||||
var classroom = Assert.Single(snapshot.Nodes, node => node.Id == "classroom-1a");
|
||||
Assert.Equal(16, classroom.PupilSlots);
|
||||
Assert.Contains(classroom.Items, item => item.Name == "Парта" && item.Count == 16);
|
||||
Assert.Contains(classroom.Items, item => item.Name == "Стул" && item.Count == 1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -23,12 +23,17 @@ public class MapViewTests
|
||||
|
||||
var officeRu = ru.Single(node => node.Id == "principals-office");
|
||||
Assert.Equal("Кабинет директора", officeRu.Name);
|
||||
Assert.Equal(["Кресло директора", "Стол", "Стул"], officeRu.Items);
|
||||
Assert.Equal(
|
||||
[new MapViewItem("Кресло директора", 1), new MapViewItem("Стол", 1), new MapViewItem("Стул", 2)],
|
||||
officeRu.Items);
|
||||
Assert.Equal(0, officeRu.PupilSlots);
|
||||
Assert.Equal(["Директор"], officeRu.Positions);
|
||||
|
||||
var officeEn = en.Single(node => node.Id == "principals-office");
|
||||
Assert.Equal("Principal's office", officeEn.Name);
|
||||
Assert.Equal(["Principal's chair", "Desk", "Chair"], officeEn.Items);
|
||||
Assert.Equal(
|
||||
[new MapViewItem("Principal's chair", 1), new MapViewItem("Desk", 1), new MapViewItem("Chair", 2)],
|
||||
officeEn.Items);
|
||||
Assert.Equal(["Principal"], officeEn.Positions);
|
||||
|
||||
var corridor = ru.Single(node => node.Id == "corridor-1");
|
||||
@@ -38,7 +43,15 @@ public class MapViewTests
|
||||
|
||||
var classroom = ru.Single(node => node.Id == "classroom-1a");
|
||||
Assert.Equal("Класс 1A", classroom.Name);
|
||||
Assert.Equal(["Доска", "Стол", "Парта"], classroom.Items);
|
||||
Assert.Equal(
|
||||
[
|
||||
new MapViewItem("Доска", 1),
|
||||
new MapViewItem("Стол", 1),
|
||||
new MapViewItem("Стул", 1),
|
||||
new MapViewItem("Парта", 16),
|
||||
],
|
||||
classroom.Items);
|
||||
Assert.Equal(16, classroom.PupilSlots);
|
||||
Assert.Equal(["Учитель"], classroom.Positions);
|
||||
Assert.Equal("Classroom 1A", en.Single(node => node.Id == "classroom-1a").Name);
|
||||
}
|
||||
|
||||
@@ -25,8 +25,20 @@ public class VanillaCoreTests
|
||||
Assert.True(catalog.Rooms.ContainsKey("Classroom"));
|
||||
Assert.Equal("Класс", catalog.Label("ru", catalog.Rooms["Classroom"]));
|
||||
Assert.Equal(["Teacher"], catalog.PositionsFor(DefKind.Room, "Classroom"));
|
||||
Assert.Equal(1, catalog.Things["StudentDesk"].PupilSlots);
|
||||
Assert.Equal(1, catalog.Things["Computer"].PupilSlots);
|
||||
Assert.Equal(0, catalog.Things["Desk"].PupilSlots);
|
||||
Assert.Equal(0, catalog.Things["Chair"].PupilSlots);
|
||||
Assert.Contains(catalog.Rooms["Classroom"].Slots, slot => slot.Key == "teacherChair" && slot.Thing == "Chair");
|
||||
Assert.Equal(16, catalog.Rooms["Classroom"].Slots.Single(slot => slot.Key == "studentDesks").Count);
|
||||
Assert.Equal(2, map.Buildings.Count);
|
||||
Assert.True(map.Rooms.Count >= 18, "Vanilla layout should look like a small school, not a stub.");
|
||||
Assert.Contains(map.Rooms, room => room.Id == "classroom-1a" && room.Label == "1A");
|
||||
Assert.Equal(
|
||||
16,
|
||||
map.Rooms.Single(room => room.Id == "classroom-1a").Slots.Single(slot => slot.Key == "studentDesks").Count);
|
||||
Assert.Contains(
|
||||
map.Rooms.Single(room => room.Id == "classroom-1a").Slots,
|
||||
slot => slot.Key == "teacherChair" && slot.Thing == "Chair");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,8 +137,15 @@ public class ProtocolCodecTests
|
||||
public void MapSnapshot_RoundTripsAndWritesHeaderOffsets()
|
||||
{
|
||||
var message = new ServerMapSnapshotMessage(7, [
|
||||
new MapSnapshotNode(0, "yard", "", "Двор", [], []),
|
||||
new MapSnapshotNode(3, "office", "floor-1", "Кабинет директора", ["Стул"], ["Директор"]),
|
||||
new MapSnapshotNode(0, "yard", "", "Двор", 0, [], []),
|
||||
new MapSnapshotNode(
|
||||
3,
|
||||
"office",
|
||||
"floor-1",
|
||||
"Кабинет директора",
|
||||
0,
|
||||
[new MapSnapshotItem("Стул", 2)],
|
||||
["Директор"]),
|
||||
]);
|
||||
var buffer = new byte[ProtocolConstants.MaxMessageSize];
|
||||
|
||||
@@ -154,17 +161,47 @@ public class ProtocolCodecTests
|
||||
Assert.Equal("yard", read.Nodes[0].Id);
|
||||
Assert.Equal("", read.Nodes[0].ParentId);
|
||||
Assert.Equal("Двор", read.Nodes[0].Name);
|
||||
Assert.Equal(["Стул"], read.Nodes[1].Items);
|
||||
Assert.Equal(0, read.Nodes[0].PupilSlots);
|
||||
Assert.Equal([new MapSnapshotItem("Стул", 2)], read.Nodes[1].Items);
|
||||
Assert.Equal(["Директор"], read.Nodes[1].Positions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MapSnapshot_WritesPupilSlotsAndStackedItemCount()
|
||||
{
|
||||
var message = new ServerMapSnapshotMessage(1, [
|
||||
new MapSnapshotNode(
|
||||
3,
|
||||
"classroom-1a",
|
||||
"floor-1",
|
||||
"Класс 1A",
|
||||
16,
|
||||
[new MapSnapshotItem("Парта", 16)],
|
||||
[]),
|
||||
]);
|
||||
var buffer = new byte[ProtocolCodec.MapSnapshotSize(message)];
|
||||
|
||||
var length = ProtocolCodec.WriteMapSnapshot(buffer, message);
|
||||
var read = ProtocolCodec.ReadMapSnapshot(buffer.AsSpan(0, length));
|
||||
|
||||
Assert.Equal(16, read.Nodes[0].PupilSlots);
|
||||
Assert.Equal([new MapSnapshotItem("Парта", 16)], read.Nodes[0].Items);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MapSnapshotSize_IsExactlyWhatTheWriterProduces()
|
||||
{
|
||||
var message = new ServerMapSnapshotMessage(7, [
|
||||
new MapSnapshotNode(0, "yard", "", "Двор", [], []),
|
||||
new MapSnapshotNode(2, "floor-1", "main", "Этаж 1", [], []),
|
||||
new MapSnapshotNode(3, "office", "floor-1", "Кабинет директора", ["Стол", "Стул"], ["Директор"]),
|
||||
new MapSnapshotNode(0, "yard", "", "Двор", 0, [], []),
|
||||
new MapSnapshotNode(2, "floor-1", "main", "Этаж 1", 0, [], []),
|
||||
new MapSnapshotNode(
|
||||
3,
|
||||
"office",
|
||||
"floor-1",
|
||||
"Кабинет директора",
|
||||
0,
|
||||
[new MapSnapshotItem("Стол", 1), new MapSnapshotItem("Стул", 2)],
|
||||
["Директор"]),
|
||||
]);
|
||||
|
||||
var size = ProtocolCodec.MapSnapshotSize(message);
|
||||
@@ -179,7 +216,7 @@ public class ProtocolCodecTests
|
||||
// A player who keeps clicking "Add room" in the create editor gets past 8 KiB somewhere
|
||||
// around sixty furnished rooms. Sizing the buffer from the message is what keeps that
|
||||
// school openable instead of killing its worker thread on the first snapshot.
|
||||
var nodes = new List<MapSnapshotNode> { new(0, "yard", "", "Двор", [], []) };
|
||||
var nodes = new List<MapSnapshotNode> { new(0, "yard", "", "Двор", 0, [], []) };
|
||||
for (var i = 1; i <= 200; i++)
|
||||
{
|
||||
nodes.Add(new MapSnapshotNode(
|
||||
@@ -187,7 +224,8 @@ public class ProtocolCodecTests
|
||||
$"principals-office-{i}",
|
||||
"floor-1",
|
||||
"Кабинет директора",
|
||||
["Кресло директора", "Стол", "Стул"],
|
||||
0,
|
||||
[new MapSnapshotItem("Кресло директора", 1), new MapSnapshotItem("Стол", 1), new MapSnapshotItem("Стул", 2)],
|
||||
["Директор"]));
|
||||
}
|
||||
|
||||
@@ -201,7 +239,9 @@ public class ProtocolCodecTests
|
||||
|
||||
Assert.Equal(nodes.Count, read.Nodes.Count);
|
||||
Assert.Equal("principals-office-200", read.Nodes[^1].Id);
|
||||
Assert.Equal(["Кресло директора", "Стол", "Стул"], read.Nodes[^1].Items);
|
||||
Assert.Equal(
|
||||
[new MapSnapshotItem("Кресло директора", 1), new MapSnapshotItem("Стол", 1), new MapSnapshotItem("Стул", 2)],
|
||||
read.Nodes[^1].Items);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user