Skip to content

Commit

Permalink
Merge pull request #2 from NMSCD/dev
Browse files Browse the repository at this point in the history
Add freighter base detection
  • Loading branch information
Lenni009 authored Feb 24, 2024
2 parents 5300be0 + 7cb5c7f commit 638a980
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 94 deletions.
56 changes: 0 additions & 56 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"@vitejs/plugin-vue": "^5.0.2",
"bulma": "^0.9.4",
"chart.js": "^4.4.1",
"pinia": "^2.1.7",
"vue-chartjs": "^5.3.0",
"vue-tsc": "^1.8.27"
}
Expand Down
19 changes: 18 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { computed, ref } from 'vue';
import BaseList from './components/BaseList.vue';
import type { Base } from '@/types/Base';
import PartChart from './components/PartChart.vue';
import { maxObjects } from './constants/base';
const isJsonInvalid = ref(false);
const baseJson = ref<Base[]>([]);
Expand All @@ -14,6 +15,8 @@ const totalPartsUsed = computed(() => {
return objectCounts.reduce((prev, cur) => prev + cur, 0);
});
const totalPartsUnused = computed(() => maxObjects - totalPartsUsed.value);
function parseOnInput(e: Event) {
if (!(e.target instanceof HTMLTextAreaElement)) return;
parseJson(e.target.value);
Expand All @@ -23,7 +26,12 @@ function parseJson(rawJson: string) {
try {
const parsedJson: Base[] = JSON.parse(rawJson);
isJsonInvalid.value = false;
const sortedJson = parsedJson.toSorted((a, b) => b.Objects.length - a.Objects.length);
const playerBases = parsedJson.filter((item) =>
['HomePlanetBase', 'FreighterBase'].includes(item.BaseType.PersistentBaseTypes)
);
const freighter = playerBases.find((item) => item.BaseType.PersistentBaseTypes === 'FreighterBase');
if (freighter) freighter.Name = 'Freighter';
const sortedJson = playerBases.toSorted((a, b) => b.Objects.length - a.Objects.length);
baseJson.value = sortedJson;
} catch (error) {
isJsonInvalid.value = true;
Expand Down Expand Up @@ -60,12 +68,21 @@ function parseJson(rawJson: string) {
v-if="baseJson.length"
class="my-4"
>
<div class="stats is-flex is-flex-wrap-wrap">
<p>Total Number of Bases: {{ totalBases }}</p>
<p>Total Parts Used: {{ totalPartsUsed }}</p>
<p>Unused Parts: {{ totalPartsUnused }}</p>
</div>
<BaseList :bases="baseJson" />
<PartChart
:bases="baseJson"
:total-parts="totalPartsUsed"
/>
</div>
</template>

<style scoped lang="scss">
.stats {
gap: 2rem;
}
</style>
7 changes: 5 additions & 2 deletions src/components/BaseItem.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<script setup lang="ts">
import type { Base } from '@/types/Base';
import { computed } from 'vue';
import { uploadLimit } from '@/constants/base';
const props = defineProps<{
base: Base;
}>();
const uploadLimit = 3000;
const isFreighterBase = props.base.BaseType.PersistentBaseTypes === 'FreighterBase';
const isNotUploadable = computed(() => props.base.Objects.length >= uploadLimit);
</script>

<template>
<div class="card p-4">
<div>Name: {{ base.Name }}</div>
<div>
Name: <span :class="{ 'is-italic': isFreighterBase }">{{ base.Name }}</span>
</div>
<div>
Parts:
<span
Expand Down
7 changes: 2 additions & 5 deletions src/components/PartChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type { Base } from '@/types/Base';
import { computed, reactive } from 'vue';
import { Pie } from 'vue-chartjs';
import { Chart as ChartJS, ArcElement, Tooltip, Legend } from 'chart.js';
import { minColourValue, maxColourValue } from '@/constants/colours';
import { maxObjects } from '@/constants/base';
ChartJS.register(ArcElement, Tooltip, Legend);
Expand All @@ -16,17 +18,12 @@ function getRndInteger(min: number, max: number) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
const minColourValue = 50;
const maxColourValue = 255;
function getRandomColour() {
const rgb = Array.from({ length: 3 }).map(() => getRndInteger(minColourValue, maxColourValue));
const hexCode = rgb.map((colour) => colour.toString(16)).join('');
return `#${hexCode}`;
}
const maxObjects = 16000;
const labels = computed(() => props.bases.map((base) => base.Name));
const objectCounts = computed(() => props.bases.map((base) => base.Objects.length));
const colours = computed(() => props.bases.map(getRandomColour));
Expand Down
2 changes: 2 additions & 0 deletions src/constants/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const maxObjects = 16000;
export const uploadLimit = 3000;
2 changes: 2 additions & 0 deletions src/constants/colours.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const minColourValue = 50;
export const maxColourValue = 255;
5 changes: 0 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ import 'bulma';
import '@/styles/styles.scss';
import App from './App.vue';
import { createApp } from 'vue';
import { createPinia } from 'pinia';

const app = createApp(App);

// state management, if required
const pinia = createPinia();
app.use(pinia);

// css selector where the app should be mounted
app.mount('#app');
24 changes: 0 additions & 24 deletions src/stores/templateData.ts

This file was deleted.

5 changes: 5 additions & 0 deletions src/styles/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
html,
body {
scrollbar-gutter: stable;
font-family: sans-serif;
}

0 comments on commit 638a980

Please sign in to comment.