Changes to frame object
This commit is contained in:
parent
e30a231fb3
commit
225d17308c
128
load/defs.js
128
load/defs.js
@ -2,63 +2,93 @@
|
||||
* ANSItex definitions
|
||||
*/
|
||||
|
||||
var ACTION_RELOAD =1; /* Reload the current frame */
|
||||
var ACTION_GOTO =2; /* Goto a specific frame */
|
||||
var ACTION_BACKUP =3; /* Goto previous frame */
|
||||
var ACTION_NEXT =4; /* Goto next frame */
|
||||
var ACTION_TERMINATE =6; /* Terminate the session */
|
||||
var ACTION_SUBMITRF =7; /* Submit form contents */
|
||||
var ACTION_STAR =7; /* Star command entry */
|
||||
var ACTION_RELOAD =1; /* Reload the current frame */
|
||||
var ACTION_GOTO =2; /* Goto a specific frame */
|
||||
var ACTION_BACKUP =3; /* Goto previous frame */
|
||||
var ACTION_NEXT =4; /* Goto next frame */
|
||||
var ACTION_TERMINATE =5; /* Terminate the session */
|
||||
var ACTION_SUBMITRF =6; /* Submit form contents */
|
||||
var ACTION_STAR =7; /* Star command entry */
|
||||
|
||||
var MODE_BL =1; /* Typing * command on baseline */
|
||||
var MODE_BL =1; /* Typing * command on baseline */
|
||||
|
||||
var FRAME_LENGTH =22; /* Length of a frame */
|
||||
var FRAME_WIDTH =80; /* Width of a frame */
|
||||
var FRAME_HEADER =56; /* Size of page owner (length) */
|
||||
var FRAME_PAGENUM =12; /* Size of page number (length with a-z) */
|
||||
var FRAME_COST =9; /* Size of cost (length without unit)*/
|
||||
var FRAME_COSTUNIT ='c'; /* Unit of cost */
|
||||
var FRAME_LENGTH =22; /* Length of a frame */
|
||||
var FRAME_WIDTH =80; /* Width of a frame */
|
||||
var FRAME_HEADER =56; /* Size of page owner (length) */
|
||||
var FRAME_PAGENUM =12; /* Size of page number (length with a-z) */
|
||||
var FRAME_COST = 9; /* Size of cost (length without unit) */
|
||||
var FRAME_COSTUNIT ='c'; /* Unit of cost */
|
||||
|
||||
var FRAME_TYPE_INFO ='i';
|
||||
var FRAME_TYPE_TERMINATE ='t';
|
||||
var FRAME_TYPE_EXTERNAL ='x';
|
||||
var FRAME_TYPE_INFO ='i';
|
||||
var FRAME_TYPE_TERMINATE ='t';
|
||||
var FRAME_TYPE_EXTERNAL ='x';
|
||||
var FRAME_TYPE_RESPONSE ='r';
|
||||
var FRAME_TYPE_LOGIN ='l';
|
||||
|
||||
var ERR_NOT_IMPLEMENTED = '\1RNOT IMPLEMENTED YET?';
|
||||
var ERR_ROUTE = '\1n\1h\1WMISTAKE? \1GTRY AGAIN OR TELL US ON *08';
|
||||
var ERR_NOT_IMPLEMENTED ='\1RNOT IMPLEMENTED YET?';
|
||||
var ERR_ROUTE ='\1n\1h\1WMISTAKE? \1GTRY AGAIN OR TELL US ON *08';
|
||||
|
||||
var LOGIN_FRAMES = ['98b'];
|
||||
var NO_HISTORY_FRAMES =['98b'];
|
||||
|
||||
// Our frame object
|
||||
function Frame(frame,index) {
|
||||
if (frame === undefined) {
|
||||
print('ERROR: frame not defined.');
|
||||
exit(1);
|
||||
}
|
||||
function Frame() {
|
||||
this.version=1;
|
||||
this.frame=null;
|
||||
this.index=null;
|
||||
this.owner=''; // @todo
|
||||
this.cost=0; // @todo
|
||||
this.content='';
|
||||
this.isPublic=false; // @todo
|
||||
this.isAccessible=false; // @todo
|
||||
this.type = FRAME_TYPE_INFO;
|
||||
this.key=[ null,null,null,null,null,null,null,null,null,null ];
|
||||
|
||||
this.version=1;
|
||||
this.frame=parseInt(frame);
|
||||
this.index=index ? index : 'a';
|
||||
this.owner=''; // @todo
|
||||
this.cost=0; // @todo
|
||||
this.content='';
|
||||
this.isPublic=false; // @todo
|
||||
this.isAccessible=false; // @todo
|
||||
this.type = FRAME_TYPE_INFO;
|
||||
this.key=[ null,null,null,null,null,null,null,null,null,null ];
|
||||
this.raw=function() {
|
||||
return base64_decode(this.content).replace(/(\r\n|\n|\r)/gm,'');
|
||||
}
|
||||
this.render=function() {
|
||||
owner = base64_decode(this.owner);
|
||||
this.raw=function() {
|
||||
return base64_decode(this.content).replace(/(\r\n|\n|\r)/gm,'');
|
||||
}
|
||||
|
||||
return '\1n'+owner+' '.repeat(FRAME_HEADER-console.strlen(owner))+'\1n '+
|
||||
'\1W\1H'+this.page+' '.repeat(FRAME_PAGENUM-this.page.length)+' '+
|
||||
'\1G\1H'+' '.repeat(FRAME_COST-this.cost.toString().length)+this.cost+FRAME_COSTUNIT+
|
||||
(console.screen_columns > 80 ? '\n\r' : '') +
|
||||
base64_decode(this.content);
|
||||
}
|
||||
this.render=function(withHeader) {
|
||||
owner = base64_decode(this.owner);
|
||||
|
||||
Object.defineProperty(this,'page', {
|
||||
get: function() {return pageStr({frame: this.frame, index: this.index }); }
|
||||
});
|
||||
header = '\n\r';
|
||||
|
||||
if (this.type != FRAME_TYPE_LOGIN)
|
||||
header = '\1n'+owner+' '.repeat(FRAME_HEADER-console.strlen(owner))+'\1n '+
|
||||
'\1W\1H'+this.page+' '.repeat(FRAME_PAGENUM-this.page.length)+' '+
|
||||
'\1G\1H'+' '.repeat(FRAME_COST-this.cost.toString().length)+this.cost+FRAME_COSTUNIT+
|
||||
(console.screen_columns > 80 ? '\n\r' : '');
|
||||
|
||||
return header + base64_decode(this.content);
|
||||
}
|
||||
|
||||
Object.defineProperty(this,'page', {
|
||||
get: function() {
|
||||
if (this.frame == null || this.index == null) return null;
|
||||
return this.frame+this.index;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Load a frame from disk (.tex file)
|
||||
Frame.prototype.load = function(filename) {
|
||||
log(LOG_DEBUG,'Loading frame from: '+filename);
|
||||
|
||||
f = new File(system.mods_dir+'ansitex/text/'+filename+'.tex');
|
||||
if (! f.exists || ! f.open('r')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
load = JSON.parse(f.read());
|
||||
|
||||
for (property in load) {
|
||||
this[property] = load[property];
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
log(LOG_ERROR,'Frame error: '+error);
|
||||
return null;
|
||||
}
|
||||
|
||||
log(LOG_DEBUG,'Loaded frame: ['+this.frame+']['+this.index+'] ('+this.page+')');
|
||||
}
|
@ -41,7 +41,7 @@ if (!String.prototype.repeat) {
|
||||
}
|
||||
|
||||
function cursorOff() {
|
||||
ansiterm.send('ext_mode','clear','cursor');
|
||||
ansi.send('ext_mode','clear','cursor');
|
||||
console.gotoxy(0,24);
|
||||
}
|
||||
|
||||
@ -88,38 +88,6 @@ function getArg(key,error,abort) {
|
||||
}
|
||||
}
|
||||
|
||||
function getFrame(page) {
|
||||
if (! page.index)
|
||||
page.index = 'a';
|
||||
|
||||
// @todo Need to filter out SAUCE
|
||||
f = new File(system.mods_dir+'ansitex/text/'+pageStr(page)+'.tex');
|
||||
if (! f.exists || ! f.open('r')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
frame = JSON.parse(f.read());
|
||||
x = new Frame(0);
|
||||
frame.render = x.render;
|
||||
frame.raw = x.raw;
|
||||
|
||||
// @todo Figure out how to delete this duplicate code
|
||||
Object.defineProperty(frame,'page', {
|
||||
get: function() {return this.frame+this.index}
|
||||
});
|
||||
|
||||
x = null;
|
||||
|
||||
} catch (error) {
|
||||
log(LOG_ERROR,error);
|
||||
return null;
|
||||
}
|
||||
|
||||
log(LOG_DEBUG,'Loaded frame: ['+frame.frame+']['+frame.index+'] ('+frame.page+')');
|
||||
return frame;
|
||||
}
|
||||
|
||||
function loadOptions() {
|
||||
ini = new File(file_cfgname(system.mods_dir,'ansitex/ctrl/videotex.ini'));
|
||||
|
||||
@ -152,6 +120,9 @@ function msgBaseImport(msgbase,page,text) {
|
||||
* Return the frame as a string
|
||||
*/
|
||||
function pageStr(page) {
|
||||
if (page.frame==null)
|
||||
return null;
|
||||
|
||||
if (! page.index)
|
||||
page.index = 'a';
|
||||
|
||||
|
16
main.js
16
main.js
@ -3,7 +3,7 @@ load('sbbsdefs.js');
|
||||
// Load text.dat defintions
|
||||
load('text.js');
|
||||
// Enable to manipulate the ANSI terminal
|
||||
ansiterm = load({},'ansiterm_lib.js');
|
||||
ansi = load({},'ansiterm_lib.js');
|
||||
|
||||
// Ansitex specific includes
|
||||
load('ansitex/load/defs.js');
|
||||
@ -16,7 +16,7 @@ while(bbs.online) {
|
||||
var inkey_timeout = 600000; // Timeout waiting for input @todo required? check if idle timetout occurs
|
||||
var fo = null; // Current Frame
|
||||
var history = []; // Page history
|
||||
ansiterm.send('ext_mode','clear','cursor');
|
||||
ansi.send('ext_mode','clear','cursor');
|
||||
|
||||
while (action != ACTION_TERMINATE) {
|
||||
bbs.nodesync(false); // @todo Stop the display of telegrams
|
||||
@ -189,7 +189,7 @@ while(bbs.online) {
|
||||
|
||||
// @todo If something on the baseline preserve it
|
||||
|
||||
ansiterm.send('ext_mode','set','cursor');
|
||||
ansi.send('ext_mode','set','cursor');
|
||||
sendBaseline('\1N\1G\1H*',true);
|
||||
action = false;
|
||||
mode = MODE_BL;
|
||||
@ -223,8 +223,10 @@ while(bbs.online) {
|
||||
|
||||
if (next_page !== null) {
|
||||
current = fo;
|
||||
fo = getFrame(next_page);
|
||||
if (! fo) {
|
||||
fo = new Frame();
|
||||
fo.load(pageStr(next_page));
|
||||
|
||||
if (fo.page == null) {
|
||||
fo = current;
|
||||
// sendbaseline ERR_PAGE
|
||||
sendBaseline(ERR_ROUTE,false);
|
||||
@ -261,9 +263,9 @@ while(bbs.online) {
|
||||
log(LOG_DEBUG,'- ACTION_GOTO: next_page ['+JSON.stringify(next_page)+'] last history ['+JSON.stringify(history[history.length-1])+']');
|
||||
|
||||
// Record our history
|
||||
if (next_page && (! history.length || (pageStr(history[history.length-1]) != pageStr(next_page)))) {
|
||||
if (next_page && (! history.length || (pageStr(history[history.length-1]) != pageStr(next_page))) && (fo.type != FRAME_TYPE_LOGIN)) {
|
||||
// Ignore the login frames
|
||||
if (LOGIN_FRAMES.indexOf(pageStr(next_page)) == -1) {
|
||||
if (NO_HISTORY_FRAMES.indexOf(pageStr(next_page)) == -1) {
|
||||
history.push(next_page);
|
||||
log(LOG_DEBUG,'- ACTION_GOTO: Added to history ['+(next_page ? pageStr(next_page) : '')+'] now ['+history.length+']');
|
||||
}
|
||||
|
9
save.js
9
save.js
@ -18,11 +18,14 @@ i = getArg('-i','No index specified with -i',true);
|
||||
// File to convert
|
||||
file = getArg('-f','No file specified with -f',false);
|
||||
|
||||
frame = getFrame({frame: p,index: i});
|
||||
frame = new Frame();
|
||||
frame.load(pageStr({frame: p,index: i}));
|
||||
|
||||
if (! send || ! frame || file) {
|
||||
if (! frame) {
|
||||
frame = new Frame(p,i);
|
||||
if (frame.page == null) {
|
||||
frame = new Frame();
|
||||
frame.frame = p;
|
||||
frame.index = i;
|
||||
}
|
||||
|
||||
// Key
|
||||
|
Loading…
Reference in New Issue
Block a user