mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
Merge branch 'master' of https://github.com/RandomityGuy/MBHaxe
This commit is contained in:
commit
03b0eced47
6 changed files with 108 additions and 52 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
package src;
|
package src;
|
||||||
|
|
||||||
|
import gui.ReplayNameDlg;
|
||||||
import gui.ConsoleDlg;
|
import gui.ConsoleDlg;
|
||||||
import src.Replay;
|
import src.Replay;
|
||||||
import touch.TouchInput;
|
import touch.TouchInput;
|
||||||
|
|
@ -218,7 +219,11 @@ class MarbleGame {
|
||||||
world.setCursorLock(false);
|
world.setCursorLock(false);
|
||||||
exitGameDlg = new ExitGameDlg((sender) -> {
|
exitGameDlg = new ExitGameDlg((sender) -> {
|
||||||
canvas.popDialog(exitGameDlg);
|
canvas.popDialog(exitGameDlg);
|
||||||
|
if (world.isRecording) {
|
||||||
|
MarbleGame.canvas.pushDialog(new ReplayNameDlg(() -> {quitMission();}));
|
||||||
|
} else {
|
||||||
quitMission();
|
quitMission();
|
||||||
|
}
|
||||||
}, (sender) -> {
|
}, (sender) -> {
|
||||||
canvas.popDialog(exitGameDlg);
|
canvas.popDialog(exitGameDlg);
|
||||||
paused = !paused;
|
paused = !paused;
|
||||||
|
|
@ -247,9 +252,6 @@ class MarbleGame {
|
||||||
var pmg = new PlayMissionGui();
|
var pmg = new PlayMissionGui();
|
||||||
PlayMissionGui.currentSelectionStatic = world.mission.index;
|
PlayMissionGui.currentSelectionStatic = world.mission.index;
|
||||||
PlayMissionGui.currentGameStatic = world.mission.game;
|
PlayMissionGui.currentGameStatic = world.mission.game;
|
||||||
if (world.isRecording) {
|
|
||||||
world.saveReplay();
|
|
||||||
}
|
|
||||||
world.dispose();
|
world.dispose();
|
||||||
world = null;
|
world = null;
|
||||||
canvas.setContent(pmg);
|
canvas.setContent(pmg);
|
||||||
|
|
@ -263,7 +265,6 @@ class MarbleGame {
|
||||||
world.dispose();
|
world.dispose();
|
||||||
}
|
}
|
||||||
world = new MarbleWorld(scene, scene2d, mission, toRecord);
|
world = new MarbleWorld(scene, scene2d, mission, toRecord);
|
||||||
toRecord = false;
|
|
||||||
world.init();
|
world.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package src;
|
package src;
|
||||||
|
|
||||||
|
import gui.ReplayCenterGui;
|
||||||
|
import gui.ReplayNameDlg;
|
||||||
import collision.Collision;
|
import collision.Collision;
|
||||||
import shapes.MegaMarble;
|
import shapes.MegaMarble;
|
||||||
import shapes.Blast;
|
import shapes.Blast;
|
||||||
|
|
@ -1162,9 +1164,7 @@ class MarbleWorld extends Scheduler {
|
||||||
}
|
}
|
||||||
this.setCursorLock(false);
|
this.setCursorLock(false);
|
||||||
this.dispose();
|
this.dispose();
|
||||||
var pmg = new PlayMissionGui();
|
MarbleGame.canvas.setContent(new ReplayCenterGui());
|
||||||
PlayMissionGui.currentSelectionStatic = mission.index + 1;
|
|
||||||
MarbleGame.canvas.setContent(pmg);
|
|
||||||
#if js
|
#if js
|
||||||
var pointercontainer = js.Browser.document.querySelector("#pointercontainer");
|
var pointercontainer = js.Browser.document.querySelector("#pointercontainer");
|
||||||
pointercontainer.hidden = false;
|
pointercontainer.hidden = false;
|
||||||
|
|
@ -1636,6 +1636,7 @@ class MarbleWorld extends Scheduler {
|
||||||
this.finishYaw = this.marble.camera.CameraYaw;
|
this.finishYaw = this.marble.camera.CameraYaw;
|
||||||
this.finishPitch = this.marble.camera.CameraPitch;
|
this.finishPitch = this.marble.camera.CameraPitch;
|
||||||
displayAlert("Congratulations! You've finished!");
|
displayAlert("Congratulations! You've finished!");
|
||||||
|
if (!this.isWatching)
|
||||||
this.schedule(this.timeState.currentAttemptTime + 2, () -> cast showFinishScreen());
|
this.schedule(this.timeState.currentAttemptTime + 2, () -> cast showFinishScreen());
|
||||||
// Stop the ongoing sounds
|
// Stop the ongoing sounds
|
||||||
if (timeTravelSound != null) {
|
if (timeTravelSound != null) {
|
||||||
|
|
@ -1650,16 +1651,17 @@ class MarbleWorld extends Scheduler {
|
||||||
}
|
}
|
||||||
|
|
||||||
function showFinishScreen() {
|
function showFinishScreen() {
|
||||||
|
if (this.isWatching)
|
||||||
|
return 0;
|
||||||
Console.log("State End");
|
Console.log("State End");
|
||||||
var egg:EndGameGui = null;
|
var egg:EndGameGui = null;
|
||||||
#if js
|
#if js
|
||||||
var pointercontainer = js.Browser.document.querySelector("#pointercontainer");
|
var pointercontainer = js.Browser.document.querySelector("#pointercontainer");
|
||||||
pointercontainer.hidden = false;
|
pointercontainer.hidden = false;
|
||||||
#end
|
#end
|
||||||
if (this.isRecording) {
|
this.schedule(this.timeState.currentAttemptTime + 3, () -> {
|
||||||
this.isRecording = false; // Stop recording here
|
this.isRecording = false; // Stop recording here
|
||||||
this.saveReplay();
|
}, "stopRecordingTimeout");
|
||||||
}
|
|
||||||
if (Util.isTouchDevice()) {
|
if (Util.isTouchDevice()) {
|
||||||
MarbleGame.instance.touchInput.setControlsEnabled(false);
|
MarbleGame.instance.touchInput.setControlsEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
@ -1667,6 +1669,7 @@ class MarbleWorld extends Scheduler {
|
||||||
if (Util.isTouchDevice()) {
|
if (Util.isTouchDevice()) {
|
||||||
MarbleGame.instance.touchInput.hideControls(@:privateAccess this.playGui.playGuiCtrl);
|
MarbleGame.instance.touchInput.hideControls(@:privateAccess this.playGui.playGuiCtrl);
|
||||||
}
|
}
|
||||||
|
var endGameCode = () -> {
|
||||||
this.dispose();
|
this.dispose();
|
||||||
var pmg = new PlayMissionGui();
|
var pmg = new PlayMissionGui();
|
||||||
PlayMissionGui.currentSelectionStatic = mission.index + 1;
|
PlayMissionGui.currentSelectionStatic = mission.index + 1;
|
||||||
|
|
@ -1674,7 +1677,14 @@ class MarbleWorld extends Scheduler {
|
||||||
#if js
|
#if js
|
||||||
pointercontainer.hidden = false;
|
pointercontainer.hidden = false;
|
||||||
#end
|
#end
|
||||||
|
}
|
||||||
|
if (MarbleGame.instance.toRecord) {
|
||||||
|
MarbleGame.canvas.pushDialog(new ReplayNameDlg(endGameCode));
|
||||||
|
} else {
|
||||||
|
endGameCode();
|
||||||
|
}
|
||||||
}, (sender) -> {
|
}, (sender) -> {
|
||||||
|
var restartGameCode = () -> {
|
||||||
MarbleGame.canvas.popDialog(egg);
|
MarbleGame.canvas.popDialog(egg);
|
||||||
this.setCursorLock(true);
|
this.setCursorLock(true);
|
||||||
this.restart(true);
|
this.restart(true);
|
||||||
|
|
@ -1685,6 +1695,27 @@ class MarbleWorld extends Scheduler {
|
||||||
MarbleGame.instance.touchInput.setControlsEnabled(true);
|
MarbleGame.instance.touchInput.setControlsEnabled(true);
|
||||||
}
|
}
|
||||||
// @:privateAccess playGui.playGuiCtrl.render(scene2d);
|
// @:privateAccess playGui.playGuiCtrl.render(scene2d);
|
||||||
|
}
|
||||||
|
if (MarbleGame.instance.toRecord) {
|
||||||
|
MarbleGame.canvas.pushDialog(new ReplayNameDlg(() -> {
|
||||||
|
this.isRecording = true;
|
||||||
|
restartGameCode();
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
restartGameCode();
|
||||||
|
}
|
||||||
|
}, (sender) -> {
|
||||||
|
var nextLevelCode = () -> {
|
||||||
|
var nextMission = mission.getNextMission();
|
||||||
|
if (nextMission != null) {
|
||||||
|
MarbleGame.instance.playMission(nextMission);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (MarbleGame.instance.toRecord) {
|
||||||
|
MarbleGame.canvas.pushDialog(new ReplayNameDlg(nextLevelCode));
|
||||||
|
} else {
|
||||||
|
nextLevelCode();
|
||||||
|
}
|
||||||
}, mission, finishTime);
|
}, mission, finishTime);
|
||||||
MarbleGame.canvas.pushDialog(egg);
|
MarbleGame.canvas.pushDialog(egg);
|
||||||
this.setCursorLock(false);
|
this.setCursorLock(false);
|
||||||
|
|
@ -1962,33 +1993,42 @@ class MarbleWorld extends Scheduler {
|
||||||
|
|
||||||
public function saveReplay() {
|
public function saveReplay() {
|
||||||
this.replay.name = MarbleGame.instance.recordingName;
|
this.replay.name = MarbleGame.instance.recordingName;
|
||||||
var replayBytes = this.replay.write();
|
|
||||||
#if hl
|
#if hl
|
||||||
// hxd.File.saveAs(replayBytes, {
|
|
||||||
// title: 'Save Replay',
|
|
||||||
// fileTypes: [
|
|
||||||
// {
|
|
||||||
// name: "Replay (*.mbr)",
|
|
||||||
// extensions: ["mbr"]
|
|
||||||
// }
|
|
||||||
// ],
|
|
||||||
// defaultPath: 'data/replay/${this.mission.title}${this.timeState.gameplayClock}.mbr'
|
|
||||||
// });
|
|
||||||
sys.FileSystem.createDirectory(haxe.io.Path.join([Settings.settingsDir, "data", "replays"]));
|
sys.FileSystem.createDirectory(haxe.io.Path.join([Settings.settingsDir, "data", "replays"]));
|
||||||
var replayPath = haxe.io.Path.join([
|
var replayPath = haxe.io.Path.join([
|
||||||
Settings.settingsDir,
|
Settings.settingsDir,
|
||||||
"data",
|
"data",
|
||||||
"replays",
|
"replays",
|
||||||
'${this.mission.title}${this.timeState.gameplayClock}.mbr'
|
'${this.replay.name}.mbr'
|
||||||
]);
|
]);
|
||||||
|
if (sys.FileSystem.exists(replayPath)) {
|
||||||
|
var count = 1;
|
||||||
|
var found = false;
|
||||||
|
while (!found) {
|
||||||
|
replayPath = haxe.io.Path.join([
|
||||||
|
Settings.settingsDir,
|
||||||
|
"data",
|
||||||
|
"replays",
|
||||||
|
'${this.replay.name} (${count}).mbr'
|
||||||
|
]);
|
||||||
|
if (!sys.FileSystem.exists(replayPath)) {
|
||||||
|
this.replay.name += ' (${count})';
|
||||||
|
found = true;
|
||||||
|
} else {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var replayBytes = this.replay.write();
|
||||||
sys.io.File.saveBytes(replayPath, replayBytes);
|
sys.io.File.saveBytes(replayPath, replayBytes);
|
||||||
#end
|
#end
|
||||||
#if js
|
#if js
|
||||||
|
var replayBytes = this.replay.write();
|
||||||
var blob = new js.html.Blob([replayBytes.getData()], {
|
var blob = new js.html.Blob([replayBytes.getData()], {
|
||||||
type: 'application/octet-stream'
|
type: 'application/octet-stream'
|
||||||
});
|
});
|
||||||
var url = js.html.URL.createObjectURL(blob);
|
var url = js.html.URL.createObjectURL(blob);
|
||||||
var fname = '${this.mission.title}${this.timeState.gameplayClock}.mbr';
|
var fname = '${this.replay.name}.mbr';
|
||||||
var element = js.Browser.document.createElement('a');
|
var element = js.Browser.document.createElement('a');
|
||||||
element.setAttribute('href', url);
|
element.setAttribute('href', url);
|
||||||
element.setAttribute('download', fname);
|
element.setAttribute('download', fname);
|
||||||
|
|
|
||||||
|
|
@ -442,6 +442,10 @@ class Replay {
|
||||||
Console.log("Replay loading failed: unknown version");
|
Console.log("Replay loading failed: unknown version");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (replayVersion < 5) { // first version with headers
|
||||||
|
Console.log('Replay loading failed: version ${replayVersion} does not have a header');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
var nameLength = data.get(1);
|
var nameLength = data.get(1);
|
||||||
this.name = data.getString(2, nameLength);
|
this.name = data.getString(2, nameLength);
|
||||||
var missionLength = data.get(2 + nameLength);
|
var missionLength = data.get(2 + nameLength);
|
||||||
|
|
@ -475,6 +479,10 @@ class Replay {
|
||||||
Console.log("Replay loading failed: unknown version");
|
Console.log("Replay loading failed: unknown version");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (replayVersion < 5) { // first version with headers
|
||||||
|
Console.log('Replay loading failed: version ${replayVersion} does not have a header');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
var nameLength = data.get(1);
|
var nameLength = data.get(1);
|
||||||
this.name = data.getString(2, nameLength);
|
this.name = data.getString(2, nameLength);
|
||||||
var missionLength = data.get(2 + nameLength);
|
var missionLength = data.get(2 + nameLength);
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ class EndGameGui extends GuiControl {
|
||||||
|
|
||||||
var scoreSubmitted:Bool = false;
|
var scoreSubmitted:Bool = false;
|
||||||
|
|
||||||
public function new(continueFunc:GuiControl->Void, restartFunc:GuiControl->Void, mission:Mission, timeState:TimeState) {
|
public function new(continueFunc:GuiControl->Void, restartFunc:GuiControl->Void, nextLevelFunc:GuiControl->Void, mission:Mission, timeState:TimeState) {
|
||||||
super();
|
super();
|
||||||
this.horizSizing = Width;
|
this.horizSizing = Width;
|
||||||
this.vertSizing = Height;
|
this.vertSizing = Height;
|
||||||
|
|
@ -77,12 +77,7 @@ class EndGameGui extends GuiControl {
|
||||||
nextLevelBtn.vertSizing = Height;
|
nextLevelBtn.vertSizing = Height;
|
||||||
nextLevelBtn.position = new Vector(0, 0);
|
nextLevelBtn.position = new Vector(0, 0);
|
||||||
nextLevelBtn.extent = new Vector(130, 110);
|
nextLevelBtn.extent = new Vector(130, 110);
|
||||||
nextLevelBtn.pressedAction = (e) -> {
|
nextLevelBtn.pressedAction = (e) -> nextLevelFunc(nextLevelBtn);
|
||||||
var nextMission = mission.getNextMission();
|
|
||||||
if (nextMission != null) {
|
|
||||||
cast(this.parent, Canvas).marbleGame.playMission(nextMission);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
nextLevel.addChild(nextLevelBtn);
|
nextLevel.addChild(nextLevelBtn);
|
||||||
|
|
||||||
function setButtonStates(enabled:Bool) {
|
function setButtonStates(enabled:Bool) {
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,8 @@ class PlayMissionGui extends GuiImage {
|
||||||
currentCategory = PlayMissionGui.currentCategoryStatic;
|
currentCategory = PlayMissionGui.currentCategoryStatic;
|
||||||
currentGame = PlayMissionGui.currentGameStatic;
|
currentGame = PlayMissionGui.currentGameStatic;
|
||||||
|
|
||||||
|
MarbleGame.instance.toRecord = false;
|
||||||
|
|
||||||
function chooseBg() {
|
function chooseBg() {
|
||||||
if (currentGame == "gold")
|
if (currentGame == "gold")
|
||||||
return ResourceLoader.getImage('data/ui/backgrounds/gold/${cast (Math.floor(Util.lerp(1, 12, Math.random())), Int)}.jpg');
|
return ResourceLoader.getImage('data/ui/backgrounds/gold/${cast (Math.floor(Util.lerp(1, 12, Math.random())), Int)}.jpg');
|
||||||
|
|
@ -667,7 +669,8 @@ class PlayMissionGui extends GuiImage {
|
||||||
pmRecord.position = new Vector(247, 46);
|
pmRecord.position = new Vector(247, 46);
|
||||||
pmRecord.extent = new Vector(43, 43);
|
pmRecord.extent = new Vector(43, 43);
|
||||||
pmRecord.pressedAction = (sender) -> {
|
pmRecord.pressedAction = (sender) -> {
|
||||||
cast(this.parent, Canvas).pushDialog(new ReplayNameDlg());
|
MarbleGame.instance.toRecord = true;
|
||||||
|
MarbleGame.canvas.pushDialog(new MessageBoxOkDlg("The next mission you play will be recorded."));
|
||||||
};
|
};
|
||||||
pmMorePopDlg.addChild(pmRecord);
|
pmMorePopDlg.addChild(pmRecord);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import src.ResourceLoader;
|
||||||
import src.Settings;
|
import src.Settings;
|
||||||
|
|
||||||
class ReplayNameDlg extends GuiControl {
|
class ReplayNameDlg extends GuiControl {
|
||||||
public function new() {
|
public function new(callback:Void->Void) {
|
||||||
super();
|
super();
|
||||||
var text = "Enter a name for the recording";
|
var text = "Enter a name for the recording";
|
||||||
this.horizSizing = Width;
|
this.horizSizing = Width;
|
||||||
|
|
@ -59,6 +59,13 @@ class ReplayNameDlg extends GuiControl {
|
||||||
textInput.text.selectionTile = h2d.Tile.fromColor(0x808080, 0, hxd.Math.ceil(textInput.text.font.lineHeight));
|
textInput.text.selectionTile = h2d.Tile.fromColor(0x808080, 0, hxd.Math.ceil(textInput.text.font.lineHeight));
|
||||||
textFrame.addChild(textInput);
|
textFrame.addChild(textInput);
|
||||||
|
|
||||||
|
textInput.text.text = MarbleGame.instance.world.mission.title;
|
||||||
|
if (MarbleGame.instance.world.finishTime == null) {
|
||||||
|
textInput.text.text += " Unfinished Run";
|
||||||
|
} else {
|
||||||
|
textInput.text.text += " " + MarbleGame.instance.world.finishTime.gameplayClock;
|
||||||
|
}
|
||||||
|
|
||||||
var yesButton = new GuiButton(loadButtonImages("data/ui/common/ok"));
|
var yesButton = new GuiButton(loadButtonImages("data/ui/common/ok"));
|
||||||
yesButton.position = new Vector(171, 124);
|
yesButton.position = new Vector(171, 124);
|
||||||
yesButton.extent = new Vector(95, 45);
|
yesButton.extent = new Vector(95, 45);
|
||||||
|
|
@ -66,9 +73,10 @@ class ReplayNameDlg extends GuiControl {
|
||||||
yesButton.accelerator = hxd.Key.ENTER;
|
yesButton.accelerator = hxd.Key.ENTER;
|
||||||
yesButton.pressedAction = (sender) -> {
|
yesButton.pressedAction = (sender) -> {
|
||||||
if (StringTools.trim(textInput.text.text) != "") {
|
if (StringTools.trim(textInput.text.text) != "") {
|
||||||
MarbleGame.instance.toRecord = true;
|
|
||||||
MarbleGame.instance.recordingName = textInput.text.text;
|
MarbleGame.instance.recordingName = textInput.text.text;
|
||||||
MarbleGame.canvas.popDialog(this);
|
MarbleGame.canvas.popDialog(this);
|
||||||
|
MarbleGame.instance.world.saveReplay();
|
||||||
|
callback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
yesNoFrame.addChild(yesButton);
|
yesNoFrame.addChild(yesButton);
|
||||||
|
|
@ -80,6 +88,7 @@ class ReplayNameDlg extends GuiControl {
|
||||||
noButton.accelerator = hxd.Key.ESCAPE;
|
noButton.accelerator = hxd.Key.ESCAPE;
|
||||||
noButton.pressedAction = (sender) -> {
|
noButton.pressedAction = (sender) -> {
|
||||||
MarbleGame.canvas.popDialog(this);
|
MarbleGame.canvas.popDialog(this);
|
||||||
|
callback();
|
||||||
}
|
}
|
||||||
yesNoFrame.addChild(noButton);
|
yesNoFrame.addChild(noButton);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue