-
Notifications
You must be signed in to change notification settings - Fork 1
feat: single function to generate mod with output format option #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
866bf40
perf: code refactor to better return cached images
SlayerOrnstein 8f36ef7
build: use `ESNext` and NodeNext` for tsconfig
SlayerOrnstein 454fe71
feat: single function to generate mod with output format option
SlayerOrnstein 84b6489
chore: remove dup encode
SlayerOrnstein 0564c9b
fix: the file wouldn't save if the path exist
SlayerOrnstein d4c5117
chore: add a try/catch in `exportCanvas`
SlayerOrnstein bf2283d
chore: test rivens based on uniqueName
SlayerOrnstein 4976b5e
chore: thorw is quality exceeds 100 or subceeds 0
SlayerOrnstein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,52 @@ | ||
| import * as assert from 'node:assert'; | ||
| import { existsSync, mkdirSync, readdirSync, writeFileSync } from 'node:fs'; | ||
| import { existsSync, mkdirSync } from 'node:fs'; | ||
| import { join } from 'node:path'; | ||
| import { readdir, writeFile } from 'node:fs/promises'; | ||
|
|
||
| import { describe, test } from 'mocha'; | ||
| import { Mod, RivenMod } from 'warframe-items'; | ||
| import { Mod } from 'warframe-items'; | ||
| import { find } from 'warframe-items/utilities'; | ||
|
|
||
| import { generateBasicMod, generateRivenMod } from '../src/generator.js'; | ||
| import { generateMod } from '../src/generator.js'; | ||
| import { Format } from '../src/utils.js'; | ||
|
|
||
| describe('Generate a mod', () => { | ||
| test('run test', async () => { | ||
| test('run test', () => { | ||
SlayerOrnstein marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const formats = ['webp', 'jpeg', 'avif', 'png']; | ||
| const mods = [ | ||
| '/Lotus/Upgrades/Mods/Warframe/Kahl/KahlAvatarAbilityStrengthMod', | ||
| '/Lotus/Upgrades/Mods/Warframe/AvatarAbilityEfficiencyMod', | ||
| '/Lotus/Upgrades/Mods/Warframe/AvatarHealthMaxMod', | ||
| '/Lotus/Upgrades/Mods/Aura/PlayerMeleeAuraMod', | ||
| '/Lotus/Upgrades/Mods/Randomized/LotusArchgunRandomModRare', | ||
| '/Lotus/Powersuits/Dragon/DragonBreathAugmentCard', | ||
| '/Lotus/Upgrades/Mods/Randomized/RawShotgunRandomMod', | ||
| ]; | ||
|
|
||
| const testPath = join('.', 'assets', 'tests'); | ||
| if (!existsSync(testPath)) mkdirSync(testPath, { recursive: true }); | ||
|
|
||
| for (let i = 0; i < mods.length; i += 1) { | ||
| const mod = find.findItem(mods[i]) as Mod; | ||
| if (!mod) continue; | ||
| const isRiven = mod.name?.includes('Riven'); | ||
| const modCanvas = isRiven | ||
| ? await generateRivenMod(mod as RivenMod) | ||
| : await generateBasicMod(mod, mod.fusionLimit); | ||
| if (!modCanvas) assert.equal(true, false, 'Failed to generate mod'); | ||
|
|
||
| writeFileSync(join('.', 'assets', 'tests', `${mod.name}.png`), modCanvas); | ||
| formats.forEach((format) => { | ||
| return async () => { | ||
| const imagePath = join(testPath, format); | ||
| if (!existsSync(imagePath)) mkdirSync(imagePath, { recursive: true }); | ||
|
|
||
| const mod = find.findItem(mods[i]) as Mod; | ||
| if (!mod) return; | ||
| const modCanvas = await generateMod(mod, undefined, { format: format as Format }); | ||
| if (!modCanvas) assert.equal(true, false, 'Failed to generate mod'); | ||
|
|
||
| if (modCanvas) await writeFile(join(imagePath, `${mod.name}.${format}`), modCanvas); | ||
| }; | ||
| }); | ||
| } | ||
| const testFiles = readdirSync(join('.', 'assets/tests')); | ||
| assert.equal(testFiles.length, mods.length); | ||
|
|
||
| formats.forEach((format) => { | ||
| return async () => { | ||
| const testFiles = await readdir(join(testPath, format)); | ||
| assert.equal(testFiles.length, mods.length); | ||
| }; | ||
| }); | ||
SlayerOrnstein marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.