some js and minor fixes

This commit is contained in:
RandomityGuy 2024-06-28 00:51:53 +05:30
parent 3a928a6014
commit fa92b6d1af
10 changed files with 74 additions and 25 deletions

View file

@ -92,7 +92,8 @@ class CameraController extends Object {
// level.scene.addEventListener(onEvent); // level.scene.addEventListener(onEvent);
// Sdl.setRelativeMouseMode(true); // Sdl.setRelativeMouseMode(true);
level.scene.camera.setFovX(Settings.optionsSettings.fovX, Settings.optionsSettings.screenWidth / Settings.optionsSettings.screenHeight); level.scene.camera.setFovX(Settings.optionsSettings.fovX, Settings.optionsSettings.screenWidth / Settings.optionsSettings.screenHeight);
lockCursor(); if (!Net.isMP)
lockCursor();
} }
public function lockCursor() { public function lockCursor() {

View file

@ -1642,11 +1642,14 @@ class Marble extends GameObject {
prevRot = this.getRotationQuat().clone(); prevRot = this.getRotationQuat().clone();
// Handle spectator hacky bullshit // 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))) { if ((connection != null && connection.spectator) || (connection == null && (Net.hostSpectate || Net.clientSpectate))) {
this.collider.transform.setPosition(new Vector(1e8, 1e8, 1e8)); this.collider.transform.setPosition(new Vector(1e8, 1e8, 1e8));
this.collisionWorld.updateTransform(this.collider); this.collisionWorld.updateTransform(this.collider);
this.setPosition(1e8, 1e8, 1e8); this.setPosition(1e8, 1e8, 1e8);
if (Net.clientSpectate && this.connection == null)
this.camera.enableSpectate();
return; return;
} }
} }

View file

@ -369,12 +369,12 @@ class MarbleWorld extends Scheduler {
if (this.isMultiplayer) { if (this.isMultiplayer) {
// Add us // Add us
if (Net.isHost) { 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 { } 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) { 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/gemshine.png",
"shapes/items/enviro1.jpg", "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/marble20.normal.png");
marblefiles.push("shapes/balls/pack1/marble18.normal.png"); marblefiles.push("shapes/balls/pack1/marble18.normal.png");
marblefiles.push("shapes/balls/pack1/marble01.normal.png"); marblefiles.push("shapes/balls/pack1/marble01.normal.png");
@ -512,15 +512,23 @@ class MarbleWorld extends Scheduler {
// Hacky // Hacky
if (client == null) { if (client == null) {
marblefiles.push(StringTools.replace(Settings.optionsSettings.marbleModel, "data/", "")); 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 { } else {
var marbleDts = MarbleSelectGui.marbleData[client.getMarbleCatId()][client.getMarbleId()].dts; // FIXME var marbleDts = MarbleSelectGui.marbleData[client.getMarbleCatId()][client.getMarbleId()].dts; // FIXME
marblefiles.push(StringTools.replace(marbleDts, "data/", "")); 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(); var gameModeFiles = this.gameMode.getPreloadFiles();
for (file in marblefiles) { for (file in marblefiles) {
worker.loadFile(file); worker.loadFile(file);
@ -571,6 +579,7 @@ class MarbleWorld extends Scheduler {
showPreGame(); showPreGame();
} else { } else {
_skipPreGame = false; _skipPreGame = false;
this.setCursorLock(true);
NetCommands.requestMidGameJoinState(Net.clientId); NetCommands.requestMidGameJoinState(Net.clientId);
} }
} }
@ -587,7 +596,7 @@ class MarbleWorld extends Scheduler {
this.initMarble(cc, () -> { this.initMarble(cc, () -> {
var addedMarble = clientMarbles.get(cc); var addedMarble = clientMarbles.get(cc);
this.restart(addedMarble); // spawn it 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(); this.playGui.redrawPlayerList();
// Sort all the marbles so that they are updated in a deterministic order // Sort all the marbles so that they are updated in a deterministic order
@ -604,7 +613,7 @@ class MarbleWorld extends Scheduler {
this.initMarble(cc, () -> { this.initMarble(cc, () -> {
var addedMarble = clientMarbles.get(cc); var addedMarble = clientMarbles.get(cc);
this.restart(addedMarble); // spawn it 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(); this.playGui.redrawPlayerList();
// Sort all the marbles so that they are updated in a deterministic order // Sort all the marbles so that they are updated in a deterministic order

View file

@ -129,7 +129,10 @@ class ResourceLoader {
} }
while (toloaddirs.length > 0) { while (toloaddirs.length > 0) {
var nextdir = toloaddirs.pop(); 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) { if (file.isDirectory) {
toloaddirs.push(file); toloaddirs.push(file);
} else { } else {
@ -179,9 +182,20 @@ class ResourceLoader {
toloadfiles.push(file); 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) { while (toloaddirs.length > 0) {
var nextdir = toloaddirs.pop(); 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) { if (file.isDirectory) {
toloaddirs.push(file); toloaddirs.push(file);
} else { } else {

View file

@ -125,6 +125,13 @@ class MPEndGameGui extends GuiImage {
exitBtn.extent = new Vector(49, 49); exitBtn.extent = new Vector(49, 49);
exitBtn.vertSizing = Top; exitBtn.vertSizing = Top;
exitBtn.horizSizing = Left; 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); sidebar.addChild(exitBtn);
var middleCtrl = new GuiControl(); var middleCtrl = new GuiControl();

View file

@ -18,6 +18,7 @@ import src.MissionList;
import net.ClientConnection.NetPlatform; import net.ClientConnection.NetPlatform;
import net.Net; import net.Net;
import net.NetCommands; import net.NetCommands;
import haxe.ds.Option;
class MPPlayMissionGui extends GuiImage { class MPPlayMissionGui extends GuiImage {
static var currentSelectionStatic:Int = -1; static var currentSelectionStatic:Int = -1;

View file

@ -51,7 +51,7 @@ class MPPreGameDlg extends GuiControl {
dialogImg.extent = new Vector(640, 480); dialogImg.extent = new Vector(640, 480);
this.addChild(dialogImg); 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.horizSizing = Left;
leaveBtn.vertSizing = Top; leaveBtn.vertSizing = Top;
leaveBtn.position = new Vector(499, 388); leaveBtn.position = new Vector(499, 388);
@ -61,7 +61,7 @@ class MPPreGameDlg extends GuiControl {
} }
dialogImg.addChild(leaveBtn); 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.horizSizing = Right;
playBtn.vertSizing = Top; playBtn.vertSizing = Top;
playBtn.position = new Vector(406, 388); playBtn.position = new Vector(406, 388);
@ -72,6 +72,15 @@ class MPPreGameDlg extends GuiControl {
for (id => client in Net.clientIdMap) { for (id => client in Net.clientIdMap) {
client.state = GAME; 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) { if (MarbleGame.instance.world != null) {
Console.log('All are ready, starting'); Console.log('All are ready, starting');
@ -83,7 +92,7 @@ class MPPreGameDlg extends GuiControl {
if (Net.isHost) if (Net.isHost)
dialogImg.addChild(playBtn); 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.horizSizing = Right;
readyBtn.vertSizing = Top; readyBtn.vertSizing = Top;
readyBtn.position = new Vector(53, 394); readyBtn.position = new Vector(53, 394);
@ -91,7 +100,7 @@ class MPPreGameDlg extends GuiControl {
readyBtn.buttonType = Toggle; readyBtn.buttonType = Toggle;
dialogImg.addChild(readyBtn); 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.horizSizing = Right;
kickBtn.vertSizing = Bottom; kickBtn.vertSizing = Bottom;
kickBtn.position = new Vector(360, 388); kickBtn.position = new Vector(360, 388);
@ -102,7 +111,7 @@ class MPPreGameDlg extends GuiControl {
if (Net.isHost) if (Net.isHost)
dialogImg.addChild(kickBtn); 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.horizSizing = Right;
spectateBtn.vertSizing = Top; spectateBtn.vertSizing = Top;
spectateBtn.position = new Vector(190, 394); spectateBtn.position = new Vector(190, 394);

View file

@ -10,6 +10,7 @@ import src.Settings;
import src.Util; import src.Util;
import src.Replay; import src.Replay;
import src.Marbleland; import src.Marbleland;
import src.MissionList;
class MainMenuGui extends GuiImage { class MainMenuGui extends GuiImage {
public function new() { public function new() {

View file

@ -192,6 +192,10 @@ class HuntMode extends NullMode {
} }
} }
override function getPreloadFiles() {
return ['data/sound/opponentdiamond.wav'];
}
function setupGems() { function setupGems() {
hideExisting(); hideExisting();
this.activeGems = []; this.activeGems = [];
@ -223,7 +227,7 @@ class HuntMode extends NullMode {
var furthest = null; var furthest = null;
for (i in 0...6) { 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) { if (lastPos != null) {
var dist = gem.gem.getAbsPos().getPosition().distance(lastPos); var dist = gem.gem.getAbsPos().getPosition().distance(lastPos);
if (dist < spawnBlock) { if (dist < spawnBlock) {
@ -241,7 +245,7 @@ class HuntMode extends NullMode {
} }
} }
if (furthest == null) { 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(); var pos = furthest.gem.getAbsPos().getPosition();

View file

@ -20,11 +20,11 @@ typedef RemoteServerInfo = {
} }
class MasterServerClient { class MasterServerClient {
#if js // #if js
static var serverIp = "wss://mbomaster.randomityguy.me:8443"; // static var serverIp = "wss://mbomaster.randomityguy.me:8443";
#else // #else
static var serverIp = "ws://89.58.58.191:8084"; static var serverIp = "ws://89.58.58.191:8084";
#end // #end
public static var instance:MasterServerClient; public static var instance:MasterServerClient;
var ws:WebSocket; var ws:WebSocket;