Skip to content

Commit

Permalink
quick decimal changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TitanPlayz100 committed Oct 29, 2024
1 parent b906e69 commit f5ca66e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/data/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const resultSuffix = {
}

export const statDecimals = {
0: ["clearlines", "pieceCount", "score", "pcs", "quads", "allspins", "level", "attack", "cleargarbage", "sent", "recieved", "combo", "maxCombo", "btbCount", "maxBTB", "tpE", "ipE", "inputs", "holds", "rotates", "ppb",],
0: ["clearlines", "pieceCount", "score", "pcs", "quads", "allspins", "level", "attack", "cleargarbage", "sent", "recieved", "combo", "maxCombo", "btbCount", "maxBTB", "tpE", "ipE", "inputs", "holds", "rotates", "ppb", "altitude"],
1: ["time", "vs", "chzind", "garbeff",],
2: ["pps", "apm", "lpm", "app", "apl", "appw", "dss", "dsp", "vsOnApm", "kps", "kpp"]
}
Expand Down
22 changes: 11 additions & 11 deletions src/display/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class Renderer {

// sidebar constants
this.sidebarStats = this.game.settings.game.sidebar;
this.sidebarFixed = this.sidebarStats.map(stat => this.createReverseLookup(statDecimals)[stat]);
this.sidebarFixed = this.sidebarStats.map(stat => reverseLookup(statDecimals)[stat]);
this.sidebarSecondary = this.sidebarStats.map(stat => statsSecondaries[stat] ?? "None");

this.sidebarStats.forEach((stat, index) => {
Expand Down Expand Up @@ -156,16 +156,6 @@ export class Renderer {
})
}

createReverseLookup(obj) {
const reverseLookup = {}
for (const [key, array] of Object.entries(obj)) {
array.forEach(item => {
reverseLookup[item] = key;
});
}
return reverseLookup
}

formatTime(s, d) {
const minutes = Math.floor(s / 60);
const seconds = (s - minutes * 60).toFixed(d)
Expand Down Expand Up @@ -196,3 +186,13 @@ export class Renderer {
this.game.boardeffects.rotate(forces[type]);
}
}

export function reverseLookup(obj) {
const reverseLookup = {}
for (const [key, array] of Object.entries(obj)) {
array.forEach(item => {
reverseLookup[item] = key;
});
}
return reverseLookup
}
9 changes: 5 additions & 4 deletions src/features/modes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Game } from "../game.js";
import gamemodeJSON from "../data/gamemodes.json" with { type: "json" };
import { gameoverResultText, gameoverText, resultSuffix } from "../data/data.js";
import { gameoverResultText, gameoverText, resultSuffix, statDecimals } from "../data/data.js";
import { reverseLookup } from "../display/renderer.js";

export class Modes {
modeJSON;
Expand Down Expand Up @@ -38,7 +39,7 @@ export class Modes {
stat = stats.score;
goal = undefined
}
this.setObjectiveText(stat, goal);
this.setObjectiveText(this.modeJSON.goalstat, stat, goal);
}

statText(stat, value, result, resultvalue) {
Expand All @@ -47,8 +48,8 @@ export class Modes {
return front + back;
}

setObjectiveText(statValue, resultValue) {
if (statValue != undefined) statValue = Math.round(statValue * 1000) / 1000
setObjectiveText(stat, statValue, resultValue) {
if (statValue != undefined) statValue = statValue.toFixed(reverseLookup(statDecimals)[stat])
let modetext = (statValue == undefined ? '' : statValue)
+ (resultValue == undefined ? '' : `/${resultValue}`)
this.game.pixi.objectiveTexts[0].text = modetext;
Expand Down

0 comments on commit f5ca66e

Please sign in to comment.