Skip to content

Commit

Permalink
DS-related fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
hovi committed Jan 4, 2023
1 parent 925992e commit 972d4c3
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 23 deletions.
1 change: 0 additions & 1 deletion CucumberTester/src/main/kotlin/bdd/CharacterActions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ class CharacterActions(connectionManager: ConnectionManager) : AbstractMultiplay
@When("Character turns on personal light.")
fun character_turns_on_personal_light() = mainClient {
character.setLight(true)
println(screens.gamePlay.data().hud.stats)
}

@When("Character suicides.")
Expand Down
31 changes: 19 additions & 12 deletions CucumberTester/src/main/kotlin/bdd/CharacterAsserts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,7 @@ class CharacterAsserts(connectionManager: ConnectionManager) : AbstractMultiplay
@Then("Character stats are:")
fun character_stats_are_changed_to(dt: DataTable) {
val dataTable = dt.asMaps().first().map { it.key to it.value.toFloat() }.toMap()
val relativeTolerance = dataTable["relative_tolerance"] ?: 0.001f
println(dataTable)
val relativeTolerance = dataTable["relative_tolerance"] ?: 0.01f
mainClient {
val observation = observer.observe() as CharacterStats
checkStats(dataTable, observation, relativeTolerance)
Expand All @@ -639,7 +638,12 @@ class CharacterAsserts(connectionManager: ConnectionManager) : AbstractMultiplay
relativeTolerance: Float
) {
dataTable[name]?.let { tableStat ->
assertEquals(tableStat / 100f, stat, absoluteTolerance = stat * relativeTolerance)
assertEquals(
tableStat / 100f,
stat,
absoluteTolerance = 1f * relativeTolerance,
message = "absoluteTolerance: ${1f * relativeTolerance}"
)
}
}

Expand All @@ -654,7 +658,9 @@ class CharacterAsserts(connectionManager: ConnectionManager) : AbstractMultiplay
@Then("health is less than maximum.")
fun health_is_less_than_maximum() {
mainClient {
assertLessThan(observer.observe().health, 1f)
repeatUntilSuccess {
assertLessThan(observer.observe().health, 1f)
}
}
}

Expand Down Expand Up @@ -682,23 +688,24 @@ class CharacterAsserts(connectionManager: ConnectionManager) : AbstractMultiplay

@Then("Personal light is off.")
fun personal_light_is_off() = mainClient {
println(screens.gamePlay.data().hud.stats)
assertEquals(0f, observer.observe().currentLightPower)
//assertFalse(observer.observe().lightEnabled, "light is supposed to be off!")
//TODO: check on hud too
}

@Then("Character is dead.")
fun character_is_dead() = mainClient {
with(observer.observe()) {
assertTrue(movement.isDead)
assertEquals(0f, health)
repeatUntilSuccess {
with(observer.observe()) {
assertTrue(movement.isDead, "Not dead based on CharacterMovement flag: $movement")
assertEquals(0f, health, "Not dead based on health: $health")
}
}
}

@Then("Remote terminal for grid {string} is disabled.")
fun remote_terminal_is_disabled(grid: String) = mainClient {
delay(200.milliseconds)
delay(500.milliseconds)
input.startPlaying(
listOf(
FrameSnapshot(
Expand All @@ -708,7 +715,7 @@ class CharacterAsserts(connectionManager: ConnectionManager) : AbstractMultiplay
)
)
)
delay(200.milliseconds)
delay(500.milliseconds)
val grids = screens.terminal.remoteAccess.data().grids
assertTrue(grids.isNotEmpty(), "No grids to see!")
assertFalse(
Expand All @@ -720,7 +727,7 @@ class CharacterAsserts(connectionManager: ConnectionManager) : AbstractMultiplay

@Then("Remote terminal for grid {string} is enabled.")
fun remote_terminal_is_enabled(grid: String) = mainClient {
delay(200.milliseconds)
delay(500.milliseconds)
input.startPlaying(
listOf(
FrameSnapshot(
Expand All @@ -730,7 +737,7 @@ class CharacterAsserts(connectionManager: ConnectionManager) : AbstractMultiplay
)
)
)
delay(200.milliseconds)
delay(500.milliseconds)
val grids = screens.terminal.remoteAccess.data().grids
assertTrue(grids.isNotEmpty(), "No grids to see!")
assertTrue(
Expand Down
55 changes: 49 additions & 6 deletions CucumberTester/src/main/kotlin/bdd/setup/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ suspend fun SpaceEngineers.dieAndConfirm(delayMs: Long = 100L) {
screens.messageBox.pressYes()
}

suspend fun SpaceEngineers.ensureCamera(cameraConfig: CameraConfig) {
fun SpaceEngineers.ensureCamera(cameraConfig: CameraConfig) {
val info = session.info()
val cameraInfo = info?.camera ?: error("No camera info")
when (cameraConfig) {
Expand All @@ -54,11 +54,54 @@ suspend fun SpaceEngineers.ensureCamera(cameraConfig: CameraConfig) {
suspend fun ConnectionManagerUser.handleScenarioParameter(key: String, value: String) {
when (key) {
"delay_after_spawn" -> delay((value.toFloat() * 1000f).toLong())
"energy" -> admin { admin.character.updateEnergy(energy = value.toFloat() / 100f) }
"hydrogen" -> admin { admin.character.updateHydrogen(hydrogen = value.toFloat() / 100f) }
"health" -> admin { admin.character.updateHealth(health = value.toFloat() / 100f) }
"oxygen" -> admin { admin.character.updateOxygen(oxygen = value.toFloat() / 100f) }
"camera" -> mainClient { ensureCamera(CameraConfig.fromText(value)) }
"energy" -> {
val id = mainClient {
admin.character.updateEnergy(energy = value.toFloat() / 100f)
admin.character.mainCharacterId()
}
admin {
admin.character.switch(id)
admin.character.updateEnergy(energy = value.toFloat() / 100f)
}
}

"hydrogen" -> {
val id = mainClient {
admin.character.updateHydrogen(hydrogen = value.toFloat() / 100f)
admin.character.mainCharacterId()
}
admin {
admin.character.switch(id)
admin.character.updateHydrogen(hydrogen = value.toFloat() / 100f)
}
}

"health" -> {
val id = mainClient {
admin.character.updateHealth(health = value.toFloat() / 100f)
admin.character.mainCharacterId()
}
admin {
admin.character.switch(id)
admin.character.updateHealth(health = value.toFloat() / 100f)
}
}

"oxygen" -> {
val id = mainClient {
admin.character.updateOxygen(oxygen = value.toFloat() / 100f)
admin.character.mainCharacterId()
}
admin {
admin.character.switch(id)
admin.character.updateOxygen(oxygen = value.toFloat() / 100f)
}
}

"camera" -> {
mainClient { ensureCamera(CameraConfig.fromText(value)) }
}

else -> error("Warning, unknown settings: $key - $value")
}
}
Expand Down
9 changes: 5 additions & 4 deletions Source/Ivxr.SePlugin/Control/CharacterController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void UpdateEnergy(float energy)

public void UpdateHealth(float health)
{
Character.StatComp.Health.Value = health * 100;
Character.StatComp.Health.CallMethod<object>("SetValue", new object[] { health * 100, null });
}


Expand Down Expand Up @@ -120,7 +120,8 @@ public void SetHelmet(bool enabled)
return;
}

Character.OxygenComponent.SwitchHelmet();
IMyControllableEntity entity = (IMyControllableEntity) Character;
entity.SwitchHelmet();
}

public void SetLight(bool enabled)
Expand Down Expand Up @@ -292,12 +293,12 @@ private MyEntityController GetEntityController()

private MyCharacter Character => m_session.Character;

private void EnsureCharacterLives(string message ="Cannot do this while dead")
private void EnsureCharacterLives(string message = "Cannot do this while dead")
{
if (Character.IsDead)
{
throw new InvalidOperationException(message);
}
}
}
}
}

0 comments on commit 972d4c3

Please sign in to comment.