diff --git a/build.gradle b/build.gradle index 49940c55..0c44f2cf 100644 --- a/build.gradle +++ b/build.gradle @@ -59,6 +59,8 @@ subprojects { implementation "org.slf4j:slf4j-api:${slf4jVersion}" testImplementation 'org.spockframework:spock-core:2.3-groovy-4.0' + testImplementation 'net.bytebuddy:byte-buddy:1.14.13' + testImplementation 'org.objenesis:objenesis:3.3' } java { diff --git a/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/graphics/ShaderConfig.groovy b/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/graphics/ShaderConfig.groovy index f0839e3d..15fdabb1 100644 --- a/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/graphics/ShaderConfig.groovy +++ b/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/graphics/ShaderConfig.groovy @@ -36,6 +36,7 @@ class ShaderConfig { ShaderConfig(String name, String vertexShaderResourcePath, String fragmentShaderResourcePath, List attributes, Uniform... uniforms) { this.name = name + // TODO: I think these need to use closeable methods as getText() won't be doing that for us right? this.vertexShaderSource = getResourceAsStream(vertexShaderResourcePath).text this.fragmentShaderSource = getResourceAsStream(fragmentShaderResourcePath).text this.attributes = attributes diff --git a/redhorizon-explorer/test/nz/net/ultraq/redhorizon/explorer/UnitTests.groovy b/redhorizon-explorer/test/nz/net/ultraq/redhorizon/explorer/UnitTests.groovy new file mode 100644 index 00000000..cdeb44c0 --- /dev/null +++ b/redhorizon-explorer/test/nz/net/ultraq/redhorizon/explorer/UnitTests.groovy @@ -0,0 +1,75 @@ +/* + * Copyright 2024, Emanuel Rabina (http://www.ultraq.net.nz/) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package nz.net.ultraq.redhorizon.explorer + +import nz.net.ultraq.redhorizon.classic.filetypes.PalFile +import nz.net.ultraq.redhorizon.classic.filetypes.ShpFile +import nz.net.ultraq.redhorizon.classic.units.Unit +import nz.net.ultraq.redhorizon.classic.units.UnitData +import nz.net.ultraq.redhorizon.engine.graphics.GraphicsRequests +import nz.net.ultraq.redhorizon.engine.graphics.GraphicsRequests.SpriteSheetRequest +import nz.net.ultraq.redhorizon.engine.graphics.SpriteSheet +import nz.net.ultraq.redhorizon.engine.scenegraph.Scene + +import org.joml.primitives.Rectanglef +import spock.lang.Specification + +import groovy.json.JsonSlurper +import java.util.concurrent.Future + +/** + * Tests for the Unit class. + * + * @author Emanuel Rabina + */ +class UnitTests extends Specification { + + def "Can attach a unit to a scene"() { + given: + // Epic scene mocking 😅 + var scene = new Scene().tap { + it.graphicsRequestHandler = Mock(GraphicsRequests) { + requestCreateOrGet(_) >> { args -> + return args[0].class == SpriteSheetRequest ? + Mock(Future) { + get() >> Mock(SpriteSheet) { + getAt(0) >> new Rectanglef(0, 0, 1, 1) + } + } : + Mock(Future) { + get() >> null + } + } + } + } + // TODO: Definitely need a resource loader extension + var spriteFile = getResourceAsStream("nz/net/ultraq/redhorizon/explorer/harv.shp").withBufferedStream { stream -> + return new ShpFile(stream) + } + var palette = getResourceAsStream("nz/net/ultraq/redhorizon/explorer/ra-temperate.pal").withBufferedStream { stream -> + return new PalFile(stream) + } + var unitData = getResourceAsStream('nz/net/ultraq/redhorizon/classic/units/data/harv.json').withBufferedReader { reader -> + return new JsonSlurper().parseText(reader.text) as UnitData + } + when: + var unit = new Unit(spriteFile, palette, unitData) + scene << unit + then: + notThrown(Exception) + } +} diff --git a/redhorizon-explorer/test/nz/net/ultraq/redhorizon/explorer/harv.shp b/redhorizon-explorer/test/nz/net/ultraq/redhorizon/explorer/harv.shp new file mode 100644 index 00000000..368a8a89 Binary files /dev/null and b/redhorizon-explorer/test/nz/net/ultraq/redhorizon/explorer/harv.shp differ diff --git a/redhorizon-explorer/test/nz/net/ultraq/redhorizon/explorer/ra-temperate.pal b/redhorizon-explorer/test/nz/net/ultraq/redhorizon/explorer/ra-temperate.pal new file mode 100644 index 00000000..bb63fcdd Binary files /dev/null and b/redhorizon-explorer/test/nz/net/ultraq/redhorizon/explorer/ra-temperate.pal differ