finally, android import export

This commit is contained in:
RandomityGuy 2025-08-17 19:49:51 +05:30
parent 56efdeedef
commit 83fbd0ea8a
4 changed files with 42 additions and 74 deletions

View file

@ -4,8 +4,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.randomityguy.mbhaxe.mbu"
android:installLocation="auto"
android:versionCode="10"
android:versionName="2.2.3">
android:versionCode="11"
android:versionName="2.2.4">
<!-- Tell the system this app requires OpenGL ES 3.0. -->
<uses-feature android:glEsVersion="0x00030000" android:required="true" />

View file

@ -42,7 +42,7 @@ class MarbleGame {
static var canvas:Canvas;
static var instance:MarbleGame;
static var currentVersion = "1.2.3";
static var currentVersion = "1.2.4";
var world:MarbleWorld;
var previewWorld:PreviewWorld;

View file

@ -256,6 +256,12 @@ class Settings {
}
@:hlNative public static function open_web_url(url:String):Void {}
@:hlNative public static function export_prefs():Void {}
@:hlNative public static function start_import_prefs(prefsCb:(b:hl.Bytes) -> Void):Void {}
@:hlNative public static function call_import_cb():Void {}
#end
public static function applySettings() {

View file

@ -1,5 +1,6 @@
package gui;
import gui.GuiControl.MouseState;
import haxe.DynamicAccess;
import src.MarbleGame;
import hxd.res.BitmapFont;
@ -10,6 +11,7 @@ import src.Util;
class ImportExportGui extends GuiImage {
var innerCtrl:GuiControl;
var importing:Bool = false;
public function new() {
var res = ResourceLoader.getImage("data/ui/xbox/BG_fadeOutSoftEdge.png").resource.toTile();
@ -24,12 +26,7 @@ class ImportExportGui extends GuiImage {
this.position = new Vector();
this.extent = new Vector(640, 480);
#if hl
var scene2d = hxd.Window.getInstance();
#end
#if (js || uwp)
var scene2d = MarbleGame.instance.scene2d;
#end
var scene2d = MarbleGame.canvas.scene2d;
var offsetX = (scene2d.width - 1280) / 2;
var offsetY = (scene2d.height - 720) / 2;
@ -64,11 +61,12 @@ class ImportExportGui extends GuiImage {
innerCtrl.addChild(btnList);
btnList.addButton(0, 'Import Progress', (e) -> {
hxd.File.browse((sel) -> {
sel.load((data) -> {
trace("Start prefs import");
importing = true;
Settings.start_import_prefs((data) -> {
try {
// convert to string
var jsonStr = data.toString();
var jsonStr = @:privateAccess String.fromUTF8(data);
// parse JSON
var json = haxe.Json.parse(jsonStr);
@ -88,52 +86,9 @@ class ImportExportGui extends GuiImage {
MarbleGame.canvas.pushDialog(new MessageBoxOkDlg("Failed to import progress data: " + e.message));
}
});
}, {
title: "Select a progress file to import",
fileTypes: [
{name: "JSON files", extensions: ["json"]},
{name: "All files", extensions: ["*"]}
],
});
});
btnList.addButton(0, 'Export Progress', (e) -> {
#if sys
#if MACOS_BUNDLE
// open the finder to that folder
Sys.command('open "${Settings.settingsDir}"');
#else
// Just open the folder in the explorer.exe
Sys.command('explorer.exe "${Settings.settingsDir}"');
#end
MarbleGame.canvas.pushDialog(new MessageBoxOkDlg("The settings.json file contains your progress data. You can copy it to another device or share it with others."));
#end
#if js
// Serialize Settings to JSON
var localStorage = js.Browser.getLocalStorage();
if (localStorage != null) {
var settingsData = localStorage.getItem("MBHaxeSettings");
if (settingsData != null) {
// Download this
var replayBytes = settingsData;
var blob = new js.html.Blob([haxe.io.Bytes.ofString(replayBytes).getData()], {
type: 'application/octet-stream'
});
var url = js.html.URL.createObjectURL(blob);
var fname = 'settings.json';
var element = js.Browser.document.createElement('a');
element.setAttribute('href', url);
element.setAttribute('download', fname);
element.style.display = 'none';
js.Browser.document.body.appendChild(element);
element.click();
js.Browser.document.body.removeChild(element);
js.html.URL.revokeObjectURL(url);
}
}
#end
Settings.export_prefs();
});
var bottomBar = new GuiControl();
@ -164,4 +119,11 @@ class ImportExportGui extends GuiImage {
super.onResize(width, height);
}
override function update(dt:Float, mouseState:MouseState) {
super.update(dt, mouseState);
if (importing) {
Settings.call_import_cb();
}
}
}