Skip to content

Commit

Permalink
#1: finish reader for scripts, add test for bfme2 rotwk scripts, add …
Browse files Browse the repository at this point in the history
…test to read bfme1 skymap settings
  • Loading branch information
DarkAtra committed Jun 5, 2021
1 parent f427bb5 commit 60e3d14
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package de.darkatra.bfme2.map

import de.darkatra.bfme2.ConversionException

@Suppress("unused")
enum class BlendDirection(
val byte: Byte
) {
Expand Down
1 change: 1 addition & 0 deletions map/src/main/kotlin/de/darkatra/bfme2/map/BlendFlags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package de.darkatra.bfme2.map
import de.darkatra.bfme2.ConversionException
import kotlin.experimental.or

@Suppress("unused")
enum class BlendFlags(
val byte: Byte
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package de.darkatra.bfme2.map

import de.darkatra.bfme2.ConversionException

@Suppress("unused")
enum class CameraAnimationFrameInterpolationType {
CATM,
LINE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package de.darkatra.bfme2.map

import de.darkatra.bfme2.ConversionException

@Suppress("unused")
enum class EvaluationIntervalType(
val uInt: UInt
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package de.darkatra.bfme2.map

import de.darkatra.bfme2.ConversionException

@Suppress("unused")
enum class MissionObjectiveType(
val uInt: UInt
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package de.darkatra.bfme2.map

import de.darkatra.bfme2.ConversionException

@Suppress("unused")
enum class PolygonTriggerType(
val uShort: UShort
) {
Expand Down
1 change: 1 addition & 0 deletions map/src/main/kotlin/de/darkatra/bfme2/map/RoadType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package de.darkatra.bfme2.map

import de.darkatra.bfme2.ConversionException

@Suppress("unused")
enum class RoadType(
val uInt: UInt
) {
Expand Down
2 changes: 2 additions & 0 deletions map/src/main/kotlin/de/darkatra/bfme2/map/ScriptActionType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package de.darkatra.bfme2.map

import de.darkatra.bfme2.ConversionException

// TODO: make it game specific as there seem to be differences between BFME and other sage games
@Suppress("unused")
enum class ScriptActionType(
private val id: UInt
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package de.darkatra.bfme2.map

import de.darkatra.bfme2.ConversionException

// TODO: make it game specific as there seem to be differences between BFME and other sage games
@Suppress("unused")
enum class ScriptArgumentType(
private val id: UInt
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package de.darkatra.bfme2.map

import de.darkatra.bfme2.ConversionException

// TODO: make it game specific as there seem to be differences between BFME and other sage games
@Suppress("unused")
enum class ScriptConditionType(
private val id: UInt
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package de.darkatra.bfme2.map

import de.darkatra.bfme2.ConversionException

@Suppress("unused")
enum class TileFlammability(
val byte: Byte
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ class ScriptReader(
MapFileReader.readAssets(reader, context) { assetName ->
when (assetName) {
AssetName.CONDITION.assetName -> MapFileReader.readAsset(reader, context, AssetName.CONDITION.assetName) { version ->
readScriptCondition(reader, context, version)
conditions.add(
readScriptCondition(reader, context, version)
)
}
else -> throw InvalidDataException("Unexpected asset with name '$assetName' in ScriptOrCondition.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package de.darkatra.bfme2.map.reader

import de.darkatra.bfme2.Color
import de.darkatra.bfme2.Vector3
import de.darkatra.bfme2.map.ScriptConditionType
import de.darkatra.bfme2.map.TimeOfDay
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

internal class MapFileReaderTest {

private val bmfe1SkyboxMap = MapFileReaderTest::class.java.getResourceAsStream("/maps/bfme1/skybox.map")!!
private val bmfe1MapWithSkyboxSettings = MapFileReaderTest::class.java.getResourceAsStream("/maps/bfme1/skybox.map")!!
private val bmfe2rotwkMapWithScripts = MapFileReaderTest::class.java.getResourceAsStream("/maps/bfme2-rotwk/script.map")!!

private val uncompressedMapPath = MapFileReaderTest::class.java.getResourceAsStream("/maps/bfme2-rotwk/Legendary War.txt")!!
private val refpackCompressedMapPath = MapFileReaderTest::class.java.getResourceAsStream("/maps/bfme2-rotwk/Legendary War.refpack")!!
Expand All @@ -17,7 +19,7 @@ internal class MapFileReaderTest {
@Test
internal fun shouldReadBfme1MapWithSkyboxSettings() {

val map = MapFileReader().read(bmfe1SkyboxMap)
val map = MapFileReader().read(bmfe1MapWithSkyboxSettings)

assertThat(map.skybox).isNotNull
assertThat(map.skybox!!.position.x).isEqualTo(500.5f)
Expand All @@ -30,6 +32,39 @@ internal class MapFileReaderTest {
assertThat(map.skybox!!.textureScheme).isEqualTo("MountainSnow")
}

@Test
internal fun shouldReadBfme2MapWithScripts() {

val map = MapFileReader().read(bmfe2rotwkMapWithScripts)

assertThat(map.playerScripts).isNotEmpty
assertThat(map.playerScripts!![0].scriptFolders).isNotEmpty
assertThat(map.playerScripts!![0].scriptFolders[0].name).isEqualTo("TestFolder")
assertThat(map.playerScripts!![0].scriptFolders[0].scripts).isNotEmpty
assertThat(map.playerScripts!![0].scriptFolders[0].scripts[0].name).isEqualTo("TestScript1")
assertThat(map.playerScripts!![0].scriptFolders[0].scripts[0].activeInEasy).isTrue
assertThat(map.playerScripts!![0].scriptFolders[0].scripts[0].activeInMedium).isTrue
assertThat(map.playerScripts!![0].scriptFolders[0].scripts[0].activeInHard).isTrue
assertThat(map.playerScripts!![0].scriptFolders[0].scripts[0].orConditions).isNotEmpty
assertThat(map.playerScripts!![0].scriptFolders[0].scripts[0].orConditions[0].conditions).isNotEmpty
assertThat(map.playerScripts!![0].scriptFolders[0].scripts[0].orConditions[0].conditions[0].type).isEqualTo(ScriptConditionType.TRUE)
assertThat(map.playerScripts!![0].scriptFolders[0].scripts[0].orConditions[0].conditions[0].inverted).isFalse
assertThat(map.playerScripts!![0].scriptFolders[0].scripts[0].actionsIfFalse).isEmpty()
assertThat(map.playerScripts!![0].scriptFolders[0].scripts[0].actionsIfTrue).isNotEmpty
assertThat(map.playerScripts!![0].scriptFolders[0].scripts[0].actionsIfTrue[0].enabled).isTrue
assertThat(map.playerScripts!![0].scriptFolders[0].scripts[1].name).isEqualTo("TestScript2")
assertThat(map.playerScripts!![0].scriptFolders[0].scripts[1].activeInEasy).isTrue
assertThat(map.playerScripts!![0].scriptFolders[0].scripts[1].activeInMedium).isFalse
assertThat(map.playerScripts!![0].scriptFolders[0].scripts[1].activeInHard).isFalse
assertThat(map.playerScripts!![0].scriptFolders[0].scripts[1].orConditions).isNotEmpty
assertThat(map.playerScripts!![0].scriptFolders[0].scripts[1].orConditions[0].conditions).isNotEmpty
assertThat(map.playerScripts!![0].scriptFolders[0].scripts[1].orConditions[0].conditions[0].type).isEqualTo(ScriptConditionType.TRUE)
assertThat(map.playerScripts!![0].scriptFolders[0].scripts[1].orConditions[0].conditions[0].inverted).isTrue
assertThat(map.playerScripts!![0].scriptFolders[0].scripts[1].actionsIfTrue).isEmpty()
assertThat(map.playerScripts!![0].scriptFolders[0].scripts[1].actionsIfFalse).isNotEmpty
assertThat(map.playerScripts!![0].scriptFolders[0].scripts[1].actionsIfFalse[0].enabled).isTrue
}

@Test
internal fun shouldReadMap() {

Expand Down
Binary file not shown.

0 comments on commit 60e3d14

Please sign in to comment.