diff --git a/src/App.vue b/src/App.vue
index e7e1332..7d25774 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -10,11 +10,11 @@ import { computed } from 'vue';
import { endpointToGlyphs } from './common';
const endpointData = useEndpointDataStore();
-const { json, filter, filterType } = storeToRefs(endpointData);
+const { allEndpoints, filter, filterType } = storeToRefs(endpointData);
const renderJson = computed(() => {
if (filter.value || filterType.value) {
- return json.value.filter(
+ return allEndpoints.value.filter(
(item) =>
(!filter.value ||
item.Name.toLowerCase().includes(filter.value.toLowerCase()) ||
@@ -22,7 +22,7 @@ const renderJson = computed(() => {
(!filterType.value || item.TeleporterType === filterType.value)
);
} else {
- return json.value;
+ return allEndpoints.value;
}
});
@@ -50,7 +50,7 @@ const renderJson = computed(() => {
import { useEndpointDataStore } from '@/store/endpointData';
+import type { TeleportEndpoint, TeleporterTypes } from '@/types/teleportEndpoint';
+import { maxStations } from '@/variables/limits';
import { storeToRefs } from 'pinia';
-import { ref } from 'vue';
+import { computed, ref } from 'vue';
const endpointData = useEndpointDataStore();
-const { json } = storeToRefs(endpointData);
+const { json, addedEndpoints, typeCounter } = storeToRefs(endpointData);
-const defaultText = 'Copy modified JSON';
-const buttonText = ref(defaultText);
-const copied = ref(false);
+const isCopied = ref(false);
+
+const buttonText = computed(() => (isCopied.value ? 'Copied!' : 'Copy modified JSON'));
+
+function getExcessEndpoints(arr: TeleportEndpoint[], type: TeleporterTypes) {
+ const endpointCount = typeCounter.value[type] ?? 0;
+ const excessEndpoints = Math.max(endpointCount - maxStations, 0);
+ const endpoints = arr.filter((item) => item.TeleporterType === type);
+ const removeStations = endpoints.slice(0, excessEndpoints);
+ return removeStations;
+}
function copyJson() {
const indent = 2;
const displayTime = 1500;
- navigator.clipboard.writeText(JSON.stringify(json.value, null, indent));
- buttonText.value = 'Copied!';
- copied.value = true;
+ const excessStations = getExcessEndpoints(json.value, 'Spacestation');
+ const excessStationsFixPos = getExcessEndpoints(json.value, 'SpacestationFixPosition');
+ const filteredEndpoints = json.value.filter(
+ (item) => !excessStations.includes(item) && !excessStationsFixPos.includes(item)
+ );
+ const combinedEndpoints = [...filteredEndpoints, ...addedEndpoints.value];
+
+ navigator.clipboard.writeText(JSON.stringify(combinedEndpoints, null, indent));
+ isCopied.value = true;
setTimeout(() => {
- buttonText.value = defaultText;
- copied.value = false;
+ isCopied.value = false;
}, displayTime);
}