Files
gitea-docker/ios/src/java/advent/core/IOSLauncher.java
2020-02-04 21:56:08 -08:00

78 lines
3.0 KiB
Java

package advent.core;
import java.util.*;
import clojure.lang.RT;
import clojure.lang.Symbol;
// import advent.ios.*;
import com.badlogic.gdx.*;
import com.badlogic.gdx.backends.iosrobovm.*;
import org.robovm.apple.foundation.*;
import org.robovm.apple.uikit.*;
import org.robovm.apple.glkit.GLKViewDrawableColorFormat;
import org.robovm.apple.glkit.GLKViewDrawableDepthFormat;
import org.robovm.apple.storekit.*;
public class IOSLauncher extends IOSApplication.Delegate {
TransactionObserver transactionObserver;
@Override
public boolean didFinishLaunching (UIApplication application, UIApplicationLaunchOptions launchOptions) {
transactionObserver = new TransactionObserver();
SKPaymentQueue.getDefaultQueue().addTransactionObserver(transactionObserver);
new GameCenter().login(application.getKeyWindow());
return super.didFinishLaunching(application, launchOptions);
}
@Override
public void willTerminate(UIApplication application) {
SKPaymentQueue.getDefaultQueue().removeTransactionObserver(transactionObserver);
super.willTerminate(application);
}
protected IOSApplication createApplication() {
IOSApplicationConfiguration config = new IOSApplicationConfiguration();
// config.colorFormat = GLKViewDrawableColorFormat.SRGBA8888;
// config.depthFormat = GLKViewDrawableDepthFormat._24;
config.orientationPortrait = false;
config.orientationLandscape = true;
config.preferredFramesPerSecond = 30;
config.useAccelerometer=false;
config.useCompass=false;
System.out.println("application created.");
HashSet<String> products = new HashSet();
products.add("fullgame");
SKProductsRequest request = new SKProductsRequest(products);
request.setDelegate(new ProductDelegate());
request.start();
RT.var("clojure.core", "require").invoke(Symbol.intern("advent.core"));
RT.var("clojure.core", "require").invoke(Symbol.intern("advent.ios"));
System.out.println("clojure loaded");
try {
NSDictionary infoDictionary = NSBundle.getMainBundle().getInfoDictionary();
String version = infoDictionary.get(new NSString("CFBundleShortVersionString")).toString();
RT.var("advent.version", "version-override").bindRoot(version);
Game game = (Game) RT.var("advent.core", "advent").deref();
System.out.println("game loaded");
return new IOSApplication(game, config);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] argv) {
NSAutoreleasePool pool = new NSAutoreleasePool();
UIApplication.main(argv, null, IOSLauncher.class);
pool.close();
}
@Override
public void didReceiveMemoryWarning(UIApplication application) {
for (int i = 0; i < 3; i++) {
System.gc();
}
}
}