silphscope 1.3.1 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  still a WIP however hopefully with some more work I can get this into a workable state...
2
2
 
3
+ (Even Newer!) Update:
4
+
5
+ moves now work... kinda... still working on getting it all the way done but it mostly works!
6
+
3
7
  (Newer!) Update:
4
8
 
5
9
  still a WIP :p but erm you can extract more graphics!
@@ -21,10 +25,11 @@ await renderAllGraphics(rom, {
21
25
  outputMonDir: "./Assets/monImages", // must I explain?
22
26
  outputIconDir: "./Assets/Icons", // same thing here :p
23
27
  outputTrainerDir: "./Assets/Trainers", // ...
28
+ outputMoveDir: "./Assets/Moves"
24
29
  });
25
30
  ```
26
31
 
27
- Of course though the above is for extracting all graphics (which is kinda a lie... In reality it only extracts mon images, item icons, and trainer images... but like I said this is a WIP :p so wait a bit please!).
32
+ Of course though the above is for extracting all graphics (which is kinda a lie... In reality it only extracts mon images, item icons, trainer images, and move images... but like I said this is a WIP :p so wait a bit please!).
28
33
 
29
34
  But if you want say just the mon images or item icons refer below:
30
35
 
@@ -62,4 +67,15 @@ await renderAllTrainers(rom, {
62
67
  outputDir: "./Assets/trainers", // more stuff
63
68
  trainerBackPics: true, // renders the like 8 trainer back pics
64
69
  })
70
+ ```
71
+
72
+ move image extraction:
73
+ ```JavaScript
74
+ import fs from "fs";
75
+ import { renderAllMoves } from "silphscope" // :O
76
+
77
+ const rom = fs.readFileSync("pokefirered.gba") // stuff stuff stuff (more stuff!)
78
+ await renderAllMoves(rom, {
79
+ outputDir: "./Assets/trainers", // (incredibly) more stuff
80
+ })
65
81
  ```
@@ -161,6 +161,7 @@
161
161
  "possibleFrameWidth": 64,
162
162
  "possibleFrameHeight": 64,
163
163
  "note": "so I think this image is actually 4 images slapped into one... as such to extract the image will need to be unusually large... so let me test this I guess :p of course though without image slicing for now",
164
+ "note2": "erm I can't really figure this out... it appears when this image was concat(ed) it got very finely mushed together... so it is kinda hard to tell where the frames are... sure the image is separated but it doesn't line up with the pret image refrences...",
164
165
  "imageSize": "64x192",
165
166
  "imageWidth": 64,
166
167
  "imageHeight": 192,
@@ -227,9 +228,12 @@
227
228
  "imageHeight": 40,
228
229
  "frameCount": 1,
229
230
  "frames": [
230
- { "x": 0, "y": 0, "width": 32, "height": 40 }
231
+ { "x": 0, "y": 0, "width": 32, "height": 32 },
232
+ { "x": 0, "y": 32, "width": 16, "height": 8 },
233
+ { "x": 16, "y": 32, "width": 8, "height": 8 }
231
234
  ],
232
- "note": "yup so this is weird :p from what I can tell the image is actually made up of a 32x32 main area then on the bottom there are 2 I think 8x16 images? I don't know :p will fix later like everything else in this repo..."
235
+ "note": "yup so this is weird :p from what I can tell the image is actually made up of a 32x32 main area then on the bottom there are 2 I think 8x16 images? I don't know :p will fix later like everything else in this repo...",
236
+ "note2": "fixed! I think..."
233
237
  },
234
238
  "TIED_BAG": {
235
239
  "index": 15,
@@ -1740,9 +1744,10 @@
1740
1744
  "frameCount": 2,
1741
1745
  "frames": [
1742
1746
  { "x": 0, "y": 0, "width": 8, "height": 8 },
1743
- { "x": 0, "y": 8, "width": 16, "height": 16 }
1747
+ { "x": 8, "y": 0, "width": 8, "height": 16 },
1748
+ { "x": 0, "y": 8, "width": 8, "height": 16 }
1744
1749
  ],
1745
- "note": "oh how I hate concat images... hopefully though my understaing of how they are working should result in a correct image..."
1750
+ "note": "unless the image data itself was wrong... the resulting image was kinda weird... but this should \"fix it\" granted it is still weird..."
1746
1751
  },
1747
1752
  "ALERT": {
1748
1753
  "index": 75,
@@ -2324,9 +2329,9 @@
2324
2329
  "PENCIL_2": {
2325
2330
  "index": 95,
2326
2331
  "animTag": "ANIM_TAG_PENCIL_2",
2327
- "imageSize": "16x42",
2332
+ "imageSize": "16x48",
2328
2333
  "imageWidth": 16,
2329
- "imageHeight": 42,
2334
+ "imageHeight": 48,
2330
2335
  "frameCount": 3,
2331
2336
  "frames": [
2332
2337
  {
@@ -2514,7 +2519,7 @@
2514
2519
  "frames": [
2515
2520
  {
2516
2521
  "x": 0,
2517
- "y": 16,
2522
+ "y": 0,
2518
2523
  "width": 16,
2519
2524
  "height": 16
2520
2525
  }
@@ -3284,7 +3289,7 @@
3284
3289
  "x": 0,
3285
3290
  "y": 0,
3286
3291
  "width": 16,
3287
- "height": 32
3292
+ "height": 16
3288
3293
  }
3289
3294
  ],
3290
3295
  "unused": true
@@ -3610,19 +3615,20 @@
3610
3615
  "possibleFrameSize": "8x8",
3611
3616
  "possibleFrameWidth": 8,
3612
3617
  "possibleFrameHeight": 8,
3613
- "imageSize": "16x80",
3618
+ "imageSize": "16x56",
3614
3619
  "imageWidth": 16,
3615
- "imageHeight": 80,
3616
- "frameCount": 6,
3620
+ "imageHeight": 56,
3621
+ "frameCount": 7,
3617
3622
  "frames": [
3618
3623
  { "x": 0, "y": 0, "width": 16, "height": 16 },
3619
- { "x": 0, "y": 16, "width": 8, "height": 16 },
3620
- { "x": 0, "y": 32, "width": 8, "height": 8 },
3621
- { "x": 0, "y": 40, "width": 8, "height": 8 },
3622
- { "x": 0, "y": 48, "width": 16, "height": 16 },
3623
- { "x": 0, "y": 64, "width": 8, "height": 16 }
3624
+ { "x": 0, "y": 16, "width": 8, "height": 8 },
3625
+ { "x": 8, "y": 16, "width": 8, "height": 8 },
3626
+ { "x": 0, "y": 24, "width": 8, "height": 8 },
3627
+ { "x": 8, "y": 24, "width": 8, "height": 8 },
3628
+ { "x": 0, "y": 32, "width": 16, "height": 16 },
3629
+ { "x": 0, "y": 48, "width": 16, "height": 8 }
3624
3630
  ],
3625
- "note": "concat images strike again! seriously though I hope this works..."
3631
+ "note": "should be fixed... I think... if not I have to redo the math on how these strange frames are arranged..."
3626
3632
  },
3627
3633
  "ICE_SPIKES": {
3628
3634
  "index": 142,
@@ -5613,7 +5619,7 @@
5613
5619
  "imageHeight": 16,
5614
5620
  "frameCount": 1,
5615
5621
  "frames": [
5616
- { "x": 0, "y": 0, "width": 8, "height": 8 }
5622
+ { "x": 0, "y": 0, "width": 16, "height": 16 }
5617
5623
  ]
5618
5624
  },
5619
5625
  "WHITE_FEATHER": {
@@ -510,9 +510,9 @@
510
510
  "note": "once again I have to open aseprite for this one... but I am too lazy to do so right now :p"
511
511
  },
512
512
  "ANIM_TAG_PENCIL_2": {
513
- "imageSize": "16x42",
513
+ "imageSize": "16x48",
514
514
  "imageWidth": 16,
515
- "imageHeight": 42,
515
+ "imageHeight": 48,
516
516
  "frameCount": 3,
517
517
  "frames": [
518
518
  { "x": 0, "y": 0, "width": 16, "height": 16 },
@@ -568,7 +568,7 @@
568
568
  "imageHeight": 16,
569
569
  "frameCount": 1,
570
570
  "frames": [
571
- { "x": 0, "y": 16, "width": 16, "height": 16 }
571
+ { "x": 0, "y": 0, "width": 16, "height": 16 }
572
572
  ]
573
573
  },
574
574
  "ANIM_TAG_FANGS": {
@@ -830,7 +830,7 @@
830
830
  "imageHeight": 16,
831
831
  "frameCount": 1,
832
832
  "frames": [
833
- { "x": 0, "y": 0, "width": 16, "height": 32 }
833
+ { "x": 0, "y": 0, "width": 16, "height": 16 }
834
834
  ]
835
835
  },
836
836
  "ANIM_TAG_MONSTER_DOLL": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "silphscope",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "A firered/leafgreen ROM asset extractor for use in web applications",
5
5
  "main": "main.js",
6
6
  "exports": {
@@ -104,6 +104,7 @@ export async function renderAllMoves(rom, options = {}) {
104
104
  const {
105
105
  moves: providedMoves = moves,
106
106
  outputDir = "./out",
107
+ renderMasterImage = true,
107
108
  } = options;
108
109
 
109
110
  fs.mkdirSync(outputDir, { recursive: true });
@@ -112,7 +113,10 @@ export async function renderAllMoves(rom, options = {}) {
112
113
  const reader = new RomReader(rom, config);
113
114
 
114
115
  for (const moveName of Object.keys(providedMoves)) {
115
- await renderMove(moveName, providedMoves, reader, rom, { outputDir });
116
+ await renderMove(moveName, providedMoves, reader, rom, {
117
+ outputDir,
118
+ renderMasterImage,
119
+ });
116
120
  console.log(`Done: ${moveName}`);
117
121
  }
118
122
  }
@@ -146,6 +150,7 @@ export async function renderAllGraphics(rom, options = {}) { // eventually I wil
146
150
 
147
151
  await renderAllMoves(rom, {
148
152
  outputDir: outputMoveDir,
153
+ renderMasterImage: true,
149
154
  })
150
155
  }
151
156
 
@@ -37,7 +37,8 @@ const extractFrameFromImage = (imageData, fullWidth, frameData) => { // in theor
37
37
 
38
38
  export async function renderMove(moveName, moves, reader, rom, options = {}) {
39
39
  const {
40
- outputDir = null
40
+ outputDir = null,
41
+ renderMasterImage = false,
41
42
  } = options;
42
43
  if (!rom || !(rom instanceof Uint8Array || Buffer.isBuffer(rom))) {
43
44
  throw new TypeError("renderMove(..., rom) requires a ROM Buffer/Uint8Array");
@@ -69,7 +70,12 @@ export async function renderMove(moveName, moves, reader, rom, options = {}) {
69
70
  if (outputDir) { // I will update this later but in theory it should also work... eventually though it will need a split inside to handle full image generation :p
70
71
  const dir = `${outputDir}/${moveName}`;
71
72
  if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
72
-
73
+ if (renderMasterImage) {
74
+ const png = new PNG({ width, height });
75
+ png.data = image;
76
+ const pngBuffer = await streamToBuffer(png.pack());
77
+ fs.writeFileSync(`${dir}/master.png`, pngBuffer);
78
+ }
73
79
  for (let i = 0; i < move.frames.length; i++) {
74
80
  const frame = move.frames[i];
75
81
  const frameImageData = extractFrameFromImage(image, width, frame);