mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-01-10 01:02:16 +00:00
100 lines
2.9 KiB
Haxe
100 lines
2.9 KiB
Haxe
package src;
|
|
|
|
import src.Mission;
|
|
import src.MissionList;
|
|
import gui.MessageBoxOkDlg;
|
|
import haxe.zip.Reader;
|
|
import haxe.io.BytesInput;
|
|
import haxe.Json;
|
|
import src.Http;
|
|
import src.Console;
|
|
import src.MarbleGame;
|
|
import src.ResourceLoader;
|
|
import src.Marbleland;
|
|
import Main;
|
|
|
|
typedef MPCustomEntry = {
|
|
artist:String,
|
|
description:String,
|
|
path:String,
|
|
title:String,
|
|
id:Int,
|
|
};
|
|
|
|
class MPCustoms {
|
|
public static var missionList:Array<MPCustomEntry> = [];
|
|
|
|
static var _requestSent = false;
|
|
|
|
public static function loadMissionList() {
|
|
if (missionList.length == 0 && !_requestSent) {
|
|
_requestSent = true;
|
|
Http.get(Main.isDiscord ? ".proxy/data/ultraCustom.json" : "https://marbleblastultra.randomityguy.me/data/ultraCustom.json", (b) -> {
|
|
var misList = Json.parse(b.toString());
|
|
missionList = misList;
|
|
missionList.sort((a, b) -> {
|
|
var a1 = a.title.toLowerCase();
|
|
var b1 = b.title.toLowerCase();
|
|
return a1 < b1 ? -1 : (a1 > b1 ? 1 : 0);
|
|
});
|
|
|
|
// Add this to marbleland customs too!
|
|
for (mis in missionList) {
|
|
var mission = new Mission();
|
|
|
|
mission.id = mis.id;
|
|
mission.path = mis.path;
|
|
mission.title = mis.title;
|
|
mission.artist = mis.artist;
|
|
mission.description = mis.description;
|
|
mission.qualifyTime = Math.POSITIVE_INFINITY;
|
|
mission.goldTime = 0;
|
|
mission.game = 'ultra';
|
|
mission.isClaMission = true;
|
|
mission.customSource = "MPCustoms";
|
|
|
|
Marbleland.ultraMissions.push(mission);
|
|
Marbleland.missions.set(mission.id, mission);
|
|
}
|
|
|
|
Console.log('Loaded ${misList.length} custom missions.');
|
|
_requestSent = false;
|
|
}, (e) -> {
|
|
Console.log('Error getting custom list from marbleland.');
|
|
_requestSent = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
public static function download(mission:MPCustomEntry, onFinish:() -> Void, onFail:() -> Void) {
|
|
var lastSlashIdx = mission.path.lastIndexOf('/');
|
|
var dlHost = Main.isDiscord ? ".proxy/" : "https://marbleblastultra.randomityguy.me/";
|
|
var dlPath = dlHost + StringTools.urlEncode(mission.path.substr(0, lastSlashIdx)) + ".zip";
|
|
Http.get(dlPath, (zipData) -> {
|
|
var reader = new Reader(new BytesInput(zipData));
|
|
var entries:Array<haxe.zip.Entry> = null;
|
|
try {
|
|
entries = [for (x in reader.read()) x];
|
|
} catch (e) {}
|
|
ResourceLoader.loadZip(entries, 'missions/mpcustom/');
|
|
if (entries != null) {
|
|
onFinish();
|
|
} else {
|
|
MarbleGame.canvas.pushDialog(new MessageBoxOkDlg("Failed to download mission"));
|
|
onFail();
|
|
}
|
|
}, (e) -> {
|
|
MarbleGame.canvas.pushDialog(new MessageBoxOkDlg("Failed to download mission"));
|
|
onFail();
|
|
});
|
|
}
|
|
|
|
public static function play(mission:MPCustomEntry, onFinish:() -> Void, onFail:() -> Void) {
|
|
download(mission, () -> {
|
|
var f = ResourceLoader.getFileEntry(mission.path);
|
|
var mis = MissionList.parseMisHeader(f.entry.getBytes().toString(), mission.path);
|
|
MarbleGame.instance.playMission(mis, true);
|
|
onFinish();
|
|
}, onFail);
|
|
}
|
|
}
|