Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android compat #471

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 12 additions & 132 deletions src/toniarts/openkeeper/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.jme3.app.state.VideoRecorderAppState;
import com.jme3.asset.AssetEventListener;
import com.jme3.asset.AssetKey;
import com.jme3.asset.AssetManager;
import com.jme3.asset.TextureKey;
import com.jme3.asset.plugins.FileLocator;
import com.jme3.light.AmbientLight;
Expand All @@ -35,11 +34,8 @@
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.opengl.GLRenderer;
import com.jme3.system.AppSettings;
import com.jme3.system.JmeSystem;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.render.batch.BatchRenderConfiguration;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
Expand All @@ -48,7 +44,6 @@
import java.io.InputStream;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
Expand All @@ -64,7 +59,6 @@
import java.util.Queue;
import java.util.ResourceBundle;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import toniarts.openkeeper.audio.plugins.MP2Loader;
import toniarts.openkeeper.cinematics.CameraSweepDataLoader;
import toniarts.openkeeper.game.data.Settings;
Expand All @@ -73,9 +67,6 @@
import toniarts.openkeeper.game.state.SoundState;
import toniarts.openkeeper.game.state.loading.TitleScreenState;
import toniarts.openkeeper.game.state.session.LocalGameSession;
import toniarts.openkeeper.setup.DKConverter;
import toniarts.openkeeper.setup.DKFolderSelector;
import toniarts.openkeeper.setup.IFrameClosingBehavior;
import toniarts.openkeeper.tools.convert.AssetsConverter;
import toniarts.openkeeper.tools.modelviewer.SoundsLoader;
import toniarts.openkeeper.utils.PathUtils;
Expand All @@ -87,17 +78,14 @@
*
* @author Toni Helenius <helenius.toni@gmail.com>
*/
public class Main extends SimpleApplication {
public final class Main extends SimpleApplication {

private static final Logger logger = System.getLogger(Main.class.getName());

private static boolean folderOk = false;
private static boolean conversionOk = false;
public static final String VERSION = "*ALPHA*";

private static final String VERSION = "*ALPHA*";
public static final String TITLE = "OpenKeeper";
private static final String USER_HOME_FOLDER = System.getProperty("user.home").concat(File.separator).concat(".").concat(TITLE).concat(File.separator);
private static final String SCREENSHOTS_FOLDER = USER_HOME_FOLDER.concat("SCRSHOTS").concat(File.separator);
private static final Object LOCK = new Object();
private static Map<String, String> params;
private static boolean debug;

Expand All @@ -108,7 +96,7 @@ private Main() {
super(new StatsAppState(), new DebugKeysAppState());
}

public static void main(String[] args) throws InvocationTargetException, InterruptedException {
public static void main(String[] args) throws Exception {

// Create main application instance
parseArguments(args);
Expand Down Expand Up @@ -166,58 +154,21 @@ private static void parseArguments(String[] args) {
* @return true if the app is ok for running!
* @throws InterruptedException lots of threads waiting
*/
private static boolean checkSetup(final Main app) throws InterruptedException {

boolean saveSetup = false;
private static boolean checkSetup(final Main app) {

// First and foremost, the folder
if (!PathUtils.checkDkFolder(getDkIIFolder())) {
logger.log(Level.INFO, "Dungeon Keeper II folder not found or valid! Prompting user!");
saveSetup = true;

// Let the user select
setLookNFeel();
DKFolderSelector frame = new DKFolderSelector() {
@Override
protected void continueOk(String path) {
PathUtils.setDKIIFolder(PathUtils.fixFilePath(path));
folderOk = true;
}
};
openFrameAndWait(frame);
} else {
folderOk = true;
logger.log(Level.WARNING, "Dungeon Keeper II folder not found or valid!");
return false;
}

// If the folder is ok, check the conversion
if (folderOk && (AssetsConverter.isConversionNeeded(Main.getSettings()))) {
logger.log(Level.INFO, "Need to convert the assets!");
saveSetup = true;

// Convert
setLookNFeel();
AssetManager assetManager = JmeSystem.newAssetManager(
Thread.currentThread().getContextClassLoader()
.getResource("com/jme3/asset/Desktop.cfg")); // Get temporary asset manager instance since we not yet have one ourselves
assetManager.registerLocator(AssetsConverter.getAssetsFolder(), FileLocator.class);
DKConverter frame = new DKConverter(getDkIIFolder(), assetManager) {
@Override
protected void continueOk() {
conversionOk = true;
}
};
openFrameAndWait(frame);
} else if (folderOk) {
conversionOk = true;
// Check if conversion is needed
if (AssetsConverter.isConversionNeeded(Main.getSettings())) {
logger.log(Level.WARNING, "Asset conversion is needed. Please run the AssetsConverter tool.");
return false;
}

// If everything is ok, we might need to save the setup
boolean result = folderOk && conversionOk;
if (result && saveSetup) {
SettingUtils.getInstance().saveSettings();
}

return result;
return true;
}

private static void initSettings(Main app) {
Expand Down Expand Up @@ -258,77 +209,6 @@ public static AppSettings getSettings() {
return SettingUtils.getInstance().getSettings();
}

/**
* Sets SWING look and feel
*/
private static void setLookNFeel() {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
System.getLogger(DKFolderSelector.class.getName()).log(Level.ERROR, (String) null, ex);
}
}

/**
* Opens up a given frame and waits for it to finish
*
* @param frame the frame to open
* @throws InterruptedException
*/
private static void openFrameAndWait(final JFrame frame) throws InterruptedException {
frame.setVisible(true);

Thread t = new Thread() {
@Override
public void run() {
synchronized (LOCK) {
while (frame.isVisible()) {
try {
LOCK.wait();
} catch (InterruptedException e) {
logger.log(Level.WARNING, "Lock interrupted!");
}
}
}
}
};
t.start();

frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent arg0) {

// See if it is allowed
if (frame instanceof IFrameClosingBehavior && !((IFrameClosingBehavior) frame).canCloseWindow()) {
return; // You shall not pass!
}

synchronized (LOCK) {
frame.dispose();
LOCK.notify();
}
}
});

// Special
if (frame instanceof DKConverter) {
((DKConverter) frame).startConversion();
}

// Wait the dialog to finish
t.join();
}

@Override
public void simpleInitApp() {

Expand Down
3 changes: 1 addition & 2 deletions src/toniarts/openkeeper/cinematics/Cinematic.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@
import com.jme3.scene.CameraNode;
import com.jme3.scene.Node;
import com.jme3.scene.control.CameraControl.ControlDirection;
import java.awt.Point;
import toniarts.openkeeper.Main;
import toniarts.openkeeper.utils.AssetUtils;
import toniarts.openkeeper.utils.Point;
import toniarts.openkeeper.utils.WorldUtils;
import toniarts.openkeeper.view.map.MapViewController;

/**
* Our wrapper on JME cinematic class, produces ready cinematics from camera
Expand Down
2 changes: 1 addition & 1 deletion src/toniarts/openkeeper/common/EntityInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
*/
package toniarts.openkeeper.common;

import java.awt.Point;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import toniarts.openkeeper.utils.Point;

/**
* Holds an entity instance, series of coordinates that together form an entity
Expand Down
2 changes: 1 addition & 1 deletion src/toniarts/openkeeper/game/component/MapTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package toniarts.openkeeper.game.component;

import com.simsilica.es.EntityComponent;
import java.awt.Point;
import toniarts.openkeeper.utils.Point;
import java.util.HashMap;
import java.util.Map;
import toniarts.openkeeper.tools.convert.map.Tile;
Expand Down
2 changes: 1 addition & 1 deletion src/toniarts/openkeeper/game/component/Navigation.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.badlogic.gdx.math.Vector2;
import com.simsilica.es.EntityComponent;
import java.awt.Point;
import toniarts.openkeeper.utils.Point;
import java.util.List;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/toniarts/openkeeper/game/component/TaskComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.simsilica.es.EntityComponent;
import com.simsilica.es.EntityId;
import java.awt.Point;
import toniarts.openkeeper.utils.Point;
import toniarts.openkeeper.game.task.TaskType;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.simsilica.es.EntityId;
import com.simsilica.es.EntitySet;
import com.simsilica.es.filter.FieldFilter;
import java.awt.Point;
import toniarts.openkeeper.utils.Point;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.lang.ref.WeakReference;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.jme3.util.SafeArrayList;
import com.simsilica.es.EntityData;
import com.simsilica.es.EntityId;
import java.awt.Point;
import java.lang.System.Logger.Level;
import java.util.AbstractMap;
import java.util.ArrayList;
Expand Down Expand Up @@ -82,6 +81,7 @@
import toniarts.openkeeper.tools.convert.map.Tile;
import toniarts.openkeeper.tools.convert.map.Trap;
import toniarts.openkeeper.tools.convert.map.Variable;
import toniarts.openkeeper.utils.Point;
import toniarts.openkeeper.utils.WorldUtils;

/**
Expand Down Expand Up @@ -713,7 +713,7 @@ public void drop(EntityId entity, Point tile, Vector2f coordinates, EntityId dro
playerHandControl.pop();

// Stuff drop differently
IRoomController roomController = mapController.getRoomControllerByCoordinates(tile.getLocation());
IRoomController roomController = mapController.getRoomControllerByCoordinates(tile);
if (entityData.getComponent(entity, CreatureComponent.class) != null) {
dropCreature(roomController, entity, tile, coordinates, playerId);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.jme3.math.Vector2f;
import com.simsilica.es.EntityId;
import java.awt.Point;
import toniarts.openkeeper.utils.Point;
import toniarts.openkeeper.game.listener.PlayerActionListener;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package toniarts.openkeeper.game.controller;

import com.jme3.math.Vector2f;
import java.awt.Point;
import toniarts.openkeeper.utils.Point;
import java.util.Collection;
import java.util.List;
import java.util.Map;
Expand Down
2 changes: 1 addition & 1 deletion src/toniarts/openkeeper/game/controller/MapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.jme3.math.Vector2f;
import com.jme3.util.SafeArrayList;
import com.simsilica.es.EntityData;
import java.awt.Point;
import toniarts.openkeeper.utils.Point;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.badlogic.gdx.ai.pfa.GraphPath;
import com.simsilica.es.EntityData;
import com.simsilica.es.EntityId;
import java.awt.Point;
import toniarts.openkeeper.utils.Point;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import toniarts.openkeeper.game.component.ChickenAi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.jme3.math.Vector3f;
import com.simsilica.es.EntityData;
import com.simsilica.es.EntityId;
import java.awt.Point;
import toniarts.openkeeper.utils.Point;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.badlogic.gdx.ai.fsm.StateMachine;
import com.simsilica.es.EntityId;
import java.awt.Point;
import toniarts.openkeeper.utils.Point;
import java.util.function.Consumer;
import toniarts.openkeeper.game.controller.entity.IEntityController;
import toniarts.openkeeper.game.controller.object.IObjectController;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.jme3.math.Vector3f;
import com.simsilica.es.EntityData;
import com.simsilica.es.EntityId;
import java.awt.Point;
import toniarts.openkeeper.utils.Point;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import java.awt.Point;
import toniarts.openkeeper.utils.Point;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package toniarts.openkeeper.game.controller.room;

import com.simsilica.es.EntityId;
import java.awt.Point;
import toniarts.openkeeper.utils.Point;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
package toniarts.openkeeper.game.controller.room;

import java.awt.Point;
import toniarts.openkeeper.utils.Point;
import toniarts.openkeeper.common.RoomInstance;
import toniarts.openkeeper.game.controller.IObjectsController;
import toniarts.openkeeper.tools.convert.map.KwdFile;
Expand Down
Loading
Loading