Skip to content

Commit eb1683e

Browse files
committed
jspcd, dry, lint
1 parent d05122d commit eb1683e

157 files changed

Lines changed: 4035 additions & 6176 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.cspell.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"ignorePaths": [
3+
"**/node_modules/**",
4+
"**/vscode-extension/**",
5+
"**/.git/**",
6+
"**/.pnpm-lock.json",
7+
".vscode",
8+
"megalinter",
9+
"package-lock.json",
10+
"report"
11+
],
12+
"language": "en",
13+
"noConfigSearch": true,
14+
"words": ["megalinter", "oxsecurity"],
15+
"version": "0.2"
16+
}

.github/workflows/mega-linter.yml

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
# MegaLinter GitHub Action configuration file
2+
# More info at https://megalinter.io
3+
---
4+
name: MegaLinter
5+
6+
# Trigger mega-linter at every push. Action will also be visible from
7+
# Pull Requests to main
8+
on:
9+
# Comment this line to trigger action only on pull-requests
10+
# (not recommended if you don't pay for GH Actions)
11+
push:
12+
13+
pull_request:
14+
branches:
15+
- main
16+
- master
17+
18+
# Comment env block if you do not want to apply fixes
19+
env:
20+
# Apply linter fixes configuration
21+
#
22+
# When active, APPLY_FIXES must also be defined as environment variable
23+
# (in github/workflows/mega-linter.yml or other CI tool)
24+
APPLY_FIXES: none
25+
26+
# Decide which event triggers application of fixes in a commit or a PR
27+
# (pull_request, push, all)
28+
APPLY_FIXES_EVENT: pull_request
29+
30+
# If APPLY_FIXES is used, defines if the fixes are directly committed (commit)
31+
# or posted in a PR (pull_request)
32+
APPLY_FIXES_MODE: commit
33+
34+
concurrency:
35+
group: ${{ github.ref }}-${{ github.workflow }}
36+
cancel-in-progress: true
37+
38+
permissions: {}
39+
40+
jobs:
41+
megalinter:
42+
name: MegaLinter
43+
runs-on: ubuntu-latest
44+
45+
# Give the default GITHUB_TOKEN write permission to commit and push, comment
46+
# issues, and post new Pull Requests; remove the ones you do not need
47+
permissions:
48+
contents: write
49+
issues: write
50+
pull-requests: write
51+
52+
steps:
53+
# Git Checkout
54+
- name: Checkout Code
55+
uses: actions/checkout@v6
56+
with:
57+
# SECURITY NOTE: Using a Personal Access Token (PAT) is NOT
58+
# recommended. Open-source projects have been heavily targeted by
59+
# supply-chain attacks in recent months, and a leaked PAT can give
60+
# attackers broad write access to your repository — better safe
61+
# than sorry! If you only need workflows to re-trigger after
62+
# MegaLinter applies fixes, prefer one of these safer alternatives:
63+
# - Manually re-run the workflow from the GitHub Actions tab, or
64+
# - Push another commit on the branch to trigger workflows again.
65+
# Only define `secrets.PAT` if you fully understand the trade-off.
66+
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
67+
persist-credentials: false # Comment this line and uncomment the next one if you use APPLY_FIXES
68+
# persist-credentials: true # zizmor: ignore[artipacked]
69+
70+
# If you use VALIDATE_ALL_CODEBASE = true, you can remove this line to
71+
# improve performance
72+
fetch-depth: 0
73+
74+
# MegaLinter
75+
- name: MegaLinter
76+
77+
# You can override MegaLinter flavor used to have faster performances
78+
# More info at https://megalinter.io/latest/flavors/
79+
uses: oxsecurity/megalinter/flavors/javascript@v9
80+
81+
id: ml
82+
83+
# All available variables are described in documentation
84+
# https://megalinter.io/latest/config-file/
85+
env:
86+
# Validates all source when push on main, else just the git diff with
87+
# main. Override with true if you always want to lint all sources
88+
#
89+
# To validate the entire codebase, set to:
90+
# VALIDATE_ALL_CODEBASE: true
91+
#
92+
# To validate only diff with main, set to:
93+
# VALIDATE_ALL_CODEBASE: >-
94+
# ${{
95+
# github.event_name == 'push' &&
96+
# github.ref == 'refs/heads/main'
97+
# }}
98+
VALIDATE_ALL_CODEBASE: true
99+
100+
# Disable LLM Advisor for bot PRs (dependabot, renovate, etc.)
101+
LLM_ADVISOR_ENABLED: >-
102+
${{
103+
github.event_name != 'pull_request' ||
104+
(github.event.pull_request.user.login != 'dependabot[bot]' &&
105+
github.event.pull_request.user.login != 'renovate[bot]' &&
106+
github.event.pull_request.user.login != 'github-actions[bot]' &&
107+
!startsWith(github.event.pull_request.user.login, 'dependabot') &&
108+
!startsWith(github.event.pull_request.user.login, 'renovate'))
109+
}}
110+
111+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
112+
113+
# Uncomment to use ApiReporter (Grafana)
114+
# API_REPORTER: true
115+
# API_REPORTER_URL: ${{ secrets.API_REPORTER_URL }}
116+
# API_REPORTER_BASIC_AUTH_USERNAME: ${{ secrets.API_REPORTER_BASIC_AUTH_USERNAME }}
117+
# API_REPORTER_BASIC_AUTH_PASSWORD: ${{ secrets.API_REPORTER_BASIC_AUTH_PASSWORD }}
118+
# API_REPORTER_METRICS_URL: ${{ secrets.API_REPORTER_METRICS_URL }}
119+
# API_REPORTER_METRICS_BASIC_AUTH_USERNAME: ${{ secrets.API_REPORTER_METRICS_BASIC_AUTH_USERNAME }}
120+
# API_REPORTER_METRICS_BASIC_AUTH_PASSWORD: ${{ secrets.API_REPORTER_METRICS_BASIC_AUTH_PASSWORD }}
121+
# API_REPORTER_DEBUG: false
122+
123+
# ADD YOUR CUSTOM ENV VARIABLES HERE TO OVERRIDE VALUES OF
124+
# .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
125+
126+
# Upload MegaLinter artifacts
127+
- name: Archive production artifacts
128+
uses: actions/upload-artifact@v7
129+
if: success() || failure()
130+
with:
131+
name: MegaLinter reports
132+
include-hidden-files: "true"
133+
path: |
134+
megalinter-reports
135+
mega-linter.log
136+
137+
# Create pull request if applicable
138+
# (for now works only on PR from same repository, not from forks)
139+
- name: Create Pull Request with applied fixes
140+
uses: peter-evans/create-pull-request@v7
141+
id: cpr
142+
if: >-
143+
steps.ml.outputs.has_updated_sources == 1 &&
144+
(
145+
env.APPLY_FIXES_EVENT == 'all' ||
146+
env.APPLY_FIXES_EVENT == github.event_name
147+
) &&
148+
env.APPLY_FIXES_MODE == 'pull_request' &&
149+
(
150+
github.event_name == 'push' ||
151+
github.event.pull_request.head.repo.full_name == github.repository
152+
) &&
153+
!contains(github.event.head_commit.message, 'skip fix')
154+
with:
155+
# SECURITY NOTE: see the warning on the checkout step above —
156+
# using `secrets.PAT` is NOT recommended for security reasons.
157+
# Prefer manually re-running the workflow or pushing another
158+
# commit on the branch to trigger workflows again.
159+
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
160+
commit-message: "[MegaLinter] Apply linters automatic fixes"
161+
title: "[MegaLinter] Apply linters automatic fixes"
162+
labels: bot
163+
164+
- name: Create PR output
165+
if: >-
166+
steps.ml.outputs.has_updated_sources == 1 &&
167+
(
168+
env.APPLY_FIXES_EVENT == 'all' ||
169+
env.APPLY_FIXES_EVENT == github.event_name
170+
) &&
171+
env.APPLY_FIXES_MODE == 'pull_request' &&
172+
(
173+
github.event_name == 'push' ||
174+
github.event.pull_request.head.repo.full_name == github.repository
175+
) &&
176+
!contains(github.event.head_commit.message, 'skip fix')
177+
env:
178+
PR_NUMBER: ${{ steps.cpr.outputs.pull-request-number }}
179+
PR_URL: ${{ steps.cpr.outputs.pull-request-url }}
180+
run: |
181+
echo "PR Number - ${PR_NUMBER}"
182+
echo "PR URL - ${PR_URL}"
183+
184+
# Push new commit if applicable
185+
# (for now works only on PR from same repository, not from forks)
186+
- name: Prepare commit
187+
if: >-
188+
steps.ml.outputs.has_updated_sources == 1 &&
189+
(
190+
env.APPLY_FIXES_EVENT == 'all' ||
191+
env.APPLY_FIXES_EVENT == github.event_name
192+
) &&
193+
env.APPLY_FIXES_MODE == 'commit' &&
194+
github.ref != 'refs/heads/main' &&
195+
(
196+
github.event_name == 'push' ||
197+
github.event.pull_request.head.repo.full_name == github.repository
198+
) &&
199+
!contains(github.event.head_commit.message, 'skip fix')
200+
run: sudo chown -Rc $UID .git/
201+
202+
- name: Commit and push applied linter fixes
203+
uses: stefanzweifel/git-auto-commit-action@v7
204+
if: >-
205+
steps.ml.outputs.has_updated_sources == 1 &&
206+
(
207+
env.APPLY_FIXES_EVENT == 'all' ||
208+
env.APPLY_FIXES_EVENT == github.event_name
209+
) &&
210+
env.APPLY_FIXES_MODE == 'commit' &&
211+
github.ref != 'refs/heads/main' &&
212+
(
213+
github.event_name == 'push' ||
214+
github.event.pull_request.head.repo.full_name == github.repository
215+
) &&
216+
!contains(github.event.head_commit.message, 'skip fix')
217+
with:
218+
branch: >-
219+
${{
220+
github.event.pull_request.head.ref ||
221+
github.head_ref ||
222+
github.ref
223+
}}
224+
commit_message: "[MegaLinter] Apply linters fixes"
225+
commit_user_name: megalinter-bot
226+
commit_user_email: 129584137+megalinter-bot@users.noreply.github.com

.jscpd.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"threshold": 0,
3+
"reporters": ["html", "markdown"],
4+
"ignore": [
5+
"**/node_modules/**",
6+
"**/.git/**",
7+
"**/.rbenv/**",
8+
"**/.venv/**",
9+
"**/*cache*/**",
10+
"**/.github/**",
11+
"**/.idea/**",
12+
"**/report/**",
13+
"**/*.svg"
14+
]
15+
}

.mega-linter.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Configuration file for MegaLinter
2+
#
3+
# See all available variables at https://megalinter.io/latest/config-file/ and in
4+
# linters documentation
5+
---
6+
# all, none, or list of linter keys
7+
APPLY_FIXES: none
8+
9+
# If you use ENABLE variable, all other languages/formats/tooling-formats will
10+
# be disabled by default
11+
# ENABLE:
12+
13+
# If you use ENABLE_LINTERS variable, all other linters will be disabled by
14+
# default
15+
# ENABLE_LINTERS:
16+
17+
# DISABLE:
18+
# - COPYPASTE # Uncomment to disable checks of excessive copy-pastes
19+
# - SPELL # Uncomment to disable checks of spelling mistakes
20+
21+
SHOW_ELAPSED_TIME: true
22+
23+
# Uncomment if you want MegaLinter to detect errors but not block CI to pass
24+
# DISABLE_ERRORS: true
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { CompendiumStore } from '@/features/compendium/store'
2+
import { CompendiumItem } from '../CompendiumItem'
3+
import { MechEquipment } from '../mech/components/equipment/MechEquipment'
4+
5+
export function resolveSpecialEquipment(ids: string[]): CompendiumItem[] {
6+
if (!ids) return []
7+
const res = ids.map(x => {
8+
const w = CompendiumStore().MechWeapons.find(item => item.ID === x)
9+
if (w) return w
10+
const s = CompendiumStore().MechSystems.find(item => item.ID === x)
11+
if (s) return s
12+
const wm = CompendiumStore().WeaponMods.find(item => item.ID === x)
13+
if (wm) return wm
14+
const pg = CompendiumStore().PilotGear.find((item: any) => item.ID === x)
15+
if (pg) return pg
16+
return false
17+
})
18+
return res as CompendiumItem[]
19+
}
20+
21+
export function resolveIntegratedEquipment(ids: string[]): MechEquipment[] {
22+
if (!ids) return []
23+
return ids.map(x => {
24+
const w = CompendiumStore().MechWeapons.find(item => item.ID === x)
25+
if (w) return w as MechEquipment
26+
return CompendiumStore().MechSystems.find(item => item.ID === x) as MechEquipment
27+
}) as MechEquipment[]
28+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { ActiveEffect, IActiveEffectData } from './ActiveEffect'
2+
3+
interface IActiveEffectCallbackData {
4+
on_miss?: string | IActiveEffectData
5+
on_attack?: string | IActiveEffectData
6+
on_hit?: string | IActiveEffectData
7+
on_crit?: string | IActiveEffectData
8+
}
9+
10+
interface IActiveEffectCallbackTarget {
11+
OnMiss?: ActiveEffect
12+
OnAttack?: ActiveEffect
13+
OnHit?: ActiveEffect
14+
OnCrit?: ActiveEffect
15+
}
16+
17+
export function initActiveEffectCallbacks(
18+
data: IActiveEffectCallbackData,
19+
target: IActiveEffectCallbackTarget,
20+
owner: any
21+
): void {
22+
if (data.on_miss) {
23+
if (typeof data.on_miss === 'string')
24+
target.OnMiss = new ActiveEffect({ name: 'On Miss Effect', detail: data.on_miss }, owner)
25+
else target.OnMiss = new ActiveEffect(data.on_miss, owner)
26+
}
27+
if (data.on_attack) {
28+
if (typeof data.on_attack === 'string')
29+
target.OnAttack = new ActiveEffect({ name: 'On Attack Effect', detail: data.on_attack }, owner)
30+
else target.OnAttack = new ActiveEffect(data.on_attack, owner)
31+
}
32+
if (data.on_hit) {
33+
if (typeof data.on_hit === 'string')
34+
target.OnHit = new ActiveEffect({ name: 'On Hit Effect', detail: data.on_hit }, owner)
35+
else target.OnHit = new ActiveEffect(data.on_hit, owner)
36+
}
37+
if (data.on_crit) {
38+
if (typeof data.on_crit === 'string')
39+
target.OnCrit = new ActiveEffect({ name: 'On Crit Effect', detail: data.on_crit }, owner)
40+
else target.OnCrit = new ActiveEffect(data.on_crit, owner)
41+
}
42+
}

src/classes/mech/components/equipment/WeaponMod.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ActiveEffect,
1010
IActiveEffectData,
1111
} from '@/classes/components/feature/active_effects/ActiveEffect'
12+
import { initActiveEffectCallbacks } from '@/classes/components/feature/active_effects/_activeEffectUtils'
1213

1314
interface IWeaponModData extends IMechEquipmentData {
1415
allowed_types?: WeaponType[]
@@ -62,26 +63,7 @@ class WeaponMod extends MechEquipment {
6263

6364
this.AddedRange = data.added_range ? data.added_range.map(x => new Range(x)) : []
6465

65-
if (data.on_miss) {
66-
if (typeof data.on_miss === 'string')
67-
this.OnMiss = new ActiveEffect({ name: 'On Miss Effect', detail: data.on_miss }, this)
68-
else this.OnMiss = new ActiveEffect(data.on_miss, this)
69-
}
70-
if (data.on_attack) {
71-
if (typeof data.on_attack === 'string')
72-
this.OnAttack = new ActiveEffect({ name: 'On Attack Effect', detail: data.on_attack }, this)
73-
else this.OnAttack = new ActiveEffect(data.on_attack, this)
74-
}
75-
if (data.on_hit) {
76-
if (typeof data.on_hit === 'string')
77-
this.OnHit = new ActiveEffect({ name: 'On Hit Effect', detail: data.on_hit }, this)
78-
else this.OnHit = new ActiveEffect(data.on_hit, this)
79-
}
80-
if (data.on_crit) {
81-
if (typeof data.on_crit === 'string')
82-
this.OnCrit = new ActiveEffect({ name: 'On Crit Effect', detail: data.on_crit }, this)
83-
else this.OnCrit = new ActiveEffect(data.on_crit, this)
84-
}
66+
initActiveEffectCallbacks(data, this, this)
8567

8668
this.ItemType = ItemType.WeaponMod
8769
}

0 commit comments

Comments
 (0)