-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0b912e
commit 4886fa6
Showing
9 changed files
with
502 additions
and
185 deletions.
There are no files selected for viewing
This file contains 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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,48 +1,66 @@ | ||
import { basename } from "node:path"; | ||
import { writeFile} from "node:fs/promises"; | ||
import { writeFile } from "node:fs/promises"; | ||
import { parseArgs } from "node:util"; | ||
import process from "node:process"; | ||
import img2mcaddon from "./mod.ts"; | ||
import type { Axis } from "../types.ts"; | ||
|
||
async function createAddon( | ||
src: string | URL, | ||
gridSize = 16, | ||
resolution = 16, | ||
dest?: string, | ||
src: string | URL, | ||
gridSize = 3, | ||
resolution = 16, | ||
dest?: string, | ||
axis?: Axis | ||
) { | ||
const addon = await img2mcaddon(src, gridSize, resolution); | ||
const addon = await img2mcaddon(src, gridSize, resolution, axis ?? "z"); | ||
|
||
const addonDest = dest ?? `${basename(src instanceof URL ? src.pathname : src).replace(/\.\w+$/, "")}.mcaddon`; | ||
const addonDest = | ||
dest ?? | ||
`${basename(src instanceof URL ? src.pathname : src).replace(/\.\w+$/, "")}.mcaddon`; | ||
|
||
await writeFile(addonDest, addon); | ||
await writeFile(addonDest, addon); | ||
|
||
console.log(`Created ${addonDest}`); | ||
console.log(`Created ${addonDest}`); | ||
} | ||
|
||
if (import.meta.main) { | ||
const { values: { src, gridSize, resolution, dest } } = parseArgs({ | ||
args: process.argv.slice(2), | ||
options: { | ||
src: { | ||
type: "string", | ||
multiple: false, | ||
}, | ||
gridSize: { | ||
type: "string", | ||
multiple: false, | ||
default: "16", | ||
}, | ||
resolution: { | ||
type: "string", | ||
multiple: false, | ||
default: "16", | ||
}, | ||
dest: { | ||
type: "string", | ||
multiple: false, | ||
}, | ||
}, | ||
}); | ||
const { | ||
values: { src, gridSize, resolution, dest, axis }, | ||
} = parseArgs({ | ||
args: process.argv.slice(2), | ||
options: { | ||
src: { | ||
type: "string", | ||
multiple: false, | ||
}, | ||
gridSize: { | ||
type: "string", | ||
multiple: false, | ||
default: "3", | ||
}, | ||
resolution: { | ||
type: "string", | ||
multiple: false, | ||
default: "16", | ||
}, | ||
dest: { | ||
type: "string", | ||
multiple: false, | ||
}, | ||
axis: { | ||
type: "string", | ||
multiple: false, | ||
default: "z", | ||
} | ||
}, | ||
}); | ||
|
||
await createAddon(src, Number(gridSize), Number(resolution), dest); | ||
process.exit(0); | ||
} | ||
await createAddon( | ||
src, | ||
Math.max(1, Number(gridSize)), | ||
Math.max(16, Math.min(1024, Number(resolution))), | ||
dest, | ||
axis as Axis | ||
); | ||
process.exit(0); | ||
} |
Oops, something went wrong.