1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-25 18:33:11 +00:00

trying to fix asset editor nametables

This commit is contained in:
Steven Hugg 2019-05-14 23:32:19 -04:00
parent de0ede9e81
commit e3a3016f9d
11 changed files with 285 additions and 232 deletions

View File

@ -94,12 +94,14 @@ TODO:
- persist palette/tilemap selections
- more tools for editing
- map editor
- arbitrary nametable editing
- metasprites
- throw errors when bad/no refs
- per-View keyboard shortcuts
- parse labels
- parse .incbin directives?
- can't replace in hex directives
- should maybe use same single-canvas editor for map + char editor
- crt0.s compiled each time?
- debug highlight doesn't go away when debugging -> running
- show breakpoint of PC or highest address on stack
@ -149,7 +151,6 @@ TODO:
- can published files retain path?
- what if import interrupted and partial files?
- CORS for some blobs?
- confusing when examples load if file not found
- don't import useless files
- support projects with subdirectories, file list?
- emulator needs reset shortcut for nes

View File

@ -1,3 +1,4 @@
/*{w:32,h:30,bpp:8,comp:"rletag",map:"nesnt"}*/
const unsigned char gameover_nam[81]={
0x01,0x00,0x01,0xfe,0x00,0x01,0x86,0x60,0x61,0x60,0x62,0x63,0x64,0x65,0x66,0x00,
0x60,0x62,0x67,0x68,0x65,0x66,0x65,0x62,0x00,0x97,0x00,0x01,0x0c,0x67,0x6a,0x67,

View File

@ -1,3 +1,4 @@
/*{w:32,h:30,bpp:8,comp:"rletag",map:"nesnt"}*/
const unsigned char level2_nam[459]={
0x01,0x00,0x01,0xc5,0x40,0x41,0x40,0x41,0x40,0x41,0x40,0x41,0x40,0x41,0x40,0x41,
0x40,0x41,0x40,0x41,0x40,0x41,0x40,0x41,0x00,0x01,0x0b,0x42,0x43,0x42,0x43,0x42,

View File

@ -1,3 +1,4 @@
/*{w:32,h:30,bpp:8,comp:"rletag",map:"nesnt"}*/
const unsigned char level3_nam[540]={
0x01,0x00,0x01,0xc5,0x40,0x41,0x40,0x41,0x40,0x41,0x40,0x41,0x40,0x41,0x40,0x41,
0x40,0x41,0x40,0x41,0x40,0x41,0x40,0x41,0x00,0x01,0x0b,0x42,0x43,0x42,0x43,0x42,

View File

@ -1,3 +1,4 @@
/*{w:32,h:30,bpp:8,comp:"rletag",map:"nesnt"}*/
const unsigned char level4_nam[640]={
0x02,0x00,0x02,0x85,0x40,0x41,0x40,0x41,0x40,0x41,0x40,0x41,0x40,0x41,0x40,0x41,
0x00,0x02,0x13,0x42,0x43,0x42,0x43,0x42,0x43,0x42,0x43,0x42,0x43,0x42,0x43,0x00,

View File

@ -1,3 +1,4 @@
/*{w:32,h:30,bpp:8,comp:"rletag",map:"nesnt"}*/
const unsigned char level5_nam[851]={
0x01,0x00,0x01,0x83,0x40,0x41,0x40,0x41,0x40,0x41,0x40,0x41,0x40,0x41,0x40,0x41,
0x40,0x41,0x40,0x41,0x40,0x41,0x40,0x41,0x40,0x41,0x40,0x41,0x00,0x01,0x07,0x42,

View File

@ -1,3 +1,4 @@
/*{w:32,h:30,bpp:8,comp:"rletag",map:"nesnt"}*/
const unsigned char level_nam[52]={
0x01,0x00,0x01,0xfe,0x00,0x01,0x89,0x67,0x00,0x65,0x66,0x67,0x68,0x65,0x66,0x67,
0x00,0x01,0x16,0x67,0x00,0x65,0x6d,0x67,0x68,0x65,0x6d,0x67,0x00,0x01,0x16,0x72,

View File

@ -1,3 +1,4 @@
/*{w:32,h:30,bpp:8,comp:"rletag",map:"nesnt"}*/
const unsigned char title_nam[380]={
0x01,0x00,0x01,0x85,0x40,0x41,0x00,0x00,0x40,0x41,0x00,0x01,0x05,0x40,0x41,0x40,
0x41,0x40,0x41,0x00,0x01,0x07,0x40,0x41,0x40,0x41,0x40,0x41,0x42,0x43,0x00,0x00,

View File

@ -1,3 +1,4 @@
/*{w:32,h:30,bpp:8,comp:"rletag",map:"nesnt"}*/
const unsigned char welldone_nam[106]={
0x02,0x00,0x02,0xfe,0x00,0x02,0x86,0x67,0x68,0x65,0x66,0x67,0x00,0x67,0x00,0x00,
0x65,0x62,0x60,0x62,0x63,0x79,0x65,0x66,0x00,0x97,0x00,0x02,0x0c,0x82,0x83,0x65,

View File

@ -704,7 +704,9 @@ export class NESNametableConverter extends Compositor {
for (var row=0; row<this.rows; row++) {
for (var col=0; col<this.cols; col++) {
var name = this.words[this.baseofs + a];
if (typeof name === 'undefined') throw "No name for address " + this.baseofs + " + " + a;
var t = this.tilemap[name];
if (!t) throw "No tilemap found for tile index " + name;
attraddr = (a & 0x2c00) | 0x3c0 | (a & 0x0C00) | ((a >> 4) & 0x38) | ((a >> 2) & 0x07);
var attr = this.words[attraddr];
var tag = name ^ (attr<<9) ^ 0x80000000;
@ -840,6 +842,40 @@ export class CharmapEditor extends PixNode {
}
}
export class MapEditor extends PixNode {
context;
parentdiv;
fmt;
constructor(context:EditorContext, parentdiv:JQuery, fmt:PixelEditorImageFormat) {
super();
this.context = context;
this.parentdiv = parentdiv;
this.fmt = fmt;
}
updateLeft() {
return true;
}
updateRight() {
if (equalNestedArrays(this.rgbimgs, this.left.rgbimgs)) return false;
this.rgbimgs = this.left.rgbimgs;
var adual = newDiv(this.parentdiv.empty(), "asset_dual"); // contains grid and editor
var agrid = newDiv(adual);
var aeditor = newDiv(adual, "asset_editor").hide(); // contains editor, when selected
// add image chooser grid
var viewer = new Viewer();
viewer.width = this.fmt.w;
viewer.height = this.fmt.h;
viewer.recreate();
viewer.updateImage(this.rgbimgs[0]);
agrid.append(viewer.canvas);
return true;
}
}
export class Viewer {
width : number;

View File

@ -924,10 +924,13 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext {
this.deferrednodes = [];
}
registerAsset(type:string, node:pixed.PixNode, deferred:boolean) {
registerAsset(type:string, node:pixed.PixNode, deferred:number) {
this.rootnodes.push(node);
if (deferred) {
if (deferred > 1)
this.deferrednodes.push(node);
else
this.deferrednodes.unshift(node);
} else {
node.refreshRight();
}
@ -973,8 +976,7 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext {
this.rootnodes.forEach((node) => {
while (node != null) {
if (node instanceof pixed.Palettizer) {
// TODO: move to node class?
var rgbimgs = node.rgbimgs; // TODO: why is null?
var rgbimgs = node.rgbimgs;
if (rgbimgs && rgbimgs.length >= matchlen) {
result.push({node:node, name:"Tilemap", images:node.images, rgbimgs:rgbimgs}); // TODO
}
@ -1178,14 +1180,14 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext {
let node = new pixed.FileDataNode(projectWindows, fileid);
const neschrfmt = {w:8,h:8,bpp:1,count:(data.length>>4),brev:true,np:2,pofs:8,remap:[0,1,2,4,5,6,7,8,9,10,11,12]}; // TODO
this.addPixelEditor(this.ensureFileDiv(fileid), node, neschrfmt);
this.registerAsset("charmap", node, true);
this.registerAsset("charmap", node, 1);
nassets++;
} else if (platform_id.startsWith('nes') && fileid.endsWith('.pal') && data instanceof Uint8Array) {
// is this a NES PAL?
let node = new pixed.FileDataNode(projectWindows, fileid);
const nespalfmt = {pal:"nes",layout:"nes"};
this.addPaletteEditor(this.ensureFileDiv(fileid), node, nespalfmt);
this.registerAsset("palette", node, false);
this.registerAsset("palette", node, 0);
nassets++;
} else if (typeof data === 'string') {
let textfrags = this.scanFileTextForAssets(fileid, data);
@ -1194,30 +1196,29 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext {
let label = fileid; // TODO: label
let node : pixed.PixNode = new pixed.TextDataNode(projectWindows, fileid, label, frag.start, frag.end);
let first = node;
// rle-compressed? TODO
// rle-compressed? TODO: how to edit?
if (frag.fmt.comp == 'rletag') {
//node = node.addRight(new pixed.Compressor());
continue; // TODO
node = node.addRight(new pixed.Compressor());
}
// is this a nes nametable?
if (frag.fmt.map == 'nesnt') {
node = node.addRight(new pixed.NESNametableConverter(this)); // TODO?
node = node.addRight(new pixed.Palettizer(this, {w:8,h:8,bpp:4})); // TODO?
const fmt = {w:8*32,h:8*30,count:1}; // TODO
node = node.addRight(new pixed.CharmapEditor(this, newDiv(this.ensureFileDiv(fileid)), fmt));
this.registerAsset("nametable", first, true);
node = node.addRight(new pixed.NESNametableConverter(this));
node = node.addRight(new pixed.Palettizer(this, {w:8,h:8,bpp:4}));
const fmt = {w:8*(frag.fmt.w||32),h:8*(frag.fmt.h||30),count:1}; // TODO: can't do custom sizes
node = node.addRight(new pixed.MapEditor(this, newDiv(this.ensureFileDiv(fileid)), fmt));
this.registerAsset("nametable", first, 2);
nassets++;
}
// is this a bitmap?
else if (frag.fmt.w > 0 && frag.fmt.h > 0) {
this.addPixelEditor(this.ensureFileDiv(fileid), node, frag.fmt);
this.registerAsset("charmap", first, true);
this.registerAsset("charmap", first, 1);
nassets++;
}
// is this a palette?
else if (frag.fmt.pal) {
this.addPaletteEditor(this.ensureFileDiv(fileid), node, frag.fmt);
this.registerAsset("palette", first, false);
this.registerAsset("palette", first, 0);
nassets++;
}
else {
@ -1249,7 +1250,14 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext {
}
});
console.log("Found " + this.rootnodes.length + " assets");
this.deferrednodes.forEach((node) => { node.refreshRight(); });
this.deferrednodes.forEach((node) => {
try {
node.refreshRight();
} catch (e) {
console.log(e);
alert(e+"");
}
});
this.deferrednodes = [];
} else {
// only refresh nodes if not actively editing