mirror of
https://github.com/orangeglo/gbnp.git
synced 2026-04-25 15:47:23 -05:00
Merge branch 'upload-entry-images' into master
This commit is contained in:
commit
08aca6c7f3
12
index.html
12
index.html
|
|
@ -67,7 +67,7 @@
|
|||
<input type="text" class='menu-text' :value="rom.menuText" @input="e => updateMenuText(rom, e.target.value)"/>
|
||||
</td>
|
||||
<td>
|
||||
<bitmap-preview :data="rom.bitmapPreviewBuffer"/>
|
||||
<bitmap-preview :data="rom.bitmapPreviewBuffer" :rom="rom" :index="index"/>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
@ -77,13 +77,7 @@
|
|||
<button v-on:click="triggerAddRomLabel" class="upload" :disabled="!menu.present() || romOverflow" type="button">
|
||||
<label for="romFileInput" ref="addRomLabel" v-on:click="stopPropagation">Add Games</label>
|
||||
</button>
|
||||
<input style="display: none" id="romFileInput" type="file" v-on:change="addROM" :disabled="!menu.present() || romOverflow" accept=".gb,.gbc" multiple>
|
||||
</td>
|
||||
<td>
|
||||
<button v-on:click="triggerAddMenuLabel" class="upload" type="button">
|
||||
<label for="menuFileInput" ref="addMenuLabel" v-on:click="stopPropagation">Load GBNP ROM</label>
|
||||
</button>
|
||||
<input style="display: none" id="menuFileInput" type="file" v-on:change="addMenu" accept=".gb,.gbc">
|
||||
|
||||
</td>
|
||||
<td></td>
|
||||
<td>{{ processor.romTotalKB() + 'k' }}</td>
|
||||
|
|
@ -199,6 +193,8 @@
|
|||
</section>
|
||||
</div>
|
||||
|
||||
<canvas id="scratch-canvas" width="96" height="8"></canvas>
|
||||
|
||||
<footer>
|
||||
<a href="https://github.com/orangeglo/gbnp">view this project on github</a>
|
||||
-
|
||||
|
|
|
|||
|
|
@ -151,21 +151,6 @@ let app = new Vue({
|
|||
|
||||
e.target.value = '';
|
||||
},
|
||||
addROM: function(e, f) {
|
||||
const files = f || e.target.files;
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
let fileReader = new FileReader();
|
||||
fileReader.onload = () => {
|
||||
const rom = new ROM(fileReader.result, this.fontIndex);
|
||||
if (rom.isMenu()) {
|
||||
const parsedRoms = this.processor.parseMenuData(fileReader.result, this.fontIndex);
|
||||
parsedRoms.forEach((rom) => this.roms.push(rom));
|
||||
} else if (!rom.bad) {
|
||||
this.roms.push(rom);
|
||||
}
|
||||
}
|
||||
fileReader.readAsArrayBuffer(files[i]);
|
||||
}
|
||||
|
||||
if (e) { e.target.value = ''; }
|
||||
},
|
||||
|
|
@ -242,4 +227,3 @@ let app = new Vue({
|
|||
}
|
||||
});
|
||||
|
||||
document.fonts.ready.then(function() { app.fontsLoaded = true });
|
||||
|
|
|
|||
|
|
@ -136,39 +136,45 @@ class ROM {
|
|||
this.updateBitmap(fontIndex);
|
||||
}
|
||||
|
||||
updateBitmap(fontIndex) {
|
||||
updateBitmap(fontIndex, uploadedImage) {
|
||||
let buffer = [];
|
||||
|
||||
const canvas = document.createElement("canvas");
|
||||
// const canvas = document.createElement("canvas");
|
||||
const canvas = document.getElementById("scratch-canvas");
|
||||
canvas.height = 8;
|
||||
canvas.width = 128;
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.imageSmoothingEnabled = false;
|
||||
ctx.fillStyle = 'white';
|
||||
ctx.fillRect(0, 0, 128, 8);
|
||||
const font = FONTS[fontIndex || 0];
|
||||
ctx.font = font.style;
|
||||
ctx.fillStyle = 'black';
|
||||
|
||||
let text = this.menuText;
|
||||
if (!uploadedImage && this.customMenuEntry) { return; }
|
||||
|
||||
// adjust JP font
|
||||
if (fontIndex == 3) {
|
||||
text = text.toUpperCase();
|
||||
text = textToFullWidthPunc(text);
|
||||
if (uploadedImage) {
|
||||
ctx.drawImage(uploadedImage, 0, 0);
|
||||
this.customMenuEntry = true;
|
||||
} else {
|
||||
ctx.fillStyle = 'white';
|
||||
ctx.fillRect(0, 0, 96, 8);
|
||||
const font = FONTS[fontIndex || 0];
|
||||
ctx.font = font.style;
|
||||
ctx.fillStyle = 'black';
|
||||
ctx.fillText(this.menuText,1,font.y);
|
||||
}
|
||||
|
||||
ctx.fillText(text,1,font.y);
|
||||
ctx.fillStyle = 'white';
|
||||
ctx.fillRect(127, 0, 127, 8);
|
||||
|
||||
const imageData = ctx.getImageData(0, 0, 128, 8).data;
|
||||
|
||||
const imageData = ctx.getImageData(0, 0, 96, 8).data;
|
||||
for (let i = 0; i < imageData.length; i+=16){
|
||||
let byte = 0;
|
||||
for (let j = 0; j < 4; j++) {
|
||||
let red = imageData[i+j*4];
|
||||
if (red < 127) {
|
||||
// if (red < 127) {
|
||||
// byte = byte | 0b11 << (6 - j*2);
|
||||
// }
|
||||
if (red < 30) {
|
||||
byte = byte | 0b00 << (6 - j*2);
|
||||
} else if (red < 160) {
|
||||
byte = byte | 0b10 << (6 - j*2);
|
||||
} else if (red < 224) {
|
||||
byte = byte | 0b01 << (6 - j*2);
|
||||
} else {
|
||||
byte = byte | 0b11 << (6 - j*2);
|
||||
}
|
||||
}
|
||||
|
|
@ -422,13 +428,6 @@ class Processor {
|
|||
romFile.seek(romFileIndex + 63); // 0x1C23F
|
||||
romFile.writeBytes(rom.bitmapBuffer);
|
||||
|
||||
// timestamp / writer id
|
||||
romFile.seek(romFileIndex + 0x1BF); //0x1C3BF
|
||||
romFile.writeBytes(stringToCharArray(timestampId));
|
||||
|
||||
// final padding
|
||||
romFile.writeByteUntil(0xFF, romFileIndex + 512);
|
||||
|
||||
romFileIndex += 512
|
||||
|
||||
// apply iG power cart hack
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user