Skip to content

Commit a331da1

Browse files
committed
add OG usage
1 parent 2dc7134 commit a331da1

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

build.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ if (!fs.existsSync('clean.nes')) {
166166
} else {
167167
console.time('patch');
168168
const patcher = require('./tools/patch/create');
169-
patcher('clean.nes', 'tetris.nes', 'tetris.bps');
169+
const pct = patcher('clean.nes', 'tetris.nes', 'tetris.bps');
170170
console.timeEnd('patch');
171+
console.log(`using ${pct}% of original file`);
171172
}
172173

173174
// stats

tools/patch/bps.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/patch/create.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
const { MarcFile, createBPSFromFiles } = require('./bps.js');
1+
const { MarcFile, createBPSFromFiles, parseBPSFile } = require('./bps.js');
22
const fs = require('fs');
33

4+
// https://github.com/blakesmith/rombp/blob/master/docs/bps_spec.md
5+
46
module.exports = function patch(original, modified, destination) {
57
const patch = createBPSFromFiles(
68
new MarcFile(original),
79
new MarcFile(modified),
810
true,
9-
).export('')._u8array;
11+
).export('');
12+
13+
fs.writeFileSync(destination, patch._u8array);
14+
15+
const bps = parseBPSFile(new MarcFile('tetris.bps'));
16+
17+
// count patch sizes
18+
let source = 0;
19+
bps.actions.forEach(action => {
20+
if ([0, 2].includes(action.type)) {
21+
source += action.length;
22+
}
23+
});
1024

11-
fs.writeFileSync(destination, patch);
25+
return (source / bps.sourceSize) * 100 | 0;
1226
}

0 commit comments

Comments
 (0)