-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5633f3d
commit c89f240
Showing
7 changed files
with
213 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import type { universes } from "../enums"; | ||
import type { LatestRun as LatestRun7 } from "../runTracking"; | ||
|
||
export type LatestRun6 = Omit<LatestRun7, "universe"> & { | ||
universe: keyof typeof universes | "bigbang" | ||
} | ||
|
||
function migrateLatestRun(latestRun: any) { | ||
if (latestRun.universe === "bigbang") { | ||
delete latestRun.universe; | ||
} | ||
} | ||
|
||
function migrateHistory(history: any) { | ||
for (let i = 0; i !== history.runs.length; ++i) { | ||
const run = history.runs[i]; | ||
const nextRun = history.runs[i + 1]; | ||
|
||
// The runs after a t3 reset may have gotten the "bigbang" universe as the page is refreshed into the universe selection | ||
if (run.universe === "bigbang") { | ||
if (nextRun === undefined) { | ||
// The last run is broken - mark migration as failed and try after the next run | ||
return false; | ||
} | ||
else if (nextRun.universe !== "bigbang") { | ||
// If the next run has a valid universe, this means we stayed in the same universe | ||
run.universe = nextRun.universe; | ||
} | ||
else { | ||
// If there are multiple t3 runs in a row, assume DE farming, which is usually done in magic | ||
run.universe = "magic"; | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
export function migrate6(config: any, history: any, latestRun: any) { | ||
if (latestRun !== null) { | ||
migrateLatestRun(latestRun); | ||
} | ||
|
||
if (migrateHistory(history)) { | ||
config.version = 7; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
import { describe, expect, it } from "@jest/globals"; | ||
|
||
import { migrate6 } from "../src/migration/6"; | ||
|
||
describe("Migration", () => { | ||
describe("6 -> 7", () => { | ||
it("should normalize latest current run universe", () => { | ||
const config = { | ||
version: 6, | ||
views: [] | ||
}; | ||
|
||
const history = { | ||
milestones: { | ||
"reset:whitehole": 0, | ||
}, | ||
runs: [] | ||
}; | ||
|
||
const latestRun = { | ||
run: 123, | ||
universe: "bigbang", | ||
resets: { "mad": 1 }, | ||
totalDays: 10, | ||
milestones: {}, | ||
raceName: "Human" | ||
}; | ||
|
||
migrate6(config, history, latestRun); | ||
|
||
expect(config).toEqual({ | ||
version: 7, | ||
views: [] | ||
}); | ||
|
||
expect(latestRun).toEqual({ | ||
run: 123, | ||
universe: undefined, | ||
resets: { "mad": 1 }, | ||
totalDays: 10, | ||
milestones: {}, | ||
raceName: "Human" | ||
}); | ||
}); | ||
|
||
it("should take the universe from the next run", () => { | ||
const config = { | ||
version: 6, | ||
views: [] | ||
}; | ||
|
||
const history = { | ||
milestones: { | ||
"reset:whitehole": 0, | ||
}, | ||
runs: [ | ||
{ "run": 123, "universe": "bigbang", "milestones": [[0, 123]] }, | ||
{ "run": 124, "universe": "heavy", "milestones": [[0, 456]] } | ||
] | ||
}; | ||
|
||
migrate6(config, history, null); | ||
|
||
expect(config).toEqual({ | ||
version: 7, | ||
views: [] | ||
}); | ||
|
||
expect(history).toEqual({ | ||
milestones: { | ||
"reset:whitehole": 0, | ||
}, | ||
runs: [ | ||
{ "run": 123, "universe": "heavy", "milestones": [[0, 123]] }, | ||
{ "run": 124, "universe": "heavy", "milestones": [[0, 456]] } | ||
] | ||
}); | ||
}); | ||
|
||
it("should assume magic if multiple bigbangs in a row", () => { | ||
const config = { | ||
version: 6, | ||
views: [] | ||
}; | ||
|
||
const history = { | ||
milestones: { | ||
"reset:whitehole": 0, | ||
}, | ||
runs: [ | ||
{ "run": 123, "universe": "bigbang", "milestones": [[0, 123]] }, | ||
{ "run": 124, "universe": "bigbang", "milestones": [[0, 456]] }, | ||
{ "run": 125, "universe": "heavy", "milestones": [[0, 789]] } | ||
] | ||
}; | ||
|
||
migrate6(config, history, null); | ||
|
||
expect(config).toEqual({ | ||
version: 7, | ||
views: [] | ||
}); | ||
|
||
expect(history).toEqual({ | ||
milestones: { | ||
"reset:whitehole": 0, | ||
}, | ||
runs: [ | ||
{ "run": 123, "universe": "magic", "milestones": [[0, 123]] }, | ||
{ "run": 124, "universe": "heavy", "milestones": [[0, 456]] }, | ||
{ "run": 125, "universe": "heavy", "milestones": [[0, 789]] } | ||
] | ||
}); | ||
}); | ||
|
||
it("should fail if the last run is bigbang", () => { | ||
const config = { | ||
version: 6, | ||
views: [] | ||
}; | ||
|
||
const history = { | ||
milestones: { | ||
"reset:whitehole": 0, | ||
}, | ||
runs: [ | ||
{ "run": 123, "universe": "bigbang", "milestones": [[0, 123]] }, | ||
{ "run": 124, "universe": "bigbang", "milestones": [[0, 456]] } | ||
] | ||
}; | ||
|
||
migrate6(config, history, null); | ||
|
||
expect(config).toEqual({ | ||
version: 6, | ||
views: [] | ||
}); | ||
|
||
expect(history).toEqual({ | ||
milestones: { | ||
"reset:whitehole": 0, | ||
}, | ||
runs: [ | ||
{ "run": 123, "universe": "magic", "milestones": [[0, 123]] }, | ||
{ "run": 124, "universe": "bigbang", "milestones": [[0, 456]] } | ||
] | ||
}); | ||
}); | ||
}); | ||
}); |