0.0.2 • Published 1 year ago

pocket-camera-save-parser v0.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

pocket-camera-save-parser

Simple parser for GameBoy/Pocket Camera written in typescript

Installation

$ npm install --save pocket-camera-save-parser

TODO

  • Get images from user gallery
  • Get last image seen by the sensor
  • Get game face image
  • Better parser for save meta information(JP&INT)
  • Write documentation for this lib
  • Parse to some image format instead of array of pixels

Usage

Simple script to get photos from save file and print it to cli can looks like

import path from 'path';

import { readFile } from 'node:fs/promises';

import { parseSaveFile, GBPixel, createHexBlob } from 'pocket-camera-save-parser';

const SAVE_FILE_PATH = path.resolve(__dirname, './input/test.sav'); // Path to your save file

type TPallette = [string, string, string, string];

const ASCII_PALLETTE: TPallette = [
  ' ',
  '.',
  ':',
  '+',
];

const renderPixel = (pixel: GBPixel) => ASCII_PALLETTE[pixel];

const loadSaveFileAsBlob = async(path: string) => {
  const data = await readFile(path);

  return createHexBlob(data);
}

const printImagesFromGBSaveInCli = async () => {
  const saveFile = await loadSaveFileAsBlob(SAVE_FILE_PATH);

  const save = await parseSaveFile(saveFile);

  save.photoSlots
    .filter(({ photoIndex }) => photoIndex > 0) // Show only not deleted images
    .map(({ image, photoIndex, slotIndex }) => {
      console.log(`---[IMAGE_ALBUM_INDEX:${photoIndex}]-[MEMORY_SLOT:${String(slotIndex).padStart(2, '0')}]${'-'.repeat(87)}`);

      image.pixels.forEach((line) => {
        console.log(line.map(renderPixel).join(''));
      })
    })
}

printImagesFromGBSaveInCli();

Aknowledgments