Provides builds for both LWJGL2 and LWJGL3.
This commit is contained in:
86
desktop/build.gradle
Normal file
86
desktop/build.gradle
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 2020 Markil 3. All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import org.apache.tools.ant.taskdefs.condition.Os
|
||||
|
||||
plugins {
|
||||
id "application"
|
||||
id "distribution"
|
||||
id "com.github.johnrengelman.shadow" version "5.0.0"
|
||||
id "edu.sc.seis.launch4j" version "2.4.5"
|
||||
id "edu.sc.seis.macAppBundle" version "2.3.0"
|
||||
}
|
||||
|
||||
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
|
||||
|
||||
dependencies {
|
||||
// Logging
|
||||
implementation "org.slf4j:slf4j-api:1.7.15"
|
||||
implementation "org.slf4j:slf4j-simple:1.7.5"
|
||||
|
||||
implementation project(':library')
|
||||
implementation "${jme3.g}:jme3-core:${jme3.version}"
|
||||
implementation "${jme3.g}:jme3-desktop:${jme3.version}"
|
||||
implementation "${jme3.g}:jme3-lwjgl3:${jme3.version}"
|
||||
}
|
||||
|
||||
// Define the main class for the application
|
||||
mainClassName = 'markil3.controller.Main'
|
||||
|
||||
/*
|
||||
* TODO - The default zipped distributions are a bit of a mess.
|
||||
*/
|
||||
jar {
|
||||
baseName rootProject.name
|
||||
version rootProject.version
|
||||
manifest {
|
||||
attributes "Main-Class": mainClassName,
|
||||
"Class-Path": configurations.runtime.files.collect {
|
||||
"lib/$it.name"
|
||||
}.join(" "),
|
||||
"Implementation-Title": rootProject.name,
|
||||
"Implementation-Version": rootProject.version,
|
||||
"Version-Code": versionNumber
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
archivesBaseName = rootProject.name
|
||||
archiveClassifier = "universal-lwjgl3"
|
||||
version = rootProject.version
|
||||
mainClassName = project.mainClassName
|
||||
}
|
||||
|
||||
launch4j {
|
||||
mainClassName = project.mainClassName
|
||||
outfile = rootProject.name + "-" + rootProject.version + "-windows-lwjgl3.exe"
|
||||
copyConfigurable = shadowJar.outputs.files
|
||||
jar = shadowJar.archiveFile.get()
|
||||
bundledJrePath = "jre"
|
||||
//icon = new File(sourceSets.main.resources.srcDirs[0], "icon256.ico")
|
||||
}
|
||||
|
||||
createExe.doLast({
|
||||
println project.tasks.installDist.outputs.files.getClass()
|
||||
for (file in new File(installDist.outputs.files[0], "lib").listFiles()) {
|
||||
println file
|
||||
}
|
||||
})
|
||||
|
||||
macAppBundle {
|
||||
mainClassName = project.mainClassName
|
||||
icon = "myIcon.icns"
|
||||
if (Os.isFamily(Os.FAMILY_MAC) && (appStyle == 'Oracle' || appStyle == 'universalJavaApplicationStub')) {
|
||||
bundleJRE = true
|
||||
}
|
||||
javaProperties.put("apple.laf.useScreenMenuBar", "true")
|
||||
backgroundImage = "doc/macbackground.png"
|
||||
jarTask = "shadowJar"
|
||||
}
|
||||
226
desktop/src/main/java/markil3/controller/Main.java
Normal file
226
desktop/src/main/java/markil3/controller/Main.java
Normal file
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
* Copyright 2020 Markil 3. All rights reserved.
|
||||
*
|
||||
* 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 markil3.controller;
|
||||
|
||||
import com.jme3.app.DebugKeysAppState;
|
||||
import com.jme3.app.SimpleApplication;
|
||||
import com.jme3.app.StatsAppState;
|
||||
import com.jme3.font.BitmapText;
|
||||
import com.jme3.input.JoystickCompatibilityMappings;
|
||||
import com.jme3.input.controls.ActionListener;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.system.AppSettings;
|
||||
import com.jme3.system.JmeSystem;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* Launch point for the application. This is primarily for demo purposes, and
|
||||
* games using this as a library can safely ignore it.
|
||||
*
|
||||
* @author Markil 3
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Main extends SimpleApplication implements ActionListener
|
||||
{
|
||||
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.
|
||||
getLogger(Main.class);
|
||||
|
||||
public static File GAME_FOLDER;
|
||||
public static File CALIBRATION_FILE;
|
||||
|
||||
public static File getGameFolder()
|
||||
{
|
||||
return GAME_FOLDER;
|
||||
}
|
||||
|
||||
private static void initializeJoystickMappings()
|
||||
{
|
||||
if (CALIBRATION_FILE == null)
|
||||
{
|
||||
CALIBRATION_FILE =
|
||||
new File(GAME_FOLDER, "controllerCalibration.properties");
|
||||
URL mappingUrl;
|
||||
switch (JmeSystem.getPlatform())
|
||||
{
|
||||
case Windows32:
|
||||
case Windows64:
|
||||
mappingUrl = Main.class.
|
||||
getResource("/joystick-mapping.windows.properties");
|
||||
break;
|
||||
case MacOSX32:
|
||||
case MacOSX64:
|
||||
case MacOSX_PPC32:
|
||||
case MacOSX_PPC64:
|
||||
mappingUrl = Main.class.
|
||||
getResource("/joystick-mapping.osx.properties");
|
||||
break;
|
||||
case Linux32:
|
||||
case Linux64:
|
||||
case Linux_ARM32:
|
||||
case Linux_ARM64:
|
||||
mappingUrl = Main.class.
|
||||
getResource("/joystick-mapping.linux.properties");
|
||||
break;
|
||||
case Android_ARM5:
|
||||
case Android_ARM6:
|
||||
case Android_ARM7:
|
||||
case Android_ARM8:
|
||||
case Android_X86:
|
||||
case Android_Other:
|
||||
mappingUrl = Main.class.
|
||||
getResource("/joystick-mapping.android.properties");
|
||||
break;
|
||||
case iOS_ARM:
|
||||
case iOS_X86:
|
||||
mappingUrl = Main.class.
|
||||
getResource("/joystick-mapping.ios.properties");
|
||||
break;
|
||||
default:
|
||||
mappingUrl = null;
|
||||
}
|
||||
if (mappingUrl != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
JoystickCompatibilityMappings
|
||||
.loadMappingProperties(mappingUrl);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
logger.error("Unable to load joystick mappings for " +
|
||||
mappingUrl, e);
|
||||
}
|
||||
}
|
||||
mappingUrl = Main.class.
|
||||
getResource("/joystick-mapping." +
|
||||
JmeSystem.getPlatform().toString().toLowerCase() +
|
||||
".properties");
|
||||
if (mappingUrl != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
JoystickCompatibilityMappings
|
||||
.loadMappingProperties(mappingUrl);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
logger.error("Unable to load joystick mappings for " +
|
||||
mappingUrl, e);
|
||||
}
|
||||
}
|
||||
if (CALIBRATION_FILE.isFile())
|
||||
{
|
||||
try
|
||||
{
|
||||
JoystickCompatibilityMappings.loadMappingProperties(
|
||||
CALIBRATION_FILE.toURI().toURL());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
logger.error("Unable to load joystick mappings.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Main app;
|
||||
AppSettings settings;
|
||||
app = new Main();
|
||||
settings = new AppSettings(true);
|
||||
settings.setTitle("Joystick Preview");
|
||||
settings.setUseJoysticks(true);
|
||||
settings.setEmulateMouse(true);
|
||||
settings.setVSync(true);
|
||||
settings.setWidth(1280);
|
||||
settings.setHeight(720);
|
||||
app.setSettings(settings);
|
||||
app.start();
|
||||
}
|
||||
|
||||
private Node calibrateButton;
|
||||
|
||||
public Main()
|
||||
{
|
||||
super(new StatsAppState(), new DebugKeysAppState(),
|
||||
new JoystickPreviewScreen());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize()
|
||||
{
|
||||
if (GAME_FOLDER == null)
|
||||
{
|
||||
GAME_FOLDER = new File(System.getProperty("user.dir"));
|
||||
if (!GAME_FOLDER.isDirectory())
|
||||
{
|
||||
if (!GAME_FOLDER.mkdir())
|
||||
{
|
||||
throw new RuntimeException(
|
||||
"Could not create game directory folder.");
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Add custom joystick mappings before the input manager is loaded.
|
||||
*/
|
||||
initializeJoystickMappings();
|
||||
super.initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void simpleInitApp()
|
||||
{
|
||||
this.calibrateButton =
|
||||
GUIUtils.createButton(this.getAssetManager(), this.guiFont,
|
||||
"calibrate", "Calibrate Gamepad");
|
||||
this.calibrateButton.setLocalTranslation((this.getCamera().getWidth() -
|
||||
((BitmapText) this.calibrateButton.getChild(1)).getLineWidth() -
|
||||
10) / 2F, this.getCamera().getHeight(), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void simpleUpdate(float tpf)
|
||||
{
|
||||
JoystickPreviewScreen screen = this.getStateManager().getState(JoystickPreviewScreen.class);
|
||||
if (this.calibrateButton.getParent() == null && screen != null)
|
||||
{
|
||||
this.guiNode.attachChild(this.calibrateButton);
|
||||
this.inputManager.addListener(this, screen.CLICK_MAPPING);
|
||||
}
|
||||
else if (this.calibrateButton.getParent() != null && screen == null)
|
||||
{
|
||||
this.guiNode.detachChild(this.calibrateButton);
|
||||
this.inputManager.removeListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAction(String name, boolean isPressed, float tpf)
|
||||
{
|
||||
String buttonId;
|
||||
JoystickPreviewScreen screen = this.getStateManager().getState(JoystickPreviewScreen.class);
|
||||
if (screen != null && name.equals(screen.CLICK_MAPPING))
|
||||
{
|
||||
buttonId = GUIUtils.handleButtonPress(this.calibrateButton,
|
||||
this.getInputManager().getCursorPosition(),
|
||||
isPressed);
|
||||
if (!isPressed && "calibrate".equals(buttonId))
|
||||
{
|
||||
this.getStateManager().detach(screen);
|
||||
this.getStateManager().attach(new CalibrateInputScreen(CALIBRATION_FILE));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user