mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-07 14:28:09 +03:00
fix incorrect goal migrations
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { IsNotNullish } from "util/misc";
|
||||
import QuickTooltip from "components/layout/misc/QuickTooltip";
|
||||
import Icon from "components/util/Icon";
|
||||
import Muted from "components/util/Muted";
|
||||
@@ -60,7 +61,10 @@ export default function RatingSystemPart({ chart, game }: { chart: ChartDocument
|
||||
>
|
||||
<div>
|
||||
<Muted>
|
||||
{ratingSystems.map((r) => r.toString(chart as any)).join(" / ")}
|
||||
{ratingSystems
|
||||
.map((r) => r.toString(chart as any))
|
||||
.filter((e) => IsNotNullish(e))
|
||||
.join(" / ")}
|
||||
</Muted>
|
||||
</div>
|
||||
</QuickTooltip>
|
||||
|
||||
@@ -11,18 +11,19 @@ async function UpdateGoals(
|
||||
) {
|
||||
const goals = await db.goals.find(query);
|
||||
|
||||
return Promise.all(
|
||||
goals.map((oldGoal) =>
|
||||
EditGoal(oldGoal, {
|
||||
...oldGoal,
|
||||
criteria: {
|
||||
...oldGoal.criteria,
|
||||
key: newCriteriaKey,
|
||||
value: newCriteriaValue?.(oldGoal) ?? oldGoal.criteria.value,
|
||||
},
|
||||
})
|
||||
)
|
||||
);
|
||||
for (const oldGoal of goals) {
|
||||
// too lazy to parallelise this wrt. the quest changes.
|
||||
// ah well
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await EditGoal(oldGoal, {
|
||||
...oldGoal,
|
||||
criteria: {
|
||||
...oldGoal.criteria,
|
||||
key: newCriteriaKey,
|
||||
value: newCriteriaValue?.(oldGoal) ?? oldGoal.criteria.value,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function perToScore(goal: GoalDocument) {
|
||||
|
||||
@@ -9,11 +9,8 @@ import {
|
||||
} from "tachi-common";
|
||||
import { GetFolderForIDGuaranteed, HumaniseChartID } from "utils/db";
|
||||
import { GetFolderChartIDs } from "utils/folder";
|
||||
import { NumToDP, HumanisedJoinArray } from "utils/misc";
|
||||
import type {
|
||||
ChartSpecificMetricValidator,
|
||||
GoalCriteriaFormatter,
|
||||
} from "game-implementations/types";
|
||||
import { HumanisedJoinArray, OnlyFloatToDP } from "utils/misc";
|
||||
import type { GoalCriteriaFormatter } from "game-implementations/types";
|
||||
import type { GPTString, Game, GoalDocument, Playtype } from "tachi-common";
|
||||
|
||||
export async function CreateGoalTitle(
|
||||
@@ -74,7 +71,7 @@ export async function CreateGoalTitle(
|
||||
// See above about switch exhaustivity
|
||||
// eslint-disable-next-line no-fallthrough
|
||||
case "proportion": {
|
||||
const propFormat = NumToDP(criteria.countNum * 100);
|
||||
const propFormat = OnlyFloatToDP(criteria.countNum * 100);
|
||||
|
||||
switch (charts.type) {
|
||||
case "multi":
|
||||
|
||||
@@ -712,6 +712,9 @@ export async function EditGoal(oldGoal: GoalDocument, newGoal: GoalDocument) {
|
||||
newGoal.playtype
|
||||
);
|
||||
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
newGoal.goalID = newGoalID;
|
||||
|
||||
await db["goal-subs"].update(
|
||||
{
|
||||
goalID: oldGoal.goalID,
|
||||
@@ -754,8 +757,6 @@ export async function EditGoal(oldGoal: GoalDocument, newGoal: GoalDocument) {
|
||||
|
||||
await db.goals.remove({ goalID: oldGoal.goalID });
|
||||
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
newGoal.goalID = newGoalID;
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
newGoal.name = await CreateGoalName(
|
||||
newGoal.charts,
|
||||
|
||||
@@ -236,6 +236,21 @@ export function NumToDP(num: number, points = 2) {
|
||||
return num.toFixed(points);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the input is a decimal, format it to N decimal places, otherwise,
|
||||
* format it to 0dp, i.e.
|
||||
*
|
||||
* 10.053 -> 10.05
|
||||
* 10 -> 10
|
||||
*/
|
||||
export function OnlyFloatToDP(num: number, points = 2) {
|
||||
if (Number.isInteger(num)) {
|
||||
return num.toFixed(0);
|
||||
}
|
||||
|
||||
return num.toFixed(points);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this game is supported by this instance of tachi or not.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user