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.mission = mission;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ class Marbleland {
|
|||
public static var goldMissions = [];
|
||||
public static var ultraMissions = [];
|
||||
public static var platinumMissions = [];
|
||||
public static var missions:Map<Int, Mission> = [];
|
||||
|
||||
public static function init() {
|
||||
Http.get('https://raw.githubusercontent.com/Vanilagy/MarbleBlast/master/src/assets/customs_gold.json', (b) -> {
|
||||
|
|
@ -77,6 +78,8 @@ class Marbleland {
|
|||
case 'platinum':
|
||||
platinumMissions.push(mission);
|
||||
}
|
||||
|
||||
missions.set(mission.id, mission);
|
||||
}
|
||||
|
||||
// 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();
|
||||
for (i in 0...trapdoorCount) {
|
||||
this.trapdoorLastContactTimes.push(br.readFloat());
|
||||
|
|
@ -246,13 +246,15 @@ class ReplayInitialState {
|
|||
for (i in 0...landMineCount) {
|
||||
this.landMineDisappearTimes.push(br.readFloat());
|
||||
}
|
||||
var pushButtonCount = br.readInt16();
|
||||
for (i in 0...pushButtonCount) {
|
||||
this.pushButtonContactTimes.push(br.readFloat());
|
||||
}
|
||||
var rcount = br.readInt16();
|
||||
for (i in 0...rcount) {
|
||||
this.randomGens.push(br.readByte());
|
||||
if (version > 5) {
|
||||
var pushButtonCount = br.readInt16();
|
||||
for (i in 0...pushButtonCount) {
|
||||
this.pushButtonContactTimes.push(br.readFloat());
|
||||
}
|
||||
var rcount = br.readInt16();
|
||||
for (i in 0...rcount) {
|
||||
this.randomGens.push(br.readByte());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -260,6 +262,7 @@ class ReplayInitialState {
|
|||
class Replay {
|
||||
public var mission:String;
|
||||
public var name:String;
|
||||
public var customId:Int;
|
||||
|
||||
var frames:Array<ReplayFrame>;
|
||||
var initialState:ReplayInitialState;
|
||||
|
|
@ -273,8 +276,9 @@ class Replay {
|
|||
var version:Int = 6;
|
||||
var readFullEntry:FileEntry;
|
||||
|
||||
public function new(mission:String) {
|
||||
public function new(mission:String, customId:Int = 0) {
|
||||
this.mission = mission;
|
||||
this.customId = customId;
|
||||
this.initialState = new ReplayInitialState();
|
||||
}
|
||||
|
||||
|
|
@ -464,6 +468,7 @@ class Replay {
|
|||
finalB.addString(this.name);
|
||||
finalB.addByte(this.mission.length);
|
||||
finalB.addString(this.mission);
|
||||
finalB.addInt32(this.customId);
|
||||
finalB.addInt32(bufsize);
|
||||
finalB.addBytes(compressed, 0, compressed.length);
|
||||
|
||||
|
|
@ -485,8 +490,16 @@ class Replay {
|
|||
this.name = data.getString(2, nameLength);
|
||||
var missionLength = data.get(2 + nameLength);
|
||||
this.mission = data.getString(3 + nameLength, missionLength);
|
||||
var uncompressedLength = data.getInt32(3 + nameLength + missionLength);
|
||||
var compressedData = data.sub(7 + nameLength + missionLength, data.length - 7 - nameLength - missionLength);
|
||||
var uncompressedLength = 0;
|
||||
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
|
||||
var uncompressed = haxe.zip.Uncompress.run(compressedData, uncompressedLength);
|
||||
|
|
@ -495,7 +508,7 @@ class Replay {
|
|||
var uncompressed = haxe.zip.InflateImpl.run(new BytesInput(compressedData), uncompressedLength);
|
||||
#end
|
||||
var br = new BytesReader(uncompressed);
|
||||
this.initialState.read(br);
|
||||
this.initialState.read(br, replayVersion);
|
||||
var frameCount = br.readInt32();
|
||||
this.frames = [];
|
||||
for (i in 0...frameCount) {
|
||||
|
|
@ -522,6 +535,9 @@ class Replay {
|
|||
this.name = data.getString(2, nameLength);
|
||||
var missionLength = data.get(2 + nameLength);
|
||||
this.mission = data.getString(3 + nameLength, missionLength);
|
||||
if (replayVersion > 5) {
|
||||
this.customId = data.getInt32(3 + nameLength + missionLength);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package gui;
|
||||
|
||||
import src.Marbleland;
|
||||
import src.Mission;
|
||||
import hxd.BitmapData;
|
||||
import hxd.res.BitmapFont;
|
||||
|
|
@ -66,8 +67,15 @@ class ReplayCenterGui extends GuiImage {
|
|||
var repmis = repl.mission;
|
||||
if (!StringTools.contains(repmis, "data/"))
|
||||
repmis = "data/" + repmis;
|
||||
var mi = MissionList.missions.get(repmis);
|
||||
MarbleGame.instance.watchMissionReplay(mi, repl);
|
||||
var mi = repl.customId == 0 ? MissionList.missions.get(repmis) : Marbleland.missions.get(repl.customId);
|
||||
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);
|
||||
|
|
@ -128,7 +136,7 @@ class ReplayCenterGui extends GuiImage {
|
|||
repmis = "data/" + repmis;
|
||||
if (MissionList.missions == null)
|
||||
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;
|
||||
m.getPreviewImage((t) -> {
|
||||
pmPreview.bmp.tile = t;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue