Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Commit

Permalink
refactor+cleanup: a lot of client clean ups and refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
leia-uwu committed Mar 3, 2024
1 parent 717cf05 commit b03d0b4
Show file tree
Hide file tree
Showing 61 changed files with 3,782 additions and 3,564 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@typescript-eslint/prefer-nullish-coalescing": 0,
"@typescript-eslint/no-this-alias": 0,
"@typescript-eslint/no-floating-promises": 0,
"@typescript-eslint/no-dynamic-delete": 0
"@typescript-eslint/no-dynamic-delete": 0,
"@typescript-eslint/no-extraneous-class": 0
}
}
8 changes: 3 additions & 5 deletions client/src/account.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import $ from "jquery";
import api from "./api";
import loadouts from "./loadouts";
import { api } from "./api";
import loadouts from "./ui/loadouts";
import { util } from "../../shared/utils/util";

function ajaxRequest(url, data, cb) {
Expand Down Expand Up @@ -33,7 +33,7 @@ function ajaxRequest(url, data, cb) {
});
}

class Account {
export class Account {
constructor(t) {
const r = this;
this.config = t;
Expand Down Expand Up @@ -450,5 +450,3 @@ class Account {
);
}
}

export default Account;
2 changes: 1 addition & 1 deletion client/src/ambiance.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { math } from "../../shared/utils/math";

export default class Ambiance {
export class Ambiance {
constructor() {
const _this = this;
this.introMusic = true;
Expand Down
5 changes: 3 additions & 2 deletions client/src/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import device from "./device";
export default {
import { device } from "./device";

export const api = {
resolveUrl: function(e) {
if (device.webview && device.version < "1.0.8") {
return `${window.location.protocol}https://surviv.io/${e[0] == "/" ? e.substring(1) : e
Expand Down
28 changes: 14 additions & 14 deletions client/src/audioManager.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { math } from "../../shared/utils/math";
import { util } from "../../shared/utils/util";
import { v2 } from "../../shared/utils/v2";
import createJS from "./createJS";
import { CreateJS } from "./createJS";
import soundDefs from "./soundDefs";

const AudioManagerMinAllowedVolume = 0.003;
const DiffLayerMult = 0.5;

export default class AudioManager {
export class AudioManager {
constructor(options) {
this.mute = false;
this.masterVolume = 1;
Expand All @@ -21,8 +21,8 @@ export default class AudioManager {
this.activeLayer = 0;
this.underground = false;
this.soundInstances = [];
createJS.Sound.volume = 0.5;
createJS.Sound.on("fileload", this.loadHandler, this);
CreateJS.Sound.volume = 0.5;
CreateJS.Sound.on("fileload", this.loadHandler, this);
}

preloadSounds() {
Expand Down Expand Up @@ -106,15 +106,15 @@ export default class AudioManager {
) {
const key = reverbKeys[i];
const reverb = reverbs[key];
createJS.Sound.registerReverb(reverb.path, key, reverb);
CreateJS.Sound.registerReverb(reverb.path, key, reverb);
}
}
}

loadSound(sound) {
const name = sound.name + sound.channel;
if (!this.sounds[name]) {
createJS.Sound.registerSound(sound.path, name, sound.options || {});
CreateJS.Sound.registerSound(sound.path, name, sound.options || {});
this.sounds[name] = {
path: sound.path,
name: sound.name,
Expand Down Expand Up @@ -143,11 +143,11 @@ export default class AudioManager {
// Update reverb, simply based on the current terrain layer
const layerVolumeMap = [0, 1, 1 / 3, 2 / 3];
const reverbVolume = this.underground ? layerVolumeMap[this.activeLayer] : 0;
createJS.Sound.setReverbs({
CreateJS.Sound.setReverbs({
cathedral: reverbVolume
});
// Update the audio backend
createJS.Sound.update(dt);
CreateJS.Sound.update(dt);
}

playSound(sound, options = {}) {
Expand Down Expand Up @@ -202,7 +202,7 @@ export default class AudioManager {
options.ignoreMinAllowable
) {
const stereoNorm = math.clamp((diff.x / range) * -1, -1, 1);
instance = createJS.Sound.play(sound + options.channel, {
instance = CreateJS.Sound.play(sound + options.channel, {
filter,
loop: options.loop ? -1 : 0,
volume: options.startSilent ? 0 : clipVolume,
Expand All @@ -216,7 +216,7 @@ export default class AudioManager {
} else {
let clipVolume = a.volume * baseVolume;
clipVolume = diffLayer ? clipVolume * DiffLayerMult : clipVolume;
instance = createJS.Sound.play(sound + options.channel, {
instance = CreateJS.Sound.play(sound + options.channel, {
filter,
loop: options.loop ? -1 : 0,
volume: options.startSilent ? 0 : clipVolume,
Expand Down Expand Up @@ -285,7 +285,7 @@ export default class AudioManager {

setMasterVolume(volume) {
volume = math.clamp(volume, 0, 1);
createJS.Sound.volume = volume;
CreateJS.Sound.volume = volume;
}

_setInstanceTypeVolume(type, volume) {
Expand Down Expand Up @@ -331,7 +331,7 @@ export default class AudioManager {

setMute(mute) {
this.mute = mute;
createJS.Sound.setMute(this.mute);
CreateJS.Sound.setMute(this.mute);
return this.mute;
}

Expand All @@ -350,7 +350,7 @@ export default class AudioManager {
}

stopAll() {
createJS.Sound.stop();
CreateJS.Sound.stop();
}

allLoaded() {
Expand All @@ -374,7 +374,7 @@ export default class AudioManager {
}

isSoundPlaying(inst) {
return !!inst && inst.playState == createJS.Sound.PLAY_SUCCEEDED;
return !!inst && inst.playState == CreateJS.Sound.PLAY_SUCCEEDED;
}

getSoundDefVolume(sound, channel) {
Expand Down
63 changes: 35 additions & 28 deletions client/src/camera.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import { math } from "../../shared/utils/math";
import { v2 } from "../../shared/utils/v2";

export default function Camera() {
this.I = 0;
this.pos = v2.create(0, 0);
this.ppu = 16;
this.O = 1.5;
this.q = 1.5;
this.screenWidth = 1;
this.screenHeight = 1;
this.shakeEnabled = true;
this.shakeInt = 0;
}
export class Camera {
constructor() {
this.I = 0;
this.pos = v2.create(0, 0);
this.ppu = 16;
this.O = 1.5;
this.q = 1.5;
this.screenWidth = 1;
this.screenHeight = 1;
this.shakeEnabled = true;
this.shakeInt = 0;
}

Camera.prototype = {
z: function() {
z() {
return this.ppu * this.O;
},
pointToScreen: function(e) {
}

pointToScreen(e) {
return {
x:
this.screenWidth * 0.5 +
Expand All @@ -26,8 +27,9 @@ Camera.prototype = {
this.screenHeight * 0.5 -
(e.y - this.pos.y) * this.z()
};
},
j: function(e) {
}

j(e) {
return {
x:
this.pos.x +
Expand All @@ -36,22 +38,27 @@ Camera.prototype = {
this.pos.y +
(this.screenHeight * 0.5 - e.y) / this.z()
};
},
pixels: function(e) {
}

pixels(e) {
return e * this.O;
},
scaleToScreen: function(e) {
}

scaleToScreen(e) {
return e * this.z();
},
setShakeEnabled: function(e) {
}

setShakeEnabled(e) {
this.shakeEnabled = e;
},
addShake: function(e, t) {
}

addShake(e, t) {
const r = v2.length(v2.sub(this.pos, e));
const a = math.delerp(r, 40, 10) * t;
this.shakeInt = Math.max(this.shakeInt, a);
},
applyShake: function() {
}

applyShake() {
if (this.shakeEnabled) {
this.pos = v2.add(
this.pos,
Expand All @@ -60,4 +67,4 @@ Camera.prototype = {
}
this.shakeInt = 0;
}
};
}
8 changes: 4 additions & 4 deletions client/src/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { util } from "../../shared/utils/util";
import device from "./device";
import loadout from "./loadouts";
import webview from "./webview";
import { device } from "./device";
import loadout from "./ui/loadouts";
import webview from "./ui/webview";

const defaultConfig = {
muteAudio: false,
Expand Down Expand Up @@ -29,7 +29,7 @@ const defaultConfig = {
perkModeRole: "",
loadout: loadout.defaultLoadout()
};
export default class ConfigManager {
export class ConfigManager {
constructor() {
this.loaded = false;
this.localStorageAvailable = true;
Expand Down
5 changes: 1 addition & 4 deletions client/src/crc.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions client/src/createJS.js
Original file line number Diff line number Diff line change
Expand Up @@ -864,5 +864,4 @@ class WebAudioEngine {
}

// Use soundjs's API
const createjs = { Sound: new WebAudioEngine() };
export default createjs;
export const CreateJS = { Sound: new WebAudioEngine() };
3 changes: 1 addition & 2 deletions client/src/crosshair.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function getCursorCSS(crosshairDef) {
return `${getBaseURL(crosshairDef)} ${dims.width / 2} ${dims.height / 2}, crosshair`;
}

const crosshair = {
export const crosshair = {
getCursorURL: function(crosshairDef) {
return getBaseURL(crosshairDef);
},
Expand Down Expand Up @@ -59,4 +59,3 @@ const crosshair = {
});
}
};
export default crosshair;
3 changes: 1 addition & 2 deletions client/src/debugLines.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,4 @@ class DebugLines {
}
}

const debugLines = new DebugLines();
export default debugLines;
export const debugLines = new DebugLines();
2 changes: 1 addition & 1 deletion client/src/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@ class Device {
}
}

export default new Device();
export const device = new Device();
Loading

0 comments on commit b03d0b4

Please sign in to comment.