mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
finally, android import export
This commit is contained in:
parent
56efdeedef
commit
83fbd0ea8a
4 changed files with 42 additions and 74 deletions
|
|
@ -4,8 +4,8 @@
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.randomityguy.mbhaxe.mbu"
|
package="com.randomityguy.mbhaxe.mbu"
|
||||||
android:installLocation="auto"
|
android:installLocation="auto"
|
||||||
android:versionCode="10"
|
android:versionCode="11"
|
||||||
android:versionName="2.2.3">
|
android:versionName="2.2.4">
|
||||||
|
|
||||||
<!-- Tell the system this app requires OpenGL ES 3.0. -->
|
<!-- Tell the system this app requires OpenGL ES 3.0. -->
|
||||||
<uses-feature android:glEsVersion="0x00030000" android:required="true" />
|
<uses-feature android:glEsVersion="0x00030000" android:required="true" />
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class MarbleGame {
|
||||||
static var canvas:Canvas;
|
static var canvas:Canvas;
|
||||||
static var instance:MarbleGame;
|
static var instance:MarbleGame;
|
||||||
|
|
||||||
static var currentVersion = "1.2.3";
|
static var currentVersion = "1.2.4";
|
||||||
|
|
||||||
var world:MarbleWorld;
|
var world:MarbleWorld;
|
||||||
var previewWorld:PreviewWorld;
|
var previewWorld:PreviewWorld;
|
||||||
|
|
|
||||||
|
|
@ -256,6 +256,12 @@ class Settings {
|
||||||
}
|
}
|
||||||
|
|
||||||
@:hlNative public static function open_web_url(url:String):Void {}
|
@: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
|
#end
|
||||||
|
|
||||||
public static function applySettings() {
|
public static function applySettings() {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package gui;
|
package gui;
|
||||||
|
|
||||||
|
import gui.GuiControl.MouseState;
|
||||||
import haxe.DynamicAccess;
|
import haxe.DynamicAccess;
|
||||||
import src.MarbleGame;
|
import src.MarbleGame;
|
||||||
import hxd.res.BitmapFont;
|
import hxd.res.BitmapFont;
|
||||||
|
|
@ -10,6 +11,7 @@ import src.Util;
|
||||||
|
|
||||||
class ImportExportGui extends GuiImage {
|
class ImportExportGui extends GuiImage {
|
||||||
var innerCtrl:GuiControl;
|
var innerCtrl:GuiControl;
|
||||||
|
var importing:Bool = false;
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
var res = ResourceLoader.getImage("data/ui/xbox/BG_fadeOutSoftEdge.png").resource.toTile();
|
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.position = new Vector();
|
||||||
this.extent = new Vector(640, 480);
|
this.extent = new Vector(640, 480);
|
||||||
|
|
||||||
#if hl
|
var scene2d = MarbleGame.canvas.scene2d;
|
||||||
var scene2d = hxd.Window.getInstance();
|
|
||||||
#end
|
|
||||||
#if (js || uwp)
|
|
||||||
var scene2d = MarbleGame.instance.scene2d;
|
|
||||||
#end
|
|
||||||
|
|
||||||
var offsetX = (scene2d.width - 1280) / 2;
|
var offsetX = (scene2d.width - 1280) / 2;
|
||||||
var offsetY = (scene2d.height - 720) / 2;
|
var offsetY = (scene2d.height - 720) / 2;
|
||||||
|
|
@ -64,76 +61,34 @@ class ImportExportGui extends GuiImage {
|
||||||
innerCtrl.addChild(btnList);
|
innerCtrl.addChild(btnList);
|
||||||
|
|
||||||
btnList.addButton(0, 'Import Progress', (e) -> {
|
btnList.addButton(0, 'Import Progress', (e) -> {
|
||||||
hxd.File.browse((sel) -> {
|
trace("Start prefs import");
|
||||||
sel.load((data) -> {
|
importing = true;
|
||||||
try {
|
Settings.start_import_prefs((data) -> {
|
||||||
// convert to string
|
try {
|
||||||
var jsonStr = data.toString();
|
// convert to string
|
||||||
// parse JSON
|
var jsonStr = @:privateAccess String.fromUTF8(data);
|
||||||
var json = haxe.Json.parse(jsonStr);
|
// parse JSON
|
||||||
|
var json = haxe.Json.parse(jsonStr);
|
||||||
|
|
||||||
var highScoreData:DynamicAccess<Array<Score>> = json.highScores;
|
var highScoreData:DynamicAccess<Array<Score>> = json.highScores;
|
||||||
for (key => value in highScoreData) {
|
for (key => value in highScoreData) {
|
||||||
Settings.highScores.set(key, value);
|
Settings.highScores.set(key, value);
|
||||||
}
|
|
||||||
var easterEggData:DynamicAccess<Float> = json.easterEggs;
|
|
||||||
if (easterEggData != null) {
|
|
||||||
for (key => value in easterEggData) {
|
|
||||||
Settings.easterEggs.set(key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MarbleGame.canvas.pushDialog(new MessageBoxOkDlg("Progress data imported successfully!"));
|
|
||||||
Settings.save();
|
|
||||||
} catch (e) {
|
|
||||||
MarbleGame.canvas.pushDialog(new MessageBoxOkDlg("Failed to import progress data: " + e.message));
|
|
||||||
}
|
}
|
||||||
});
|
var easterEggData:DynamicAccess<Float> = json.easterEggs;
|
||||||
}, {
|
if (easterEggData != null) {
|
||||||
title: "Select a progress file to import",
|
for (key => value in easterEggData) {
|
||||||
fileTypes: [
|
Settings.easterEggs.set(key, value);
|
||||||
{name: "JSON files", extensions: ["json"]},
|
}
|
||||||
{name: "All files", extensions: ["*"]}
|
}
|
||||||
],
|
MarbleGame.canvas.pushDialog(new MessageBoxOkDlg("Progress data imported successfully!"));
|
||||||
|
Settings.save();
|
||||||
|
} catch (e) {
|
||||||
|
MarbleGame.canvas.pushDialog(new MessageBoxOkDlg("Failed to import progress data: " + e.message));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
btnList.addButton(0, 'Export Progress', (e) -> {
|
btnList.addButton(0, 'Export Progress', (e) -> {
|
||||||
#if sys
|
Settings.export_prefs();
|
||||||
#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
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var bottomBar = new GuiControl();
|
var bottomBar = new GuiControl();
|
||||||
|
|
@ -164,4 +119,11 @@ class ImportExportGui extends GuiImage {
|
||||||
|
|
||||||
super.onResize(width, height);
|
super.onResize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override function update(dt:Float, mouseState:MouseState) {
|
||||||
|
super.update(dt, mouseState);
|
||||||
|
if (importing) {
|
||||||
|
Settings.call_import_cb();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue