From fa92b6d1af7144e053e52f75d59bba310f7ac359 Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Fri, 28 Jun 2024 00:51:53 +0530 Subject: [PATCH] some js and minor fixes --- src/CameraController.hx | 3 ++- src/Marble.hx | 5 ++++- src/MarbleWorld.hx | 29 +++++++++++++++++++---------- src/ResourceLoader.hx | 18 ++++++++++++++++-- src/gui/MPEndGameGui.hx | 7 +++++++ src/gui/MPPlayMissionGui.hx | 1 + src/gui/MPPreGameDlg.hx | 19 ++++++++++++++----- src/gui/MainMenuGui.hx | 1 + src/modes/HuntMode.hx | 8 ++++++-- src/net/MasterServerClient.hx | 8 ++++---- 10 files changed, 74 insertions(+), 25 deletions(-) diff --git a/src/CameraController.hx b/src/CameraController.hx index 82c42207..1e418c21 100644 --- a/src/CameraController.hx +++ b/src/CameraController.hx @@ -92,7 +92,8 @@ class CameraController extends Object { // level.scene.addEventListener(onEvent); // Sdl.setRelativeMouseMode(true); level.scene.camera.setFovX(Settings.optionsSettings.fovX, Settings.optionsSettings.screenWidth / Settings.optionsSettings.screenHeight); - lockCursor(); + if (!Net.isMP) + lockCursor(); } public function lockCursor() { diff --git a/src/Marble.hx b/src/Marble.hx index 0cf0e41d..f492c8d5 100644 --- a/src/Marble.hx +++ b/src/Marble.hx @@ -1642,11 +1642,14 @@ class Marble extends GameObject { prevRot = this.getRotationQuat().clone(); // Handle spectator hacky bullshit - if (Net.isMP) { + if (Net.isMP && this.level.serverStartTicks != 0) { if ((connection != null && connection.spectator) || (connection == null && (Net.hostSpectate || Net.clientSpectate))) { this.collider.transform.setPosition(new Vector(1e8, 1e8, 1e8)); this.collisionWorld.updateTransform(this.collider); this.setPosition(1e8, 1e8, 1e8); + + if (Net.clientSpectate && this.connection == null) + this.camera.enableSpectate(); return; } } diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index 7f396730..69692102 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -369,12 +369,12 @@ class MarbleWorld extends Scheduler { if (this.isMultiplayer) { // Add us if (Net.isHost) { - this.playGui.addPlayer(0, Settings.highscoreName.substr(0, 15), true); + this.playGui.addPlayer(0, (Net.hostSpectate ? "[S] " : "") + Settings.highscoreName.substr(0, 15), true); } else { - this.playGui.addPlayer(Net.clientId, Settings.highscoreName.substr(0, 15), true); + this.playGui.addPlayer(Net.clientId, (Net.clientSpectate ? "[S] " : "") + Settings.highscoreName.substr(0, 15), true); } for (client in Net.clientIdMap) { - this.playGui.addPlayer(client.id, client.name.substr(0, 15), false); + this.playGui.addPlayer(client.id, (client.spectator ? "[S] " : "") + client.name.substr(0, 15), false); } } @@ -503,7 +503,7 @@ class MarbleWorld extends Scheduler { "shapes/items/gemshine.png", "shapes/items/enviro1.jpg", ]; - if (this.game == "ultra") { + if (this.game == "ultra" || Net.isMP) { marblefiles.push("shapes/balls/pack1/marble20.normal.png"); marblefiles.push("shapes/balls/pack1/marble18.normal.png"); marblefiles.push("shapes/balls/pack1/marble01.normal.png"); @@ -512,15 +512,23 @@ class MarbleWorld extends Scheduler { // Hacky if (client == null) { marblefiles.push(StringTools.replace(Settings.optionsSettings.marbleModel, "data/", "")); + + if (Settings.optionsSettings.marbleCategoryIndex == 0) + marblefiles.push("shapes/balls/" + Settings.optionsSettings.marbleSkin + ".marble.png"); + else + marblefiles.push("shapes/balls/pack1/" + Settings.optionsSettings.marbleSkin + ".marble.png"); } else { var marbleDts = MarbleSelectGui.marbleData[client.getMarbleCatId()][client.getMarbleId()].dts; // FIXME marblefiles.push(StringTools.replace(marbleDts, "data/", "")); + + var marbleSkin = MarbleSelectGui.marbleData[client.getMarbleCatId()][client.getMarbleId()].skin; + + if (client.getMarbleCatId() == 0) + marblefiles.push("shapes/balls/" + marbleSkin + ".marble.png"); + else + marblefiles.push("shapes/balls/pack1/" + marbleSkin + ".marble.png"); } - if (Settings.optionsSettings.marbleCategoryIndex == 0) - marblefiles.push("shapes/balls/" + Settings.optionsSettings.marbleSkin + ".marble.png"); - else - marblefiles.push("shapes/balls/pack1/" + Settings.optionsSettings.marbleSkin + ".marble.png"); var gameModeFiles = this.gameMode.getPreloadFiles(); for (file in marblefiles) { worker.loadFile(file); @@ -571,6 +579,7 @@ class MarbleWorld extends Scheduler { showPreGame(); } else { _skipPreGame = false; + this.setCursorLock(true); NetCommands.requestMidGameJoinState(Net.clientId); } } @@ -587,7 +596,7 @@ class MarbleWorld extends Scheduler { this.initMarble(cc, () -> { var addedMarble = clientMarbles.get(cc); this.restart(addedMarble); // spawn it - this.playGui.addPlayer(cc.id, cc.getName(), false); + this.playGui.addPlayer(cc.id, (cc.spectator ? "[S] " : "") + cc.getName(), false); this.playGui.redrawPlayerList(); // Sort all the marbles so that they are updated in a deterministic order @@ -604,7 +613,7 @@ class MarbleWorld extends Scheduler { this.initMarble(cc, () -> { var addedMarble = clientMarbles.get(cc); this.restart(addedMarble); // spawn it - this.playGui.addPlayer(cc.id, cc.getName(), false); + this.playGui.addPlayer(cc.id, (cc.spectator ? "[S] " : "") + cc.getName(), false); this.playGui.redrawPlayerList(); // Sort all the marbles so that they are updated in a deterministic order diff --git a/src/ResourceLoader.hx b/src/ResourceLoader.hx index 1bc8a472..8e543cb6 100644 --- a/src/ResourceLoader.hx +++ b/src/ResourceLoader.hx @@ -129,7 +129,10 @@ class ResourceLoader { } while (toloaddirs.length > 0) { var nextdir = toloaddirs.pop(); - for (file in fileSystem.dir(nextdir.path.substring(2))) { + var pathToSearch = nextdir.path; + if (StringTools.startsWith(pathToSearch, "./")) + pathToSearch = pathToSearch.substring(2); + for (file in fileSystem.dir(pathToSearch)) { if (file.isDirectory) { toloaddirs.push(file); } else { @@ -179,9 +182,20 @@ class ResourceLoader { toloadfiles.push(file); } } + filestats = fileSystem.dir("multiplayer/hunt"); + for (file in filestats) { + if (file.isDirectory) { + toloaddirs.push(file); + } else { + toloadfiles.push(file); + } + } while (toloaddirs.length > 0) { var nextdir = toloaddirs.pop(); - for (file in fileSystem.dir(nextdir.path.substring(2))) { + var pathToSearch = nextdir.path; + if (StringTools.startsWith(pathToSearch, "./")) + pathToSearch = pathToSearch.substring(2); + for (file in fileSystem.dir(pathToSearch)) { if (file.isDirectory) { toloaddirs.push(file); } else { diff --git a/src/gui/MPEndGameGui.hx b/src/gui/MPEndGameGui.hx index 94cf6122..1ac4902d 100644 --- a/src/gui/MPEndGameGui.hx +++ b/src/gui/MPEndGameGui.hx @@ -125,6 +125,13 @@ class MPEndGameGui extends GuiImage { exitBtn.extent = new Vector(49, 49); exitBtn.vertSizing = Top; exitBtn.horizSizing = Left; + exitBtn.pressedAction = (e) -> { + MarbleGame.canvas.popDialog(this); + MarbleGame.instance.paused = false; + MarbleGame.instance.quitMission(); + Net.disconnect(); + MarbleGame.canvas.setContent(new JoinServerGui()); + } sidebar.addChild(exitBtn); var middleCtrl = new GuiControl(); diff --git a/src/gui/MPPlayMissionGui.hx b/src/gui/MPPlayMissionGui.hx index 1eb71338..5f32e139 100644 --- a/src/gui/MPPlayMissionGui.hx +++ b/src/gui/MPPlayMissionGui.hx @@ -18,6 +18,7 @@ import src.MissionList; import net.ClientConnection.NetPlatform; import net.Net; import net.NetCommands; +import haxe.ds.Option; class MPPlayMissionGui extends GuiImage { static var currentSelectionStatic:Int = -1; diff --git a/src/gui/MPPreGameDlg.hx b/src/gui/MPPreGameDlg.hx index bfef6360..faebbeeb 100644 --- a/src/gui/MPPreGameDlg.hx +++ b/src/gui/MPPreGameDlg.hx @@ -51,7 +51,7 @@ class MPPreGameDlg extends GuiControl { dialogImg.extent = new Vector(640, 480); this.addChild(dialogImg); - var leaveBtn = new GuiButton(loadButtonImages("/data/ui/mp/pre/leave")); + var leaveBtn = new GuiButton(loadButtonImages("data/ui/mp/pre/leave")); leaveBtn.horizSizing = Left; leaveBtn.vertSizing = Top; leaveBtn.position = new Vector(499, 388); @@ -61,7 +61,7 @@ class MPPreGameDlg extends GuiControl { } dialogImg.addChild(leaveBtn); - var playBtn = new GuiButton(loadButtonImagesExt("/data/ui/mp/pre/play")); + var playBtn = new GuiButton(loadButtonImagesExt("data/ui/mp/pre/play")); playBtn.horizSizing = Right; playBtn.vertSizing = Top; playBtn.position = new Vector(406, 388); @@ -72,6 +72,15 @@ class MPPreGameDlg extends GuiControl { for (id => client in Net.clientIdMap) { client.state = GAME; } + if (Settings.serverSettings.forceSpectators) { + for (id => client in Net.clientIdMap) { + client.spectator = true; // Make them spectator + } + } + var b = Net.sendPlayerInfosBytes(); // Update spectator status + for (cc in Net.clients) { + cc.sendBytes(b); + } if (MarbleGame.instance.world != null) { Console.log('All are ready, starting'); @@ -83,7 +92,7 @@ class MPPreGameDlg extends GuiControl { if (Net.isHost) dialogImg.addChild(playBtn); - var readyBtn = new GuiButton(loadButtonImages("/data/ui/mp/pre/ready")); + var readyBtn = new GuiButton(loadButtonImages("data/ui/mp/pre/ready")); readyBtn.horizSizing = Right; readyBtn.vertSizing = Top; readyBtn.position = new Vector(53, 394); @@ -91,7 +100,7 @@ class MPPreGameDlg extends GuiControl { readyBtn.buttonType = Toggle; dialogImg.addChild(readyBtn); - var kickBtn = new GuiButton(loadButtonImages("/data/ui/mp/play/kick")); + var kickBtn = new GuiButton(loadButtonImages("data/ui/mp/play/kick")); kickBtn.horizSizing = Right; kickBtn.vertSizing = Bottom; kickBtn.position = new Vector(360, 388); @@ -102,7 +111,7 @@ class MPPreGameDlg extends GuiControl { if (Net.isHost) dialogImg.addChild(kickBtn); - var spectateBtn = new GuiButton(loadButtonImages("/data/ui/mp/pre/spectate")); + var spectateBtn = new GuiButton(loadButtonImages("data/ui/mp/pre/spectate")); spectateBtn.horizSizing = Right; spectateBtn.vertSizing = Top; spectateBtn.position = new Vector(190, 394); diff --git a/src/gui/MainMenuGui.hx b/src/gui/MainMenuGui.hx index 59452c53..e4f9e5fe 100644 --- a/src/gui/MainMenuGui.hx +++ b/src/gui/MainMenuGui.hx @@ -10,6 +10,7 @@ import src.Settings; import src.Util; import src.Replay; import src.Marbleland; +import src.MissionList; class MainMenuGui extends GuiImage { public function new() { diff --git a/src/modes/HuntMode.hx b/src/modes/HuntMode.hx index 8eb356b4..e9d67329 100644 --- a/src/modes/HuntMode.hx +++ b/src/modes/HuntMode.hx @@ -192,6 +192,10 @@ class HuntMode extends NullMode { } } + override function getPreloadFiles() { + return ['data/sound/opponentdiamond.wav']; + } + function setupGems() { hideExisting(); this.activeGems = []; @@ -223,7 +227,7 @@ class HuntMode extends NullMode { var furthest = null; for (i in 0...6) { - var gem = gemSpawnPoints[rng.randRange(0, gemSpawnPoints.length - 1)]; + var gem = gemSpawnPoints[Std.int(rng.randRange(0, gemSpawnPoints.length - 1))]; if (lastPos != null) { var dist = gem.gem.getAbsPos().getPosition().distance(lastPos); if (dist < spawnBlock) { @@ -241,7 +245,7 @@ class HuntMode extends NullMode { } } if (furthest == null) { - furthest = gemSpawnPoints[rng.randRange(0, gemSpawnPoints.length - 1)]; + furthest = gemSpawnPoints[Std.int(rng.randRange(0, gemSpawnPoints.length - 1))]; } var pos = furthest.gem.getAbsPos().getPosition(); diff --git a/src/net/MasterServerClient.hx b/src/net/MasterServerClient.hx index 289f434c..fa746fd9 100644 --- a/src/net/MasterServerClient.hx +++ b/src/net/MasterServerClient.hx @@ -20,11 +20,11 @@ typedef RemoteServerInfo = { } class MasterServerClient { - #if js - static var serverIp = "wss://mbomaster.randomityguy.me:8443"; - #else + // #if js + // static var serverIp = "wss://mbomaster.randomityguy.me:8443"; + // #else static var serverIp = "ws://89.58.58.191:8084"; - #end + // #end public static var instance:MasterServerClient; var ws:WebSocket;