gbp-decode
Advanced tools
+3
-2
| { | ||
| "name": "gbp-decode", | ||
| "version": "1.3.10", | ||
| "version": "1.3.11", | ||
| "description": "A set of functions to decode gameboy printer code", | ||
@@ -22,3 +22,4 @@ "scripts": { | ||
| "files": [ | ||
| "dist" | ||
| "dist/shared/*", | ||
| "dist/main.*" | ||
| ], | ||
@@ -25,0 +26,0 @@ "repository": { |
| 'use strict'; | ||
| const fs = require('node:fs/promises'); | ||
| const path = require('node:path'); | ||
| const completeFrame = require('./shared/gbp-decode.ccdfabeb.cjs'); | ||
| function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; } | ||
| const fs__default = /*#__PURE__*/_interopDefaultCompat(fs); | ||
| const path__default = /*#__PURE__*/_interopDefaultCompat(path); | ||
| const toByteArray = (fileContents) => fileContents.split("\n").filter((line) => !line.startsWith("//")).map((line) => line.trim()).map( | ||
| (line) => line.split(" ").filter(Boolean).map((cc) => parseInt(cc, 16)) | ||
| ).flat(); | ||
| const outDir = path__default.join(process.cwd(), "out"); | ||
| const runStandard = async (fileName, outKey) => { | ||
| const filePath = path__default.join(process.cwd(), "in", fileName); | ||
| let fileContents; | ||
| let rawPackets; | ||
| let parsedPackets; | ||
| let dataPackets; | ||
| let decompPackets; | ||
| let printInfoPackets; | ||
| let harmonizedPackets; | ||
| let classicPrintStreamImages; | ||
| try { | ||
| fileContents = await fs__default.readFile(filePath, { encoding: "utf8" }); | ||
| } catch (error) { | ||
| console.error(error.message); | ||
| process.exit(-1); | ||
| } | ||
| rawPackets = toByteArray(fileContents); | ||
| parsedPackets = completeFrame.parsePackets(rawPackets); | ||
| dataPackets = completeFrame.getImageDataStream(parsedPackets); | ||
| decompPackets = completeFrame.decompressDataStream(dataPackets); | ||
| printInfoPackets = completeFrame.decodePrintCommands(decompPackets); | ||
| harmonizedPackets = completeFrame.harmonizePalettes(printInfoPackets); | ||
| classicPrintStreamImages = completeFrame.transformToClassic(harmonizedPackets); | ||
| try { | ||
| await Promise.all(classicPrintStreamImages.map(async (image, index) => { | ||
| image.unshift('!{"command":"INIT"}'); | ||
| await fs__default.writeFile(path__default.join(outDir, `out_${outKey}_${index}.txt`), image.join("\n"), { encoding: "utf8" }); | ||
| })); | ||
| } catch (error) { | ||
| console.error(error); | ||
| } | ||
| }; | ||
| const runReduced = async (fileName, outKey) => { | ||
| const filePath = path__default.join(process.cwd(), "in", fileName); | ||
| let fileContents; | ||
| let reducedPackages; | ||
| let rawPackets; | ||
| let parsedPackets; | ||
| let dataPackets; | ||
| let decompPackets; | ||
| let printInfoPackets; | ||
| let harmonizedPackets; | ||
| let reducedClassicPrintStreamImages; | ||
| let classicPrintStreamImages; | ||
| try { | ||
| fileContents = await fs__default.readFile(filePath, { encoding: "utf8" }); | ||
| } catch (error) { | ||
| console.error(error.message); | ||
| process.exit(-1); | ||
| } | ||
| reducedPackages = toByteArray(fileContents); | ||
| rawPackets = completeFrame.parseReducedPackets(reducedPackages); | ||
| parsedPackets = completeFrame.inflateTransferPackages(rawPackets); | ||
| dataPackets = completeFrame.getImageDataStream(parsedPackets); | ||
| decompPackets = completeFrame.decompressDataStream(dataPackets); | ||
| printInfoPackets = completeFrame.decodePrintCommands(decompPackets); | ||
| harmonizedPackets = completeFrame.harmonizePalettes(printInfoPackets); | ||
| reducedClassicPrintStreamImages = completeFrame.transformToClassic(harmonizedPackets); | ||
| classicPrintStreamImages = completeFrame.completeFrame(reducedClassicPrintStreamImages); | ||
| try { | ||
| await Promise.all(classicPrintStreamImages.map(async (image, index) => { | ||
| image.unshift('!{"command":"INIT"}'); | ||
| await fs__default.writeFile(path__default.join(outDir, `out_${outKey}_${index}.txt`), image.join("\n"), { encoding: "utf8" }); | ||
| })); | ||
| } catch (error) { | ||
| console.error(error); | ||
| } | ||
| }; | ||
| fs__default.mkdir(outDir, { | ||
| recursive: true | ||
| }).then(() => { | ||
| runStandard("alice.txt", "alice"); | ||
| runStandard("all.txt", "all"); | ||
| runStandard("comp.txt", "comp"); | ||
| runStandard("gradient.txt", "gradient"); | ||
| runStandard("uncomp.txt", "uncomp"); | ||
| runStandard("white.txt", "white"); | ||
| runReduced("pico.txt", "pico"); | ||
| }); |
| export { } |
| export { } |
| export { } |
| import fs from 'node:fs/promises'; | ||
| import path from 'node:path'; | ||
| import { p as parsePackets, g as getImageDataStream, d as decompressDataStream, a as decodePrintCommands, h as harmonizePalettes, t as transformToClassic, b as parseReducedPackets, i as inflateTransferPackages, c as completeFrame } from './shared/gbp-decode.1cf0b17c.mjs'; | ||
| const toByteArray = (fileContents) => fileContents.split("\n").filter((line) => !line.startsWith("//")).map((line) => line.trim()).map( | ||
| (line) => line.split(" ").filter(Boolean).map((cc) => parseInt(cc, 16)) | ||
| ).flat(); | ||
| const outDir = path.join(process.cwd(), "out"); | ||
| const runStandard = async (fileName, outKey) => { | ||
| const filePath = path.join(process.cwd(), "in", fileName); | ||
| let fileContents; | ||
| let rawPackets; | ||
| let parsedPackets; | ||
| let dataPackets; | ||
| let decompPackets; | ||
| let printInfoPackets; | ||
| let harmonizedPackets; | ||
| let classicPrintStreamImages; | ||
| try { | ||
| fileContents = await fs.readFile(filePath, { encoding: "utf8" }); | ||
| } catch (error) { | ||
| console.error(error.message); | ||
| process.exit(-1); | ||
| } | ||
| rawPackets = toByteArray(fileContents); | ||
| parsedPackets = parsePackets(rawPackets); | ||
| dataPackets = getImageDataStream(parsedPackets); | ||
| decompPackets = decompressDataStream(dataPackets); | ||
| printInfoPackets = decodePrintCommands(decompPackets); | ||
| harmonizedPackets = harmonizePalettes(printInfoPackets); | ||
| classicPrintStreamImages = transformToClassic(harmonizedPackets); | ||
| try { | ||
| await Promise.all(classicPrintStreamImages.map(async (image, index) => { | ||
| image.unshift('!{"command":"INIT"}'); | ||
| await fs.writeFile(path.join(outDir, `out_${outKey}_${index}.txt`), image.join("\n"), { encoding: "utf8" }); | ||
| })); | ||
| } catch (error) { | ||
| console.error(error); | ||
| } | ||
| }; | ||
| const runReduced = async (fileName, outKey) => { | ||
| const filePath = path.join(process.cwd(), "in", fileName); | ||
| let fileContents; | ||
| let reducedPackages; | ||
| let rawPackets; | ||
| let parsedPackets; | ||
| let dataPackets; | ||
| let decompPackets; | ||
| let printInfoPackets; | ||
| let harmonizedPackets; | ||
| let reducedClassicPrintStreamImages; | ||
| let classicPrintStreamImages; | ||
| try { | ||
| fileContents = await fs.readFile(filePath, { encoding: "utf8" }); | ||
| } catch (error) { | ||
| console.error(error.message); | ||
| process.exit(-1); | ||
| } | ||
| reducedPackages = toByteArray(fileContents); | ||
| rawPackets = parseReducedPackets(reducedPackages); | ||
| parsedPackets = inflateTransferPackages(rawPackets); | ||
| dataPackets = getImageDataStream(parsedPackets); | ||
| decompPackets = decompressDataStream(dataPackets); | ||
| printInfoPackets = decodePrintCommands(decompPackets); | ||
| harmonizedPackets = harmonizePalettes(printInfoPackets); | ||
| reducedClassicPrintStreamImages = transformToClassic(harmonizedPackets); | ||
| classicPrintStreamImages = completeFrame(reducedClassicPrintStreamImages); | ||
| try { | ||
| await Promise.all(classicPrintStreamImages.map(async (image, index) => { | ||
| image.unshift('!{"command":"INIT"}'); | ||
| await fs.writeFile(path.join(outDir, `out_${outKey}_${index}.txt`), image.join("\n"), { encoding: "utf8" }); | ||
| })); | ||
| } catch (error) { | ||
| console.error(error); | ||
| } | ||
| }; | ||
| fs.mkdir(outDir, { | ||
| recursive: true | ||
| }).then(() => { | ||
| runStandard("alice.txt", "alice"); | ||
| runStandard("all.txt", "all"); | ||
| runStandard("comp.txt", "comp"); | ||
| runStandard("gradient.txt", "gradient"); | ||
| runStandard("uncomp.txt", "uncomp"); | ||
| runStandard("white.txt", "white"); | ||
| runReduced("pico.txt", "pico"); | ||
| }); |
38050
-15.8%9
-35.71%921
-16.12%