mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-01-10 16:29:48 +00:00
asmmain.js; fixed disappearing pixel editor bug (?)
This commit is contained in:
parent
b2264d75cf
commit
9108bb5e1c
@ -102,7 +102,6 @@ TODO:
|
||||
- pulldown shows wrong file if preset not present
|
||||
- landscape mode for arcade ports
|
||||
- pixel editor
|
||||
- edit sprites and tiles at same time (multiple views)
|
||||
- persist palette/tilemap selections
|
||||
- more tools for editing
|
||||
- map editor
|
||||
@ -111,7 +110,6 @@ TODO:
|
||||
- capture so we get mouseUp() out of frame
|
||||
- per-View keyboard shortcuts
|
||||
- parse labels
|
||||
- editing too fast refreshes kills the editor, also doesn't update palette
|
||||
- crt0.s compiled each time?
|
||||
- debug highlight doesn't go away when debugging -> running
|
||||
- show breakpoint of PC or highest address on stack
|
||||
|
@ -8,7 +8,7 @@ export type UintArray = number[] | Uint8Array | Uint16Array | Uint32Array; //{[i
|
||||
|
||||
// TODO: separate view/controller
|
||||
export interface EditorContext {
|
||||
setCurrentEditor(div:JQuery, editing:JQuery) : void;
|
||||
setCurrentEditor(div:JQuery, editing:JQuery, node:PixNode) : void;
|
||||
getPalettes(matchlen : number) : SelectablePalette[];
|
||||
getTilemaps(matchlen : number) : SelectableTilemap[];
|
||||
}
|
||||
@ -807,7 +807,7 @@ export class CharmapEditor extends PixNode {
|
||||
chooser.recreate(agrid, (index, viewer) => {
|
||||
var escale = Math.ceil(192 / this.fmt.w);
|
||||
var editview = this.createEditor(aeditor, viewer, escale);
|
||||
this.context.setCurrentEditor(aeditor, $(viewer.canvas));
|
||||
this.context.setCurrentEditor(aeditor, $(viewer.canvas), this);
|
||||
this.rgbimgs[index] = viewer.rgbdata;
|
||||
});
|
||||
// add palette selector
|
||||
|
56
src/views.ts
56
src/views.ts
@ -906,6 +906,7 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext {
|
||||
maindiv : JQuery;
|
||||
cureditordiv : JQuery;
|
||||
cureditelem : JQuery;
|
||||
cureditnode : pixed.PixNode;
|
||||
rootnodes : pixed.PixNode[];
|
||||
deferrednodes : pixed.PixNode[];
|
||||
|
||||
@ -979,8 +980,16 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext {
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
isEditing() {
|
||||
return this.cureditordiv != null;
|
||||
}
|
||||
|
||||
getCurrentEditNode() {
|
||||
return this.cureditnode;
|
||||
}
|
||||
|
||||
setCurrentEditor(div : JQuery, editing : JQuery) {
|
||||
setCurrentEditor(div:JQuery, editing:JQuery, node:pixed.PixNode) {
|
||||
const timeout = 250;
|
||||
if (this.cureditordiv != div) {
|
||||
if (this.cureditordiv) {
|
||||
@ -1002,6 +1011,10 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext {
|
||||
this.cureditelem = editing;
|
||||
this.cureditelem.addClass('selected');
|
||||
}
|
||||
while (node.left) {
|
||||
node = node.left;
|
||||
}
|
||||
this.cureditnode = node;
|
||||
}
|
||||
|
||||
scanFileTextForAssets(id : string, data : string) {
|
||||
@ -1055,6 +1068,7 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext {
|
||||
return result;
|
||||
}
|
||||
|
||||
// TODO: move to pixeleditor.ts?
|
||||
addPaletteEditorViews(parentdiv:JQuery, pal2rgb:pixed.PaletteFormatToRGB, callback) {
|
||||
var adual = $('<div class="asset_dual"/>').appendTo(parentdiv);
|
||||
var aeditor = $('<div class="asset_editor"/>').hide(); // contains editor, when selected
|
||||
@ -1100,7 +1114,7 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext {
|
||||
callback(i, index);
|
||||
updateCell(cell, i);
|
||||
});
|
||||
this.setCurrentEditor(aeditor, cell);
|
||||
this.setCurrentEditor(aeditor, cell, pal2rgb);
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -1139,9 +1153,19 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext {
|
||||
});
|
||||
}
|
||||
|
||||
ensureFileDiv(fileid : string) : JQuery<HTMLElement> {
|
||||
var divid = this.getFileDivId(fileid);
|
||||
var body = $(document.getElementById(divid));
|
||||
if (body.length === 0) {
|
||||
var filediv = newDiv(this.maindiv, 'asset_file');
|
||||
var header = newDiv(filediv, 'asset_file_header').text(fileid);
|
||||
body = newDiv(filediv).attr('id',divid).addClass('disable-select');
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
refreshAssetsInFile(fileid : string, data : FileData) : number {
|
||||
let nassets = 0;
|
||||
let filediv = $('#'+this.getFileDivId(fileid)).empty();
|
||||
// TODO: check fmt w/h/etc limits
|
||||
// TODO: defer editor creation
|
||||
// TODO: only refresh when needed
|
||||
@ -1149,7 +1173,7 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext {
|
||||
// is this a NES CHR?
|
||||
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(filediv, node, neschrfmt);
|
||||
this.addPixelEditor(this.ensureFileDiv(fileid), node, neschrfmt);
|
||||
this.registerAsset("charmap", node, true);
|
||||
nassets++;
|
||||
} else if (typeof data === 'string') {
|
||||
@ -1168,19 +1192,19 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext {
|
||||
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(filediv), fmt));
|
||||
node = node.addRight(new pixed.CharmapEditor(this, newDiv(this.ensureFileDiv(fileid)), fmt));
|
||||
this.registerAsset("nametable", first, true);
|
||||
nassets++;
|
||||
}
|
||||
// is this a bitmap?
|
||||
else if (frag.fmt.w > 0 && frag.fmt.h > 0) {
|
||||
this.addPixelEditor(filediv, node, frag.fmt);
|
||||
this.addPixelEditor(this.ensureFileDiv(fileid), node, frag.fmt);
|
||||
this.registerAsset("charmap", first, true);
|
||||
nassets++;
|
||||
}
|
||||
// is this a palette?
|
||||
else if (frag.fmt.pal) {
|
||||
this.addPaletteEditor(filediv, node, frag.fmt);
|
||||
this.addPaletteEditor(this.ensureFileDiv(fileid), node, frag.fmt);
|
||||
this.registerAsset("palette", first, false);
|
||||
nassets++;
|
||||
}
|
||||
@ -1200,28 +1224,28 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext {
|
||||
// TODO: recreate editors when refreshing
|
||||
// TODO: look for changes, not moveCursor
|
||||
refresh(moveCursor : boolean) {
|
||||
// clear and refresh all files/nodes?
|
||||
if (moveCursor) {
|
||||
this.maindiv.empty();
|
||||
this.clearAssets();
|
||||
current_project.iterateFiles((id, data) => {
|
||||
var divid = this.getFileDivId(id);
|
||||
var filediv = newDiv(this.maindiv, 'asset_file');
|
||||
var header = newDiv(filediv, 'asset_file_header').text(id);
|
||||
var body = newDiv(filediv).attr('id',divid).addClass('disable-select');
|
||||
current_project.iterateFiles((fileid, data) => {
|
||||
try {
|
||||
var nassets = this.refreshAssetsInFile(id, data);
|
||||
if (nassets == 0) filediv.hide();
|
||||
var nassets = this.refreshAssetsInFile(fileid, data);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
filediv.text(e+""); // TODO: error msg?
|
||||
this.ensureFileDiv(fileid).text(e+""); // TODO: error msg?
|
||||
}
|
||||
});
|
||||
console.log("Found " + this.rootnodes.length + " assets");
|
||||
this.deferrednodes.forEach((node) => { node.refreshRight(); });
|
||||
this.deferrednodes = [];
|
||||
} else {
|
||||
// only refresh nodes if not actively editing
|
||||
// since we could be in the middle of an operation that hasn't been committed
|
||||
for (var node of this.rootnodes) {
|
||||
node.refreshRight();
|
||||
if (node !== this.getCurrentEditNode()) {
|
||||
node.refreshRight();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
38
src/worker/asmmain.js
Normal file
38
src/worker/asmmain.js
Normal file
@ -0,0 +1,38 @@
|
||||
|
||||
var asmmod = require('../../gen/worker/assembler');
|
||||
var fs = require('fs');
|
||||
|
||||
var args = process.argv;
|
||||
if (args.length < 3) {
|
||||
console.log("Usage: asmmain config.json [file.asm...]");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// load JSON config
|
||||
var configFilename = args[2];
|
||||
var configFile = fs.readFileSync(configFilename, 'utf8');
|
||||
var configJson = JSON.parse(configFile);
|
||||
|
||||
var binout = [];
|
||||
for (var fi=3; fi<args.length; fi++) {
|
||||
// assemble file
|
||||
var asmFilename = args[fi];
|
||||
var asm = new asmmod.Assembler(configJson);
|
||||
asm.loadInclude = function(fn) { };
|
||||
asm.loadModule = function(fn) { };
|
||||
var asmtext = fs.readFileSync(asmFilename, 'utf8');
|
||||
var out = asm.assembleFile(asmtext);
|
||||
if (out.errors && out.errors.length) {
|
||||
for (var ei=0; ei<out.errors.length; ei++) {
|
||||
var err = out.errors[ei];
|
||||
console.log(asmFilename + "(" + err.line + "): " + err.msg);
|
||||
}
|
||||
process.exit(2);
|
||||
}
|
||||
binout = binout.concat(out.output);
|
||||
}
|
||||
|
||||
// print output
|
||||
for (var i=0; i<binout.length; i++) {
|
||||
console.log(binout[i].toString(16));
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user