Skip to content

Commit

Permalink
refactor: Improve Gamemodes structure
Browse files Browse the repository at this point in the history
Tried to get as close to what Goc asked for in #23
This fixes an issue with panel IDs bugging out because the shortName was used as an ID and Pano doesn't like it containing a hash
  • Loading branch information
tsa96 committed Oct 24, 2022
1 parent 0fca6a7 commit a3c6b4c
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 24 deletions.
59 changes: 44 additions & 15 deletions scripts/common/gamemodes.js
@@ -1,63 +1,92 @@
'use strict';

const Gamemodes = {
1: {
const GameMode = {
SURF: 1,
BHOP: 2,
CLIMB: 3,
RJ: 4,
SJ: 5,
TRICKSURF: 6,
AHOP: 7,
PARKOUR: 8,
CONC: 9,
DEFRAG: 10
};

const GameModeWithNull = {
UNKNOWN: 0,
...GameMode
};

const GameModeInfo = {
[GameMode.SURF]: {
idName: 'Surf',
name: '#Gamemode_Surf',
shortName: '#Gamemode_Surf_Short',
prefix: 'surf_'
},
2: {
[GameMode.BHOP]: {
idName: 'Bhop',
name: '#Gamemode_Bhop',
shortName: '#Gamemode_Bhop_Short',
prefix: 'bhop_'
},
3: {
[GameMode.CLIMB]: {
idName: 'Climb',
name: '#Gamemode_Climb',
shortName: '#Gamemode_Climb_Short',
prefix: 'climb_'
},
4: {
[GameMode.RJ]: {
idName: 'RJ',
name: '#Gamemode_RJ',
shortName: '#Gamemode_RJ_Short',
prefix: 'rj_'
},
5: {
[GameMode.SJ]: {
idName: 'SJ',
name: '#Gamemode_SJ',
shortName: '#Gamemode_SJ_Short',
prefix: 'sj_'
},
6: {
[GameMode.TRICKSURF]: {
idName: 'Tricksurf',
name: '#Gamemode_Tricksurf',
shortName: '#Gamemode_Tricksurf_Short',
prefix: 'tsurf_'
},
7: {
[GameMode.AHOP]: {
idName: 'Ahop',
name: '#Gamemode_Ahop',
shortName: '#Gamemode_Ahop_Short',
prefix: 'ahop_'
},
8: {
[GameMode.PARKOUR]: {
idName: 'Parkour',
name: '#Gamemode_Parkour',
shortName: '#Gamemode_Parkour_Short',
prefix: 'pk_'
},
9: {
[GameMode.CONC]: {
idName: 'Conc',
name: '#Gamemode_Conc',
shortName: '#Gamemode_Conc_Short',
prefix: 'conc_'
},
10: {
[GameMode.DEFRAG]: {
idName: 'Defrag',
name: '#Gamemode_Defrag',
shortName: '#Gamemode_Defrag_Short',
prefix: 'df_'
}
};

const GamemodesWithNull = {
0: {
const GameModeInfoWithNull = {
[GameModeWithNull.UNKNOWN]: {
idName: 'Unknown',
name: '#Gamemode_Unknown',
shortName: '#Unknown',
shortName: '#Gamemode_Unknown',
prefix: ''
},
...Gamemodes
...GameModeInfo
};
2 changes: 1 addition & 1 deletion scripts/hud/cgaz.js
Expand Up @@ -90,7 +90,7 @@ class Cgaz {
static bShouldUpdateStyles = false;

static onLoad() {
if (GAMEMODE_WITH_NULL[GameModeAPI.GetCurrentGameMode()].name !== 'Defrag') return;
if (GameModeAPI.GetCurrentGameMode() === GameMode.DEFRAG) return;

this.onAccelConfigChange();
this.onProjectionChange();
Expand Down
2 changes: 1 addition & 1 deletion scripts/hud/hud_leaderboards.js
Expand Up @@ -38,7 +38,7 @@ class HudLeaderboards {
static setMapData(isOfficial) {
$.GetContextPanel().SetHasClass('hud-leaderboards--unofficial', !isOfficial);

const img = GamemodesWithNull[GameModeAPI.GetCurrentGameMode()].shortName.toLowerCase();
const img = GameModeInfoWithNull[GameModeAPI.GetCurrentGameMode()].shortName.toLowerCase();

this.panels.gamemodeImage.SetImage(`file://{images}/gamemodes/${img}.svg`);

Expand Down
2 changes: 1 addition & 1 deletion scripts/hud/synchronizer.js
Expand Up @@ -30,7 +30,7 @@ class Synchronizer {
static onLoad() {
this.initializeSettings();

this.bIsDefragging = GAMEMODE_WITH_NULL[GameModeAPI.GetCurrentGameMode()].name === 'Defrag';
this.bIsDefragging = GameModeAPI.GetCurrentGameMode() === GameMode.DEFRAG;

this.maxSpeed = 30; // bhop max air speed
this.syncGain = 1; // scale how fast the bars move
Expand Down
10 changes: 5 additions & 5 deletions scripts/mainmenu_learn.js
Expand Up @@ -27,16 +27,16 @@ class Learn {
static lessonData = {};
static modes = {};
static {
// Create modes obj in form
// Create modes obj in form { Surf: { button: ..., list: ... }}
Object.values(GAMEMODE).forEach((modeData) => {
this.modes[modeData.shortName] = {
button: $(`#${modeData.shortName}Radio`),
list: $.CreatePanel('Panel', this.panels.listContainer, `${modeData.shortName}List`, {
this.modes[modeData.idName] = {
button: $(`#${modeData.idName}Radio`),
list: $.CreatePanel('Panel', this.panels.listContainer, `${modeData.idName}List`, {
class: 'learn-list'
})
};

this.lessonData[modeData.shortName] = {};
this.lessonData[modeData.idName] = {};
});
}

Expand Down
5 changes: 4 additions & 1 deletion scripts/mainmenu_mapselector.js
Expand Up @@ -59,7 +59,7 @@ class MapSelection {

$.RegisterEventHandler('PanelLoaded', $.GetContextPanel(), () => {
// Populate the gameModeData object, finding all the filter buttons
this.gameModeData = { ...GamemodesWithNull };
this.gameModeData = { ...GameModeInfoWithNull };

Object.keys(this.gameModeData).forEach(
(mode) => (this.gameModeData[mode].filterButton = $(`#${this.gameModeData[mode].idName}FilterButton`))
Expand Down Expand Up @@ -103,6 +103,7 @@ class MapSelection {
static initGamemodeButtons() {
Object.entries(this.gameModeData).forEach(([mode, values]) => {
const filterButton = values.filterButton;
$.Msg(filterButton);
if (filterButton === null) return;

filterButton.SetPanelEvent('oncontextmenu', () => this.clearOtherModes(mode));
Expand Down Expand Up @@ -134,6 +135,8 @@ class MapSelection {
// Set unchecked counter to -1, if you're using this you've got the hang of it, no more popups for you!
this.timesModeButtonsUnchecked = -1;

$.Msg(selectedMode);

const selectedModeButton = this.gameModeData[selectedMode].filterButton;

// No matter what, we want our selected button to be checked
Expand Down

0 comments on commit a3c6b4c

Please sign in to comment.