Skip to content

Commit b87fa76

Browse files
committed
Fix tags and authors not showing up on local mods
Fixes #21
1 parent 7a580b8 commit b87fa76

4 files changed

Lines changed: 26 additions & 12 deletions

File tree

src/filters.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ export function createFuzzyFilteredModList<T extends ModEntry>(filters: Fliters,
5151
let mod: ModEntryServer | undefined = origMod.isLocal ? origMod.serverCounterpart : origMod
5252

5353
let author: number = 0
54-
if (mod) {
54+
if (mod?.authors) {
5555
const res = fuzzysort.go(filters.name!, mod.authors)
5656
author = res[0]?.score.map(-1000000, 0, 0, 1000) || 0
5757
}
5858

5959
let tag: number = 0
60-
if (mod) {
60+
if (mod?.tags) {
6161
const res = fuzzysort.go(filters.name!, mod.tags)
6262
tag = res[0]?.score.map(-1000000, 0, 0, 1000) || 0
6363
}

src/gui/list-entry.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ modmanager.gui.ListEntry = ig.FocusGui.extend({
119119
this.addChildGui(this.nameIconPrefixesText)
120120

121121
if (!isGrid) {
122-
if (serverMod?.tags) {
123-
const tags = serverMod.tags
122+
const tags = serverMod?.tags ?? localMod?.tags
123+
if (tags) {
124124
const str = tags.map(a => `\\c[0]${a}\\c[0]`).join(', ')
125125
this.tags = new sc.TextGui(str, {
126126
font: sc.fontsystem.smallFont,
@@ -140,8 +140,8 @@ modmanager.gui.ListEntry = ig.FocusGui.extend({
140140
this.description.setPos(4 + this.iconOffset, 14)
141141
this.addChildGui(this.description)
142142

143-
if (serverMod?.authors) {
144-
const authors = serverMod.authors
143+
const authors = serverMod?.authors ?? localMod?.authors
144+
if (authors && authors.length > 0) {
145145
const str = `by ${authors.map(a => `\\c[3]${a}\\c[0]`).join(', ')}`
146146
this.authors = new sc.TextGui(str, { font: sc.fontsystem.smallFont, linePadding: -1 })
147147
this.addChildGui(this.authors)
@@ -167,7 +167,8 @@ modmanager.gui.ListEntry = ig.FocusGui.extend({
167167

168168
if (serverMod?.stars !== undefined) {
169169
this.starCount = new sc.TextGui(`${serverMod.stars}\\i[save-star]`)
170-
this.starCount.setPos(496 - this.starCount.hook.size.x, 0)
170+
this.starCount.setAlign(ig.GUI_ALIGN_X.RIGHT, ig.GUI_ALIGN_Y.TOP)
171+
this.starCount.setPos(53, 0)
171172
this.addChildGui(this.starCount)
172173
}
173174
}
@@ -238,7 +239,9 @@ modmanager.gui.ListEntry = ig.FocusGui.extend({
238239
const spaceLeft =
239240
this.hook.size.x -
240241
this.authors.hook.pos.x -
241-
(this.hook.size.x - (this.starCount?.hook.pos.x ?? this.versionText.hook.pos.x))
242+
(this.starCount
243+
? this.starCount.hook.pos.x + this.starCount.hook.size.x
244+
: this.versionText.hook.pos.x + this.versionText.hook.size.x)
242245
const freeSpace = spaceLeft - this.authors.hook.size.x
243246
if (freeSpace <= 0) {
244247
this.authors.setFont(sc.fontsystem.tinyFont)

src/local-mods.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ModManager from './plugin'
44
import { ModEntry, ModEntryLocal, ModEntryServer } from './types'
55
import { ModDB } from './moddb'
66
import { ModInstaller } from './mod-installer'
7+
import type { ValidTags } from 'ccmoddb/build/src/types'
78

89
type CCL2Mod = {
910
baseDirectory: string
@@ -16,6 +17,8 @@ type CCL2Mod = {
1617
icons?: { '24'?: string }
1718
repository?: string
1819
homepage?: string
20+
tags?: ValidTags[]
21+
authors?: string[] | string
1922

2023
active?: boolean
2124
}
@@ -166,6 +169,7 @@ export class LocalMods {
166169
}
167170

168171
private static convertCCL2Mod(mod: CCL2Mod): ModEntryLocal {
172+
const authors = mod.authors
169173
return {
170174
database: 'LOCAL',
171175
isLocal: true,
@@ -181,6 +185,8 @@ export class LocalMods {
181185
? mod.baseDirectory.substring(0, mod.baseDirectory.length - 1)
182186
: mod.baseDirectory,
183187
repositoryUrl: mod.repository,
188+
authors: authors ? (typeof authors === 'string' ? [authors] : authors) : [],
189+
tags: mod.tags ?? [],
184190

185191
active: !mod.disabled,
186192
iconConfig: mod.icons?.['24']
@@ -197,6 +203,8 @@ export class LocalMods {
197203
}
198204

199205
private static convertCCL3Mod(mod: Mod): ModEntryLocal {
206+
// @ts-expect-error
207+
const authors: string[] | string = mod.authors
200208
const active = mod == modloader._runtimeMod ? true : (sc.options.get(`modEnabled-${mod.id}`) as boolean)
201209
return {
202210
database: 'LOCAL',
@@ -214,6 +222,9 @@ export class LocalMods {
214222
}, {}),
215223
path: mod.baseDirectory.substring(0, mod.baseDirectory.length - 1),
216224
repositoryUrl: mod.manifest.repository,
225+
authors: authors ? (typeof authors === 'string' ? [authors] : authors) : [],
226+
// @ts-expect-error
227+
tags: mod.tags ?? [],
217228

218229
active,
219230
iconConfig: mod.manifest.icons?.['24']

src/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ interface ModEntryBase extends ModEntryBaseBase {
5353
awaitingRestart?: boolean
5454
/** Mod repository web link */
5555
repositoryUrl?: string
56+
/** Author list, may be empty */
57+
authors?: string[]
58+
/** Mod tag list */
59+
tags?: ValidTags[]
5660
}
5761

5862
export interface ModEntryServer extends ModEntryBase {
@@ -63,14 +67,10 @@ export interface ModEntryServer extends ModEntryBase {
6367
installation: InstallMethod[]
6468
/** UNIX timestamp of the last commit of the primary git branch of the repostory provided by "repositoryUrl", fetched by CCModDB */
6569
lastUpdateTimestamp?: number
66-
/** Author list, may be empty */
67-
authors: string[]
6870
/** GitHub star count, local mods have this set if they have a server counterpart */
6971
stars?: number
7072
/** Represents the release page info fetched from the mods repository */
7173
releasePages?: ReleasePage[]
72-
/** Mod tag list */
73-
tags: ValidTags[]
7474
/** The testing counterpart */
7575
testingVersion?: ModEntryServer
7676
/* Dependency version requirements, cached by the installer */

0 commit comments

Comments
 (0)