Skip to content

Commit

Permalink
Move getPlatform to shared code
Browse files Browse the repository at this point in the history
  • Loading branch information
insraq committed Mar 5, 2025
1 parent b4ebc92 commit e69a43f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion server
18 changes: 17 additions & 1 deletion shared/utilities/DatabaseShared.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MAX_CHAT_PER_CHANNEL } from "../logic/Constants";
import type { IPlatformInfo, IUser } from "./Database";
import { Platform, type IPlatformInfo, type IUser } from "./Database";
import { safeAdd } from "./Helper";

export function vacuumChat<T extends { channel: string } | object>(old: T[]): T[] {
Expand Down Expand Up @@ -28,3 +28,19 @@ export function isSaveOwner(info: IPlatformInfo, user: IUser): boolean {
}
return false;
}

export function getPlatform(userId: string | null | undefined): Platform {
if (!userId) {
return Platform.None;
}
if (userId.startsWith("steam:")) {
return Platform.Steam;
}
if (userId.startsWith("ios:")) {
return Platform.iOS;
}
if (userId.startsWith("android:")) {
return Platform.Android;
}
return Platform.None;
}
2 changes: 1 addition & 1 deletion src/scripts/ui/CrossPlatformSavePage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from "react";
import { getPlatform } from "../../../server/src/DatabaseHelper";
import { Platform } from "../../../shared/utilities/Database";
import { getPlatform } from "../../../shared/utilities/DatabaseShared";
import { isNullOrUndefined } from "../../../shared/utilities/Helper";
import { L, t } from "../../../shared/utilities/i18n";
import "../../css/CrossPlatformSavePage.css";
Expand Down
3 changes: 1 addition & 2 deletions src/scripts/ui/StatisticsBuildingBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,7 @@ function ResourcesTab({ gameState }: IBuildingComponentProps): React.ReactNode {
const input = inputs.get(res) ?? 0;
const deficit = output - input;
const amount = Tick.current.resourceAmount.get(res) ?? 0;
const timeLeft =
deficit < 0 ? Math.abs((1000 * amount ?? 0) / deficit) : Number.POSITIVE_INFINITY;
const timeLeft = deficit < 0 ? Math.abs((1000 * amount) / deficit) : Number.POSITIVE_INFINITY;

return (
<tr key={res}>
Expand Down

0 comments on commit e69a43f

Please sign in to comment.