Skip to content

Commit

Permalink
Test to capture adding a unit to a scene
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraq committed Apr 8, 2024
1 parent 80b586a commit 53b83ce
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ShaderConfig {
ShaderConfig(String name, String vertexShaderResourcePath, String fragmentShaderResourcePath, List<Attribute> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
Binary file not shown.
Binary file not shown.

0 comments on commit 53b83ce

Please sign in to comment.