WIP: Using new page object, frames stored and retrieved in msgbase, code cleanup, more optimisations needed

This commit is contained in:
Deon George 2023-12-24 20:11:40 +11:00
parent 29f82592ac
commit 701dd9f5e8
4 changed files with 104 additions and 159 deletions

View File

@ -40,7 +40,7 @@
+ Character must be set to NULL when it's a control character
= EXAMPLE:
a = new Page('TEX') // root frame 80 x 24 for ANSItex
a = new Page() // root frame 80 x 24 for ANSItex
b = new Window(1,1,40,22,a.content) // b frame 40 x 22 - starting at 1,1
c = new Window(41,1,40,22,a.content) // c frame 40 x 22 - starting at 41,1 (child of a)
d = new Window(1,1,21,10,c) // d frame 20 x 11 - starting at 1,1 of c
@ -109,7 +109,7 @@ require('sbbsdefs.js','SS_USERON'); // Need for our ANSI colors eg: BG_*
* - save - Save the frame to the msgbase
* - load - Load the frame from the msgbase
*/
function Page(service,debug) {
function Page(debug) {
this.__window__ = {
layout: undefined, // Window - Full page content
header: undefined, // Window - Page Title
@ -155,32 +155,28 @@ function Page(service,debug) {
* @param service
* @param debug
*/
function init(service,debug) {
log(LOG_DEBUG,'- PAGE::init(): type ['+service+']');
function init(debug) {
log(LOG_DEBUG,'- PAGE::init(): type ['+SESSION_EXT+']');
this.__window__.layout = new Window(1,1,FRAME_WIDTH,FRAME_HEIGHT+1,'LAYOUT',this,debug);
this.__window__.body = new Window(1,2,FRAME_WIDTH,FRAME_HEIGHT,'CONTENT',this.__window__.layout,debug);
this.__window__.header = new Window(1,1,FRAME_WIDTH,1,'HEADER',this.__window__.layout,debug);
this.__window__.provider = new Window(1,1,FRAME_PROVIDER_LENGTH,1,'PROVIDER',this.__window__.header,debug);
switch (SESSION_EXT) {
case 'tex':
require('ansitex/load/session/ansitex.js','SESSION_ANSITEX');
this.__window__.layout = new Window(1,1,ANSI_FRAME_WIDTH,ANSI_FRAME_HEIGHT+1,'LAYOUT',this,debug);
this.__window__.body = new Window(1,2,ANSI_FRAME_WIDTH,ANSI_FRAME_HEIGHT,'CONTENT',this.__window__.layout,debug);
this.__window__.header = new Window(1,1,ANSI_FRAME_WIDTH,1,'HEADER',this.__window__.layout,debug);
this.__window__.provider = new Window(1,1,ANSI_FRAME_PROVIDER_LENGTH,1,'PROVIDER',this.__window__.header,debug);
this.__window__.pagenum = new Window(57,1,ANSI_FRAME_PAGE_LENGTH,1,'#',this.__window__.header,debug);
this.__window__.cost = new Window(71,1,ANSI_FRAME_COST_LENGTH,1,'$',this.__window__.header,debug);
this.__window__.pagenum = new Window(57,1,FRAME_PAGE_LENGTH,1,'#',this.__window__.header,debug);
this.__window__.cost = new Window(71,1,FRAME_COST_LENGTH,1,'$',this.__window__.header,debug);
break;
case 'vtx':
require('ansitex/load/session/viewdata.js','SESSION_VIEWDATA');
// @todo VTX hasnt been worked on at all - need at last a viewdata2attrs function
this.__window__.layout = new Window(1,1,VIEWDATA_FRAME_WIDTH,VIEWDATA_FRAME_HEIGHT+1,'LAYOUT',this,debug);
this.__window__.body = new Window(1,2,VIEWDATA_FRAME_WIDTH,VIEWDATA_FRAME_HEIGHT,'CONTENT',this.__window__.layout,debug)
this.__window__.header = new Window(1,1,VIEWDATA_FRAME_WIDTH,1,'HEADER',this.__window__.layout,debug);
this.__window__.provider = new Window(1,1,VIEWDATA_FRAME_PROVIDER_LENGTH,1,'PROVIDER',this.__window__.header,debug);
this.__window__.pagenum = new Window(24,1,VIEWDATA_FRAME_PAGE_LENGTH,1,'#',this.__window__.header,debug);
this.__window__.cost = new Window(35,1,VIEWDATA_FRAME_COST_LENGTH,1,'$',this.__window__.header,debug);
this.__window__.pagenum = new Window(24,1,FRAME_PAGE_LENGTH,1,'#',this.__window__.header,debug);
this.__window__.cost = new Window(35,1,FRAME_COST_LENGTH,1,'$',this.__window__.header,debug);
break;
@ -214,27 +210,27 @@ function Page(service,debug) {
}
});
Page.prototype.__defineGetter__('cost',function() {
return Number(this.__properties__.cost);
});
Page.prototype.__defineSetter__('cost',function(int) {
if (typeof int !== 'number')
throw new Error('Cost must be a number');
this.__properties__.cost = int;
if ((''+int).length > FRAME_COST_LENGTH-1-FRAME_ATTR_LENGTH)
throw new Error('Cost too large');
// Populate the cost window
switch (SESSION_EXT) {
case 'tex':
if ((''+int).length > ANSI_FRAME_COST_LENGTH-1-ANSI_FRAME_ATTR_LENGTH)
throw new Error('Cost too large');
this.__window__.cost.__properties__.content = anstoattrs(ESC+'[1;32m'+padright(int,ANSI_FRAME_COST_LENGTH-1-ANSI_FRAME_ATTR_LENGTH,' ')+'c').content;
this.__window__.cost.__properties__.content = rawtoattrs(ESC+'[1;32m'+padright(int,FRAME_COST_LENGTH-1-FRAME_ATTR_LENGTH,' ')+FRAME_COSTUNIT).content;
break;
case 'vtx':
if ((''+int).length > VIEWDATA_FRAME_COST_LENGTH-1-VIEWDATA_FRAME_ATTR_LENGTH)
throw new Error('Cost too large');
this.__window__.cost.__properties__.content = bintoattrs(VIEWDATA_BIN_GREEN+padright(int,VIEWDATA_FRAME_COST_LENGTH-1-VIEWDATA_FRAME_ATTR_LENGTH,' ')+'c').content;
this.__window__.cost.__properties__.content = rawtoattrs(VIEWDATA_BIN_GREEN+padright(int,FRAME_COST_LENGTH-1-FRAME_ATTR_LENGTH,' ')+FRAME_COSTUNIT).content;
break;
@ -242,9 +238,6 @@ function Page(service,debug) {
throw new Error(SESSION_EXT+' type not implemented');
}
});
Page.prototype.__defineGetter__('cost',function() {
return Number(this.__properties__.cost);
});
Page.prototype.__defineGetter__('dimensions',function() {
return this.__properties__.width+' X '+this.__properties__.height;
@ -301,20 +294,17 @@ function Page(service,debug) {
this.__properties__.name = object;
if ((''+this.__properties__.name.frame).length > FRAME_PAGE_LENGTH-1-FRAME_ATTR_LENGTH)
throw new Error('Pagenum too large');
switch (SESSION_EXT) {
case 'tex':
if ((''+this.__properties__.name.frame).length > ANSI_FRAME_PAGE_LENGTH-1-ANSI_FRAME_ATTR_LENGTH)
throw new Error('Pagenum too large');
this.__window__.pagenum.__properties__.content = anstoattrs(ESC+'[1;37m'+this.__properties__.name.toString()).content;
this.__window__.pagenum.__properties__.content = rawtoattrs(ESC+'[1;37m'+this.__properties__.name.toString()).content;
break;
case 'vtx':
if ((''+this.__properties__.name.frame).length > VIEWDATA_FRAME_PAGE_LENGTH-1-VIEWDATA_FRAME_ATTR_LENGTH)
throw new Error('Pagenum too large');
this.__window__.pagenum.__properties__.content = bintoattrs(VIEWDATA_BIN_WHITE+this.__properties__.name.toString()).content;
this.__window__.pagenum.__properties__.content = rawtoattrs(VIEWDATA_BIN_WHITE+this.__properties__.name.toString()).content;
break;
@ -341,17 +331,17 @@ function Page(service,debug) {
switch (SESSION_EXT) {
case 'tex':
provider = anstoattrs(ansi+ESC+'[0m').content;
provider = rawtoattrs(ansi+ESC+'[0m').content;
if (provider[1].filter(function(child) { return child.ch; }).length-1 > ANSI_FRAME_PROVIDER_LENGTH)
if (provider[1].filter(function(child) { return child.ch; }).length-1 > FRAME_PROVIDER_LENGTH)
throw new Error('Provider too large');
break;
case 'vtx':
provider = bintoattrs(ansi).content;
provider = rawtoattrs(ansi).content;
if (provider[1].length-1 > VIEWDATA_FRAME_PROVIDER_LENGTH)
if (provider[1].length-1 > FRAME_PROVIDER_LENGTH)
throw new Error('Provider too large');
break;
@ -472,13 +462,13 @@ function Page(service,debug) {
var attr;
new_screen = BG_BLACK|LIGHTGRAY;
switch (SESSION_EXT) {
case 'tex':
new_screen = BG_BLACK|LIGHTGRAY;
break;
case 'vtx':
new_screen = BG_BLACK|LIGHTGRAY;
new_line = BG_BLACK|LIGHTGRAY;
break;
@ -937,8 +927,10 @@ function Page(service,debug) {
switch (ext) {
// ANSI files
case 'ans':
log(LOG_DEBUG,'Processing ANSI file');
var page = anstoattrs(contents,this.width,this.__window__.body.y,this.__window__.body.x);
// ViewData files
case 'bin':
log(LOG_DEBUG,'Processing ANSI/VIEWDATA file');
var page = rawtoattrs(contents,this.width,this.__window__.body.y,this.__window__.body.x,debug);
this.__window__.body.__properties__.content = page.content;
this.dynamic_fields = page.dynamic_fields;
@ -969,9 +961,9 @@ function Page(service,debug) {
log(LOG_INFO,'- Parsing content');
if (ext === 'tex')
var page = anstoattrs(base64_decode(contents[index]).replace("\x0a\x0d\x0a\x0d","\x0a\x0d"),this.width,this.__window__.body.y,this.__window__.body.x);
var page = rawtoattrs(base64_decode(contents[index]).replace("\x0a\x0d\x0a\x0d","\x0a\x0d"),this.width,this.__window__.body.y,this.__window__.body.x);
else if (ext === 'vtx')
var page = bintoattrs(base64_decode(contents[index]),this.width,this.__window__.body.y,this.__window__.body.x);
var page = rawtoattrs(base64_decode(contents[index]),this.width,this.__window__.body.y,this.__window__.body.x);
this.__window__.body.__properties__.content = page.content;
this.dynamic_fields = page.dynamic_fields;
@ -1022,15 +1014,6 @@ function Page(service,debug) {
this.key = contents[index];
break;
/*
case 'name':
log(LOG_INFO,'- PAGE name : '+JSON.stringify(contents[index]));
this.name.frame = contents[index].frame;
this.name.index = contents[index].index;
break;
*/
case 'type':
this.type = contents[index];
break;
@ -1040,7 +1023,6 @@ function Page(service,debug) {
break;
case 'window':
log(LOG_DEBUG,' - RAW: '+JSON.stringify(contents[index]));
for (var y in contents[index]) {
//log(LOG_DEBUG,' - Y: '+y+', '+JSON.stringify(contents[index][y]));
@ -1058,13 +1040,11 @@ function Page(service,debug) {
);
}
}
log(LOG_DEBUG,' - CONTENT: '+JSON.stringify(this.__window__.body.__properties__.content));
break;
default:
log(LOG_ERROR,'! Frame property not handled: '+index+', value:'+contents[index]);
//this[index] = contents[index];
}
}
@ -1086,30 +1066,6 @@ function Page(service,debug) {
break;
// ViewData files
case 'bin':
log(LOG_DEBUG,'Processing VIEWDATA file');
var page = bintoattrs(contents,this.width,this.__window__.body.y,this.__window__.body.x,debug);
this.__window__.body.__properties__.content = page.content;
this.dynamic_fields = page.dynamic_fields;
// Our fields are sorted in x descending order
this.input_fields = page.input_fields.sort(function(a,b) { return a.x < b.x ? 1 : -1; });
break;
/*
case 'ASC':
case 'MSG':
case 'TXT':
lines = contents.split(/\r*\n/);
while (lines.length > 0)
this.putmsg(lines.shift()+"\r\n");
break;
*/
default:
throw new Error('Unsupported filetype:'+ext);
}
@ -1170,13 +1126,13 @@ function Page(service,debug) {
switch (SESSION_EXT) {
case 'tex':
this.__window__.pagenum.__properties__.content = anstoattrs(ESC+'[1;37m'+this.name.toString()).content;
this.__window__.pagenum.__properties__.content = rawtoattrs(ESC+'[1;37m'+this.name.toString()).content;
this.provider = base64_decode(po.logoans);
break;
case 'vtx':
this.__window__.pagenum.__properties__.content = bintoattrs(VIEWDATA_BIN_WHITE+this.name.toString()).content;
this.__window__.pagenum.__properties__.content = rawtoattrs(VIEWDATA_BIN_WHITE+this.name.toString()).content;
this.provider = base64_decode(po.logovtx);
break;
@ -1250,16 +1206,6 @@ function Page(service,debug) {
content[FRAME_SAVE_ATTRS[index]] = this.key;
break;
/*
case 'name':
content[FRAME_SAVE_ATTRS[index]] = { frame: this.name.frame, index: this.name.index };
break;
case 'owner':
content[FRAME_SAVE_ATTRS[index]] = this.owner;
break;
*/
case 'type':
content[FRAME_SAVE_ATTRS[index]] = this.type;
break;
@ -1301,7 +1247,6 @@ function Page(service,debug) {
log(LOG_DEBUG,'** Save frame with keys'+JSON.stringify(Object.keys(content)));
//ma = new MsgBase(MSG_BASE);
if (! mb.save_msg(
{
subject: this.name.toString(),

View File

@ -105,7 +105,7 @@ function Session() {
throw new Error('page must be a PageObject');
this.baselineSend('LOADING');
this.page = new Page(SESSION_EXT);
this.page = new Page();
this.page.get(page);
this.baselineClear();
}

View File

@ -1,12 +1,12 @@
const SESSION_ANSITEX = (1<<1);
const SESSION_EXT = 'tex';
const SESSION_ANSITEX = (1<<1);
const SESSION_EXT = 'tex';
const ANSI_FRAME_WIDTH = 80;
const ANSI_FRAME_HEIGHT = 22;
const ANSI_FRAME_PROVIDER_LENGTH = 55;
const ANSI_FRAME_PAGE_LENGTH = 13;
const ANSI_FRAME_COST_LENGTH = 10;
const ANSI_FRAME_ATTR_LENGTH = 0; // Space that an attribute takes
const FRAME_WIDTH = 80;
const FRAME_HEIGHT = 22;
const FRAME_PROVIDER_LENGTH = 55;
const FRAME_PAGE_LENGTH = 13;
const FRAME_COST_LENGTH = 10;
const FRAME_ATTR_LENGTH = 0; // Space that an attribute takes
/**
* This function converts ANSI text into an array of attributes
@ -20,7 +20,7 @@ const ANSI_FRAME_ATTR_LENGTH = 0; // Space that an attribute takes
* @param xoffset - fields offset as discovered
* @param debug - Enable debug mode
*/
function anstoattrs(contents,width,yoffset,xoffset,debug) {
function rawtoattrs(contents,width,yoffset,xoffset,debug) {
if (debug)
writeln('DEBUG active: '+debug);

View File

@ -1,59 +1,59 @@
var SESSION_VIEWDATA = (1<<2);
var SESSION_EXT = 'vtx';
const SESSION_VIEWDATA = (1<<2);
const SESSION_EXT = 'vtx';
var VIEWDATA_FRAME_WIDTH = 40;
var VIEWDATA_FRAME_HEIGHT = 22;
var VIEWDATA_FRAME_PROVIDER_LENGTH = 23;
var VIEWDATA_FRAME_PAGE_LENGTH = 11;
var VIEWDATA_FRAME_COST_LENGTH = 6;
const VIEWDATA_FRAME_ATTR_LENGTH = 0; // Space that an attribute takes
const FRAME_WIDTH = 40;
const FRAME_HEIGHT = 22;
const FRAME_PROVIDER_LENGTH = 23;
const FRAME_PAGE_LENGTH = 11;
const FRAME_COST_LENGTH = 6;
const FRAME_ATTR_LENGTH = 0; // Space that an attribute takes
var VIEWDATA_LEFT = '\x08';
var VIEWDATA_RIGHT = '\x09';
var VIEWDATA_DOWN = '\x0a'; // \n
var VIEWDATA_UP = '\x0b';
var VIEWDATA_CLS = '\x0c';
var VIEWDATA_CR = '\x0d'; // \r
var VIEWDATA_CON = '\x11';
var VIEWDATA_COFF = '\x14';
var VIEWDATA_HOME = '\x1e';
const VIEWDATA_LEFT = '\x08';
const VIEWDATA_RIGHT = '\x09';
const VIEWDATA_DOWN = '\x0a'; // \n
const VIEWDATA_UP = '\x0b';
const VIEWDATA_CLS = '\x0c';
const VIEWDATA_CR = '\x0d'; // \r
const VIEWDATA_CON = '\x11';
const VIEWDATA_COFF = '\x14';
const VIEWDATA_HOME = '\x1e';
var VIEWDATA_BLINK = '\x48';
var VIEWDATA_STEADY = '\x49';
var VIEWDATA_NORMAL = '\x4c';
var VIEWDATA_DOUBLE = '\x4d';
var VIEWDATA_CONCEAL = '\x58';
var VIEWDATA_BLOCKS = '\x59';
var VIEWDATA_SEPARATED = '\x5a';
var VIEWDATA_BLACKBACK = '\x5c';
var VIEWDATA_NEWBACK = '\x5d';
var VIEWDATA_HOLD = '\x5e';
var VIEWDATA_REVEAL = '\x5f';
const VIEWDATA_BLINK = '\x48';
const VIEWDATA_STEADY = '\x49';
const VIEWDATA_NORMAL = '\x4c';
const VIEWDATA_DOUBLE = '\x4d';
const VIEWDATA_CONCEAL = '\x58';
const VIEWDATA_BLOCKS = '\x59';
const VIEWDATA_SEPARATED = '\x5a';
const VIEWDATA_BLACKBACK = '\x5c';
const VIEWDATA_NEWBACK = '\x5d';
const VIEWDATA_HOLD = '\x5e';
const VIEWDATA_REVEAL = '\x5f';
var VIEWDATA_RED = '\x41';
var VIEWDATA_GREEN = '\x42';
var VIEWDATA_YELLOW = '\x43'; // C
var VIEWDATA_BLUE = '\x44';
var VIEWDATA_MAGENTA = '\x45';
var VIEWDATA_CYAN = '\x46';
var VIEWDATA_WHITE = '\x47';
const VIEWDATA_RED = '\x41';
const VIEWDATA_GREEN = '\x42';
const VIEWDATA_YELLOW = '\x43'; // C
const VIEWDATA_BLUE = '\x44';
const VIEWDATA_MAGENTA = '\x45';
const VIEWDATA_CYAN = '\x46';
const VIEWDATA_WHITE = '\x47';
var VIEWDATA_MOSIAC_RED = '\x51';
var VIEWDATA_MOSIAC_GREEN = '\x52';
var VIEWDATA_MOSIAC_YELLOW = '\x53';
var VIEWDATA_MOSIAC_BLUE = '\x54';
var VIEWDATA_MOSIAC_MAGENTA = '\x55';
var VIEWDATA_MOSIAC_CYAN = '\x56';
var VIEWDATA_MOSIAC_WHITE = '\x57'; // W
const VIEWDATA_MOSIAC_RED = '\x51';
const VIEWDATA_MOSIAC_GREEN = '\x52';
const VIEWDATA_MOSIAC_YELLOW = '\x53';
const VIEWDATA_MOSIAC_BLUE = '\x54';
const VIEWDATA_MOSIAC_MAGENTA = '\x55';
const VIEWDATA_MOSIAC_CYAN = '\x56';
const VIEWDATA_MOSIAC_WHITE = '\x57'; // W
/* BINARY DUMP LEVEL 1 ATTRIBUTES */
var VIEWDATA_BIN_RED = '\x01';
var VIEWDATA_BIN_GREEN = '\x02';
var VIEWDATA_BIN_YELLOW = '\x03';
var VIEWDATA_BIN_BLUE = '\x04';
var VIEWDATA_BIN_MAGENTA = '\x05';
var VIEWDATA_BIN_CYAN = '\x06';
var VIEWDATA_BIN_WHITE = '\x07';
const VIEWDATA_BIN_RED = '\x01';
const VIEWDATA_BIN_GREEN = '\x02';
const VIEWDATA_BIN_YELLOW = '\x03';
const VIEWDATA_BIN_BLUE = '\x04';
const VIEWDATA_BIN_MAGENTA = '\x05';
const VIEWDATA_BIN_CYAN = '\x06';
const VIEWDATA_BIN_WHITE = '\x07';
/**
* ViewData characters are 7bit (0x00-0x7f)
@ -91,7 +91,7 @@ var VIEWDATA_BIN_WHITE = '\x07';
var MOSIAC = 0x10;
// Toggles
var CONCEAL = 0x20;
var CONCEAL = 0x20;
var REVEAL = 0x2000; // @temp Turns off Conceal
var SEPARATED = 0x40;
@ -103,9 +103,9 @@ var DOUBLE = 0x100;
var NORMAL = 0x1000; // @temp Turns off Double Height
var HOLD = 0x200;
var RELEASE = 0x20000; // @temp turns off Hold
var RELEASE = 0x20000; // @temp turns off Hold
var NEWBACK = 0x400;
var NEWBACK = 0x400;
var BLACKBACK = 0x800;
/**
@ -117,7 +117,7 @@ var BLACKBACK = 0x800;
* @param xoffset - fields offset as discovered
* @param debug - Enable debug mode
*/
function bintoattrs(contents,width,yoffset,xoffset,debug) {
function rawtoattrs(contents,width,yoffset,xoffset,debug) {
if (debug)
writeln('DEBUG active: '+debug);