silphscope 1.4.21 → 1.4.23

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.
@@ -45,8 +45,8 @@ export async function renderBallParticle(ballName, balls, reader, rom, options =
45
45
  throw new TypeError("renderBallParticle(..., rom) requires a ROM Buffer/Uint8Array");
46
46
  }
47
47
 
48
- let fileCount = 0;
49
- const results = returnFileBuffer? [] : null;
48
+ let fullFileCount = 0;
49
+ const results = returnFileBuffer ? [] : null;
50
50
  const ball = balls[ballName];
51
51
  if (!ball) {
52
52
  throw new Error(`Missing Ball: ${ballName}`);
@@ -72,43 +72,65 @@ export async function renderBallParticle(ballName, balls, reader, rom, options =
72
72
 
73
73
  const png = new PNG({ width, height });
74
74
  png.data = image;
75
- const pngBuffer = PNG.sync.write(png, {
75
+ const pngBuffer = PNG.sync.write(png, {
76
76
  filterType: pngFilterType,
77
- deflateLevel: pngCompressionLevel,
77
+ deflateLevel: pngCompressionLevel,
78
78
  });
79
79
 
80
+ const dir = `${outputDir}/${ballName}`;
80
81
  if (outputDir) {
81
- const dir = `${outputDir}/${ballName}`;
82
- if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
83
- if (renderMasterBallParticleImage) {
84
- fs.writeFileSync(`${dir}/master-particle.png`, pngBuffer);
85
- fileCount += 1;
86
- if (returnFileBuffer) {
87
- results.push(pngBuffer);
88
- }
82
+ await fs.promises.mkdir(dir, { recursive: true });
83
+ }
84
+ if (renderMasterBallParticleImage) {
85
+ if (outputDir) {
86
+ await fs.promises.writeFile(`${dir}/master-particle.png`, pngBuffer);
87
+ fullFileCount += 1;
89
88
  }
90
- for (let i = 0; i < ball.particleFrames.length; i++) {
91
- const frame = ball.particleFrames[i];
92
- const frameImageData = extractFrameFromImage(image, width, frame);
93
-
94
- const png = new PNG({ width: frame.width, height: frame.height });
95
- png.data = frameImageData;
96
- const pngFrameBuffer = PNG.sync.write(png, {
97
- filterType: pngFilterType,
98
- deflateLevel: pngCompressionLevel,
89
+ if (returnFileBuffer) {
90
+ results.push({
91
+ name: `${ballName}-particle-full-sprite`,
92
+ category: "ball",
93
+ asset: "sprite",
94
+ path: `out/balls/${ballName}/master-particle`,
95
+ buffer: pngBuffer,
96
+ meta: {
97
+ particleOrBall: "particle",
98
+ },
99
99
  });
100
+ }
101
+ }
102
+ for (let i = 0; i < ball.particleFrames.length; i++) {
103
+ const frame = ball.particleFrames[i];
104
+ const frameImageData = extractFrameFromImage(image, width, frame);
100
105
 
106
+ const png = new PNG({ width: frame.width, height: frame.height });
107
+ png.data = frameImageData;
108
+ const pngFrameBuffer = PNG.sync.write(png, {
109
+ filterType: pngFilterType,
110
+ deflateLevel: pngCompressionLevel,
111
+ });
112
+
113
+ if (outputDir) {
101
114
  const fileName = `${dir}/particle-${i}.png`;
102
115
  fs.writeFileSync(fileName, pngFrameBuffer);
103
- fileCount += 1;
104
- if (returnFileBuffer) {
105
- results.push(pngFrameBuffer);
106
- }
116
+ fullFileCount += 1;
117
+ }
118
+ if (returnFileBuffer) {
119
+ results.push({
120
+ name: `${ballName}-particle-frame${i}`,
121
+ category: "ball",
122
+ asset: "frame",
123
+ path: `out/balls/${ballName}/particle-${i}`,
124
+ buffer: pngFrameBuffer,
125
+ meta: {
126
+ particleOrBall: "particle",
127
+ },
128
+ });
107
129
  }
108
130
  }
109
131
 
110
132
  return {
111
133
  ...(returnFileBuffer && { results }),
112
- fileCount,
134
+ fullFileCount,
113
135
  };
114
136
  }
@@ -49,7 +49,7 @@ export async function renderBall(ballName, balls, reader, rom, options = {}) {
49
49
  }
50
50
 
51
51
  let fullFileCount = 0;
52
- const results = returnFileBuffer? [] : null;
52
+ const results = returnFileBuffer ? [] : null;
53
53
  const ball = balls[ballName];
54
54
  if (!ball) {
55
55
  throw new Error(`Missing Ball: ${ballName}`);
@@ -60,9 +60,9 @@ export async function renderBall(ballName, balls, reader, rom, options = {}) {
60
60
  pngCompressionLevel,
61
61
  returnFileBuffer,
62
62
  outputDir,
63
- renderMasterBallParticleImage,
63
+ renderMasterBallParticleImage,
64
64
  });
65
- fullFileCount += renderBallParticleData.fileCount;
65
+ fullFileCount += renderBallParticleData.fullFileCount;
66
66
  if (returnFileBuffer) {
67
67
  results.push(...renderBallParticleData.results);
68
68
  }
@@ -87,38 +87,61 @@ export async function renderBall(ballName, balls, reader, rom, options = {}) {
87
87
 
88
88
  const png = new PNG({ width, height });
89
89
  png.data = image;
90
- const pngBuffer = PNG.sync.write(png, {
90
+ const pngBuffer = PNG.sync.write(png, {
91
91
  filterType: pngFilterType,
92
- deflateLevel: pngCompressionLevel,
92
+ deflateLevel: pngCompressionLevel,
93
93
  });
94
94
 
95
+ const dir = `${outputDir}/${ballName}`;
95
96
  if (outputDir) {
96
- const dir = `${outputDir}/${ballName}`;
97
97
  await fs.promises.mkdir(dir, { recursive: true });
98
- if (renderMasterBallImage) {
98
+ }
99
+ if (renderMasterBallImage) {
100
+ if (outputDir) {
99
101
  await fs.promises.writeFile(`${dir}/master-image.png`, pngBuffer)
100
102
  fullFileCount += 1;
101
- if (returnFileBuffer) {
102
- results.push(pngBuffer);
103
- }
104
103
  }
105
- for (let i = 0; i < ball.frames.length; i++) {
106
- const frame = ball.frames[i];
107
- const frameImageData = extractFrameFromImage(image, width, frame);
108
-
109
- const png = new PNG({ width: frame.width, height: frame.height });
110
- png.data = frameImageData;
111
- const pngFrameBuffer = PNG.sync.write(png, {
112
- filterType: pngFilterType,
113
- deflateLevel: pngCompressionLevel,
104
+ if (returnFileBuffer) {
105
+ results.push({
106
+ name: `${ballName}-full-sprite`,
107
+ category: "ball",
108
+ asset: "sprite",
109
+ path: `out/balls/${ballName}/master-image`,
110
+ buffer: pngBuffer,
111
+ meta: {
112
+ particleOrBall: "ball",
113
+ },
114
114
  });
115
+ }
116
+ }
117
+
118
+ for (let i = 0; i < ball.frames.length; i++) {
119
+ const frame = ball.frames[i];
120
+ const frameImageData = extractFrameFromImage(image, width, frame);
115
121
 
122
+ const png = new PNG({ width: frame.width, height: frame.height });
123
+ png.data = frameImageData;
124
+ const pngFrameBuffer = PNG.sync.write(png, {
125
+ filterType: pngFilterType,
126
+ deflateLevel: pngCompressionLevel,
127
+ });
128
+
129
+ if (outputDir) {
116
130
  const fileName = `${dir}/frame-${i}.png`;
117
131
  await fs.promises.writeFile(fileName, pngFrameBuffer);
118
132
  fullFileCount += 1;
119
- if (returnFileBuffer) {
120
- results.push(pngFrameBuffer);
121
- }
133
+ }
134
+ if (returnFileBuffer) {
135
+ results.push({
136
+ name: `${ballName}-frame${1}`,
137
+ category: "ball",
138
+ asset: "frame",
139
+ path: `out/balls/${ballName}/frame-${i}`,
140
+ buffer: pngFrameBuffer,
141
+ meta: {
142
+ particleOrBall: "ball",
143
+ },
144
+ });
122
145
  }
123
146
  }
124
147