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);
// Sdl.setRelativeMouseMode(true);
level.scene.camera.setFovX(Settings.optionsSettings.fovX, Settings.optionsSettings.screenWidth / Settings.optionsSettings.screenHeight);
lockCursor();
if (!Net.isMP)
lockCursor();
}
public function lockCursor() {

View file

@ -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;
}
}

View file

@ -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

View file

@ -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 {

View file

@ -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();

View file

@ -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;

View file

@ -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);

View file

@ -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() {

View file

@ -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();

View file

@ -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;