Skip to content

Commit

Permalink
Cleanup of remaining CLI tools
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraq committed Jun 1, 2024
1 parent 75f430b commit 90c41a3
Show file tree
Hide file tree
Showing 22 changed files with 84 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ class ShpFileWriter extends FileWriter<ImageFile, ShpFileWriterOptions> {
def (width, height, numImages) = options

// Check options for converting a single image to an SHP file are valid
assert width < MAX_WIDTH: "Image width must be less than ${MAX_WIDTH}"
assert height < MAX_HEIGHT: "Image height must be less than ${MAX_HEIGHT}"
assert source.width % width == 0: "Source file doesn't divide cleanly into ${width}x${height} images"
assert source.height % height == 0: "Source file doesn't divide cleanly into ${width}x${height} images"
assert source.format == FORMAT_INDEXED: 'Source file must contain paletted image data'
assert width < MAX_WIDTH : "Image width must be less than ${MAX_WIDTH}"
assert height < MAX_HEIGHT : "Image height must be less than ${MAX_HEIGHT}"
assert source.width % width == 0 : "Source file doesn't divide cleanly into ${width}x${height} images"
assert source.height % height == 0 : "Source file doesn't divide cleanly into ${width}x${height} images"
assert source.format == FORMAT_INDEXED : 'Source file must contain paletted image data'

def output = new NativeDataOutputStream(outputStream)

Expand Down Expand Up @@ -86,11 +86,9 @@ class ShpFileWriter extends FileWriter<ImageFile, ShpFileWriterOptions> {
output.write(image.array(), 0, image.limit())
}
}
}

/**
* SHP file writing options.
*
* @author Emanuel Rabina
*/
record ShpFileWriterOptions(int width, int height, int numImages) {}
/**
* SHP file writing options.
*/
static record ShpFileWriterOptions(int width, int height, int numImages) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class ShpFileWriterDune2 extends FileWriter<ImageFile, ShpFileWriterDune2Options
def (width, height, numImages, faction) = options

// Check options for converting a single image to an SHP file are valid
assert width < MAX_WIDTH: "Image width must be less than ${MAX_WIDTH}"
assert height < MAX_HEIGHT: "Image height must be less than ${MAX_HEIGHT}"
assert source.width % width == 0: "Source file doesn't divide cleanly into ${width}x${height} images"
assert source.height % height == 0: "Source file doesn't divide cleanly into ${width}x${height} images"
assert source.format == FORMAT_INDEXED: 'Source file must contain paletted image data'
assert width < MAX_WIDTH : "Image width must be less than ${MAX_WIDTH}"
assert height < MAX_HEIGHT : "Image height must be less than ${MAX_HEIGHT}"
assert source.width % width == 0 : "Source file doesn't divide cleanly into ${width}x${height} images"
assert source.height % height == 0 : "Source file doesn't divide cleanly into ${width}x${height} images"
assert source.format == FORMAT_INDEXED : 'Source file must contain paletted image data'

def widths = new int[numImages]
Arrays.fill(widths, width)
Expand Down Expand Up @@ -140,9 +140,9 @@ class ShpFileWriterDune2 extends FileWriter<ImageFile, ShpFileWriterDune2Options
output.write(encodedImage.array())
}
}
}

/**
* Dune 2 SHP file writing options.
*/
record ShpFileWriterDune2Options(int width, int height, int numImages, boolean faction) {}
/**
* Dune 2 SHP file writing options.
*/
static record ShpFileWriterDune2Options(int width, int height, int numImages, boolean faction) {}
}
2 changes: 1 addition & 1 deletion redhorizon-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ if (targetPlatform.startsWith('macos')) {
}

application {
mainClass = 'nz.net.ultraq.redhorizon.cli.RedHorizonCli'
mainClass = 'nz.net.ultraq.redhorizon.cli.RedHorizon'
applicationName = 'redhorizon'
applicationDefaultJvmArgs = args
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

package nz.net.ultraq.redhorizon.cli

import nz.net.ultraq.redhorizon.explorer.Explorer

import picocli.CommandLine.Command
import picocli.CommandLine.Mixin
import picocli.CommandLine.Model.CommandSpec
import picocli.CommandLine.Spec

Expand All @@ -31,18 +28,15 @@ import java.util.concurrent.Callable
* @author Emanuel Rabina
*/
@Command(name = 'explorer')
class ExplorerCli implements Callable<Integer> {
class Explorer implements Callable<Integer> {

@Spec
CommandSpec commandSpec

@Mixin
PaletteOptions paletteOptions

@Override
Integer call() {

new Explorer(commandSpec.parent().version()[0], paletteOptions.loadPalette(true))
new nz.net.ultraq.redhorizon.explorer.Explorer(commandSpec.parent().version()[0])
return 0
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package nz.net.ultraq.redhorizon.cli

import nz.net.ultraq.redhorizon.cli.converter.ConverterCli
import nz.net.ultraq.redhorizon.cli.mixtools.MixCli
import nz.net.ultraq.redhorizon.cli.converter.Converter
import nz.net.ultraq.redhorizon.cli.mixtools.Mix

import picocli.CommandLine
import picocli.CommandLine.Command
Expand All @@ -39,13 +39,13 @@ import picocli.CommandLine.IVersionProvider
description = 'The Red Horizon command-line interface',
mixinStandardHelpOptions = true,
subcommands = [
ConverterCli,
ExplorerCli,
MixCli
Converter,
Explorer,
Mix
],
versionProvider = VersionProvider
)
class RedHorizonCli {
class RedHorizon {

/**
* Read the version number from the `cli.properties` file.
Expand All @@ -70,6 +70,6 @@ class RedHorizonCli {
* @param args
*/
static void main(String[] args) {
System.exit(new CommandLine(new RedHorizonCli()).execute(args))
System.exit(new CommandLine(new RedHorizon()).execute(args))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ import picocli.CommandLine.Command
],
mixinStandardHelpOptions = true,
subcommands = [
Pcx2CpsConverterCli,
Png2ShpConverterCli,
Png2ShpDune2ConverterCli
Pcx2CpsConverter,
Png2ShpConverter,
Png2ShpDune2Converter
],
synopsisSubcommandLabel = 'COMMAND'
)
class ConverterCli {
class Converter {
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import java.util.concurrent.Callable
name = 'pcx2cps',
description = 'Convert a PCX file to a Command & Conquer CPS file'
)
class Pcx2CpsConverterCli implements Callable<Integer> {
class Pcx2CpsConverter implements Callable<Integer> {

private static final Logger logger = LoggerFactory.getLogger(Pcx2CpsConverterCli)
private static final Logger logger = LoggerFactory.getLogger(Pcx2CpsConverter)

@Parameters(index = '0', description = 'A 320x200 PCX image. If creating a paletted CPS, then the PCX file must have an internal palette.')
File sourceFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package nz.net.ultraq.redhorizon.cli.converter

import nz.net.ultraq.redhorizon.classic.filetypes.ShpFileWriter
import nz.net.ultraq.redhorizon.classic.filetypes.ShpFileWriterOptions
import nz.net.ultraq.redhorizon.classic.filetypes.ShpFileWriter.ShpFileWriterOptions
import nz.net.ultraq.redhorizon.filetypes.PngFile

import org.slf4j.Logger
Expand All @@ -37,9 +37,9 @@ import java.util.concurrent.Callable
name = 'png2shp',
description = 'Convert a paletted PNG file to a Command & Conquer SHP file'
)
class Png2ShpConverterCli implements Callable<Integer> {
class Png2ShpConverter implements Callable<Integer> {

private static final Logger logger = LoggerFactory.getLogger(Png2ShpConverterCli)
private static final Logger logger = LoggerFactory.getLogger(Png2ShpConverter)

@Parameters(index = '0', description = 'The sounce PNG image.')
File sourceFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package nz.net.ultraq.redhorizon.cli.converter

import nz.net.ultraq.redhorizon.classic.filetypes.ShpFileWriterDune2
import nz.net.ultraq.redhorizon.classic.filetypes.ShpFileWriterDune2Options
import nz.net.ultraq.redhorizon.classic.filetypes.ShpFileWriterDune2.ShpFileWriterDune2Options
import nz.net.ultraq.redhorizon.filetypes.PngFile

import org.slf4j.Logger
Expand All @@ -37,9 +37,9 @@ import java.util.concurrent.Callable
name = 'png2shpd2',
description = 'Convert a paletted PNG file to a Dune 2 SHP file'
)
class Png2ShpDune2ConverterCli implements Callable<Integer> {
class Png2ShpDune2Converter implements Callable<Integer> {

private static final Logger logger = LoggerFactory.getLogger(Png2ShpDune2ConverterCli)
private static final Logger logger = LoggerFactory.getLogger(Png2ShpDune2Converter)

@Parameters(index = '0', description = 'The sounce PNG image.')
File sourceFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import picocli.CommandLine.Command
description = 'Tools related to C&C mix files',
mixinStandardHelpOptions = true,
subcommands = [
ExtractorCli,
IdCalculatorCli
MixExtractor,
MixIdCalculator
]
)
class MixCli {
class Mix {
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ import java.util.concurrent.Callable
description = 'Extract an entry from a mix file, saving it to disk with the same name.',
mixinStandardHelpOptions = true
)
class ExtractorCli implements Callable<Integer> {
class MixExtractor implements Callable<Integer> {

private static final Logger logger = LoggerFactory.getLogger(ExtractorCli)
private static final Logger logger = LoggerFactory.getLogger(MixExtractor)

@Spec
CommandSpec commandSpec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ import java.util.concurrent.Callable
description = 'Calculate the mix entry ID of a file name',
mixinStandardHelpOptions = true
)
class IdCalculatorCli implements Callable<Integer> {
class MixIdCalculator implements Callable<Integer> {

private static final Logger logger = LoggerFactory.getLogger(IdCalculatorCli)
private static final Logger logger = LoggerFactory.getLogger(MixIdCalculator)

@Spec
CommandSpec commandSpec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ import static com.github.valfirst.slf4jtest.Assertions.assertThat
*
* @author Emanuel Rabina
*/
class Pcx2CpsConverterCliTests extends Specification {
class Pcx2CpsConverterTests extends Specification {

private final logger = TestLoggerFactory.getTestLogger(Pcx2CpsConverterCli)
private final logger = TestLoggerFactory.getTestLogger(Pcx2CpsConverter)

def "Converts a PCX file to a CPS file"() {
given:
var pcxPath = 'nz/net/ultraq/redhorizon/cli/converter/alipaper.pcx'
var cpsTempFile = File.createTempFile('alipaper', '.cps')
var converter = new Pcx2CpsConverterCli(
var converter = new Pcx2CpsConverter(
sourceFile: getResourceAsFile(pcxPath),
destFile: cpsTempFile,
overwrite: true
Expand All @@ -57,7 +57,7 @@ class Pcx2CpsConverterCliTests extends Specification {

def "Source file not found"() {
given:
var converter = new Pcx2CpsConverterCli(
var converter = new Pcx2CpsConverter(
sourceFile: Mock(File) {
toString() >> 'not-a-file.pcx'
}
Expand All @@ -73,7 +73,7 @@ class Pcx2CpsConverterCliTests extends Specification {

def "Destination file already exists"() {
given:
var converter = new Pcx2CpsConverterCli(
var converter = new Pcx2CpsConverter(
sourceFile: Mock(File) {
exists() >> true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class Application implements EventTarget {

private static final Logger logger = LoggerFactory.getLogger(Application)

final String windowTitle
final String name
final String version

private final Engine engine = new Engine()
private final InputEventStream inputEventStream = new InputEventStream()
Expand Down Expand Up @@ -94,7 +95,7 @@ class Application implements EventTarget {
Application addGraphicsSystem(GraphicsConfiguration config = new GraphicsConfiguration(),
ImGuiElement... uiElements) {

var graphicsSystem = new GraphicsSystem(windowTitle, inputEventStream, config)
var graphicsSystem = new GraphicsSystem("${name} - ${version}", inputEventStream, config)
graphicsSystem.on(WindowCreatedEvent) { event ->
inputEventStream.addInputSource(event.window)
}
Expand Down
Loading

0 comments on commit 90c41a3

Please sign in to comment.