android port

This commit is contained in:
RandomityGuy 2022-08-12 12:39:52 +05:30
parent 0e2e18a3ac
commit 61140be919
23 changed files with 182 additions and 35 deletions

View file

@ -1,8 +1,10 @@
-cp src -cp src
-lib heaps -lib heaps
-lib hlsdl -lib hlsdl
-lib zyheaps
-hl marblegame.hl -hl marblegame.hl
-D windowSize=1280x720 -D windowSize=1280x720
-D keep-inline-positions -D keep-inline-positions
-D android
--main Main --main Main
-debug -debug

BIN
data/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
data/icons/icon-128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
data/icons/icon-144.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

BIN
data/icons/icon-180.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

BIN
data/icons/icon-192.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

BIN
data/icons/icon-256.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

BIN
data/icons/icon-32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
data/icons/icon-48.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

BIN
data/icons/icon-512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 KiB

BIN
data/icons/icon-64.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

BIN
data/icons/icon-96.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

68
data/manifest.json Normal file
View file

@ -0,0 +1,68 @@
{
"name": "Marble Blast Gold Haxe Port",
"short_name": "Marble Blast Gold",
"description": "A reimplementation of Marble Blast Gold in Haxe",
"dir": "ltr",
"start_url": "/index.html?app=true",
"scope": "/",
"display": "fullscreen",
"orientation": "landscape",
"background_color": "black",
"theme_color": "black",
"categories": [
"games"
],
"lang": "en-US",
"icons": [
{
"src": "/data/icons/icon-512.png",
"type": "image/png",
"sizes": "512x512"
},
{
"src": "/data/icons/icon-256.png",
"type": "image/png",
"sizes": "256x256"
},
{
"src": "/data/icons/icon-192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "/data/icons/icon-180.png",
"type": "image/png",
"sizes": "180x180"
},
{
"src": "/data/icons/icon-144.png",
"type": "image/png",
"sizes": "144x144"
},
{
"src": "/data/icons/icon-128.png",
"type": "image/png",
"sizes": "128x128"
},
{
"src": "/data/icons/icon-96.png",
"type": "image/png",
"sizes": "96x96"
},
{
"src": "/data/icons/icon-64.png",
"type": "image/png",
"sizes": "64x64"
},
{
"src": "/data/icons/icon-48.png",
"type": "image/png",
"sizes": "48x48"
},
{
"src": "/data/icons/icon-32.png",
"type": "image/png",
"sizes": "32x32"
}
]
}

View file

@ -4,6 +4,9 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>Marble Blast Gold Haxe Port</title> <title>Marble Blast Gold Haxe Port</title>
<link rel="shortcut icon" href="./data/icon.png" id="favicon">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="manifest" href="/data/manifest.json">
<style> <style>
body { body {
margin: 0; margin: 0;

View file

@ -475,7 +475,7 @@ class DifBuilder {
tex = tex.split('/')[1]; tex = tex.split('/')[1];
} }
#if js #if (js || android)
path = StringTools.replace(path, "data/", ""); path = StringTools.replace(path, "data/", "");
#end #end

View file

@ -1,5 +1,6 @@
package; package;
import hxd.Key;
import src.Util; import src.Util;
import src.ResourceLoader; import src.ResourceLoader;
#if js #if js
@ -23,41 +24,76 @@ class Main extends hxd.App {
var debugProfiler:h3d.impl.Benchmark; var debugProfiler:h3d.impl.Benchmark;
var loaded:Bool = false; var loaded:Bool = false;
var keyCounter:Text;
override function init() { override function init() {
super.init(); super.init();
#if hl #if (hl && !android)
hl.UI.closeConsole(); hl.UI.closeConsole();
#end #end
#if js #if js
var zoomRatio = Util.isTouchDevice() ? js.Browser.window.screen.height * js.Browser.window.devicePixelRatio / 600 : js.Browser.window.devicePixelRatio; // js.Browser.window.devicePixelRatio; var zoomRatio = Util.isTouchDevice() ? js.Browser.window.screen.height * js.Browser.window.devicePixelRatio / 600 : js.Browser.window.devicePixelRatio; // js.Browser.window.devicePixelRatio;
s2d.scaleMode = Zoom(zoomRatio); s2d.scaleMode = Zoom(zoomRatio);
#end #end
#if android
Window.getInstance().addEventTarget(ev -> {
if (ev.kind == EPush || ev.kind == ERelease || ev.kind == EMove) {
@:privateAccess s2d.window.curMouseX = cast ev.relX;
@:privateAccess s2d.window.curMouseY = cast ev.relY;
ev.propagate = true;
}
if (ev.kind == EPush) {
@:privateAccess Key.keyPressed[Key.MOUSE_LEFT] = Key.getFrame();
}
if (ev.kind == ERelease) {
@:privateAccess Key.keyPressed[Key.MOUSE_LEFT] = -Key.getFrame();
}
});
#end
ResourceLoader.init(s2d, () -> { ResourceLoader.init(s2d, () -> {
Settings.init(); Settings.init();
AudioManager.init(); AudioManager.init();
AudioManager.playShell(); AudioManager.playShell();
marbleGame = new MarbleGame(s2d, s3d); marbleGame = new MarbleGame(s2d, s3d);
MarbleGame.canvas.setContent(new MainMenuGui()); MarbleGame.canvas.setContent(new MainMenuGui());
// world = new MarbleWorld(s3d, s2d, mission);
// world.init(); keyCounter = new Text(DefaultFont.get(), s2d);
// world.start(); keyCounter.color = new Vector(1, 1, 1, 1);
// debugProfiler = new h3d.impl.Benchmark(s2d);
// debugProfiler.y = 40;
// fpsCounter = new Text(DefaultFont.get(), s2d);
// fpsCounter.y = 40;
// fpsCounter.color = new Vector(1, 1, 1, 1);
loaded = true; loaded = true;
}); });
// ResourceLoader.init(s2d, () -> {
// Settings.init();
// AudioManager.init();
// AudioManager.playShell();
// marbleGame = new MarbleGame(s2d, s3d);
// MarbleGame.canvas.setContent(new MainMenuGui());
// // world = new MarbleWorld(s3d, s2d, mission);
// // world.init();
// // world.start();
// // debugProfiler = new h3d.impl.Benchmark(s2d);
// // debugProfiler.y = 40;
// // fpsCounter = new Text(DefaultFont.get(), s2d);
// // fpsCounter.y = 40;
// // fpsCounter.color = new Vector(1, 1, 1, 1);
// loaded = true;
// });
} }
override function update(dt:Float) { override function update(dt:Float) {
super.update(dt); super.update(dt);
if (loaded) { if (loaded) {
marbleGame.update(dt); marbleGame.update(dt);
keyCounter.text = 'Mouse: ${Window.getInstance().mouseX} ${Window.getInstance().mouseY}';
// world.update(dt); // world.update(dt);
// fpsCounter.text = 'FPS: ${this.engine.fps}'; // fpsCounter.text = 'FPS: ${this.engine.fps}';
} }

View file

@ -87,7 +87,7 @@ class Mission {
var path = StringTools.replace(rawElementPath.substring(rawElementPath.indexOf('data/')), "\"", ""); var path = StringTools.replace(rawElementPath.substring(rawElementPath.indexOf('data/')), "\"", "");
if (StringTools.contains(path, 'interiors_mbg/')) if (StringTools.contains(path, 'interiors_mbg/'))
path = StringTools.replace(path, 'interiors_mbg/', 'interiors/'); path = StringTools.replace(path, 'interiors_mbg/', 'interiors/');
#if js #if (js || android)
path = StringTools.replace(path, "data/", ""); path = StringTools.replace(path, "data/", "");
#end #end
if (ResourceLoader.fileSystem.exists(path)) if (ResourceLoader.fileSystem.exists(path))

View file

@ -18,10 +18,10 @@ class MissionList {
if (_build) if (_build)
return; return;
function parseDifficulty(difficulty:String) { function parseDifficulty(difficulty:String) {
#if hl #if (hl && !android)
var difficultyFiles = ResourceLoader.fileSystem.dir("data/missions/" + difficulty); var difficultyFiles = ResourceLoader.fileSystem.dir("data/missions/" + difficulty);
#end #end
#if js #if (js || android)
var difficultyFiles = ResourceLoader.fileSystem.dir("missions/" + difficulty); var difficultyFiles = ResourceLoader.fileSystem.dir("missions/" + difficulty);
#end #end
var difficultyMissions = []; var difficultyMissions = [];

View file

@ -1,6 +1,6 @@
package src; package src;
#if js #if (js || android)
import fs.ManifestLoader; import fs.ManifestLoader;
import fs.ManifestBuilder; import fs.ManifestBuilder;
import fs.ManifestProgress; import fs.ManifestProgress;
@ -18,16 +18,16 @@ import hxd.res.Loader;
import src.Resource; import src.Resource;
class ResourceLoader { class ResourceLoader {
#if hl #if (hl && !android)
public static var fileSystem:FileSystem = new LocalFileSystem(".", null); public static var fileSystem:FileSystem = new LocalFileSystem(".", null);
#end #end
#if js #if (js || android)
public static var fileSystem:FileSystem = null; public static var fileSystem:FileSystem = null;
#end #end
#if hl #if (hl && !android)
public static var loader = new Loader(fileSystem); public static var loader = new Loader(fileSystem);
#end #end
#if js #if (js || android)
public static var loader:Loader = null; public static var loader:Loader = null;
#end #end
static var interiorResources:Map<String, Resource<Dif>> = new Map(); static var interiorResources:Map<String, Resource<Dif>> = new Map();
@ -39,7 +39,7 @@ class ResourceLoader {
// static var threadPool:FixedThreadPool = new FixedThreadPool(4); // static var threadPool:FixedThreadPool = new FixedThreadPool(4);
public static function init(scene2d:h2d.Scene, onLoadedFunc:Void->Void) { public static function init(scene2d:h2d.Scene, onLoadedFunc:Void->Void) {
#if js #if (js || android)
var mfileSystem = ManifestBuilder.create("data"); var mfileSystem = ManifestBuilder.create("data");
var mloader = new ManifestLoader(mfileSystem); var mloader = new ManifestLoader(mfileSystem);
@ -50,13 +50,13 @@ class ResourceLoader {
}, scene2d); }, scene2d);
preloader.start(); preloader.start();
#end #end
#if hl #if (hl && !android)
onLoadedFunc(); onLoadedFunc();
#end #end
} }
public static function loadInterior(path:String) { public static function loadInterior(path:String) {
#if js #if (js || android)
path = StringTools.replace(path, "data/", ""); path = StringTools.replace(path, "data/", "");
#end #end
if (interiorResources.exists(path)) if (interiorResources.exists(path))
@ -76,7 +76,7 @@ class ResourceLoader {
} }
public static function loadDts(path:String) { public static function loadDts(path:String) {
#if js #if (js || android)
path = StringTools.replace(path, "data/", ""); path = StringTools.replace(path, "data/", "");
#end #end
if (dtsResources.exists(path)) if (dtsResources.exists(path))
@ -96,7 +96,7 @@ class ResourceLoader {
} }
public static function getTexture(path:String) { public static function getTexture(path:String) {
#if js #if (js || android)
path = StringTools.replace(path, "data/", ""); path = StringTools.replace(path, "data/", "");
#end #end
if (textureCache.exists(path)) if (textureCache.exists(path))
@ -118,7 +118,7 @@ class ResourceLoader {
} }
public static function getImage(path:String) { public static function getImage(path:String) {
#if js #if (js || android)
path = StringTools.replace(path, "data/", ""); path = StringTools.replace(path, "data/", "");
#end #end
if (imageCache.exists(path)) if (imageCache.exists(path))
@ -133,7 +133,7 @@ class ResourceLoader {
} }
public static function getAudio(path:String) { public static function getAudio(path:String) {
#if js #if (js || android)
path = StringTools.replace(path, "data/", ""); path = StringTools.replace(path, "data/", "");
#end #end
if (audioCache.exists(path)) if (audioCache.exists(path))
@ -160,7 +160,7 @@ class ResourceLoader {
} }
public static function getFileEntry(path:String) { public static function getFileEntry(path:String) {
#if js #if (js || android)
path = StringTools.replace(path, "data/", ""); path = StringTools.replace(path, "data/", "");
#end #end
var file = loader.load(path); var file = loader.load(path);
@ -176,7 +176,7 @@ class ResourceLoader {
} }
public static function getFullNamesOf(path:String) { public static function getFullNamesOf(path:String) {
#if js #if (js || android)
path = StringTools.replace(path, "data/", ""); path = StringTools.replace(path, "data/", "");
#end #end
var files = fileSystem.dir(Path.directory(path)); // FileSystem.readDirectory(Path.directory(path)); var files = fileSystem.dir(Path.directory(path)); // FileSystem.readDirectory(Path.directory(path));

View file

@ -168,7 +168,7 @@ class Settings {
outputData.highScores = jobj; outputData.highScores = jobj;
#end #end
var json = Json.stringify(outputData); var json = Json.stringify(outputData);
#if hl #if (hl && !android)
File.saveContent("settings.json", json); File.saveContent("settings.json", json);
#end #end
#if js #if js

View file

@ -332,13 +332,22 @@ class Util {
#if hl #if hl
switch (Settings.isTouch) { switch (Settings.isTouch) {
case None: case None:
#if android
Settings.isTouch = Some(true);
return true;
#else
Settings.isTouch = Some(false); Settings.isTouch = Some(false);
return false; return false;
#end
case Some(val): case Some(val):
return val; return val;
} }
#if android
return true;
#else
return false; return false;
#end #end
#end
} }
public static function isSafari() { public static function isSafari() {

View file

@ -28,6 +28,9 @@ import haxe.io.Encoding;
import haxe.io.Path; import haxe.io.Path;
import haxe.io.Bytes; import haxe.io.Bytes;
#if android
// import zygame.utils.hl.AssetsTools;
#end
@:allow(fs.ManifestFileSystem) @:allow(fs.ManifestFileSystem)
class ManifestEntry extends FileEntry { class ManifestEntry extends FileEntry {
private var fs:ManifestFileSystem; private var fs:ManifestFileSystem;
@ -38,7 +41,7 @@ class ManifestEntry extends FileEntry {
private var file:String; private var file:String;
private var originalFile:String; private var originalFile:String;
#if sys #if (sys && !android)
private var fio:sys.io.FileInput; private var fio:sys.io.FileInput;
#else #else
private var bytes:Bytes; private var bytes:Bytes;
@ -59,7 +62,7 @@ class ManifestEntry extends FileEntry {
} }
override public function getSign():Int { override public function getSign():Int {
#if sys #if (sys && !android)
var old = if (fio == null) -1 else fio.tell(); var old = if (fio == null) -1 else fio.tell();
open(); open();
var i = fio.readInt32(); var i = fio.readInt32();
@ -74,14 +77,20 @@ class ManifestEntry extends FileEntry {
} }
override public function getBytes():Bytes { override public function getBytes():Bytes {
#if sys #if (sys && !android)
return sys.io.File.getBytes(file); return sys.io.File.getBytes(file);
#elseif android
bytes = sys.io.File.getBytes(file); // AssetsTools.getBytes(file);
return bytes;
#else #else
return bytes; return bytes;
#end #end
} }
override function readBytes(out:haxe.io.Bytes, outPos:Int, pos:Int, len:Int):Int { override function readBytes(out:haxe.io.Bytes, outPos:Int, pos:Int, len:Int):Int {
if (this.bytes == null) {
this.bytes = getBytes();
}
if (pos + len > bytes.length) if (pos + len > bytes.length)
len = bytes.length - pos; len = bytes.length - pos;
if (len < 0) if (len < 0)
@ -132,7 +141,8 @@ class ManifestEntry extends FileEntry {
} }
#else #else
if (onReady != null) if (onReady != null)
haxe.Timer.delay(onReady, 1); onReady();
// haxe.Timer.delay(onReady, 1);
#end #end
} }
@ -198,8 +208,11 @@ class ManifestEntry extends FileEntry {
} }
override private function get_size():Int { override private function get_size():Int {
#if sys #if (sys && !android)
return sys.FileSystem.stat(file).size; return sys.FileSystem.stat(file).size;
#elseif android
var fb = sys.io.File.getBytes(file); // AssetsTools.getBytes(file);
return fb != null ? fb.length : 0;
#else #else
return bytes != null ? bytes.length : 0; return bytes != null ? bytes.length : 0;
#end #end
@ -211,7 +224,7 @@ class ManifestEntry extends FileEntry {
c.dispose(); c.dispose();
contents = null; contents = null;
} }
#if sys #if (sys && !android)
close(); close();
#else #else
bytes = null; bytes = null;

16
zyheaps.xml Normal file
View file

@ -0,0 +1,16 @@
<project>
<meta title="Marble Blast Gold" package="com.marble.blast" version="1.0.0" company="RandomityGuy" />
<!-- Main app -->
<app main="Main" path="Export" file="MBHaxe"/>
<!-- Assets -->
<assets path="data" rename="data" />
<!-- Haxelib -->
<haxelib name="zyheaps" />
<haxelib name="heaps" />
<!-- Sources -->
<source name="src" />
<!-- Android Config -->
<define name="NDK_DIR" value="E:/Android/ndk/18.1.5063045" />
<define name="ANDROID_SDK_DIR" value="E:/Android" />
<define name="NDK_VERSION" value="18.1.5063045" />
</project>