mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
replay support for marbleland levels
This commit is contained in:
parent
07bd6a15c8
commit
311579e631
4 changed files with 43 additions and 16 deletions
|
|
@ -201,7 +201,7 @@ class MarbleWorld extends Scheduler {
|
||||||
this.scene2d = scene2d;
|
this.scene2d = scene2d;
|
||||||
this.mission = mission;
|
this.mission = mission;
|
||||||
this.game = mission.game.toLowerCase();
|
this.game = mission.game.toLowerCase();
|
||||||
this.replay = new Replay(mission.path);
|
this.replay = new Replay(mission.path, mission.isClaMission ? mission.id : 0);
|
||||||
this.isRecording = record;
|
this.isRecording = record;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ class Marbleland {
|
||||||
public static var goldMissions = [];
|
public static var goldMissions = [];
|
||||||
public static var ultraMissions = [];
|
public static var ultraMissions = [];
|
||||||
public static var platinumMissions = [];
|
public static var platinumMissions = [];
|
||||||
|
public static var missions:Map<Int, Mission> = [];
|
||||||
|
|
||||||
public static function init() {
|
public static function init() {
|
||||||
Http.get('https://raw.githubusercontent.com/Vanilagy/MarbleBlast/master/src/assets/customs_gold.json', (b) -> {
|
Http.get('https://raw.githubusercontent.com/Vanilagy/MarbleBlast/master/src/assets/customs_gold.json', (b) -> {
|
||||||
|
|
@ -77,6 +78,8 @@ class Marbleland {
|
||||||
case 'platinum':
|
case 'platinum':
|
||||||
platinumMissions.push(mission);
|
platinumMissions.push(mission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
missions.set(mission.id, mission);
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort according to name
|
// sort according to name
|
||||||
|
|
|
||||||
|
|
@ -231,7 +231,7 @@ class ReplayInitialState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function read(br:BytesReader) {
|
public function read(br:BytesReader, version:Int) {
|
||||||
var trapdoorCount = br.readInt16();
|
var trapdoorCount = br.readInt16();
|
||||||
for (i in 0...trapdoorCount) {
|
for (i in 0...trapdoorCount) {
|
||||||
this.trapdoorLastContactTimes.push(br.readFloat());
|
this.trapdoorLastContactTimes.push(br.readFloat());
|
||||||
|
|
@ -246,13 +246,15 @@ class ReplayInitialState {
|
||||||
for (i in 0...landMineCount) {
|
for (i in 0...landMineCount) {
|
||||||
this.landMineDisappearTimes.push(br.readFloat());
|
this.landMineDisappearTimes.push(br.readFloat());
|
||||||
}
|
}
|
||||||
var pushButtonCount = br.readInt16();
|
if (version > 5) {
|
||||||
for (i in 0...pushButtonCount) {
|
var pushButtonCount = br.readInt16();
|
||||||
this.pushButtonContactTimes.push(br.readFloat());
|
for (i in 0...pushButtonCount) {
|
||||||
}
|
this.pushButtonContactTimes.push(br.readFloat());
|
||||||
var rcount = br.readInt16();
|
}
|
||||||
for (i in 0...rcount) {
|
var rcount = br.readInt16();
|
||||||
this.randomGens.push(br.readByte());
|
for (i in 0...rcount) {
|
||||||
|
this.randomGens.push(br.readByte());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -260,6 +262,7 @@ class ReplayInitialState {
|
||||||
class Replay {
|
class Replay {
|
||||||
public var mission:String;
|
public var mission:String;
|
||||||
public var name:String;
|
public var name:String;
|
||||||
|
public var customId:Int;
|
||||||
|
|
||||||
var frames:Array<ReplayFrame>;
|
var frames:Array<ReplayFrame>;
|
||||||
var initialState:ReplayInitialState;
|
var initialState:ReplayInitialState;
|
||||||
|
|
@ -273,8 +276,9 @@ class Replay {
|
||||||
var version:Int = 6;
|
var version:Int = 6;
|
||||||
var readFullEntry:FileEntry;
|
var readFullEntry:FileEntry;
|
||||||
|
|
||||||
public function new(mission:String) {
|
public function new(mission:String, customId:Int = 0) {
|
||||||
this.mission = mission;
|
this.mission = mission;
|
||||||
|
this.customId = customId;
|
||||||
this.initialState = new ReplayInitialState();
|
this.initialState = new ReplayInitialState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -464,6 +468,7 @@ class Replay {
|
||||||
finalB.addString(this.name);
|
finalB.addString(this.name);
|
||||||
finalB.addByte(this.mission.length);
|
finalB.addByte(this.mission.length);
|
||||||
finalB.addString(this.mission);
|
finalB.addString(this.mission);
|
||||||
|
finalB.addInt32(this.customId);
|
||||||
finalB.addInt32(bufsize);
|
finalB.addInt32(bufsize);
|
||||||
finalB.addBytes(compressed, 0, compressed.length);
|
finalB.addBytes(compressed, 0, compressed.length);
|
||||||
|
|
||||||
|
|
@ -485,8 +490,16 @@ class Replay {
|
||||||
this.name = data.getString(2, nameLength);
|
this.name = data.getString(2, nameLength);
|
||||||
var missionLength = data.get(2 + nameLength);
|
var missionLength = data.get(2 + nameLength);
|
||||||
this.mission = data.getString(3 + nameLength, missionLength);
|
this.mission = data.getString(3 + nameLength, missionLength);
|
||||||
var uncompressedLength = data.getInt32(3 + nameLength + missionLength);
|
var uncompressedLength = 0;
|
||||||
var compressedData = data.sub(7 + nameLength + missionLength, data.length - 7 - nameLength - missionLength);
|
var compressedData:haxe.io.Bytes = null;
|
||||||
|
if (replayVersion > 5) {
|
||||||
|
this.customId = data.getInt32(3 + nameLength + missionLength);
|
||||||
|
uncompressedLength = data.getInt32(7 + nameLength + missionLength);
|
||||||
|
compressedData = data.sub(11 + nameLength + missionLength, data.length - 11 - nameLength - missionLength);
|
||||||
|
} else {
|
||||||
|
uncompressedLength = data.getInt32(3 + nameLength + missionLength);
|
||||||
|
compressedData = data.sub(7 + nameLength + missionLength, data.length - 7 - nameLength - missionLength);
|
||||||
|
}
|
||||||
|
|
||||||
#if hl
|
#if hl
|
||||||
var uncompressed = haxe.zip.Uncompress.run(compressedData, uncompressedLength);
|
var uncompressed = haxe.zip.Uncompress.run(compressedData, uncompressedLength);
|
||||||
|
|
@ -495,7 +508,7 @@ class Replay {
|
||||||
var uncompressed = haxe.zip.InflateImpl.run(new BytesInput(compressedData), uncompressedLength);
|
var uncompressed = haxe.zip.InflateImpl.run(new BytesInput(compressedData), uncompressedLength);
|
||||||
#end
|
#end
|
||||||
var br = new BytesReader(uncompressed);
|
var br = new BytesReader(uncompressed);
|
||||||
this.initialState.read(br);
|
this.initialState.read(br, replayVersion);
|
||||||
var frameCount = br.readInt32();
|
var frameCount = br.readInt32();
|
||||||
this.frames = [];
|
this.frames = [];
|
||||||
for (i in 0...frameCount) {
|
for (i in 0...frameCount) {
|
||||||
|
|
@ -522,6 +535,9 @@ class Replay {
|
||||||
this.name = data.getString(2, nameLength);
|
this.name = data.getString(2, nameLength);
|
||||||
var missionLength = data.get(2 + nameLength);
|
var missionLength = data.get(2 + nameLength);
|
||||||
this.mission = data.getString(3 + nameLength, missionLength);
|
this.mission = data.getString(3 + nameLength, missionLength);
|
||||||
|
if (replayVersion > 5) {
|
||||||
|
this.customId = data.getInt32(3 + nameLength + missionLength);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package gui;
|
package gui;
|
||||||
|
|
||||||
|
import src.Marbleland;
|
||||||
import src.Mission;
|
import src.Mission;
|
||||||
import hxd.BitmapData;
|
import hxd.BitmapData;
|
||||||
import hxd.res.BitmapFont;
|
import hxd.res.BitmapFont;
|
||||||
|
|
@ -66,8 +67,15 @@ class ReplayCenterGui extends GuiImage {
|
||||||
var repmis = repl.mission;
|
var repmis = repl.mission;
|
||||||
if (!StringTools.contains(repmis, "data/"))
|
if (!StringTools.contains(repmis, "data/"))
|
||||||
repmis = "data/" + repmis;
|
repmis = "data/" + repmis;
|
||||||
var mi = MissionList.missions.get(repmis);
|
var mi = repl.customId == 0 ? MissionList.missions.get(repmis) : Marbleland.missions.get(repl.customId);
|
||||||
MarbleGame.instance.watchMissionReplay(mi, repl);
|
if (mi.isClaMission) {
|
||||||
|
mi.download(() -> {
|
||||||
|
MarbleGame.instance.watchMissionReplay(mi, repl);
|
||||||
|
});
|
||||||
|
playButton.disabled = true; // Don't let us play anything else
|
||||||
|
} else {
|
||||||
|
MarbleGame.instance.watchMissionReplay(mi, repl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wnd.addChild(playButton);
|
wnd.addChild(playButton);
|
||||||
|
|
@ -128,7 +136,7 @@ class ReplayCenterGui extends GuiImage {
|
||||||
repmis = "data/" + repmis;
|
repmis = "data/" + repmis;
|
||||||
if (MissionList.missions == null)
|
if (MissionList.missions == null)
|
||||||
MissionList.buildMissionList();
|
MissionList.buildMissionList();
|
||||||
var m = MissionList.missions.get(repmis);
|
var m = thisReplay.customId == 0 ? MissionList.missions.get(repmis) : Marbleland.missions.get(thisReplay.customId);
|
||||||
missionName.text.text = m.title;
|
missionName.text.text = m.title;
|
||||||
m.getPreviewImage((t) -> {
|
m.getPreviewImage((t) -> {
|
||||||
pmPreview.bmp.tile = t;
|
pmPreview.bmp.tile = t;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue