generated from Eisvana/app-template
-
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.
Merge pull request #95 from NMSCD/dev
display timestamp
- Loading branch information
Showing
13 changed files
with
565 additions
and
380 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,10 @@ | ||
// chatGPT's version of the file downloader | ||
export function downloadFile(data: string, fileName: string) { | ||
const blob = new File([data], fileName, { type: 'application/json' }); | ||
const url = URL.createObjectURL(blob); | ||
const a = document.createElement('a'); | ||
a.href = url; | ||
a.download = fileName; | ||
a.click(); | ||
URL.revokeObjectURL(url); | ||
} |
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,21 @@ | ||
import type { Mapping } from '../types/mapping'; | ||
|
||
// obfuscate keys for compression | ||
export function reverseMapKeys(json: object, mapping: Mapping) { | ||
if (Array.isArray(json)) { | ||
return json.map((item) => reverseMapKeys(item, mapping)); | ||
} else if (typeof json === 'object' && json !== null) { | ||
const newJson = {}; | ||
for (const key in json) { | ||
const mappedKey = mapping.find((m) => m.Value === key)?.Key; | ||
if (mappedKey) { | ||
newJson[mappedKey] = reverseMapKeys(json[key], mapping); | ||
} else { | ||
newJson[key] = reverseMapKeys(json[key], mapping); | ||
} | ||
} | ||
return newJson; | ||
} else { | ||
return json; | ||
} | ||
} |
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,17 @@ | ||
const formatTimePart = (timePart: number) => timePart.toString().padStart(2, '0'); | ||
|
||
/** | ||
* | ||
* @param timestamp takes playtime in seconds from TotalPlayTime | ||
*/ | ||
export function formatTime(timestamp: number) { | ||
const secondsInMinutes = 60; | ||
const secondsInHours = secondsInMinutes ** 2; | ||
const hours = Math.floor(timestamp / secondsInHours); | ||
const hoursInSeconds = hours * secondsInHours; | ||
const secondsWithoutHours = timestamp - hoursInSeconds; | ||
const minutes = Math.floor(secondsWithoutHours / secondsInMinutes); | ||
const minutesInSeconds = minutes * secondsInMinutes; | ||
const seconds = secondsWithoutHours - minutesInSeconds; | ||
return `${formatTimePart(hours)}:${formatTimePart(minutes)}:${formatTimePart(seconds)}`; | ||
} |
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,5 @@ | ||
declare global { | ||
async function decompressSave(file: File, mapping: { Key: string; Value: string }[]): Promise<object | string>; | ||
} | ||
|
||
export {}; |
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,4 @@ | ||
export type Mapping = { | ||
Key: string; | ||
Value: string; | ||
}[]; |
Oops, something went wrong.