Skip to content

Commit

Permalink
show count if it doesn't match the number of segments
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-vorobiov committed Sep 21, 2024
1 parent c0693f8 commit 093f286
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 20 deletions.
2 changes: 1 addition & 1 deletion evolve_analytics.meta.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name Evolve Analytics
// @namespace http://tampermonkey.net/
// @version 0.3.3
// @version 0.3.4
// @description Track and see detailed information about your runs
// @author Sneed
// @match https://pmotschmann.github.io/Evolve/
Expand Down
2 changes: 1 addition & 1 deletion src/enums/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { buildings } from "./buildings";

export { segments as buildingSegments } from "./segments";
export { techs } from "./research";

export const events = {
Expand Down
23 changes: 23 additions & 0 deletions src/enums/segments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export const segments: Record<string, number> = {
"space-terraformer": 100,
"space-jump_gate": 100,
"starDock-seeder": 100,
"space-world_collider": 1859,
"space-mass_relay": 100,
"space-ai_core": 100,
"tauceti-ringworld": 1000,
"tauceti-jump_gate": 100,
"tauceti-alien_station": 100,
"tauceti-matrioshka_brain": 1000,
"tauceti-ignition_device": 10,
"interstellar-dyson": 100,
"interstellar-dyson_sphere": 100,
"interstellar-orichalcum_sphere": 100,
"interstellar-stellar_engine": 100,
"interstellar-stargate": 200,
"interstellar-space_elevator": 100,
"interstellar-gravity_dome": 100,
"interstellar-ascension_machine": 100,
"portal-east_tower": 388,
"portal-west_tower": 388,
};
2 changes: 1 addition & 1 deletion src/evolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { resets, universes } from "./enums";
declare const unsafeWindow: any;

export type BuildingInfoTabs = {
[k in "city" | "space" | "interstellar" | "galaxy" | "portal"]: Record<string, {
[tab in "city" | "space" | "starDock" | "interstellar" | "galaxy" | "portal" | "tauceti"]: Record<string, {
count: number;
}>
}
Expand Down
33 changes: 17 additions & 16 deletions src/milestones.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { buildings, techs, events, resets } from "./enums";
import { buildings, buildingSegments, techs, events, resets } from "./enums";
import { patternMatch } from "./utils";
import type { Game } from "./game";

Expand All @@ -20,37 +20,38 @@ export function makeMilestoneChecker(game: Game, milestone: string): MilestoneCh
};
}

export function milestoneName(milestone: string): [string, string] {
const name: [string, string] | undefined = patternMatch(milestone, [
[/built:(.+?):(\d+)/, (id, count) => [buildings[id], count]],
[/tech:(.+)/, (id) => [techs[id], "Research"]],
[/event:(.+)/, (id) => [events[id as keyof typeof events], "Event"]],
[/reset:(.+)/, (reset) => [resets[reset as keyof typeof resets], "Reset"]]
export function milestoneName(milestone: string): [string, string, boolean] {
const name: [string, string, boolean] | undefined = patternMatch(milestone, [
[/built:(.+?):(\d+)/, (id, count) => [buildings[id], count, Number(count) !== (buildingSegments[id] ?? 1)]],
[/tech:(.+)/, (id) => [techs[id], "Research", false]],
[/event:(.+)/, (id) => [events[id as keyof typeof events], "Event", false]],
[/reset:(.+)/, (reset) => [resets[reset as keyof typeof resets], "Reset", false]]
]);

return name ?? [milestone, "Unknown"];
return name ?? [milestone, "Unknown", false];
}

export function generateMilestoneNames(milestones: string[]): string[] {
const candidates: Record<string, [number, string][]> = {};
const candidates: Record<string, [number, string, boolean][]> = {};

for (let i = 0; i != milestones.length; ++i) {
const [name, discriminator] = milestoneName(milestones[i]);
(candidates[name] ??= []).push([i, discriminator]);
const [name, discriminator, force] = milestoneName(milestones[i]);
(candidates[name] ??= []).push([i, discriminator, force]);
}

const names = new Array<string>(milestones.length);

for (const [name, discriminators] of Object.entries(candidates)) {
// The only milestone with this name - no need for disambiguation
if (discriminators.length === 1) {
names[discriminators[0][0]] = name;
}
else {
// Add a discriminator if there are multiple milestones with the same name
// Or if the count of a "built" milestone differs from the segment number of the building
if (discriminators.length > 1 || discriminators[0][2]) {
for (const [i, discriminator] of discriminators) {
names[i] = `${name} (${discriminator})`;
}
}
else {
names[discriminators[0][0]] = name;
}
}

return names;
Expand Down
30 changes: 29 additions & 1 deletion test/milestones.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("Milestones", () => {

it("should not disambiguate if there are no conflicts", () => {
const names = generateMilestoneNames([
"built:interstellar-mining_droid:123",
"built:interstellar-mining_droid:1",
"tech:master_craftsman"
]);

Expand Down Expand Up @@ -67,5 +67,33 @@ describe("Milestones", () => {
"Apartment (Research)"
]);
});

it("should disambiguate if the count does not match the number of segments", () => {
const names = generateMilestoneNames([
"built:city-apartment:123",
"built:arpa-lhc:456",
"built:interstellar-stargate:100"
]);

expect(names).toEqual([
"Apartment (123)",
"Supercollider (456)",
"Blackhole Stargate (100)"
]);
});

it("should nto disambiguate if the count matches the number of segments", () => {
const names = generateMilestoneNames([
"built:city-apartment:1",
"built:arpa-lhc:1",
"built:interstellar-stargate:200"
]);

expect(names).toEqual([
"Apartment",
"Supercollider",
"Blackhole Stargate"
]);
});
});
});

0 comments on commit 093f286

Please sign in to comment.