diff --git a/redhorizon-classic/source/nz/net/ultraq/redhorizon/classic/maps/Map.groovy b/redhorizon-classic/source/nz/net/ultraq/redhorizon/classic/maps/Map.groovy index c8b97100..2b4132c3 100644 --- a/redhorizon-classic/source/nz/net/ultraq/redhorizon/classic/maps/Map.groovy +++ b/redhorizon-classic/source/nz/net/ultraq/redhorizon/classic/maps/Map.groovy @@ -354,7 +354,6 @@ class Map extends Node { } return newSpriteSheet } - // TODO: This can be some batching request method .thenApplyAsync { spriteSheet -> List allVertices = [] List allTextureUVs = [] diff --git a/redhorizon-cli/build.gradle b/redhorizon-cli/build.gradle index 4f45ee87..6ee6dde0 100644 --- a/redhorizon-cli/build.gradle +++ b/redhorizon-cli/build.gradle @@ -31,6 +31,7 @@ dependencies { implementation platform("org.lwjgl:lwjgl-bom:${lwjglVersion}") implementation "ch.qos.logback:logback-core:${logbackVersion}" implementation "info.picocli:picocli:${picocliVersion}" + implementation 'nz.net.ultraq.preferences:preferences:3.1.0' implementation "org.apache.groovy:groovy-json:${groovyVersion}" implementation "org.joml:joml:${jomlVersion}" implementation "org.joml:joml-primitives:${jomlPrimitivesVersion}" diff --git a/redhorizon-cli/source/nz/net/ultraq/redhorizon/cli/Explorer.groovy b/redhorizon-cli/source/nz/net/ultraq/redhorizon/cli/Explorer.groovy index bc48ef82..e8ff02cd 100644 --- a/redhorizon-cli/source/nz/net/ultraq/redhorizon/cli/Explorer.groovy +++ b/redhorizon-cli/source/nz/net/ultraq/redhorizon/cli/Explorer.groovy @@ -16,8 +16,15 @@ package nz.net.ultraq.redhorizon.cli +import nz.net.ultraq.preferences.Preferences +import nz.net.ultraq.redhorizon.explorer.ExplorerOptions + import picocli.CommandLine.Command +import picocli.CommandLine.IDefaultValueProvider +import picocli.CommandLine.Model.ArgSpec import picocli.CommandLine.Model.CommandSpec +import picocli.CommandLine.Model.OptionSpec +import picocli.CommandLine.Option import picocli.CommandLine.Parameters import picocli.CommandLine.Spec @@ -28,23 +35,63 @@ import java.util.concurrent.Callable * * @author Emanuel Rabina */ -@Command(name = 'explorer') +@Command(name = 'explorer', defaultValueProvider = DefaultOptionsProvider) class Explorer implements Callable { static { System.setProperty('logback.configurationFile', 'logback-application.xml') } + private static final Preferences userPreferences = new Preferences() + @Spec CommandSpec commandSpec @Parameters(index = '0', defaultValue = '', description = 'Path to a file to open on launch') File file + @Option(names = '--maximized', description = 'Start the application maximized. Remembers your last usage.') + boolean maximized + + @Option(names = '--touchpad-input', description = 'Start the application using touchpad controls. Remembers your last usage.') + boolean touchpadInput + @Override Integer call() { - new nz.net.ultraq.redhorizon.explorer.Explorer(commandSpec.parent().version()[0], file) + // Load options from command line or preferences + var explorerOptions = new ExplorerOptions( + maximized: maximized, + touchpadInput: touchpadInput + ) + + new nz.net.ultraq.redhorizon.explorer.Explorer(commandSpec.parent().version()[0], explorerOptions, file) + + // Save preferences for next time + userPreferences.set(ExplorerPreferences.WINDOW_MAXIMIZED, explorerOptions.maximized) + userPreferences.set(ExplorerPreferences.TOUCHPAD_INPUT, explorerOptions.touchpadInput) + return 0 } + + /** + * Provide default options for the user-remembered options. + */ + static class DefaultOptionsProvider implements IDefaultValueProvider { + + @Override + String defaultValue(ArgSpec argSpec) { + + if (argSpec.option) { + var option = (OptionSpec)argSpec + if (option.longestName() == '--maximized') { + return userPreferences.get(ExplorerPreferences.WINDOW_MAXIMIZED) + } + if (option.longestName() == '--touchpad-input') { + return userPreferences.get(ExplorerPreferences.TOUCHPAD_INPUT).toString() + } + } + return null + } + } } diff --git a/redhorizon-explorer/source/nz/net/ultraq/redhorizon/explorer/ExplorerPreferences.groovy b/redhorizon-cli/source/nz/net/ultraq/redhorizon/cli/ExplorerPreferences.groovy similarity index 95% rename from redhorizon-explorer/source/nz/net/ultraq/redhorizon/explorer/ExplorerPreferences.groovy rename to redhorizon-cli/source/nz/net/ultraq/redhorizon/cli/ExplorerPreferences.groovy index 63e19944..b19e9eac 100644 --- a/redhorizon-explorer/source/nz/net/ultraq/redhorizon/explorer/ExplorerPreferences.groovy +++ b/redhorizon-cli/source/nz/net/ultraq/redhorizon/cli/ExplorerPreferences.groovy @@ -14,7 +14,7 @@ * limitations under the License. */ -package nz.net.ultraq.redhorizon.explorer +package nz.net.ultraq.redhorizon.cli import nz.net.ultraq.preferences.UserPreference diff --git a/redhorizon-explorer/build.gradle b/redhorizon-explorer/build.gradle index 884d0a1d..27faad47 100644 --- a/redhorizon-explorer/build.gradle +++ b/redhorizon-explorer/build.gradle @@ -24,7 +24,6 @@ dependencies { implementation platform("org.lwjgl:lwjgl-bom:${lwjglVersion}") implementation "ch.qos.logback:logback-classic:${logbackVersion}" implementation files("../libraries/imgui-java-binding-with-tablesortspecs-${imguiVersion}.jar") - implementation 'nz.net.ultraq.preferences:preferences:3.1.0' implementation "org.apache.groovy:groovy-json:${groovyVersion}" implementation "org.joml:joml:${jomlVersion}" implementation "org.joml:joml-primitives:${jomlPrimitivesVersion}" diff --git a/redhorizon-explorer/source/nz/net/ultraq/redhorizon/explorer/Explorer.groovy b/redhorizon-explorer/source/nz/net/ultraq/redhorizon/explorer/Explorer.groovy index b6664934..9a55a492 100644 --- a/redhorizon-explorer/source/nz/net/ultraq/redhorizon/explorer/Explorer.groovy +++ b/redhorizon-explorer/source/nz/net/ultraq/redhorizon/explorer/Explorer.groovy @@ -16,7 +16,6 @@ package nz.net.ultraq.redhorizon.explorer -import nz.net.ultraq.preferences.Preferences import nz.net.ultraq.redhorizon.classic.filetypes.IniFile import nz.net.ultraq.redhorizon.classic.filetypes.MapFile import nz.net.ultraq.redhorizon.classic.filetypes.MixFile @@ -79,10 +78,10 @@ import java.util.concurrent.CopyOnWriteArrayList class Explorer { private static final Logger logger = LoggerFactory.getLogger(Explorer) - private static final Preferences userPreferences = new Preferences() private static final Dimension renderResolution = new Dimension(1280, 800) private static final float volume = 0.5f + private final ExplorerOptions options private final List entries = new CopyOnWriteArrayList<>() private final EntryList entryList = new EntryList(entries) private final MixDatabase mixDatabase = new MixDatabase() @@ -100,7 +99,6 @@ class Explorer { private File currentDirectory private InputStream selectedFileInputStream private PaletteType currentPalette - private boolean touchpadInput private List removeEventFunctions = [] /** @@ -110,15 +108,15 @@ class Explorer { * @param openOnLaunch * Optional, a file to open on launch of the explorer. */ - Explorer(String version, File openOnLaunch) { + Explorer(String version, ExplorerOptions options, File openOnLaunch) { - touchpadInput = userPreferences.get(ExplorerPreferences.TOUCHPAD_INPUT) + this.options = options new Application('Explorer', version) .addAudioSystem() .addGraphicsSystem(new GraphicsConfiguration( clearColour: Colour.GREY, - maximized: userPreferences.get(ExplorerPreferences.WINDOW_MAXIMIZED), + maximized: options.maximized, renderResolution: renderResolution, startWithChrome: true ), new LogPanel(true), entryList, nodeList) @@ -137,7 +135,7 @@ class Explorer { this.scene = scene application.on(WindowMaximizedEvent) { event -> - userPreferences.set(ExplorerPreferences.WINDOW_MAXIMIZED, event.maximized) + options.maximized = event.maximized } buildList(new File(System.getProperty("user.dir"))) @@ -175,12 +173,11 @@ class Explorer { scene.gameMenu.optionsMenu << new MenuItem() { @Override void render() { - if (ImGui.menuItem('Touchpad input', null, touchpadInput)) { - touchpadInput = !touchpadInput - userPreferences.set(ExplorerPreferences.TOUCHPAD_INPUT, touchpadInput) + if (ImGui.menuItem('Touchpad input', null, options.touchpadInput)) { + options.touchpadInput = !options.touchpadInput var mapNode = (Map)scene.findDescendent { node -> node instanceof Map } if (mapNode) { - ((MapViewerScript)mapNode.script).touchpadInput = touchpadInput + ((MapViewerScript)mapNode.script).touchpadInput = options.touchpadInput } } } @@ -509,7 +506,7 @@ class Explorer { */ private void preview(MapFile mapFile, String objectId) { - var mapViewerScript = new MapViewerScript(camera, nodeList, touchpadInput) + var mapViewerScript = new MapViewerScript(camera, nodeList, options.touchpadInput) time("Loading map ${objectId}", logger) { -> resourceManager.withDirectory(currentDirectory) { -> var map = new Map(mapFile, resourceManager).attachScript(mapViewerScript) diff --git a/redhorizon-explorer/source/nz/net/ultraq/redhorizon/explorer/ExplorerOptions.groovy b/redhorizon-explorer/source/nz/net/ultraq/redhorizon/explorer/ExplorerOptions.groovy new file mode 100644 index 00000000..ef27ec6a --- /dev/null +++ b/redhorizon-explorer/source/nz/net/ultraq/redhorizon/explorer/ExplorerOptions.groovy @@ -0,0 +1,28 @@ +/* + * 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 + +/** + * Options to pass to, and retrieve from, the Explorer application. + * + * @author Emanuel Rabina + */ +class ExplorerOptions { + + boolean maximized + boolean touchpadInput +}