aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/APITypes.d.ts25
-rw-r--r--src/lib/MayorSkin.svelte41
-rw-r--r--src/lib/utils.ts46
3 files changed, 100 insertions, 12 deletions
diff --git a/src/lib/APITypes.d.ts b/src/lib/APITypes.d.ts
index 119e5b6..3a54cea 100644
--- a/src/lib/APITypes.d.ts
+++ b/src/lib/APITypes.d.ts
@@ -138,3 +138,28 @@ export interface Collection {
level: number
category: CollectionCategory
}
+
+export interface MayorPerk {
+ name: string
+ description: string
+}
+
+export interface Candidate {
+ name: string
+ perks: MayorPerk[]
+ votes: number
+ color: string | null
+}
+
+export interface ElectionData {
+ last_updated: number
+ previous: {
+ year: number
+ winner: string
+ candidates: Candidate[]
+ }
+ current: {
+ year: number
+ candidates: Candidate[]
+ } | null
+} \ No newline at end of file
diff --git a/src/lib/MayorSkin.svelte b/src/lib/MayorSkin.svelte
new file mode 100644
index 0000000..c3a90ec
--- /dev/null
+++ b/src/lib/MayorSkin.svelte
@@ -0,0 +1,41 @@
+<script lang="ts">
+ import { toTitleCase } from '$lib/utils'
+ export let name: string
+
+ const skinIds = {
+ // normal mayors
+ barry: 'f04c591b164746e848f3d6a451ee87a62dd193e5c45e94ed78e72df119aca426',
+ paul: '1b59c43d8dbccfd7ec6e6394b6304b70d4ed315add0494ee77c733f41818c73a',
+ aatrox: 'c1bdf505bb8c0f1f3365a03032de1931663ff71c57e022558de312b8f1b5c445',
+ foxy: '3485a717fa0f51d7fadc66a5d5e9853905bef914e3b2848a2f128e63d2db87',
+ cole: '16422de08848952d1cbead66bbbad6f07191bdcc952f3d1036aeb0c22938f39b',
+ marina: '807fc9bee8d3344e840e4031a37249a4c3c87fc80cf16432cc5c2153d1f9c53d',
+ diaz: '9cf4737cd444b590545734a6408cbe23c182f4283f167a3e3c09532ccbef17f9',
+ diana: '83cc1cf672a4b2540be346ead79ac2d9ed19d95b6075bf95be0b6d0da61377be',
+
+ // special mayors
+ derpy: 'be0f89466528ad5eca5a6506adddd896ff78c4fd21facaa74a8c4a809c89207',
+ scorpius: '8f26fa0c47536e78e337257d898af8b1ebc87c0894503375234035ff2c7ef8f0',
+
+ // unique mayors
+ technoblade: '786c039d969d1839155255e38e7b06a626ea9f8baf9cb55e0a77311efe18a3e',
+ dante: '5af658e00ac0d0ce0686e79f59c067b9577c01ba57ad8c6575db8490c3161772',
+ faith: '64b39d0756b92b8b7599d1f971580088954e21c5f60c673d0d4f63693fb002b5',
+ }
+
+ let url: string
+ $: {
+ if (name.toLowerCase() === 'derpy') url = '/villager.png'
+ else url = `https://mc-heads.net/body/${skinIds[name.toLowerCase()]}`
+ }
+</script>
+
+<img src={url} alt="Mayor {toTitleCase(name)}" />
+
+<style>
+ img {
+ display: block;
+ width: 5em;
+ margin: 0 auto;
+ }
+</style>
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
index aabd981..d6e8e13 100644
--- a/src/lib/utils.ts
+++ b/src/lib/utils.ts
@@ -81,28 +81,40 @@ function moveToEndOfId(word: string, thing: string) {
return thing
}
-export function millisecondsToTime(totalMilliseconds: number) {
+interface MillisecondsToTimeOpts {
+ parts: number
+}
+
+export function millisecondsToTime(totalMilliseconds: number, opts: MillisecondsToTimeOpts = { parts: 2 }) {
const totalSeconds = totalMilliseconds / 1000
const totalMinutes = totalSeconds / 60
const totalHours = totalMinutes / 60
const totalDays = totalHours / 24
const milliseconds = Math.floor(totalMilliseconds) % 1000
+
const seconds = Math.floor(totalSeconds) % 60
const minutes = Math.floor(totalMinutes) % 60
const hours = Math.floor(totalHours) % 24
const days = Math.floor(totalDays)
+
const stringUnits: string[] = []
- if (days > 1) stringUnits.push(`${days} days`)
- else if (days == 1) stringUnits.push(`${days} day`)
- if (hours > 1) stringUnits.push(`${hours} hours`)
- else if (hours == 1) stringUnits.push(`${hours} hour`)
- if (minutes > 1) stringUnits.push(`${minutes} minutes`)
- else if (minutes == 1) stringUnits.push(`${minutes} minute`)
- if (seconds > 1) stringUnits.push(`${seconds} seconds`)
- else if (seconds == 1) stringUnits.push(`${seconds} second`)
- if (milliseconds > 1) stringUnits.push(`${milliseconds} milliseconds`)
- else if (milliseconds == 1) stringUnits.push(`${milliseconds} millisecond`)
- return stringUnits.slice(0, 2).join(' and ')
+
+ if (totalDays > 1) stringUnits.push(`${days} days`)
+ else if (totalDays == 1) stringUnits.push(`${days} day`)
+ if (totalHours > 1) stringUnits.push(`${hours} hours`)
+ else if (totalHours == 1) stringUnits.push(`${hours} hour`)
+ if (totalMinutes > 1) stringUnits.push(`${minutes} minutes`)
+ else if (totalMinutes == 1) stringUnits.push(`${minutes} minute`)
+ if (totalSeconds > 1) stringUnits.push(`${seconds} seconds`)
+ else if (totalSeconds == 1) stringUnits.push(`${seconds} second`)
+ if (totalMilliseconds > 1) stringUnits.push(`${milliseconds} milliseconds`)
+ else if (totalMilliseconds == 1) stringUnits.push(`${milliseconds} millisecond`)
+ // comma separated, "and" before last
+
+ let partsCount = opts.parts
+ if (stringUnits.length < opts.parts) partsCount = stringUnits.length
+ if (partsCount === 1) return stringUnits[0]
+ return stringUnits.slice(0, partsCount - 1).join(', ') + ' and ' + stringUnits[partsCount - 1]
}
export function cleanId(id: string) {
@@ -171,4 +183,14 @@ export function formatNumberFromUnit(n: number, unit: null | 'date' | 'time' | s
default:
return `${n.toLocaleString()} ${unit}`
}
+}
+
+/** Get the milliseconds since epoch for a given SkyBlock date. The year, month, and day are 1 indexed. */
+export function skyblockTime(year: number, month = 1, day = 1) {
+ const sbEpoch = 1560275700000
+ let time = sbEpoch
+ if (year) time += 446400000 * (year)
+ if (month) time += 37200000 * (month - 1)
+ if (day) time += 1200000 * (day - 1)
+ return time
} \ No newline at end of file