Skip to content

Commit

Permalink
Merge branch '0.4.2'
Browse files Browse the repository at this point in the history
pukmajster committed Nov 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents a1d80c4 + f4942d2 commit d6bbc22
Showing 6 changed files with 111 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "funky",
"version": "0.4.1",
"version": "0.4.2",
"description": "Open-source mod manager for Left 4 Dead 2",
"main": "./out/main/index.js",
"author": "Žan Pukmajster",
2 changes: 1 addition & 1 deletion src/renderer/src/App.svelte
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
import CategoriesPanel from './components/library/CategoriesPanel.svelte'
import AddonLibrary from './components/library/AddonLibrary.svelte'
import { onMount } from 'svelte'
import Conflicts from './components/library/Conflicts.svelte'
import Conflicts from './features/library/conflicts/Conflicts.svelte'
import { view } from './stores/view'
import LibraryShuffles from './components/library/LibraryShuffles.svelte'
storePopup.set({ computePosition, autoUpdate, offset, shift, flip, arrow })
31 changes: 0 additions & 31 deletions src/renderer/src/components/library/Conflicts.svelte

This file was deleted.

50 changes: 50 additions & 0 deletions src/renderer/src/features/library/conflicts/ConflictGroup.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<script lang="ts">
import type { Addon } from 'shared'
import AddonCard from '../../../components/addons/AddonCard.svelte'
import { findRepeatedValues } from '../../../utils'
export let group: Addon[]
export let index: number
$: sharedFiles = findRepeatedValues(...group.map((addon) => addon.files)).filter(
(file) => file !== 'addoninfo.txt' && file !== 'addonimage.jpg'
)
export let showFiles: boolean
</script>

<div class="p-4 bg-surface-700/70 rounded-lg gap-2">
<p class=" mb-3 text-sm text-surface-400">Conflict #{index + 1}</p>

<div class="library-list">
{#each group as addon}
<AddonCard mode="card" {addon} />
{/each}
</div>

{#if showFiles}
<div class="p-3 bg-surface-900 mt-5 rounded-lg max-h-80 overflow-y-auto">
<p class=" text-xs text-surface-400">
{sharedFiles.length} file(s) conflicting between {group.length} mods
</p>
<div class="mt-2">
{#each sharedFiles as file}
<div class="text-xs text-red-400">
{file}
</div>
{/each}
</div>
</div>
{/if}
</div>

<style lang="postcss">
.library-list {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(186px, 1fr));
grid-auto-rows: minmax(min-content, max-content);
align-items: stretch;
gap: 12px;
}
</style>
43 changes: 43 additions & 0 deletions src/renderer/src/features/library/conflicts/Conflicts.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<script>
import { conflictGroups } from '../../../stores/conflicts'
import { view } from '../../../stores/view'
import ConflictGroup from './ConflictGroup.svelte'
let showFiles = false
function toggleShowSharedFiles() {
showFiles = !showFiles
}
</script>

<div class:hidden={$view != 'conflicts'}>
<div class="relative">
<div class=" pb-32 p-4 flex flex-col max-w-[900px] mx-auto gap-4">
<div
class="absolute top-0 left-0 right-0 min-h-[260px] -z-20 bg-gradient-to-b from-red-600/20 to-transparent"
/>

<div class="py-4 px-4">
<div class="flex justify-between items-center">
<h5 class="h3">Conflicts</h5>

<button class="btn variant-filled-surface btn-sm" on:click={toggleShowSharedFiles}>
{showFiles ? 'Hide' : 'Show'} conflict details
</button>
</div>

<p class="text-sm mt-2 text-surface-300">
See exactly which mods are conflicting with each other.
{#if showFiles}
<br />
Common files, such as <span class="font-semibold">addoninfo.txt</span> and
<span class="font-semibold">addonimage.jpg</span>, are excluded from conflicts.
{/if}
</p>
</div>

{#each $conflictGroups as group, i}
<ConflictGroup {showFiles} index={i} {group} />
{/each}
</div>
</div>
</div>
16 changes: 16 additions & 0 deletions src/renderer/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -2,6 +2,22 @@ export function arraysShareValues<T>(array1: T[], array2: T[]): boolean {
return array1.filter((element) => array2.includes(element)).length > 0
}

export function findRepeatedValues<T>(...arrays: T[][]): T[] {
const elementCount: Map<T, number> = new Map()

// Count occurrences of each element across all arrays
arrays.forEach((array) => {
array.forEach((item) => {
elementCount.set(item, (elementCount.get(item) || 0) + 1)
})
})

// Filter elements that appear more than once
return Array.from(elementCount)
.filter(([, count]) => count > 1)
.map(([item]) => item)
}

export function trimString(string: string, length: number): string {
return string.length > length ? string.substring(0, length) + '...' : string
}

0 comments on commit d6bbc22

Please sign in to comment.