Skip to content

Commit

Permalink
Merge pull request massif-press#1999 from msprijatelj/feat/useLicenseID
Browse files Browse the repository at this point in the history
feat(compendium): filter on license_id when present
  • Loading branch information
jarena3 authored Jun 27, 2022
2 parents 5c8af63 + 7ab9d62 commit ee793d6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/classes/pilot/components/license/License.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@ class License {
this.FrameID = frame.ID
this.Brew = frame.Brew || 'Core'

function licenseMatch(licenseItem: LicensedItem, licenseFrame: Frame): boolean {
if (!!licenseItem.LicenseID) {
return licenseItem.LicenseID === licenseFrame.ID
} else {
return (licenseItem.License.toUpperCase() === licenseFrame.Name.toUpperCase()) && (licenseItem.Source.toUpperCase() === licenseFrame.Source.toUpperCase())
}
}

const items: LicensedItem[] = _.cloneDeep(store.getters.getItemCollection('MechWeapons'))
.concat(
store.getters.getItemCollection('WeaponMods'),
store.getters.getItemCollection('MechSystems')
)
.filter((x: LicensedItem) => (x.License.toUpperCase() === frame.Name.toUpperCase()) && x.Source.toUpperCase() === frame.Source.toUpperCase())
.filter((x: LicensedItem) => licenseMatch(x, frame))

const lls = [...items].map(i => i.LicenseLevel)

Expand Down
7 changes: 7 additions & 0 deletions src/classes/pilot/components/license/LicensedItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ interface ILicensedItemData extends ICompendiumItemData {
source: string
license: string
license_level: number
license_id?: string
}

abstract class LicensedItem extends CompendiumItem {
public readonly Source: string
public readonly LicenseLevel: number
private _license: string
private _license_id: string

public constructor(data: ILicensedItemData, packTags?: ITagCompendiumData[], packName?: string) {
super(data, packTags, packName)
this.Source = data.source ? data.source.toUpperCase() : ''
this._license = data.license || ''
this._license_id = data.license_id || ''
this.LicenseLevel = parseInt(data.license_level as any) || 0
}

Expand All @@ -41,6 +44,10 @@ abstract class LicensedItem extends CompendiumItem {
return this.Source
}

public get LicenseID(): string {
return this._license_id
}

public get RequiredLicense(): ILicenseRequirement {
return {
source: this.Source,
Expand Down
9 changes: 8 additions & 1 deletion src/features/compendium/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,15 @@ export class CompendiumStore extends VuexModule {
}

get Licenses(): License[] {
function variantLicenseMatch(variantFrame: Frame, licenseFrame: Frame): boolean {
if (!!variantFrame.Variant && !!variantFrame.LicenseID) {
return variantFrame.LicenseID === licenseFrame.ID
} else {
return (variantFrame.Variant.toUpperCase() === licenseFrame.Name.toUpperCase()) && (variantFrame.Source.toUpperCase() === licenseFrame.Source.toUpperCase())
}
}
return this.Frames.filter(x => x.Source !== 'GMS' && !x.IsHidden).map(frame => {
const variants = this.Frames.filter(f => (f.Variant.toUpperCase() === frame.Name.toUpperCase()) && (f.Source.toUpperCase() === frame.Source.toUpperCase()))
const variants = this.Frames.filter(f => variantLicenseMatch(f, frame))
return new License(frame, variants)
})
}
Expand Down

0 comments on commit ee793d6

Please sign in to comment.