mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-25 09:29:12 +01:00
fix(physics): a // comment in a .fiz is skipped, as the game does
Include parameters written one per line with a // note after them
("68 //MaxLoad") gave the note's words as parameters of their own, so
LoadAccepted=(p3) in db/zans_v1 read "68" and the load list showed a number.
This commit is contained in:
@@ -65,6 +65,36 @@ public class PhysicsAndAssetsTests
|
|||||||
Assert.Equal(125, physics.VMax);
|
Assert.Equal(125, physics.VMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Comments_between_include_parameters_are_not_parameters()
|
||||||
|
{
|
||||||
|
// As in the game: db/zans_v1/astra_rail_14_96m_86m3_ke_1.fiz feeds zans.fiz.inc this way.
|
||||||
|
const string fiz = """
|
||||||
|
include
|
||||||
|
zans.fiz.inc
|
||||||
|
21000 //masa
|
||||||
|
68 //MaxLoad
|
||||||
|
aviation_fuel,crude_oil,petrol
|
||||||
|
14.96 //L
|
||||||
|
end
|
||||||
|
""";
|
||||||
|
var installation = new TestInstallation(new InMemoryFileSystem()
|
||||||
|
.WithFile(Fiz("db", "zans_v1", "astra"), fiz)
|
||||||
|
.WithFile(TestInstallation.At("dynamic", "db", "zans_v1", "zans.fiz.inc"),
|
||||||
|
"""
|
||||||
|
Param. Category=train M=(p1) Vmax=100 # masa [kg]
|
||||||
|
Load: MaxLoad=(p2) LoadQ=tonns LoadAccepted=(p3) LoadSpeed=0.1
|
||||||
|
Dimensions: L=(p4) H=4.285
|
||||||
|
"""));
|
||||||
|
|
||||||
|
var physics = installation.Physics.For("db/zans_v1/", "astra")!;
|
||||||
|
|
||||||
|
Assert.Equal(21000, physics.Mass);
|
||||||
|
Assert.Equal(68, physics.MaxLoad);
|
||||||
|
Assert.Equal("aviation_fuel,crude_oil,petrol", physics.LoadAccepted);
|
||||||
|
Assert.Equal(14.96, physics.Length);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void An_include_named_in_other_case_is_followed()
|
public void An_include_named_in_other_case_is_followed()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -265,10 +265,14 @@ public sealed class FizPhysicsRepository : IPhysicsRepository
|
|||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
foreach (string line in text.Split('\n'))
|
foreach (string line in text.Split('\n'))
|
||||||
{
|
{
|
||||||
|
// Both kinds the game skips: "68 //MaxLoad" passes one include parameter, not two.
|
||||||
string stripped = line;
|
string stripped = line;
|
||||||
int comment = stripped.IndexOf('#');
|
int comment = stripped.IndexOf('#');
|
||||||
if (comment >= 0)
|
if (comment >= 0)
|
||||||
stripped = stripped[..comment];
|
stripped = stripped[..comment];
|
||||||
|
int slashes = stripped.IndexOf("//", StringComparison.Ordinal);
|
||||||
|
if (slashes >= 0)
|
||||||
|
stripped = stripped[..slashes];
|
||||||
sb.Append(stripped).Append(' ');
|
sb.Append(stripped).Append(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user